diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/response/SimpleApplyRes.java b/src/main/java/com/gongjakso/server/domain/apply/dto/response/SimpleApplyRes.java new file mode 100644 index 00000000..3ac49bf3 --- /dev/null +++ b/src/main/java/com/gongjakso/server/domain/apply/dto/response/SimpleApplyRes.java @@ -0,0 +1,39 @@ +package com.gongjakso.server.domain.apply.dto.response; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.gongjakso.server.domain.apply.entity.Apply; +import jakarta.validation.constraints.NotNull; +import lombok.Builder; + +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +public record SimpleApplyRes( + @NotNull + Long applyId, + + @NotNull + Long teamId, + + @NotNull + Long memberId, + String memberName, + Long portfolioId, + String portfolioName, + String status, + String part, + Boolean isViewed +) { + public static SimpleApplyRes of(Apply apply){ + return SimpleApplyRes.builder() + .applyId(apply.getId()) + .teamId(apply.getTeam().getId()) + .memberId(apply.getMember().getId()) + .memberName(apply.getMember().getName()) + .portfolioId(apply.getPortfolioInfo().getPortfolio() != null ? apply.getPortfolioInfo().getPortfolio().getId() : null) + .portfolioName(apply.getPortfolioInfo().getPortfolio() != null ? apply.getPortfolioInfo().getPortfolio().getPortfolioName() : null) + .status(apply.getStatus().name()) + .part(apply.getPart()) + .isViewed(apply.isViewed()) + .build(); + } +} diff --git a/src/main/java/com/gongjakso/server/domain/apply/enumerate/ApplyStatus.java b/src/main/java/com/gongjakso/server/domain/apply/enumerate/ApplyStatus.java index f69a6bf3..ed36827f 100644 --- a/src/main/java/com/gongjakso/server/domain/apply/enumerate/ApplyStatus.java +++ b/src/main/java/com/gongjakso/server/domain/apply/enumerate/ApplyStatus.java @@ -6,9 +6,9 @@ @Getter @RequiredArgsConstructor public enum ApplyStatus { - COMPLETED("지원 완료"), - ACCEPTED("합격"), - REJECTED("불합격"); + COMPLETED("합류 대기중"), + ACCEPTED("합류 완료"), + REJECTED("미선발"); private final String description; } diff --git a/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java b/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java index 11e41767..d4a45899 100644 --- a/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java +++ b/src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java @@ -3,10 +3,13 @@ import com.gongjakso.server.domain.apply.entity.Apply; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface ApplyRepository extends JpaRepository, ApplyRepositoryCustom { Boolean existsByMemberIdAndTeamIdAndDeletedAtIsNull(Long memberId, Long teamId); Optional findByIdAndDeletedAtIsNull(Long applyId); Optional findByTeamIdAndDeletedAtIsNull(Long teamId); + Optional findByTeamIdAndMemberIdAndDeletedAtIsNull(Long teamId, Long memberId); + List findAllByTeamIdAndDeletedAtIsNull(Long teamId); } diff --git a/src/main/java/com/gongjakso/server/domain/contest/repository/ContestRepositoryCustom.java b/src/main/java/com/gongjakso/server/domain/contest/repository/ContestRepositoryCustom.java index d23f9339..e1fbf013 100644 --- a/src/main/java/com/gongjakso/server/domain/contest/repository/ContestRepositoryCustom.java +++ b/src/main/java/com/gongjakso/server/domain/contest/repository/ContestRepositoryCustom.java @@ -6,5 +6,12 @@ import org.springframework.data.domain.Pageable; public interface ContestRepositoryCustom { + /** + * 찾고자하는 단어 검색 + * @param word searchWord + * @param sort 정렬순 + */ Page searchList (String word, String sort, Pageable pageable); + + } diff --git a/src/main/java/com/gongjakso/server/domain/contest/repository/ContestRepositoryImpl.java b/src/main/java/com/gongjakso/server/domain/contest/repository/ContestRepositoryImpl.java index 12d72885..4dbd9cb0 100644 --- a/src/main/java/com/gongjakso/server/domain/contest/repository/ContestRepositoryImpl.java +++ b/src/main/java/com/gongjakso/server/domain/contest/repository/ContestRepositoryImpl.java @@ -21,8 +21,6 @@ public ContestRepositoryImpl(EntityManager em) { this.queryFactory = new JPAQueryFactory(em); } - //최신순으로 정렬 - //제목,본문 기준으로 검색 @Override public Page searchList(String word, String sortAt, Pageable pageable) { List contestList = queryFactory diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/controller/PortfolioController.java b/src/main/java/com/gongjakso/server/domain/portfolio/controller/PortfolioController.java index 3b1d1f57..8fc78010 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/controller/PortfolioController.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/controller/PortfolioController.java @@ -1,6 +1,7 @@ package com.gongjakso.server.domain.portfolio.controller; import com.gongjakso.server.domain.portfolio.dto.request.PortfolioReq; +import com.gongjakso.server.domain.portfolio.dto.response.ExistPortfolioRes; import com.gongjakso.server.domain.portfolio.dto.response.PortfolioRes; import com.gongjakso.server.domain.portfolio.dto.response.SimplePortfolioRes; import com.gongjakso.server.domain.portfolio.service.PortfolioService; @@ -11,14 +12,8 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -66,4 +61,33 @@ public ApplicationResponse deletePortfolio(@AuthenticationPrincipal Princi public ApplicationResponse> getMyPortfolios(@AuthenticationPrincipal PrincipalDetails principalDetails) { return ApplicationResponse.ok(portfolioService.getMyPortfolios(principalDetails.getMember())); } + + @Operation(description = "포트폴리오 파일 및 링크 업로드 API") + @PostMapping("/exist-portfolio") + public ApplicationResponse updateExistPortfolio(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestPart(required = false,name = "file") MultipartFile file, @RequestPart(required = false,name = "notionUri") String notionUri){ + portfolioService.saveExistPortfolio(principalDetails.getMember(),file,notionUri); + return ApplicationResponse.ok(); + } + + @Operation(description = "포트폴리오 파일 및 링크 업로드 삭제 API") + @DeleteMapping("/exist-portfolio/{portfolio_id}") + public ApplicationResponse deleteExistPortfolio(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("portfolio_id") Long portfolioId){ + portfolioService.deleteExistPortfolio(principalDetails.getMember(),portfolioId); + return ApplicationResponse.ok(); + } + + @Operation(description = "포트폴리오 파일 및 링크 업로드 업데이트 API") + @PatchMapping("/exist-portfolio/{portfolio_id}") + public ApplicationResponse updateExistPortfolio(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("portfolio_id") Long portfolioId, @RequestPart(required = false,name = "file") MultipartFile file, @RequestPart(required = false,name = "notionUri") String notionUri){ + portfolioService.updateExistPortfolio(principalDetails.getMember(),portfolioId,file,notionUri); + return ApplicationResponse.ok(); + } + + @Operation(description = "포트폴리오 파일 및 링크 업로드 가져오기 API") + @GetMapping("/exist-portfolio/{portfolio_id}") + public ApplicationResponse findExistPortfolio(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("portfolio_id") Long portfolioId){ + return ApplicationResponse.ok(portfolioService.findExistPorfolio(principalDetails.getMember(),portfolioId)); + } + + } diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/dto/response/ExistPortfolioRes.java b/src/main/java/com/gongjakso/server/domain/portfolio/dto/response/ExistPortfolioRes.java new file mode 100644 index 00000000..5143d332 --- /dev/null +++ b/src/main/java/com/gongjakso/server/domain/portfolio/dto/response/ExistPortfolioRes.java @@ -0,0 +1,15 @@ +package com.gongjakso.server.domain.portfolio.dto.response; + +import com.gongjakso.server.domain.portfolio.entity.Portfolio; + +public record ExistPortfolioRes( + String fileUri, + String notionUri +) { + public static ExistPortfolioRes of(Portfolio portfolio) { + return new ExistPortfolioRes( + portfolio.getFileUri(), + portfolio.getNotionUri() + ); + } +} diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/dto/response/SimplePortfolioRes.java b/src/main/java/com/gongjakso/server/domain/portfolio/dto/response/SimplePortfolioRes.java index ee60919d..b7e2cfd3 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/dto/response/SimplePortfolioRes.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/dto/response/SimplePortfolioRes.java @@ -1,19 +1,25 @@ package com.gongjakso.server.domain.portfolio.dto.response; +import com.fasterxml.jackson.annotation.JsonInclude; import com.gongjakso.server.domain.portfolio.entity.Portfolio; import java.time.LocalDateTime; +@JsonInclude(JsonInclude.Include.NON_NULL) public record SimplePortfolioRes( Long PortfolioId, String PortfolioName, - LocalDateTime modifiedAt + LocalDateTime modifiedAt, + Boolean isRegistered, + Boolean isExistedPortfolio ) { - public static SimplePortfolioRes of(Portfolio portfolio) { + public static SimplePortfolioRes of(Portfolio portfolio, Boolean isRegistered, Boolean isExistedPortfolio) { return new SimplePortfolioRes( - portfolio.getId(), - portfolio.getPortfolioName(), - portfolio.getModifiedAt() + isRegistered ? portfolio.getId() : null, + isRegistered ? portfolio.getPortfolioName() : null, + isRegistered ? portfolio.getModifiedAt() : null, + isRegistered, + isExistedPortfolio ); } } diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/entity/Portfolio.java b/src/main/java/com/gongjakso/server/domain/portfolio/entity/Portfolio.java index ff563f67..a7682519 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/entity/Portfolio.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/entity/Portfolio.java @@ -1,5 +1,6 @@ package com.gongjakso.server.domain.portfolio.entity; +import com.gongjakso.server.domain.contest.dto.request.UpdateContestDto; import com.gongjakso.server.domain.member.entity.Member; import com.gongjakso.server.domain.portfolio.vo.PortfolioData; import com.gongjakso.server.global.common.BaseTimeEntity; @@ -12,6 +13,7 @@ import org.hibernate.annotations.JdbcTypeCode; import org.hibernate.annotations.SQLDelete; import org.hibernate.type.SqlTypes; +import org.springframework.data.redis.connection.ReactiveGeoCommands; @Getter @Entity @@ -36,13 +38,32 @@ public class Portfolio extends BaseTimeEntity { @JdbcTypeCode(SqlTypes.JSON) private PortfolioData portfolioData; - @Builder + @Column(name = "file_uri",columnDefinition = "text") + private String fileUri; + + @Column(name = "notion_uri",columnDefinition = "text") + private String notionUri; + + @Builder(builderMethodName = "portfolioBuilder") public Portfolio(Member member, String portfolioName, PortfolioData portfolioData) { this.member = member; this.portfolioName = portfolioName; this.portfolioData = portfolioData; } + @Builder(builderMethodName = "existPortfolioBuilder") + public Portfolio(Member member, String portfolioName, String fileUri, String notionUri){ + this.member = member; + this.portfolioName = portfolioName; + this.fileUri = fileUri; + this.notionUri = notionUri; + } + public void updatePortfolioUri(Portfolio portfolio, String fileUri, String notionUri) { + this.fileUri = (fileUri == null) ? this.fileUri : fileUri; + this.notionUri = (notionUri == null) ? this.notionUri : notionUri; + } + + public void updateName(String updatedName) { this.portfolioName = updatedName; } diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepository.java b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepository.java index cb0cc04b..6b20ed0e 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepository.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepository.java @@ -1,11 +1,14 @@ package com.gongjakso.server.domain.portfolio.repository; +import com.gongjakso.server.domain.member.entity.Member; import com.gongjakso.server.domain.portfolio.entity.Portfolio; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; public interface PortfolioRepository extends JpaRepository, PortfolioRepositoryCustom{ Optional findByIdAndDeletedAtIsNull(Long portfolioId); - long countByDeletedAtIsNull(); + Optional findPortfolioById(Long portfolioId); } diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryCustom.java b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryCustom.java index d7ddf394..c21b09b0 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryCustom.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryCustom.java @@ -7,4 +7,5 @@ public interface PortfolioRepositoryCustom { List findByMemberAndDeletedAtIsNull(Member member); + Boolean existsExistPortfolioByMember(Member member); } diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryImpl.java b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryImpl.java index df152c6b..4f01f4f7 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryImpl.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/repository/PortfolioRepositoryImpl.java @@ -20,4 +20,13 @@ public List findByMemberAndDeletedAtIsNull(Member member) { .and(portfolio.deletedAt.isNull())) .fetch(); } + + public Boolean existsExistPortfolioByMember(Member member){ + return queryFactory + .selectFrom(portfolio) + .where(portfolio.member.eq(member) + .and(portfolio.fileUri.isNotNull().or(portfolio.notionUri.isNotNull())) + .and(portfolio.deletedAt.isNull())) + .fetchFirst()!=null; + } } diff --git a/src/main/java/com/gongjakso/server/domain/portfolio/service/PortfolioService.java b/src/main/java/com/gongjakso/server/domain/portfolio/service/PortfolioService.java index f94554fd..72aebe0e 100644 --- a/src/main/java/com/gongjakso/server/domain/portfolio/service/PortfolioService.java +++ b/src/main/java/com/gongjakso/server/domain/portfolio/service/PortfolioService.java @@ -2,6 +2,7 @@ import com.gongjakso.server.domain.member.entity.Member; import com.gongjakso.server.domain.portfolio.dto.request.PortfolioReq; +import com.gongjakso.server.domain.portfolio.dto.response.ExistPortfolioRes; import com.gongjakso.server.domain.portfolio.dto.response.PortfolioRes; import com.gongjakso.server.domain.portfolio.dto.response.SimplePortfolioRes; import com.gongjakso.server.domain.portfolio.entity.Portfolio; @@ -10,9 +11,12 @@ import com.gongjakso.server.global.exception.ApplicationException; import com.gongjakso.server.global.exception.ErrorCode; import java.util.List; + +import com.gongjakso.server.global.util.s3.S3Client; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; @Service @Transactional(readOnly = true) @@ -20,6 +24,9 @@ public class PortfolioService { private final PortfolioRepository portfolioRepository; + private final S3Client s3Client; + private final String S3_PORTFOLIO_DIR_NAME = "portfolio"; + // PortfolioName 생성 로직을 분리 private String generatePortfolioName(String portfolioName) { @@ -104,11 +111,7 @@ public PortfolioRes registerPortfolio(Member member, PortfolioReq portfolioReq) String portfolioName = generatePortfolioName(portfolioReq.portfolioName()); PortfolioData portfolioData = convertToPortfolioData(portfolioReq); - Portfolio portfolio = Portfolio.builder() - .member(member) - .portfolioName(portfolioName) - .portfolioData(portfolioData) - .build(); + Portfolio portfolio = new Portfolio(member,portfolioName,portfolioData); Portfolio savedPortfolio = portfolioRepository.save(portfolio); @@ -161,8 +164,75 @@ public void deletePortfolio(Member member, Long portfolioId) { public List getMyPortfolios(Member member) { List portfolioList = portfolioRepository.findByMemberAndDeletedAtIsNull(member); + + if (portfolioList.isEmpty()) { + return List.of(SimplePortfolioRes.of(null, false, null)); + } + return portfolioList.stream() - .map(SimplePortfolioRes::of) + .map(portfolio -> SimplePortfolioRes.of(portfolio, true, portfolio.getFileUri() != null || portfolio.getNotionUri() != null)) .toList(); } + + @Transactional + public void saveExistPortfolio(Member member, MultipartFile file, String notionUri){ + //등록된 파일이나 노션 링크 있는지 확인 + //Validation + Boolean isExist = portfolioRepository.existsExistPortfolioByMember(member); + if (isExist){ + throw new ApplicationException(ErrorCode.ALREADY_EXIST_EXCEPTION); + } + if (file == null && notionUri == null){ + throw new ApplicationException(ErrorCode.PORTFOLIO_SAVE_FAILED_EXCEPTION); + } + //Business + String s3Url = null; + if ( file!=null ) { + s3Url = s3Client.upload(file, S3_PORTFOLIO_DIR_NAME); + } + Portfolio portfolio = new Portfolio(member,generatePortfolioName(null),s3Url,notionUri); + portfolioRepository.save(portfolio); + } + + @Transactional + public void deleteExistPortfolio(Member member, Long id){ + Portfolio portfolio = portfolioRepository.findById(id).orElseThrow(()-> new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)); + if(!member.getId().equals(portfolio.getMember().getId())){ + throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); + } + if(portfolio.getFileUri() != null || !portfolio.getFileUri().isEmpty()){ + s3Client.delete(portfolio.getFileUri()); + } + portfolioRepository.delete(portfolio); + } + + @Transactional + public void updateExistPortfolio(Member member, Long id, MultipartFile file, String notionUri){ + //등록된 파일이나 노션 링크 있는지 확인 + //Validation + Portfolio portfolio = portfolioRepository.findById(id).orElseThrow(()-> new ApplicationException(ErrorCode.PORTFOLIO_NOT_FOUND_EXCEPTION)); + if(!member.getId().equals(portfolio.getMember().getId())){ + throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION); + } + //Business + String s3Url = null; + if ( file!=null ) { + if(portfolio.getFileUri()!=null && !portfolio.getFileUri().isEmpty()){ + s3Client.delete(portfolio.getFileUri()); + } + s3Url = s3Client.upload(file, S3_PORTFOLIO_DIR_NAME); + } + portfolio.updatePortfolioUri(portfolio,s3Url,notionUri); + portfolioRepository.save(portfolio); + } + + public ExistPortfolioRes findExistPorfolio(Member member, Long id){ + //Validation + Portfolio portfolio = portfolioRepository.findById(id).orElseThrow(()-> new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)); + if (!portfolio.getMember().getId().equals(member.getId())) { + throw new ApplicationException(ErrorCode.FORBIDDEN_EXCEPTION); + } + return new ExistPortfolioRes(portfolio.getFileUri(),portfolio.getNotionUri()); + } + } \ No newline at end of file diff --git a/src/main/java/com/gongjakso/server/domain/team/controller/TeamController.java b/src/main/java/com/gongjakso/server/domain/team/controller/TeamController.java index de8d0fc6..78a9bd8b 100644 --- a/src/main/java/com/gongjakso/server/domain/team/controller/TeamController.java +++ b/src/main/java/com/gongjakso/server/domain/team/controller/TeamController.java @@ -1,5 +1,6 @@ package com.gongjakso.server.domain.team.controller; +import com.gongjakso.server.domain.apply.dto.response.SimpleApplyRes; import com.gongjakso.server.domain.team.dto.request.TeamReq; import com.gongjakso.server.domain.team.dto.response.ScrapRes; import com.gongjakso.server.domain.team.dto.response.SimpleTeamRes; @@ -20,6 +21,7 @@ import org.springframework.web.bind.annotation.*; import java.time.LocalDate; +import java.util.List; @RestController @@ -172,4 +174,11 @@ public ApplicationResponse changeTeamStatus(@AuthenticationPrincipal Pr @RequestParam(value = "status") String status) { return ApplicationResponse.ok(teamService.changeTeamStatus(principalDetails.getMember(), contestId, teamId, status)); } + + @Operation(summary = "특정 팀의 지원자 리스트 조회", description = "특정 팀의 지원자 리스트를 조회하는 API") + @GetMapping("/team/{team_id}") + public ApplicationResponse> getAppliesByTeam(@AuthenticationPrincipal PrincipalDetails principalDetails, + @PathVariable("team_id") Long teamId) { + return ApplicationResponse.ok(teamService.getApplyList(principalDetails.getMember(), teamId)); + } } diff --git a/src/main/java/com/gongjakso/server/domain/team/dto/response/TeamRes.java b/src/main/java/com/gongjakso/server/domain/team/dto/response/TeamRes.java index 52fa7f9b..931bf873 100644 --- a/src/main/java/com/gongjakso/server/domain/team/dto/response/TeamRes.java +++ b/src/main/java/com/gongjakso/server/domain/team/dto/response/TeamRes.java @@ -3,6 +3,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import com.gongjakso.server.domain.apply.entity.Apply; import com.gongjakso.server.domain.team.entity.Team; import com.gongjakso.server.domain.team.vo.RecruitPart; import io.swagger.v3.oas.annotations.media.Schema; @@ -82,7 +83,13 @@ public record TeamRes( int viewCount, @Schema(description = "사용자 역할", example = "LEADER") - String teamRole + String teamRole, + + @Schema(description = "지원 상태", example = "합류 대기중 | 합류 완료 | 미선발") + String applyStatus, + + @Schema(description = "지원 ID", example = "1") + Long applyId ) { @Builder @@ -108,7 +115,7 @@ public static RecruitPartRes of(RecruitPart recruitPart) { } - public static TeamRes of(Team team, String teamRole) { + public static TeamRes of(Team team, String teamRole, Apply apply) { List recruitPartRes = (team.getRecruitPart() != null) ? team.getRecruitPart().stream() .map(RecruitPartRes::of) .toList() : null; @@ -136,6 +143,8 @@ public static TeamRes of(Team team, String teamRole) { .contestLink(team.getContest().getContestLink()) .scrapCount(team.getScrapCount()) .teamRole(teamRole) + .applyStatus(apply != null ? apply.getStatus().getDescription() : null) + .applyId(apply != null ? apply.getId() : null) .build(); } } diff --git a/src/main/java/com/gongjakso/server/domain/team/repository/TeamRepositoryImpl.java b/src/main/java/com/gongjakso/server/domain/team/repository/TeamRepositoryImpl.java index 6592b63b..bb67f36c 100644 --- a/src/main/java/com/gongjakso/server/domain/team/repository/TeamRepositoryImpl.java +++ b/src/main/java/com/gongjakso/server/domain/team/repository/TeamRepositoryImpl.java @@ -199,6 +199,7 @@ public Page findParticipatePagination(Long memberId, Pageable pag Long total = queryFactory.select(team.count()) .from(team) .where( + team.status.in(teamStatusList), team.deletedAt.isNull() ) .fetchOne(); @@ -232,6 +233,7 @@ public Page findScrapPagination(Long memberId, Pageable pageable) Long total = queryFactory.select(team.count()) .from(team) .where( + team.id.in(teamIdList), team.deletedAt.isNull() ) .fetchOne(); diff --git a/src/main/java/com/gongjakso/server/domain/team/service/TeamService.java b/src/main/java/com/gongjakso/server/domain/team/service/TeamService.java index 9432555a..cbdd10ae 100644 --- a/src/main/java/com/gongjakso/server/domain/team/service/TeamService.java +++ b/src/main/java/com/gongjakso/server/domain/team/service/TeamService.java @@ -1,5 +1,6 @@ package com.gongjakso.server.domain.team.service; +import com.gongjakso.server.domain.apply.dto.response.SimpleApplyRes; import com.gongjakso.server.domain.apply.entity.Apply; import com.gongjakso.server.domain.apply.repository.ApplyRepository; import com.gongjakso.server.domain.contest.entity.Contest; @@ -46,7 +47,7 @@ public TeamRes createTeam(Member member, Long contestId, TeamReq teamReq) { Team savedTeam = teamRepository.save(team); // Response - return TeamRes.of(savedTeam, "LEADER"); + return TeamRes.of(savedTeam, "LEADER", null); } @Transactional @@ -68,7 +69,7 @@ public TeamRes updateTeam(Member member, Long contestId, Long teamId, TeamReq te Team updatedTeam = teamRepository.save(team); // Response - return TeamRes.of(updatedTeam, "LEADER"); + return TeamRes.of(updatedTeam, "LEADER", null); } @Transactional @@ -91,7 +92,7 @@ public TeamRes extendRecruit(Member member, Long contestId, Long teamId, LocalDa Team updatedTeam = teamRepository.save(team); // Response - return TeamRes.of(updatedTeam, "LEADER"); + return TeamRes.of(updatedTeam, "LEADER", null); } @Transactional @@ -113,7 +114,7 @@ public TeamRes closeRecruit(Member member, Long contestId, Long teamId) { Team updatedTeam = teamRepository.save(team); // Response - return TeamRes.of(updatedTeam, "LEADER"); + return TeamRes.of(updatedTeam, "LEADER", null); } @Transactional @@ -135,7 +136,7 @@ public TeamRes cancelRecruit(Member member, Long contestId, Long teamId) { Team updatedTeam = teamRepository.save(team); // Response - return TeamRes.of(updatedTeam, "LEADER"); + return TeamRes.of(updatedTeam, "LEADER", null); } @Transactional @@ -167,19 +168,19 @@ public TeamRes getTeam(Member member, Long contestId, Long teamId) { throw new ApplicationException(ErrorCode.TEAM_NOT_FOUND_EXCEPTION); } - List appliers = applyRepository.findByTeamIdAndDeletedAtIsNull(teamId).stream() - .map(Apply::getMember) - .toList(); - String teamRole = "GENERAL"; + Apply apply = null; + if(member != null && team.getMember().getId().equals(member.getId())){ teamRole = "LEADER"; - }else if(member != null && appliers.stream().anyMatch(applier -> applier.getId().equals(member.getId()))){ + }else if(member != null && applyRepository.findByTeamIdAndMemberIdAndDeletedAtIsNull(teamId, member.getId()).isPresent()){ teamRole = "APPLIER"; + apply = applyRepository.findByTeamIdAndMemberIdAndDeletedAtIsNull(teamId, member.getId()) + .orElseThrow(() -> new ApplicationException(ErrorCode.APPLY_NOT_FOUND_EXCEPTION)); } // Business Logic - return TeamRes.of(team, teamRole); + return TeamRes.of(team, teamRole, apply); } public Page getTeamListWithContest(Long contestId, String province, String district, Pageable pageable) { @@ -298,6 +299,20 @@ public TeamRes changeTeamStatus(Member member, Long contestId, Long teamId, Stri Team updatedTeam = teamRepository.save(team); // Response - return TeamRes.of(updatedTeam, "LEADER"); + return TeamRes.of(updatedTeam, "LEADER", null); + } + + public List getApplyList(Member member, Long teamId) { + // Validation + Team team = teamRepository.findByIdAndDeletedAtIsNull(teamId) + .orElseThrow(() -> new ApplicationException(ErrorCode.TEAM_NOT_FOUND_EXCEPTION)); + if (!team.getMember().getId().equals(member.getId())) { + throw new ApplicationException(ErrorCode.FORBIDDEN_EXCEPTION); + } + + // Business Logic & Response + return applyRepository.findAllByTeamIdAndDeletedAtIsNull(teamId).stream() + .map(SimpleApplyRes::of) + .toList(); } }