Skip to content

Commit

Permalink
#25 controller,Dto,Service 기본 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
sycuuui committed Jan 30, 2024
1 parent 6c04468 commit 2b174db
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.gongjakso.server.domain.apply.controller;

import com.gongjakso.server.domain.apply.dto.AddApplyReq;
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.repository.ApplyRepository;
import com.gongjakso.server.domain.apply.service.ApplyService;
import com.gongjakso.server.global.common.ApplicationResponse;
Expand All @@ -20,13 +21,14 @@ public class ApplyController {
private final ApplyRepository applyRepository;
//지원 요청 api
@PostMapping("/{post_id}")
public ApplicationResponse<Void> addApply(@AuthenticationPrincipal PrincipalDetails principalDetails, @PathVariable("post_id") Long postId, @RequestBody AddApplyReq req){
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<Void> getApply(@PathVariable("post_id") Long postId, @RequestBody AddApplyReq req){
return ApplicationResponse.ok();
public ApplicationResponse<ApplyRes> getApply(@PathVariable("post_id") Long postId){
return applyService.findApply(postId);
}
@PatchMapping("/{apply_id}/open")
public ApplicationResponse<Void> updateIsOpenStatus(@AuthenticationPrincipal PrincipalDetails principalDetails,@PathVariable("apply_id") Long applyId){
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/gongjakso/server/domain/apply/dto/ApplyList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.gongjakso.server.domain.member.entity.Member;
import com.gongjakso.server.domain.post.entity.Post;

public record AddApplyReq(
public record ApplyReq(
String application,
String recruit_part,
String type,
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/gongjakso/server/domain/apply/dto/ApplyRes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.gongjakso.server.domain.apply.dto;

import com.gongjakso.server.domain.apply.entity.Apply;
import com.gongjakso.server.domain.post.entity.Post;

import java.time.LocalDate;
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, Apply apply,int current_person,List<ApplyList> apply_list){
return new ApplyRes(post.getStartDate(),post.getEndDate(),post.getMaxPerson(),current_person,apply_list);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.gongjakso.server.domain.apply.service;

import com.gongjakso.server.domain.apply.dto.AddApplyReq;
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.domain.post.service.PostService;
import com.gongjakso.server.global.common.ApplicationResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -20,7 +20,7 @@
public class ApplyService {
private final ApplyRepository applyRepository;
private final PostRepository postRepository;
public Apply save(Member member, Long post_id,AddApplyReq req){
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
Expand All @@ -30,6 +30,11 @@ public Apply save(Member member, Long post_id,AddApplyReq req){
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));

}

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);
Expand Down

0 comments on commit 2b174db

Please sign in to comment.