-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
107 additions
and
87 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/com/listywave/auth/dev/domain/DevAccount.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.listywave.auth.dev.domain; | ||
|
||
import static jakarta.persistence.FetchType.LAZY; | ||
|
||
import com.listywave.user.application.domain.User; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.MapsId; | ||
import jakarta.persistence.OneToOne; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class DevAccount { | ||
|
||
@Id | ||
@Column(name = "user_id", nullable = false, unique = true) | ||
private Long id; | ||
|
||
@MapsId | ||
@OneToOne(fetch = LAZY) | ||
@JoinColumn(name = "user_id", nullable = false, unique = true) | ||
private User user; | ||
|
||
@Column(nullable = false, unique = true) | ||
private String account; | ||
|
||
@Column(nullable = false) | ||
private String password; | ||
|
||
public void validatePassword(String password) { | ||
if (this.password.equals(password)) { | ||
return; | ||
} | ||
throw new IllegalArgumentException("비밀번호가 틀렸습니다."); | ||
} | ||
|
||
public Long getUserId() { | ||
return user.getId(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/listywave/auth/dev/presentation/DevAuthController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.listywave.auth.dev.presentation; | ||
|
||
import com.listywave.auth.application.domain.JwtManager; | ||
import com.listywave.auth.application.dto.LoginResponse; | ||
import com.listywave.auth.dev.domain.DevAccount; | ||
import com.listywave.auth.dev.repository.DevAccountRepository; | ||
import com.listywave.user.application.domain.User; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@Profile("!prod") | ||
@RequiredArgsConstructor | ||
public class DevAuthController { | ||
|
||
private final JwtManager jwtManager; | ||
private final DevAccountRepository devAccountRepository; | ||
|
||
@PostMapping("/login/local") | ||
ResponseEntity<LoginResponse> localLogin(@RequestBody LocalLoginRequest request) { | ||
String account = request.account(); | ||
String password = request.password(); | ||
|
||
Optional<DevAccount> optional = devAccountRepository.findByAccount(account); | ||
DevAccount devAccount = optional.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 계정입니다.")); | ||
|
||
devAccount.validatePassword(password); | ||
User user = devAccount.getUser(); | ||
String accessToken = jwtManager.createAccessToken(user.getId()); | ||
String refreshToken = jwtManager.createRefreshToken(user.getId()); | ||
LoginResponse response = LoginResponse.of(user, accessToken, refreshToken, false); | ||
return ResponseEntity.ok(response); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/listywave/auth/dev/presentation/LocalLoginRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.listywave.auth.dev.presentation; | ||
|
||
public record LocalLoginRequest( | ||
String account, | ||
String password | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/listywave/auth/dev/repository/DevAccountRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.listywave.auth.dev.repository; | ||
|
||
import com.listywave.auth.dev.domain.DevAccount; | ||
import java.util.Optional; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
@Profile("!prod") | ||
public interface DevAccountRepository extends JpaRepository<DevAccount, Long> { | ||
|
||
Optional<DevAccount> findByAccount(String account); | ||
} |
85 changes: 0 additions & 85 deletions
85
src/main/java/com/listywave/auth/presentation/LocalAuthController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters