Skip to content

Commit

Permalink
[REFACTOR] 팀원 초대 시 닉네임으로 초대되게 끔 구현 (#166)
Browse files Browse the repository at this point in the history
* ♻️refactor: 팀 초대 시 사용자 닉네임으로 받게 구현 (#165)

* 💄style:최종코드 수정 (#165)

* 💄style: 최종코드 수정 (#165)

* ♻️refactor: 불필요한 예외처리 제외 (#165)
  • Loading branch information
600gramSik authored Aug 3, 2024
1 parent 55be219 commit 3b1425b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public interface ProfileJpaRepository extends JpaRepository<Profile, Long> {
Optional<Profile> findByUserId(Long userId);

Profile findByNickname(String nickname);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.capstone.BnagFer.domain.accounts.entity.User;
import com.capstone.BnagFer.domain.report.entity.UserActivity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.capstone.BnagFer.domain.myteam.entity.TeamInvite;

public record TeamInviteRequestDto(
Long userId,
String nickName,
Long teamId) {

public TeamInvite toEntity(User invitedUser, Team team, User inviter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ public record TeamInviteResponseDto(
Long inviteId,
Long teamId,
Long invitedUserId,
String nickName,
Long inviterId) {

public static TeamInviteResponseDto from(TeamInvite teamInvite) {
return TeamInviteResponseDto.builder()
.inviteId(teamInvite.getId())
.teamId(teamInvite.getTeam().getId())
.invitedUserId(teamInvite.getInvitedUser().getId())
.nickName(teamInvite.getInvitedUser().getProfile().getNickname())
.inviterId(teamInvite.getInviter().getId())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.capstone.BnagFer.domain.myteam.service;

import com.capstone.BnagFer.domain.accounts.entity.Profile;
import com.capstone.BnagFer.domain.accounts.entity.User;
import com.capstone.BnagFer.domain.accounts.repository.UserJpaRepository;
import com.capstone.BnagFer.domain.accounts.repository.ProfileJpaRepository;
import com.capstone.BnagFer.domain.accounts.service.account.AccountsCommonService;
import com.capstone.BnagFer.domain.myteam.dto.request.TeamInviteRequestDto;
import com.capstone.BnagFer.domain.myteam.dto.response.TeamInviteResponseDto;
Expand All @@ -21,18 +22,18 @@
@RequiredArgsConstructor
@Transactional
public class TeamInviteService {

private final TeamInviteRepository teamInviteRepository;
private final AccountsCommonService accountsCommonService;
private final TeamRepository teamRepository;
private final TeamMembersRepository teamMembersRepository;
private final UserJpaRepository userJpaRepository;
private final ProfileJpaRepository profileJpaRepository;
public TeamInviteResponseDto inviteTeamMembers(TeamInviteRequestDto request, User inviter) {
// 초대하려는 사용자를 ID로 찾아오고, 없으면 USER_NOT_FOUND 예외를 던진다
User invitedUser = userJpaRepository.findById(request.userId())
.orElseThrow(() -> new TeamMemberExceptionHandler(ErrorCode.USER_NOT_FOUND));

// 초대가 이루어질 팀을 ID로 찾아오고, 없으면 TEAM_NOT_FOUND 예외를 던진다
Profile profile = profileJpaRepository.findByNickname(request.nickName());
if(profile==null){
throw new TeamMemberExceptionHandler(ErrorCode.USER_NOT_FOUND);
}
User invitedUser = profile.getUser();
//초대가 이루어질 팀을 ID로 찾아오고, 없으면 TEAM_NOT_FOUND 예외를 던진다
Team team = teamRepository.findById(request.teamId())
.orElseThrow(() -> new TeamExceptionHandler(ErrorCode.TEAM_NOT_FOUND));

Expand Down

0 comments on commit 3b1425b

Please sign in to comment.