diff --git a/src/main/java/treehouse/server/api/invitation/implement/InvitationQueryAdapter.java b/src/main/java/treehouse/server/api/invitation/implement/InvitationQueryAdapter.java index 3996821..f6c4d64 100644 --- a/src/main/java/treehouse/server/api/invitation/implement/InvitationQueryAdapter.java +++ b/src/main/java/treehouse/server/api/invitation/implement/InvitationQueryAdapter.java @@ -43,4 +43,8 @@ public Invitation findByReceiverAndTreeHouse(User user, TreeHouse treeHouse) { return invitationRepository.findByReceiverAndTreeHouse(user, treeHouse) .orElseThrow(() -> new InvitationException(GlobalErrorCode.INVITATION_NOT_FOUND)); } + + public Invitation findByPhoneAndTreeHouse(String phone, TreeHouse treeHouse) { + return invitationRepository.findByPhoneAndTreeHouse(phone, treeHouse); + } } diff --git a/src/main/java/treehouse/server/api/invitation/persistence/InvitationRepository.java b/src/main/java/treehouse/server/api/invitation/persistence/InvitationRepository.java index 83d5129..0a81e23 100644 --- a/src/main/java/treehouse/server/api/invitation/persistence/InvitationRepository.java +++ b/src/main/java/treehouse/server/api/invitation/persistence/InvitationRepository.java @@ -16,7 +16,7 @@ public interface InvitationRepository extends JpaRepository { Boolean existsByPhone(String phoneNumber); - Boolean existsByPhoneAndTreeHouse(String phoneNumber, TreeHouse treehouse); + Boolean existsByPhoneAndTreeHouse(String phone, TreeHouse treehouse); Optional findByReceiverAndTreeHouse(User user, TreeHouse treeHouse); } diff --git a/src/main/java/treehouse/server/api/member/presentation/MemberApi.java b/src/main/java/treehouse/server/api/member/presentation/MemberApi.java index e64af99..ead577e 100644 --- a/src/main/java/treehouse/server/api/member/presentation/MemberApi.java +++ b/src/main/java/treehouse/server/api/member/presentation/MemberApi.java @@ -3,6 +3,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.annotation.Validated; @@ -29,7 +30,7 @@ public class MemberApi { @PostMapping("/members/register") @Operation(summary = "트리하우스 회원가입 🔑 ✅", description = "트리하우스 멤버로 가입합니다.") public CommonResponse registerTreehouseMember( - @RequestBody final MemberRequestDTO.registerMember request, + @RequestBody @Valid final MemberRequestDTO.registerMember request, @AuthMember @Parameter(hidden = true) User user ) { return CommonResponse.onSuccess(memberService.register(user, request)); diff --git a/src/main/java/treehouse/server/api/member/presentation/dto/MemberRequestDTO.java b/src/main/java/treehouse/server/api/member/presentation/dto/MemberRequestDTO.java index 46c7cc2..3dd69b4 100644 --- a/src/main/java/treehouse/server/api/member/presentation/dto/MemberRequestDTO.java +++ b/src/main/java/treehouse/server/api/member/presentation/dto/MemberRequestDTO.java @@ -1,15 +1,24 @@ package treehouse.server.api.member.presentation.dto; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; import lombok.Getter; public class MemberRequestDTO { @Getter public static class registerMember { + @NotNull(message = "트리하우스 id가 필요합니다.") private Long treehouseId; + + @NotBlank(message = "유저 이름이 필요합니다.") private String userName; + + @NotBlank(message = "멤버이름(트리하우스에서 사용할 이름)이 필요합니다.") private String memberName; + private String bio; + private String profileImageURL; } diff --git a/src/main/java/treehouse/server/api/user/business/UserService.java b/src/main/java/treehouse/server/api/user/business/UserService.java index 351eddb..f761402 100644 --- a/src/main/java/treehouse/server/api/user/business/UserService.java +++ b/src/main/java/treehouse/server/api/user/business/UserService.java @@ -4,12 +4,14 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import treehouse.server.api.invitation.implement.InvitationCommandAdapter; import treehouse.server.api.invitation.implement.InvitationQueryAdapter; import treehouse.server.api.user.implement.UserCommandAdapter; import treehouse.server.api.user.implement.UserQueryAdapter; import treehouse.server.api.user.persistence.UserRepository; import treehouse.server.api.user.presentation.dto.UserRequestDTO; import treehouse.server.api.user.presentation.dto.UserResponseDTO; +import treehouse.server.global.entity.Invitation.Invitation; import treehouse.server.global.entity.User.User; import treehouse.server.global.entity.member.Member; import treehouse.server.global.entity.redis.RefreshToken; @@ -37,6 +39,7 @@ public class UserService { private final RedisService redisService; + private final InvitationCommandAdapter invitationCommandAdapter; private final InvitationQueryAdapter invitationQueryAdapter; private final UserRepository userRepository; @@ -56,6 +59,11 @@ public User findById(Long id){ public UserResponseDTO.registerUser register(UserRequestDTO.registerUser request){ User user = UserMapper.toUser(request.getUserName(), request.getPhoneNumber()); User savedUser = userCommandAdapter.register(user); + List receivedInvitations = invitationQueryAdapter.findAllByPhone(request.getPhoneNumber()); + receivedInvitations.forEach(invitation -> { + invitation.setReceiver(savedUser); + invitationCommandAdapter.saveInvitation(invitation); + }); TokenDTO loginResult = userCommandAdapter.login(savedUser); return UserMapper.toRegister(savedUser,loginResult.getAccessToken(), loginResult.getRefreshToken()); diff --git a/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java b/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java index cca3b28..78091a6 100644 --- a/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java +++ b/src/main/java/treehouse/server/global/entity/Invitation/Invitation.java @@ -34,7 +34,9 @@ public class Invitation extends BaseDateTimeEntity { @JoinColumn(name = "receiverId") @ManyToOne(fetch = FetchType.LAZY) + @Setter private User receiver; + @JoinColumn(name = "treeId") @ManyToOne(fetch = FetchType.LAZY) private TreeHouse treeHouse; diff --git a/src/main/java/treehouse/server/global/entity/member/Member.java b/src/main/java/treehouse/server/global/entity/member/Member.java index f0a35c8..f1183e9 100644 --- a/src/main/java/treehouse/server/global/entity/member/Member.java +++ b/src/main/java/treehouse/server/global/entity/member/Member.java @@ -26,6 +26,8 @@ public class Member extends BaseDateTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; + + @Column(nullable = false) private String name; //트리에서 사용할 닉네임 private String bio; //자기소개