-
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 : update RegisterMember API logic
- Modified RegisterMember API to accommodate the separation of member and account entities. - Updated data handling and validation processes to align with the new structure. - Made minimal changes to the login API to ensure basic functionality; further logic improvements are needed.
- Loading branch information
1 parent
7485a23
commit 684baa4
Showing
33 changed files
with
386 additions
and
192 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/com/titi/titi_auth/adapter/out/persistence/SaveAccountPortAdapter.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,28 @@ | ||
package com.titi.titi_auth.adapter.out.persistence; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.titi.titi_auth.application.port.out.persistence.SaveAccountPort; | ||
import com.titi.titi_auth.data.jpa.entity.AccountEntity; | ||
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 SaveAccountPortAdapter implements SaveAccountPort { | ||
|
||
private final AccountEntityRepository accountEntityRepository; | ||
|
||
@Override | ||
public Account invoke(Account account) { | ||
if (account.id() != null) { | ||
throw new IllegalArgumentException("account.id() must be null."); | ||
} | ||
final AccountEntity accountEntity = accountEntityRepository.save(EntityMapper.INSTANCE.toEntity(account)); | ||
return EntityMapper.INSTANCE.toDomain(accountEntity); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/titi/titi_auth/application/port/in/CreateAccountUseCase.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,24 @@ | ||
package com.titi.titi_auth.application.port.in; | ||
|
||
import lombok.Builder; | ||
|
||
public interface CreateAccountUseCase { | ||
|
||
Result invoke(Command command); | ||
|
||
@Builder | ||
record Command( | ||
String username, | ||
String encodedEncryptedPassword | ||
) { | ||
|
||
} | ||
|
||
@Builder | ||
record Result( | ||
Long accountId | ||
) { | ||
|
||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/titi/titi_auth/application/port/out/persistence/SaveAccountPort.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,9 @@ | ||
package com.titi.titi_auth.application.port.out.persistence; | ||
|
||
import com.titi.titi_auth.domain.Account; | ||
|
||
public interface SaveAccountPort { | ||
|
||
Account invoke(Account account); | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/titi/titi_auth/application/service/CreateAccountService.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,59 @@ | ||
package com.titi.titi_auth.application.service; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.titi.titi_auth.application.port.in.CreateAccountUseCase; | ||
import com.titi.titi_auth.application.port.out.persistence.FindAccountPort; | ||
import com.titi.titi_auth.application.port.out.persistence.SaveAccountPort; | ||
import com.titi.titi_auth.common.TiTiAuthBusinessCodes; | ||
import com.titi.titi_auth.common.TiTiAuthException; | ||
import com.titi.titi_auth.domain.Account; | ||
import com.titi.titi_auth.domain.AccountStatus; | ||
import com.titi.titi_auth.domain.Authority; | ||
import com.titi.titi_auth.domain.EncodedEncryptedPassword; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CreateAccountService implements CreateAccountUseCase { | ||
|
||
private final PasswordEncoder passwordEncoder; | ||
private final FindAccountPort findAccountPort; | ||
private final SaveAccountPort saveAccountPort; | ||
@Value("${crypto.secret-key}") | ||
private String secretKey; | ||
|
||
@Override | ||
public Result invoke(Command command) { | ||
this.validateUsername(command.username()); | ||
final String rawPassword = EncodedEncryptedPassword.builder() | ||
.value(command.encodedEncryptedPassword()) | ||
.build() | ||
.getRawPassword(this.secretKey.getBytes(StandardCharsets.UTF_8)); | ||
final String encodedEncryptedPassword = this.passwordEncoder.encode(rawPassword); | ||
final Account account = this.saveAccountPort.invoke( | ||
Account.builder() | ||
.username(command.username()) | ||
.encodedEncryptedPassword(encodedEncryptedPassword) | ||
.accountStatus(AccountStatus.ACTIVATED) | ||
.authority(Authority.MEMBER) | ||
.build() | ||
); | ||
return Result.builder() | ||
.accountId(account.id()) | ||
.build(); | ||
} | ||
|
||
private void validateUsername(String username) { | ||
final Account account = Account.builder().username(username).build(); | ||
if (this.findAccountPort.invoke(account).isPresent()) { | ||
throw new TiTiAuthException(TiTiAuthBusinessCodes.UNAVAILABLE_USERNAME); | ||
} | ||
} | ||
|
||
} |
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
2 changes: 1 addition & 1 deletion
2
...main/member/EncodedEncryptedPassword.java → ...auth/domain/EncodedEncryptedPassword.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
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/titi/titi_user/adapter/out/auth/CreateAccountPortAdapter.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,36 @@ | ||
package com.titi.titi_user.adapter.out.auth; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.titi.exception.TiTiException; | ||
import com.titi.titi_auth.application.port.in.CreateAccountUseCase; | ||
import com.titi.titi_user.application.port.out.auth.CreateAccountPort; | ||
import com.titi.titi_user.common.TiTiUserBusinessCodes; | ||
import com.titi.titi_user.common.TiTiUserException; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class CreateAccountPortAdapter implements CreateAccountPort { | ||
|
||
private final CreateAccountUseCase createAccountUseCase; | ||
|
||
@Override | ||
public Result invoke(Command command) { | ||
try { | ||
final CreateAccountUseCase.Result createAccountResult = this.createAccountUseCase.invoke( | ||
CreateAccountUseCase.Command.builder() | ||
.username(command.username()) | ||
.encodedEncryptedPassword(command.encodedEncryptedPassword()) | ||
.build() | ||
); | ||
return Result.builder() | ||
.accountId(createAccountResult.accountId()) | ||
.build(); | ||
} catch (TiTiException e) { | ||
throw new TiTiUserException(TiTiUserBusinessCodes.UNAVAILABLE_USERNAME); | ||
} | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
...ernal/GenerateAccessTokenPortAdapter.java → .../auth/GenerateAccessTokenPortAdapter.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
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/titi/titi_user/application/port/out/auth/CreateAccountPort.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,24 @@ | ||
package com.titi.titi_user.application.port.out.auth; | ||
|
||
import lombok.Builder; | ||
|
||
public interface CreateAccountPort { | ||
|
||
Result invoke(Command command); | ||
|
||
@Builder | ||
record Command( | ||
String username, | ||
String encodedEncryptedPassword | ||
) { | ||
|
||
} | ||
|
||
@Builder | ||
record Result( | ||
Long accountId | ||
) { | ||
|
||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...out/internal/GenerateAccessTokenPort.java → ...ort/out/auth/GenerateAccessTokenPort.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
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
Oops, something went wrong.