Skip to content

Commit

Permalink
Merge pull request #126 from Team-Shaka/fix/125
Browse files Browse the repository at this point in the history
⚡️ Fix: 회원가입 시 초대장 처리 및 트리하우스 가입 유효성 검사
  • Loading branch information
koojun99 authored Sep 11, 2024
2 parents 1f83c3d + 9dfb24a commit 4b6ab9b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface InvitationRepository extends JpaRepository<Invitation, Long> {

Boolean existsByPhone(String phoneNumber);

Boolean existsByPhoneAndTreeHouse(String phoneNumber, TreeHouse treehouse);
Boolean existsByPhoneAndTreeHouse(String phone, TreeHouse treehouse);

Optional<Invitation> findByReceiverAndTreeHouse(User user, TreeHouse treeHouse);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +30,7 @@ public class MemberApi {
@PostMapping("/members/register")
@Operation(summary = "트리하우스 회원가입 🔑 ✅", description = "트리하우스 멤버로 가입합니다.")
public CommonResponse<MemberResponseDTO.registerMember> 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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -37,6 +39,7 @@ public class UserService {

private final RedisService redisService;

private final InvitationCommandAdapter invitationCommandAdapter;
private final InvitationQueryAdapter invitationQueryAdapter;
private final UserRepository userRepository;

Expand All @@ -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<Invitation> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; //자기소개
Expand Down

0 comments on commit 4b6ab9b

Please sign in to comment.