Skip to content
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

Refactor: 팀 프로필 조회시 조회한 사용자가 팀의 ADMIN인지 여부 확인 응답 추가 #335

Merged
merged 1 commit into from
Feb 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.codiary.backend.domain.team.entity.TeamBannerImage;
import com.codiary.backend.domain.team.entity.TeamMember;
import com.codiary.backend.domain.team.entity.TeamProfileImage;
import com.codiary.backend.domain.team.enumerate.TeamMemberRole;
import com.codiary.backend.domain.team.service.TeamMemberService;
import com.codiary.backend.domain.team.service.TeamService;
import com.codiary.backend.global.apiPayload.ApiResponse;
Expand Down Expand Up @@ -59,7 +60,10 @@ public ApiResponse<TeamResponseDTO.TeamProfileDTO> getTeamProfile(
@AuthenticationPrincipal CustomMemberDetails memberDetails
) {
Team fetchedTeam = teamService.getTeamProfile(teamId, memberDetails.getId());
return ApiResponse.onSuccess(SuccessStatus.TEAM_OK, TeamConverter.toTeamProfileResponseDto(fetchedTeam));
TeamMember currentMember = teamMemberService.getTeamMemberRoleInTeam(teamId, memberDetails.getId());
boolean isAdmin = currentMember != null && currentMember.getTeamMemberRole() == TeamMemberRole.ADMIN;

return ApiResponse.onSuccess(SuccessStatus.TEAM_OK, TeamConverter.toTeamProfileResponseDto(fetchedTeam, currentMember, isAdmin));
}

@GetMapping("/{team_id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static TeamResponseDTO.TeamDTO toTeamResponseDto(Team team) {
}

//팀 팔로우 여부 구현 후 수정 필요
public static TeamResponseDTO.TeamProfileDTO toTeamProfileResponseDto(Team team){
public static TeamResponseDTO.TeamProfileDTO toTeamProfileResponseDto(Team team, TeamMember currentMember, boolean isAdmin){
return TeamResponseDTO.TeamProfileDTO.builder()
.teamId(team.getTeamId())
.name(team.getName())
Expand All @@ -49,6 +49,8 @@ public static TeamResponseDTO.TeamProfileDTO toTeamProfileResponseDto(Team team)
.isFollowed(false)
.teamMemberList(team.getTeamMemberList() == null ? null :
TeamConverter.toTeamMemberListResponseDTO(team))
.currentMemberId(currentMember != null ? currentMember.getTeamMemberId() : null)
.isAdmin(isAdmin)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public record TeamProfileDTO(
String discord,
String instagram,
Boolean isFollowed,
Long currentMemberId,
Boolean isAdmin,
List<TeamMemberDTO> teamMemberList) {}

@JsonInclude(JsonInclude.Include.NON_NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,12 @@ public List<TeamMember> getMemberTeam(Long memberId, Long currentId) {

return teamMemberRepository.findByMember(member);
}

public TeamMember getTeamMemberRoleInTeam(Long teamId, Long memberId) {
return teamMemberRepository.findByTeamAndMember(
teamRepository.findById(teamId).orElseThrow(() -> new GeneralException(ErrorStatus.TEAM_NOT_FOUND)),
memberRepository.findById(memberId).orElseThrow(() -> new GeneralException(ErrorStatus.MEMBER_NOT_FOUND))
).orElse(null);
}

}
Loading