-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Gongjakso/feat/apply
Feat/apply
- Loading branch information
Showing
10 changed files
with
173 additions
and
32 deletions.
There are no files selected for viewing
49 changes: 37 additions & 12 deletions
49
src/main/java/com/gongjakso/server/domain/apply/controller/ApplyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,51 @@ | ||
package com.gongjakso.server.domain.apply.controller; | ||
|
||
import com.gongjakso.server.domain.apply.dto.AddApplyReq; | ||
import com.gongjakso.server.domain.apply.entity.Apply; | ||
import com.gongjakso.server.domain.apply.dto.ApplyReq; | ||
import com.gongjakso.server.domain.apply.dto.ApplicationRes; | ||
import com.gongjakso.server.domain.apply.dto.ApplyRes; | ||
import com.gongjakso.server.domain.apply.service.ApplyService; | ||
import com.gongjakso.server.global.common.ApplicationResponse; | ||
import com.gongjakso.server.global.security.PrincipalDetails; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/v1/apply") | ||
@Tag(name = "Apply", description = "팀 빌딩 관련 API") | ||
public class ApplyController { | ||
private final ApplyService applyService; | ||
@PostMapping("/1") | ||
public ResponseEntity<Apply> addApply(@RequestBody AddApplyReq req){ | ||
Apply savedApply = applyService.save(req); | ||
return ResponseEntity.status(HttpStatus.CREATED).body(savedApply); | ||
//지원 요청 api | ||
@PostMapping("/{post_id}") | ||
public ApplicationResponse<Void> addApply(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId, @RequestBody ApplyReq req){ | ||
applyService.save(principalDetails.getMember(),postId,req); | ||
return ApplicationResponse.created(); | ||
} | ||
//프로젝트 지원서 요청 api | ||
@GetMapping("/{post_id}") | ||
public ApplicationResponse<ApplyRes> getApply(@PathVariable("post_id") Long postId){ | ||
return applyService.findApply(postId); | ||
} | ||
//지원서 열람 요청 api | ||
@PatchMapping("/{apply_id}/open") | ||
public ApplicationResponse<Void> updateIsOpenStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){ | ||
return applyService.updateOpen(applyId); | ||
} | ||
//지원서 지원 요청 api | ||
@PatchMapping("/{apply_id}/recruit") | ||
public ApplicationResponse<Void> updateIsRecruitStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){ | ||
return applyService.updateRecruit(applyId,true); | ||
} | ||
//지원서 미선발 요청 api | ||
@PatchMapping("/{apply_id}/not-recruit") | ||
public ApplicationResponse<Void> updateNotRecruitStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){ | ||
return applyService.updateRecruit(applyId,false); | ||
} | ||
// 특정 지원자 지원서 가져오는 api | ||
@GetMapping("/{apply_id}/application") | ||
public ApplicationResponse<ApplicationRes> findApplication(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){ | ||
return applyService.findApplication(applyId); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/gongjakso/server/domain/apply/dto/ApplicationRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.gongjakso.server.domain.apply.dto; | ||
|
||
import com.gongjakso.server.domain.apply.entity.Apply; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ApplicationRes( | ||
String application, | ||
String recruit_part | ||
// String[] category | ||
) { | ||
public static ApplicationRes of(Apply apply){ | ||
return new ApplicationRes(apply.getApplication(), apply.getRecruit_part()); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/gongjakso/server/domain/apply/dto/ApplyList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.gongjakso.server.domain.apply.dto; | ||
|
||
import com.gongjakso.server.domain.apply.entity.Apply; | ||
|
||
public record ApplyList( | ||
Long apply_id, | ||
String name, | ||
String state | ||
) { | ||
public static ApplyList of(Apply apply,String state){ | ||
return new ApplyList(apply.getApplyId(),apply.getMember().getName(),state); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 15 additions & 1 deletion
16
src/main/java/com/gongjakso/server/domain/apply/dto/ApplyRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,18 @@ | ||
package com.gongjakso.server.domain.apply.dto; | ||
|
||
public record ApplyRes() { | ||
import com.gongjakso.server.domain.post.entity.Post; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record ApplyRes( | ||
LocalDateTime startDate, | ||
LocalDateTime endDate, | ||
Long max_person, | ||
int current_person, | ||
List<ApplyList> apply_list | ||
) { | ||
public static ApplyRes of(Post post, int current_person,List<ApplyList> apply_list){ | ||
return new ApplyRes(post.getStartDate(),post.getEndDate(),post.getMaxPerson(),current_person,apply_list); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
src/main/java/com/gongjakso/server/domain/apply/repository/ApplyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package com.gongjakso.server.domain.apply.repository; | ||
|
||
import com.gongjakso.server.domain.apply.entity.Apply; | ||
import com.gongjakso.server.domain.post.entity.Post; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface ApplyRepository extends JpaRepository<Apply,Long> { | ||
} | ||
long countApplyByPost(Post post); | ||
List<Apply> findAllByPost(Post post); | ||
} |
62 changes: 59 additions & 3 deletions
62
src/main/java/com/gongjakso/server/domain/apply/service/ApplyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,74 @@ | ||
package com.gongjakso.server.domain.apply.service; | ||
|
||
import com.gongjakso.server.domain.apply.dto.AddApplyReq; | ||
import com.gongjakso.server.domain.apply.dto.ApplyList; | ||
import com.gongjakso.server.domain.apply.dto.ApplyReq; | ||
import com.gongjakso.server.domain.apply.dto.ApplicationRes; | ||
import com.gongjakso.server.domain.apply.dto.ApplyRes; | ||
import com.gongjakso.server.domain.apply.entity.Apply; | ||
import com.gongjakso.server.domain.apply.repository.ApplyRepository; | ||
import com.gongjakso.server.domain.member.entity.Member; | ||
import com.gongjakso.server.domain.post.entity.Post; | ||
import com.gongjakso.server.domain.post.repository.PostRepository; | ||
import com.gongjakso.server.global.common.ApplicationResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.stereotype.Service; | ||
import org.webjars.NotFoundException; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class ApplyService { | ||
private final ApplyRepository applyRepository; | ||
public Apply save(AddApplyReq req){ | ||
return applyRepository.save(req.toEntity()); | ||
private final PostRepository postRepository; | ||
public Apply save(Member member, Long post_id, ApplyReq req){ | ||
Post post = postRepository.findByPostId(post_id); | ||
if (post == null) { | ||
// Handle the case where the Post entity with the given post_id is not found | ||
throw new NotFoundException("Post not found with id: " + post_id); | ||
} | ||
Apply apply = req.toEntity(member, post); | ||
return applyRepository.save(apply); | ||
} | ||
|
||
public ApplicationResponse<ApplyRes> findApply(Long post_id){ | ||
Post post = postRepository.findById(post_id).orElseThrow(()->new NotFoundException("Post not found with id: " + post_id)); | ||
int current_person = (int) applyRepository.countApplyByPost(post); | ||
List<Apply> applies = applyRepository.findAllByPost(post); | ||
List<ApplyList> applyLists = applies.stream() | ||
.map(apply -> ApplyList.of(apply, decisionState(apply))) | ||
.collect(Collectors.toList()); | ||
ApplyRes applyRes = ApplyRes.of(post,current_person,applyLists); | ||
return ApplicationResponse.ok(applyRes); | ||
} | ||
private String decisionState(Apply apply){ | ||
if(apply.getIs_pass()) { | ||
return "합류 완료"; | ||
}else { | ||
if(apply.getIs_open()){ | ||
return "열람 완료"; | ||
}else { | ||
return "미선발"; | ||
} | ||
} | ||
} | ||
public ApplicationResponse<Void> updateOpen(Long apply_id){ | ||
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new NotFoundException("Apply not found with id: " + apply_id)); | ||
apply.setIs_open(true); | ||
return ApplicationResponse.ok(); | ||
} | ||
public ApplicationResponse<Void> updateRecruit(Long apply_id, Boolean isRecruit){ | ||
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new NotFoundException("Apply not found with id: " + apply_id)); | ||
apply.setIs_pass(isRecruit); | ||
return ApplicationResponse.ok(); | ||
} | ||
public ApplicationResponse<ApplicationRes> findApplication(Long apply_id){ | ||
Apply apply = applyRepository.findById(apply_id).orElseThrow(()->new NotFoundException("Apply not found with id: " + apply_id)); | ||
// ApplicationRes applicationRes = ApplicationRes.builder().application(apply.getApplication()).recruit_part(apply.getRecruit_part()).build(); | ||
ApplicationRes applicationRes = ApplicationRes.of(apply); | ||
return ApplicationResponse.ok(applicationRes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters