Skip to content

Commit

Permalink
Merge pull request #214 from Gongjakso/feat/apply
Browse files Browse the repository at this point in the history
fix: 팀에 대한 사용자 역할 추가 반환
  • Loading branch information
yumzen authored Sep 21, 2024
2 parents 9cd3c6f + 71deec4 commit 52c21cc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
public interface ApplyRepository extends JpaRepository<Apply, Long>, ApplyRepositoryCustom {
Boolean existsByMemberIdAndTeamIdAndDeletedAtIsNull(Long memberId, Long teamId);
Optional<Apply> findByIdAndDeletedAtIsNull(Long applyId);
Optional<Apply> findByTeamIdAndDeletedAtIsNull(Long teamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ public ApplicationResponse<Void> deleteTeam(@AuthenticationPrincipal PrincipalDe

@Operation(summary = "팀 조회 API", description = "특정 공모전에 해당하는 팀을 조회하는 API")
@GetMapping("/contest/{contest_id}/team/{team_id}")
public ApplicationResponse<TeamRes> getTeam(@PathVariable(value = "contest_id") Long contestId,
public ApplicationResponse<TeamRes> getTeam(@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable(value = "contest_id") Long contestId,
@PathVariable(value = "team_id") Long teamId) {
return ApplicationResponse.ok(teamService.getTeam(contestId, teamId));
return ApplicationResponse.ok(teamService.getTeam(principalDetails == null ? null : principalDetails.getMember(), contestId, teamId));
}

@Operation(summary = "팀 리스트 조회 API", description = "특정 공모전에 해당하는 팀 리스트를 조회하는 API (오프셋 기반 페이지네이션)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public record TeamRes(
int scrapCount,

@Schema(description = "조회 수", example = "100")
int viewCount
int viewCount,

@Schema(description = "사용자 역할", example = "LEADER")
String teamRole
) {

@Builder
Expand All @@ -96,7 +99,7 @@ public static RecruitPartRes of(RecruitPart recruitPart) {

}

public static TeamRes of(Team team) {
public static TeamRes of(Team team, String teamRole) {
List<RecruitPartRes> recruitPartRes = (team.getRecruitPart() != null) ? team.getRecruitPart().stream()
.map(RecruitPartRes::of)
.toList() : null;
Expand All @@ -120,6 +123,7 @@ public static TeamRes of(Team team) {
.finishedAt(team.getFinishedAt())
.channelLink(team.getChannelLink())
.scrapCount(team.getScrapCount())
.teamRole(teamRole)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gongjakso.server.domain.team.service;

import com.gongjakso.server.domain.apply.entity.Apply;
import com.gongjakso.server.domain.apply.repository.ApplyRepository;
import com.gongjakso.server.domain.contest.entity.Contest;
import com.gongjakso.server.domain.contest.repository.ContestRepository;
import com.gongjakso.server.domain.member.entity.Member;
Expand All @@ -20,6 +22,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

@Service
@RequiredArgsConstructor
Expand All @@ -29,6 +32,7 @@ public class TeamService {
private final TeamRepository teamRepository;
private final ContestRepository contestRepository;
private final ScrapRepository scrapRepository;
private final ApplyRepository applyRepository;

@Transactional
public TeamRes createTeam(Member member, Long contestId, TeamReq teamReq) {
Expand All @@ -41,7 +45,7 @@ public TeamRes createTeam(Member member, Long contestId, TeamReq teamReq) {
Team savedTeam = teamRepository.save(team);

// Response
return TeamRes.of(savedTeam);
return TeamRes.of(savedTeam, "LEADER");
}

@Transactional
Expand All @@ -63,7 +67,7 @@ public TeamRes updateTeam(Member member, Long contestId, Long teamId, TeamReq te
Team updatedTeam = teamRepository.save(team);

// Response
return TeamRes.of(updatedTeam);
return TeamRes.of(updatedTeam, "LEADER");
}

@Transactional
Expand All @@ -86,7 +90,7 @@ public TeamRes extendRecruit(Member member, Long contestId, Long teamId, LocalDa
Team updatedTeam = teamRepository.save(team);

// Response
return TeamRes.of(updatedTeam);
return TeamRes.of(updatedTeam, "LEADER");
}

@Transactional
Expand All @@ -108,7 +112,7 @@ public TeamRes closeRecruit(Member member, Long contestId, Long teamId) {
Team updatedTeam = teamRepository.save(team);

// Response
return TeamRes.of(updatedTeam);
return TeamRes.of(updatedTeam, "LEADER");
}

@Transactional
Expand All @@ -130,7 +134,7 @@ public TeamRes cancelRecruit(Member member, Long contestId, Long teamId) {
Team updatedTeam = teamRepository.save(team);

// Response
return TeamRes.of(updatedTeam);
return TeamRes.of(updatedTeam, "LEADER");
}

@Transactional
Expand All @@ -152,7 +156,7 @@ public void deleteTeam(Member member, Long contestId, Long teamId) {
}

// TODO: 조회수 관련 로직 도입 및 @Transactional 도입 필요
public TeamRes getTeam(Long contestId, Long teamId) {
public TeamRes getTeam(Member member, Long contestId, Long teamId) {
// Validation
contestRepository.findByIdAndDeletedAtIsNull(contestId)
.orElseThrow(() -> new ApplicationException(ErrorCode.CONTEST_NOT_FOUND_EXCEPTION));
Expand All @@ -162,8 +166,19 @@ public TeamRes getTeam(Long contestId, Long teamId) {
throw new ApplicationException(ErrorCode.TEAM_NOT_FOUND_EXCEPTION);
}

List<Member> appliers = applyRepository.findByTeamIdAndDeletedAtIsNull(teamId).stream()
.map(Apply::getMember)
.toList();

String teamRole = "GENERAL";
if(member != null && team.getMember().getId().equals(member.getId())){
teamRole = "LEADER";
}else if(member != null && appliers.stream().anyMatch(applier -> applier.getId().equals(member.getId()))){
teamRole = "APPLIER";
}

// Business Logic
return TeamRes.of(team);
return TeamRes.of(team, teamRole);
}

public Page<SimpleTeamRes> getTeamListWithContest(Long contestId, String province, String district, Pageable pageable) {
Expand Down

0 comments on commit 52c21cc

Please sign in to comment.