Skip to content

Commit

Permalink
Merge pull request #250 from Gongjakso/feat/apply
Browse files Browse the repository at this point in the history
fix: 포트폴리오 권한 및 지원 응답 데이터 변경
  • Loading branch information
yumzen authored Sep 24, 2024
2 parents 309cd31 + ddc6603 commit 76d1342
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,18 +14,26 @@
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,

@NotNull
Long memberId,

@NotNull
String name,

String phone,

String major,

@Nullable
Long portfolioId,

Expand All @@ -41,11 +51,11 @@ public record ApplyRes(

@Size(max = 20)
@NotNull
String part,
String applyPart,

int scrapCount,

int remainingDays,
int dDay,

LocalDate startedAt,

Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 생성 로직을 분리
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,4 +24,6 @@ public interface TeamRepositoryCustom {
Page<SimpleTeamRes> findParticipatePagination(Long memberId, Pageable pageable);

Page<SimpleTeamRes> findScrapPagination(Long memberId, Pageable pageable);

Boolean equalsLeaderIdAndMember(Portfolio portfolio, Member member);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -265,4 +267,22 @@ private List<OrderSpecifier<?>> 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;
}
}

0 comments on commit 76d1342

Please sign in to comment.