-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #77 : migrate checkUsernameAPI's module
- Moved checkUsernameAPI logic and tests from user domain to auth domain. - Updated endpoint.
- Loading branch information
1 parent
8418b72
commit 3407379
Showing
20 changed files
with
417 additions
and
55 deletions.
There are no files selected for viewing
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/titi/titi_auth/adapter/out/persistence/FindAccountPortAdapter.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,26 @@ | ||
package com.titi.titi_auth.adapter.out.persistence; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.titi.titi_auth.application.port.out.persistence.FindAccountPort; | ||
import com.titi.titi_auth.data.jpa.entity.mapper.EntityMapper; | ||
import com.titi.titi_auth.data.jpa.repository.AccountEntityRepository; | ||
import com.titi.titi_auth.domain.Account; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class FindAccountPortAdapter implements FindAccountPort { | ||
|
||
private final AccountEntityRepository accountEntityRepository; | ||
|
||
@Override | ||
public Optional<Account> invoke(Account account) { | ||
return this.accountEntityRepository.findByEntity(EntityMapper.INSTANCE.toEntity(account)) | ||
.map(EntityMapper.INSTANCE::toDomain); | ||
} | ||
|
||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/titi/titi_auth/application/port/out/persistence/FindAccountPort.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,11 @@ | ||
package com.titi.titi_auth.application.port.out.persistence; | ||
|
||
import java.util.Optional; | ||
|
||
import com.titi.titi_auth.domain.Account; | ||
|
||
public interface FindAccountPort { | ||
|
||
Optional<Account> invoke(Account account); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/titi/titi_auth/application/service/CheckUsernameService.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,25 @@ | ||
package com.titi.titi_auth.application.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.titi.titi_auth.application.port.in.CheckUsernameUseCase; | ||
import com.titi.titi_auth.application.port.out.persistence.FindAccountPort; | ||
import com.titi.titi_auth.domain.Account; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CheckUsernameService implements CheckUsernameUseCase { | ||
|
||
private final FindAccountPort findAccountPort; | ||
|
||
@Override | ||
public Result invoke(Command command) { | ||
final Account account = Account.builder().username(command.username()).build(); | ||
return CheckUsernameUseCase.Result.builder() | ||
.isPresent(this.findAccountPort.invoke(account).isPresent()) | ||
.build(); | ||
} | ||
|
||
} |
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
45 changes: 45 additions & 0 deletions
45
src/main/java/com/titi/titi_auth/data/jpa/entity/AccountEntity.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,45 @@ | ||
package com.titi.titi_auth.data.jpa.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import com.titi.infrastructure.persistence.jpa.entity.BaseEntity; | ||
import com.titi.titi_auth.domain.AccountStatus; | ||
import com.titi.titi_auth.domain.Authority; | ||
|
||
@Entity(name = "accounts") | ||
@Getter | ||
@Builder(toBuilder = true) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class AccountEntity extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String username; | ||
|
||
@Column(nullable = false) | ||
private String password; | ||
|
||
@Enumerated(value = EnumType.STRING) | ||
@Column(nullable = false) | ||
private Authority authority; | ||
|
||
@Enumerated(value = EnumType.STRING) | ||
@Column(nullable = false) | ||
private AccountStatus accountStatus; | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/titi/titi_auth/data/jpa/entity/mapper/EntityMapper.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,18 @@ | ||
package com.titi.titi_auth.data.jpa.entity.mapper; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
import com.titi.titi_auth.data.jpa.entity.AccountEntity; | ||
import com.titi.titi_auth.domain.Account; | ||
|
||
@Mapper | ||
public interface EntityMapper { | ||
|
||
EntityMapper INSTANCE = Mappers.getMapper(EntityMapper.class); | ||
|
||
AccountEntity toEntity(Account account); | ||
|
||
Account toDomain(AccountEntity accountEntity); | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/titi/titi_auth/data/jpa/repository/AccountEntityRepository.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,10 @@ | ||
package com.titi.titi_auth.data.jpa.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.titi.titi_auth.data.jpa.entity.AccountEntity; | ||
import com.titi.titi_auth.data.jpa.repository.querydsl.AccountEntityQuerydsl; | ||
|
||
public interface AccountEntityRepository extends JpaRepository<AccountEntity, Long>, AccountEntityQuerydsl { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/titi/titi_auth/data/jpa/repository/querydsl/AccountEntityQuerydsl.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,11 @@ | ||
package com.titi.titi_auth.data.jpa.repository.querydsl; | ||
|
||
import java.util.Optional; | ||
|
||
import com.titi.titi_auth.data.jpa.entity.AccountEntity; | ||
|
||
public interface AccountEntityQuerydsl { | ||
|
||
Optional<AccountEntity> findByEntity(AccountEntity accountEntity); | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
src/main/java/com/titi/titi_auth/data/jpa/repository/querydsl/AccountEntityQuerydslImpl.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,52 @@ | ||
package com.titi.titi_auth.data.jpa.repository.querydsl; | ||
|
||
import static com.titi.titi_auth.data.jpa.entity.QAccountEntity.*; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.titi.titi_auth.data.jpa.entity.AccountEntity; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class AccountEntityQuerydslImpl implements AccountEntityQuerydsl { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public Optional<AccountEntity> findByEntity(AccountEntity entity) { | ||
return Optional.ofNullable( | ||
jpaQueryFactory | ||
.selectFrom(accountEntity) | ||
.where( | ||
idEq(entity), | ||
usernameEq(entity), | ||
authorityEq(entity), | ||
accountStatusEq(entity) | ||
) | ||
.fetchOne() | ||
); | ||
} | ||
|
||
private BooleanExpression idEq(AccountEntity entity) { | ||
return entity.getId() != null ? accountEntity.id.eq(entity.getId()) : null; | ||
} | ||
|
||
private BooleanExpression usernameEq(AccountEntity entity) { | ||
return entity.getUsername() != null ? accountEntity.username.eq(entity.getUsername()) : null; | ||
} | ||
|
||
private BooleanExpression authorityEq(AccountEntity entity) { | ||
return entity.getAuthority() != null ? accountEntity.authority.eq(entity.getAuthority()) : null; | ||
} | ||
|
||
private BooleanExpression accountStatusEq(AccountEntity entity) { | ||
return entity.getAccountStatus() != null ? accountEntity.accountStatus.eq(entity.getAccountStatus()) : null; | ||
} | ||
|
||
} |
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,14 @@ | ||
package com.titi.titi_auth.domain; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record Account( | ||
Long id, | ||
String username, | ||
String password, | ||
Authority authority, | ||
AccountStatus accountStatus | ||
) { | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/titi/titi_auth/domain/AccountStatus.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,33 @@ | ||
package com.titi.titi_auth.domain; | ||
|
||
public enum AccountStatus { | ||
/** | ||
* The account is in a normal and usable state. <br/> | ||
* The account owner can log in and access the application. | ||
*/ | ||
ACTIVATED, | ||
/** | ||
* An account exists but is in an unusable state. <br/> | ||
* This could be a temporary condition, or it might occur when the account owner deactivates the account without deleting it. <br/> | ||
* Inactive accounts are typically eligible for reactivation. | ||
*/ | ||
DEACTIVATED, | ||
/** | ||
* The account is temporarily suspended. <br/> | ||
* This can occur due to security issues, payment problems, or transitions to a dormant state. <br/> | ||
* In this state, the account owner cannot access the application. | ||
*/ | ||
SUSPENDED, | ||
/** | ||
* The account is permanently suspended. <br/> | ||
* This can occur due to violations of the terms of service, among other reasons. <br/> | ||
* In this state, the account owner cannot access the application. | ||
*/ | ||
BLOCKED, | ||
/** | ||
* The account has been permanently deleted. <br/> | ||
* This typically occurs when the account owner initiates the deletion or when an administrator removes the account. <br/> | ||
* Deleted accounts cannot be reactivated. | ||
*/ | ||
DELETED | ||
} |
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,5 @@ | ||
package com.titi.titi_auth.domain; | ||
|
||
public enum Authority { | ||
MEMBER, ADMIN | ||
} |
25 changes: 0 additions & 25 deletions
25
src/main/java/com/titi/titi_user/application/service/CheckUsernameService.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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.titi.titi_user.adapter.in.web.api; | ||
package com.titi.titi_auth.adapter.in.web.api; | ||
|
||
import static org.mockito.ArgumentMatchers.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
@@ -19,8 +19,8 @@ | |
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.ResultActions; | ||
|
||
import com.titi.titi_user.application.port.in.CheckUsernameUseCase; | ||
import com.titi.titi_user.common.TiTiUserBusinessCodes; | ||
import com.titi.titi_auth.application.port.in.CheckUsernameUseCase; | ||
import com.titi.titi_auth.common.TiTiAuthBusinessCodes; | ||
|
||
@WebMvcTest(controllers = CheckUsernameController.class) | ||
class CheckUsernameControllerTest { | ||
|
@@ -33,13 +33,13 @@ class CheckUsernameControllerTest { | |
|
||
private static Stream<Arguments> whenSuccessToCheckUsername() { | ||
return Stream.of( | ||
Arguments.of(false, TiTiUserBusinessCodes.DOES_NOT_EXIST_USERNAME), | ||
Arguments.of(true, TiTiUserBusinessCodes.ALREADY_EXISTS_USERNAME) | ||
Arguments.of(false, TiTiAuthBusinessCodes.DOES_NOT_EXIST_USERNAME), | ||
Arguments.of(true, TiTiAuthBusinessCodes.ALREADY_EXISTS_USERNAME) | ||
); | ||
} | ||
|
||
private ResultActions mockCheckUsername(String username) throws Exception { | ||
return mockMvc.perform(get("/api/user/members/check") | ||
return mockMvc.perform(get("/api/auth/members/check") | ||
.queryParam("username", username) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.with(csrf())); | ||
|
@@ -48,7 +48,7 @@ private ResultActions mockCheckUsername(String username) throws Exception { | |
@ParameterizedTest | ||
@MethodSource | ||
@WithMockUser | ||
void whenSuccessToCheckUsername(boolean isPresent, TiTiUserBusinessCodes businessCodes) throws Exception { | ||
void whenSuccessToCheckUsername(boolean isPresent, TiTiAuthBusinessCodes businessCodes) throws Exception { | ||
// given | ||
given(checkUsernameUseCase.invoke(any())).willReturn(CheckUsernameUseCase.Result.builder().isPresent(isPresent).build()); | ||
final String username = "[email protected]"; | ||
|
Oops, something went wrong.