Skip to content

Commit

Permalink
Fix: 수정사항 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
yumzen committed Sep 16, 2024
1 parent 3fa0c8c commit 3e3cc09
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.gongjakso.server.domain.apply.service.ApplyService;
import com.gongjakso.server.domain.apply.dto.request.ApplyReq;
import com.gongjakso.server.domain.apply.dto.response.ApplyRes;
import com.gongjakso.server.domain.team.dto.StatusReq;
import com.gongjakso.server.domain.apply.dto.request.StatusReq;
import com.gongjakso.server.global.common.ApplicationResponse;
import com.gongjakso.server.global.security.PrincipalDetails;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -41,7 +41,7 @@ public ApplicationResponse<Page<ApplyRes>> getMyApplies(@AuthenticationPrincipal
return ApplicationResponse.ok(applyService.getMyApplies(principalDetails.getMember(), pageable));
}

@Operation(summary = "특정 지원자 지원서 가져오기", description = "특정 지원자의 지원서를 가져오는 API")
@Operation(summary = "특정 지원자 지원서 열람하기", description = "특정 지원자의 지원서를 열람하는 API")
@GetMapping("/{apply_id}")
public ApplicationResponse<ApplyRes> getApply(@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable("apply_id") Long applyId) {
Expand All @@ -56,13 +56,6 @@ public ApplicationResponse<ApplyRes> selectApply(@AuthenticationPrincipal Princi
return ApplicationResponse.ok(applyService.selectApply(principalDetails.getMember(), applyId, req));
}

@Operation(summary = "지원서 열람", description = "지원서 열람 열람 여부 관리 API")
@PatchMapping("/view/{apply_id}")
public ApplicationResponse<ApplyRes> viewApply(@AuthenticationPrincipal PrincipalDetails principalDetails,
@PathVariable("apply_id") Long applyId) {
return ApplicationResponse.ok(applyService.viewApply(principalDetails.getMember(), applyId));
}

@Operation(summary = "지원 취소", description = "지원자가 지원 취소하는 API")
@DeleteMapping("/{apply_id}")
public ApplicationResponse<Void> cancelApply(@AuthenticationPrincipal PrincipalDetails principalDetails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.gongjakso.server.domain.apply.entity.PortfolioInfo;
import com.gongjakso.server.domain.team.entity.Team;
import com.gongjakso.server.domain.apply.enumerate.ApplyStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand All @@ -17,20 +18,25 @@
public record ApplyReq(

@Nullable
@Schema(description = "포트폴리오 ID", example = "1")
Long portfolioId,

@NotNull
@Schema(description = "포트폴리오 공개 설정", example = "false")
Boolean isPrivate,

@Size(max = 500)
@Schema(description = "지원 이유", example = "저는 데이터 사이언스 과목을 수강하며 데이터에 관한 기본적인 내용들을 배우며 이런 데이터를 잘 활용하고, 이용하는 것이 중요한 역량이 될 것 같다고 판단했습니다. 그래서 관련된 역량을 쌓고자 공모전에 출품하고 싶다는 생각을 가지게 되었고, 공공데이터 공모전이 적합하다고 생각했습니다!")
String body,

@Size(max = 20)
@NotNull
@Schema(description = "지원 상태", example = "COMPLETED")
ApplyStatus status,

@Size(max = 20)
@NotNull
@Schema(description = "지원 파트", example = "기획")
String part
) {
public static Apply toEntity(ApplyReq req, Team team, Member member, @Nullable Portfolio portfolio) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.gongjakso.server.domain.team.dto;
package com.gongjakso.server.domain.apply.dto.request;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.gongjakso.server.domain.apply.enumerate.ApplyStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Builder;
Expand All @@ -12,6 +13,7 @@ public record StatusReq(

@Size(max = 20)
@NotNull
@Schema(description = "지원 상태", example = "SELECTED")
ApplyStatus status
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.fasterxml.jackson.annotation.JsonInclude;
import com.gongjakso.server.domain.apply.entity.Apply;
import com.gongjakso.server.domain.apply.enumerate.ApplyStatus;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
Expand Down Expand Up @@ -36,7 +35,7 @@ public record ApplyRes(

@Size(max = 20)
@NotNull
ApplyStatus status,
String status,

@Size(max = 20)
@NotNull
Expand Down Expand Up @@ -69,7 +68,7 @@ public static ApplyRes of(Apply apply) {
.portfolioId(apply.getPortfolioInfo().getPortfolio() != null ? apply.getPortfolioInfo().getPortfolio().getId() : null)
.portfolioTitle(apply.getPortfolioInfo().getPortfolio() != null ? apply.getPortfolioInfo().getPortfolio().getTitle() : null)
.body(apply.getBody())
.status(apply.getStatus())
.status(apply.getStatus().getDescription())
.part(apply.getPart())
.isViewed(apply.isViewed())
.deleteAt(apply.getDeletedAt())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.gongjakso.server.domain.apply.entity;

import com.gongjakso.server.domain.portfolio.entity.Portfolio;
import jakarta.persistence.Embeddable;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -17,7 +14,7 @@
@Builder
public class PortfolioInfo {

@OneToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "portfolio_id", columnDefinition = "bigint")
private Portfolio portfolio;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public enum ApplyStatus {
ACCEPTED("합격"),
REJECTED("불합격");

private final String status;
private final String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ public Page<ApplyRes> findByMemberAndPage(Member member, Pageable pageable) {
.leftJoin(apply.member).fetchJoin()
.leftJoin(apply.portfolioInfo.portfolio).fetchJoin()
.leftJoin(apply.team.member).fetchJoin()
.where(apply.member.eq(member), apply.deletedAt.isNull())
.where(apply.member.eq(member),
apply.deletedAt.isNull(),
apply.team.deletedAt.isNull(),
apply.member.deletedAt.isNull(),
apply.team.member.deletedAt.isNull(),
apply.portfolioInfo.portfolio.deletedAt.isNull())
.orderBy(apply.createdAt.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
Expand All @@ -39,7 +44,12 @@ public Page<ApplyRes> findByMemberAndPage(Member member, Pageable pageable) {
Long total = queryFactory
.select(apply.count())
.from(apply)
.where(apply.member.eq(member), apply.deletedAt.isNull())
.where(apply.member.eq(member),
apply.deletedAt.isNull(),
apply.team.deletedAt.isNull(),
apply.member.deletedAt.isNull(),
apply.team.member.deletedAt.isNull(),
apply.portfolioInfo.portfolio.deletedAt.isNull())
.fetchOne();

return new PageImpl<>(content, pageable, total != null ? total : 0L);
Expand All @@ -53,7 +63,12 @@ public Optional<Apply> findApplyDetails(Long applyId) {
.leftJoin(apply.team).fetchJoin()
.leftJoin(apply.team.member).fetchJoin()
.leftJoin(apply.portfolioInfo.portfolio).fetchJoin()
.where(apply.id.eq(applyId), apply.deletedAt.isNull())
.where(apply.id.eq(applyId),
apply.deletedAt.isNull(),
apply.team.deletedAt.isNull(),
apply.member.deletedAt.isNull(),
apply.team.member.deletedAt.isNull(),
apply.portfolioInfo.portfolio.deletedAt.isNull())
.fetchOne());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.gongjakso.server.domain.portfolio.repository.PortfolioRepository;
import com.gongjakso.server.domain.apply.dto.request.ApplyReq;
import com.gongjakso.server.domain.apply.dto.response.ApplyRes;
import com.gongjakso.server.domain.team.dto.StatusReq;
import com.gongjakso.server.domain.apply.dto.request.StatusReq;
import com.gongjakso.server.domain.apply.entity.Apply;
import com.gongjakso.server.domain.team.entity.Team;
import com.gongjakso.server.domain.apply.repository.ApplyRepository;
Expand All @@ -30,11 +30,7 @@ public class ApplyService {
private final TeamRepository teamRepository;

public ApplyRes apply(Member member, Long teamId, ApplyReq applyReq) {
//Validation: member, teamId, 지원 가능 기간인지, 리더가 지원하는지, 이미 지원했는지, 본인의 포트폴리오인지 유효성 검사
if(member == null) {
throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION);
}

//Validation: teamId, 지원 가능 기간인지, 리더가 지원하는지, 이미 지원했는지, 본인의 포트폴리오인지 유효성 검사
Team team = teamRepository.findTeamById(teamId)
.orElseThrow(() -> new ApplicationException(ErrorCode.TEAM_NOT_FOUND_EXCEPTION));

Expand Down Expand Up @@ -73,11 +69,6 @@ public ApplyRes apply(Member member, Long teamId, ApplyReq applyReq) {
}

public Page<ApplyRes> getMyApplies(Member member, Pageable pageable) {
//Validation: member 조회
if(member == null) {
throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION);
}

//Business Logic
Page<ApplyRes> applyPage = applyRepository.findByMemberAndPage(member, pageable);

Expand All @@ -90,12 +81,16 @@ public ApplyRes getApply(Member member, Long applyId) {
Apply apply = applyRepository.findApplyDetails(applyId)
.orElseThrow(() -> new ApplicationException(ErrorCode.APPLY_NOT_FOUND_EXCEPTION));

if (member == null
|| !member.getId().equals(apply.getTeam().getMember().getId())
if (!member.getId().equals(apply.getTeam().getMember().getId())
&& !member.getId().equals(apply.getMember().getId())) {
throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION);
}

if(!apply.isViewed() && member.getId().equals(apply.getTeam().getMember().getId())) {
apply.setViewed();
applyRepository.save(apply);
}

//Response
return ApplyRes.of(apply);
}
Expand All @@ -104,7 +99,7 @@ public ApplyRes selectApply(Member member, Long applyId, StatusReq req){
//Validation: Apply가 유효하지 않거나, 리더가 아닌 경우 예외 처리
Apply apply = applyRepository.findApplyDetails(applyId).orElseThrow(() -> new ApplicationException(ErrorCode.APPLY_NOT_FOUND_EXCEPTION));

if(member == null || !member.getId().equals(apply.getTeam().getMember().getId())){
if(!member.getId().equals(apply.getTeam().getMember().getId())){
throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION);
}

Expand All @@ -119,29 +114,12 @@ public ApplyRes selectApply(Member member, Long applyId, StatusReq req){
return ApplyRes.of(apply);
}

public ApplyRes viewApply(Member member, Long applyId) {
//Validation: Apply가 유효하지 않거나, 지원자나 리더가 아닌 경우 예외 처리
Apply apply = applyRepository.findApplyDetails(applyId).orElseThrow(() -> new ApplicationException(ErrorCode.APPLY_NOT_FOUND_EXCEPTION));

if(member==null || !member.getId().equals(apply.getTeam().getMember().getId())){
throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION);
}

//Business Logic
apply.setViewed();

applyRepository.save(apply);

//Response
return ApplyRes.of(apply);
}

public void cancelApply(Member member, Long applyId) {
//Validation: Apply가 유효하지 않거나, 지원자 아닌 경우 예외 처리
Apply apply = applyRepository.findByIdAndDeletedAtIsNull(applyId)
.orElseThrow(() -> new ApplicationException(ErrorCode.APPLY_NOT_FOUND_EXCEPTION));

if(member == null || !member.getId().equals(apply.getMember().getId())){
if(!member.getId().equals(apply.getMember().getId())){
throw new ApplicationException(ErrorCode.UNAUTHORIZED_EXCEPTION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

import com.gongjakso.server.domain.portfolio.entity.Portfolio;

import java.time.LocalDateTime;

public record SimplePortfolioRes(
Long PortfolioId,
String PortfolioTitle
String PortfolioTitle,
LocalDateTime modifiedAt
) {
public static SimplePortfolioRes of(Portfolio portfolio) {
return new SimplePortfolioRes(
portfolio.getId(),
portfolio.getTitle()
portfolio.getTitle(),
portfolio.getModifiedAt()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/api/v1/auth/**").permitAll()
.requestMatchers("/api/v1/member/**").authenticated()
.requestMatchers("/api/v1/contest/{contest_id}/team/**").authenticated()
.requestMatchers("/api/v2/apply/**").authenticated()
// 이외의 모든 요청은 인증 정보 필요
.anyRequest().permitAll());

Expand Down

0 comments on commit 3e3cc09

Please sign in to comment.