-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 회원가입 api 개발 #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "feat/#28-\uD68C\uC6D0\uAC00\uC785-api"
Changes from all commits
c0686c2
dad6d07
792b17c
4d9dfa9
f495e32
72d55d1
b1f9372
2d325bf
a61d2a4
fc5d27f
4c86408
41a9346
bad9a59
05ac77f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,26 @@ | ||
| package konkuk.thip.user.adapter.in.web; | ||
|
|
||
| import konkuk.thip.common.dto.BaseResponse; | ||
| import konkuk.thip.user.adapter.in.web.request.UserSignupRequest; | ||
| import konkuk.thip.user.adapter.in.web.response.UserSignupResponse; | ||
| import konkuk.thip.user.application.port.in.UserSignupUseCase; | ||
| import konkuk.thip.user.application.port.in.dto.UserSignupCommand; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.validation.annotation.Validated; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class UserCommandController { | ||
|
|
||
| private final UserSignupUseCase userSignupUseCase; | ||
|
|
||
| @PostMapping("/users/signup") | ||
| public BaseResponse<UserSignupResponse> signup(@Validated @RequestBody UserSignupRequest request) { | ||
| return BaseResponse.ok(UserSignupResponse.of( | ||
| userSignupUseCase.signup(request.toCommand())) | ||
| ); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,28 @@ | ||
| package konkuk.thip.user.adapter.in.web.request; | ||
|
|
||
| import lombok.Getter; | ||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
| import konkuk.thip.user.application.port.in.dto.UserSignupCommand; | ||
| import org.hibernate.validator.constraints.Length; | ||
|
|
||
| @Getter | ||
| public class UserSignupRequest { | ||
| public record UserSignupRequest( | ||
| @NotNull(message = "aliasId는 필수입니다.") | ||
| Long aliasId, | ||
|
|
||
| @NotBlank(message = "닉네임은 공백일 수 없습니다.") | ||
| @Length(max = 10, message = "닉네임은 최대 10자 입니다.") | ||
| String nickname, | ||
|
|
||
| @NotBlank(message = "이메일은 공백일 수 없습니다.") | ||
| @Email(message = "이메일 형식이 올바르지 않습니다.") | ||
| String email | ||
| ) { | ||
| public UserSignupCommand toCommand() { | ||
| return UserSignupCommand.builder() | ||
| .aliasId(aliasId) | ||
| .nickname(nickname) | ||
| .email(email) | ||
| .build(); | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package konkuk.thip.user.adapter.in.web.response; | ||
|
|
||
| public record UserSignupResponse(Long userId) { | ||
| public static UserSignupResponse of(Long userId) { | ||
| return new UserSignupResponse(userId); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,12 @@ public class AliasJpaEntity extends BaseJpaEntity { | |
| @Column(name = "alias_id") | ||
| private Long aliasId; | ||
|
|
||
| @Column(name = "alias_value",length = 50, nullable = false) | ||
| @Column(name = "alias_value", length = 50, nullable = false) | ||
| private String value; | ||
|
|
||
| @Column(name = "image_url", columnDefinition = "TEXT", nullable = false) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻👍🏻 |
||
| private String imageUrl; | ||
|
|
||
| @Column(name = "alias_color", length = 10, nullable = false) | ||
| private String color; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package konkuk.thip.user.adapter.out.persistence; | ||
|
|
||
| import konkuk.thip.common.exception.EntityNotFoundException; | ||
| import konkuk.thip.user.adapter.out.jpa.AliasJpaEntity; | ||
| import konkuk.thip.user.adapter.out.mapper.AliasMapper; | ||
| import konkuk.thip.user.application.port.out.AliasCommandPort; | ||
| import konkuk.thip.user.domain.Alias; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import static konkuk.thip.common.exception.code.ErrorCode.ALIAS_NOT_FOUND; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class AliasCommandPersistenceAdapter implements AliasCommandPort { | ||
|
|
||
| private final AliasMapper aliasMapper; | ||
| private final AliasJpaRepository aliasJpaRepository; | ||
|
|
||
| @Override | ||
| public Alias findById(Long aliasId) { | ||
| AliasJpaEntity aliasJpaEntity = aliasJpaRepository.findById(aliasId).orElseThrow( | ||
| () -> new EntityNotFoundException(ALIAS_NOT_FOUND)); | ||
|
|
||
| return aliasMapper.toDomainEntity(aliasJpaEntity); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,31 @@ | ||
| package konkuk.thip.user.adapter.out.persistence; | ||
|
|
||
| import konkuk.thip.common.exception.EntityNotFoundException; | ||
| import konkuk.thip.user.adapter.out.jpa.AliasJpaEntity; | ||
| import konkuk.thip.user.adapter.out.jpa.UserJpaEntity; | ||
| import konkuk.thip.user.adapter.out.mapper.UserMapper; | ||
| import konkuk.thip.user.application.port.out.UserCommandPort; | ||
| import konkuk.thip.user.domain.User; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import static konkuk.thip.common.exception.code.ErrorCode.ALIAS_NOT_FOUND; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class UserCommandPersistenceAdapter implements UserCommandPort { | ||
|
|
||
| private final UserJpaRepository jpaRepository; | ||
| private final UserJpaRepository userJpaRepository; | ||
| private final AliasJpaRepository aliasJpaRepository; | ||
|
|
||
| private final UserMapper userMapper; | ||
|
|
||
| @Override | ||
| public Long save(User user) { | ||
| AliasJpaEntity aliasJpaEntity = aliasJpaRepository.findById(user.getAliasId()).orElseThrow( | ||
| () -> new EntityNotFoundException(ALIAS_NOT_FOUND)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻👍🏻 |
||
|
|
||
| UserJpaEntity userJpaEntity = userMapper.toJpaEntity(user, aliasJpaEntity); | ||
| return userJpaRepository.save(userJpaEntity).getUserId(); | ||
| } | ||
|
Comment on lines
+23
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 : 음 저는 여기서 id를 반환하지 않고 User 엔티티 자체를 반환한 후 컨트롤러 핸들러 안의 response dto의 매개변수로 User 엔티티 자체를 넣어서 그 안에서 파싱되도록 하는 것이 더 캡슐화가 잘 지켜지는 것 아닐까 싶은데 다른 분들은 어떻게 생각하시나욥
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 음 저는 User 도메인은 application 패키지를 벗어나지 않는게 좋다고 생각합니다! |
||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package konkuk.thip.user.application.port.in; | ||
|
|
||
| import konkuk.thip.user.application.port.in.dto.UserSignupCommand; | ||
|
|
||
| public interface UserSignupUseCase { | ||
|
|
||
| Long signup(UserSignupCommand command); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package konkuk.thip.user.application.port.in.dto; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record UserSignupCommand( | ||
| Long aliasId, | ||
| String nickname, | ||
| String email | ||
| ) {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package konkuk.thip.user.application.port.out; | ||
|
|
||
| import konkuk.thip.user.domain.Alias; | ||
|
|
||
| public interface AliasCommandPort { | ||
|
|
||
| Alias findById(Long aliasId); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| package konkuk.thip.user.application.port.out; | ||
|
|
||
| import konkuk.thip.user.domain.User; | ||
|
|
||
| public interface UserCommandPort { | ||
|
|
||
| Long save(User user); | ||
|
|
||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package konkuk.thip.user.application.service; | ||
|
|
||
| import konkuk.thip.user.application.port.in.UserSignupUseCase; | ||
| import konkuk.thip.user.application.port.in.dto.UserSignupCommand; | ||
| import konkuk.thip.user.application.port.out.AliasCommandPort; | ||
| import konkuk.thip.user.application.port.out.UserCommandPort; | ||
| import konkuk.thip.user.domain.Alias; | ||
| import konkuk.thip.user.domain.User; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import static konkuk.thip.user.adapter.out.jpa.UserRole.USER; | ||
|
|
||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class UserSignupService implements UserSignupUseCase { | ||
|
|
||
| private final UserCommandPort userCommandPort; | ||
| private final AliasCommandPort aliasCommandPort; | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public Long signup(UserSignupCommand command) { | ||
| Alias alias = aliasCommandPort.findById(command.aliasId()); | ||
| User user = User.withoutId( | ||
| command.email(), command.nickname(), alias.getImageUrl(), USER.getType(), alias.getId() | ||
| ); | ||
|
|
||
| return userCommandPort.save(user); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 이거 잘못되어 있었네요,, 수정 감사합니다 ~