diff --git a/src/main/java/com/gongjakso/server/domain/apply/dto/response/ApplyRes.java b/src/main/java/com/gongjakso/server/domain/apply/dto/response/ApplyRes.java index 92e2c26..c5c5b4a 100644 --- a/src/main/java/com/gongjakso/server/domain/apply/dto/response/ApplyRes.java +++ b/src/main/java/com/gongjakso/server/domain/apply/dto/response/ApplyRes.java @@ -1,6 +1,8 @@ package com.gongjakso.server.domain.apply.dto.response; 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 jakarta.annotation.Nullable; import jakarta.validation.constraints.NotNull; @@ -12,11 +14,12 @@ import java.time.Period; @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) @Builder public record ApplyRes( @NotNull - Long applyId, + Long id, @NotNull Long teamId, @@ -24,6 +27,13 @@ public record ApplyRes( @NotNull Long memberId, + @NotNull + String name, + + String phone, + + String major, + @Nullable Long portfolioId, @@ -41,11 +51,11 @@ public record ApplyRes( @Size(max = 20) @NotNull - String part, + String applyPart, int scrapCount, - int remainingDays, + int dDay, LocalDate startedAt, @@ -62,23 +72,26 @@ public record ApplyRes( ) { public static ApplyRes of(Apply apply) { return ApplyRes.builder() - .applyId(apply.getId()) + .id(apply.getId()) .teamId(apply.getTeam().getId()) .teamName(apply.getTeam().getTitle()) .memberId(apply.getMember().getId()) + .name(apply.getMember().getName()) + .phone(apply.getMember().getPhone()) + .major(apply.getMember().getMajor()) .leaderName(apply.getTeam().getMember().getName()) .portfolioId(apply.getPortfolioInfo().getPortfolio() != null ? apply.getPortfolioInfo().getPortfolio().getId() : null) .portfolioName(apply.getPortfolioInfo().getPortfolio() != null ? apply.getPortfolioInfo().getPortfolio().getPortfolioName() : null) .isPrivate(apply.getPortfolioInfo().isPrivate()) .body(apply.getBody()) .status(apply.getStatus().getDescription()) - .part(apply.getPart()) + .applyPart(apply.getPart()) .isViewed(apply.isViewed()) .deleteAt(apply.getDeletedAt()) .scrapCount(apply.getTeam().getScrapCount()) .startedAt(apply.getTeam().getStartedAt()) .finishedAt(apply.getTeam().getFinishedAt()) - .remainingDays(Period.between(LocalDate.now(), apply.getTeam().getFinishedAt()).getDays()) + .dDay(Period.between(LocalDate.now(), apply.getTeam().getFinishedAt()).getDays()) .build(); } } 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 index 3ac49bf..2d955d2 100644 --- 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 @@ -1,15 +1,18 @@ package com.gongjakso.server.domain.apply.dto.response; 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 jakarta.validation.constraints.NotNull; import lombok.Builder; @Builder @JsonInclude(JsonInclude.Include.NON_NULL) +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public record SimpleApplyRes( @NotNull - Long applyId, + Long id, @NotNull Long teamId, @@ -20,19 +23,19 @@ public record SimpleApplyRes( Long portfolioId, String portfolioName, String status, - String part, + String applyPart, Boolean isViewed ) { public static SimpleApplyRes of(Apply apply){ return SimpleApplyRes.builder() - .applyId(apply.getId()) + .id(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()) + .applyPart(apply.getPart()) .isViewed(apply.isViewed()) .build(); } 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 9f8be97..d748cd8 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 @@ -9,10 +9,10 @@ import com.gongjakso.server.domain.portfolio.enumerate.DataType; import com.gongjakso.server.domain.portfolio.vo.PortfolioData; import com.gongjakso.server.domain.portfolio.repository.PortfolioRepository; +import com.gongjakso.server.domain.team.repository.TeamRepository; import com.gongjakso.server.global.exception.ApplicationException; import com.gongjakso.server.global.exception.ErrorCode; import java.util.List; -import java.util.Locale; import com.gongjakso.server.global.util.s3.S3Client; import lombok.RequiredArgsConstructor; @@ -28,6 +28,7 @@ public class PortfolioService { private final PortfolioRepository portfolioRepository; private final S3Client s3Client; private final String S3_PORTFOLIO_DIR_NAME = "portfolio"; + private final TeamRepository teamRepository; // PortfolioName 생성 로직을 분리 @@ -123,7 +124,7 @@ public PortfolioRes registerPortfolio(Member member, PortfolioReq portfolioReq) public PortfolioRes getPortfolio(Member member, Long portfolioId) { Portfolio portfolio = portfolioRepository.findByIdAndDeletedAtIsNull(portfolioId) .orElseThrow(() -> new ApplicationException(ErrorCode.PORTFOLIO_NOT_FOUND_EXCEPTION)); - if (!portfolio.getMember().getId().equals(member.getId())) { + if (!portfolio.getMember().getId().equals(member.getId()) && !teamRepository.equalsLeaderIdAndMember(portfolio, member)) { throw new ApplicationException(ErrorCode.FORBIDDEN_EXCEPTION); } diff --git a/src/main/java/com/gongjakso/server/domain/team/repository/TeamRepositoryCustom.java b/src/main/java/com/gongjakso/server/domain/team/repository/TeamRepositoryCustom.java index 22d23ee..731251e 100644 --- a/src/main/java/com/gongjakso/server/domain/team/repository/TeamRepositoryCustom.java +++ b/src/main/java/com/gongjakso/server/domain/team/repository/TeamRepositoryCustom.java @@ -1,5 +1,7 @@ package com.gongjakso.server.domain.team.repository; +import com.gongjakso.server.domain.member.entity.Member; +import com.gongjakso.server.domain.portfolio.entity.Portfolio; import com.gongjakso.server.domain.team.dto.response.SimpleTeamRes; import com.gongjakso.server.domain.team.entity.Team; import org.springframework.data.domain.Page; @@ -22,4 +24,6 @@ public interface TeamRepositoryCustom { Page findParticipatePagination(Long memberId, Pageable pageable); Page findScrapPagination(Long memberId, Pageable pageable); + + Boolean equalsLeaderIdAndMember(Portfolio portfolio, Member member); } 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 bb67f36..15dac78 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 @@ -1,5 +1,7 @@ package com.gongjakso.server.domain.team.repository; +import com.gongjakso.server.domain.member.entity.Member; +import com.gongjakso.server.domain.portfolio.entity.Portfolio; import com.gongjakso.server.domain.team.dto.response.SimpleTeamRes; import com.gongjakso.server.domain.team.entity.Team; import com.gongjakso.server.domain.team.enumerate.TeamStatus; @@ -265,4 +267,22 @@ private List> getSort(Pageable pageable) { return orderSpecifierList; } + + public Boolean equalsLeaderIdAndMember(Portfolio portfolio, Member member) { + BooleanBuilder booleanBuilder = new BooleanBuilder(); + + booleanBuilder.and(apply.portfolioInfo.portfolio.isNotNull()) + .and(apply.portfolioInfo.portfolio.eq(portfolio)) + .and(apply.deletedAt.isNull()) + .and(team.deletedAt.isNull()); + + booleanBuilder.and(team.member.eq(member)); + + return queryFactory + .selectOne() + .from(apply) + .join(apply.team, team) + .where(booleanBuilder) + .fetchFirst() != null; + } }