-
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.
Browse files
Browse the repository at this point in the history
Feature/#47
- Loading branch information
Showing
17 changed files
with
457 additions
and
24 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
dodam-api/src/main/java/b1nd/dodamapi/recruit/RecruitController.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,52 @@ | ||
package b1nd.dodamapi.recruit; | ||
|
||
import b1nd.dodamapi.common.response.Response; | ||
import b1nd.dodamapi.common.response.ResponseData; | ||
import b1nd.dodamcore.recruit.application.RecruitService; | ||
import b1nd.dodamcore.recruit.application.dto.req.RecruitReq; | ||
import b1nd.dodamcore.recruit.application.dto.res.RecruitPageRes; | ||
import b1nd.dodamcore.recruit.application.dto.res.RecruitRes; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/recruit") | ||
@RequiredArgsConstructor | ||
public class RecruitController { | ||
|
||
private final RecruitService recruitService; | ||
|
||
@GetMapping | ||
public ResponseData<RecruitPageRes> getRecruits(@RequestParam(name = "page") int page) { | ||
RecruitPageRes recruitList = recruitService.getRecruitsByPaging(page); | ||
return ResponseData.ok("채용 의뢰서 조회 성공", recruitList); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseData<RecruitRes> getRecruitById(@PathVariable int id) { | ||
RecruitRes recruit = recruitService.getRecruitById(id); | ||
return ResponseData.ok("채용 의뢰서 단일 조회 성공", recruit); | ||
} | ||
|
||
@PostMapping | ||
public Response createRecruit(@RequestBody @Valid RecruitReq createRecruitReq) { | ||
recruitService.createRecruit(createRecruitReq); | ||
return Response.created("채용 의뢰서 작성 성공"); | ||
} | ||
|
||
@PatchMapping("/{id}") | ||
public Response modifyRecruit( | ||
@PathVariable int id, | ||
@RequestBody RecruitReq modifyRecruitReq | ||
) { | ||
recruitService.modifyRecruit(id, modifyRecruitReq); | ||
return Response.ok("채용 의뢰서 수정 성공"); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public Response deleteRecruit(@PathVariable int id) { | ||
recruitService.deleteRecruit(id); | ||
return Response.ok("채용 의뢰서 삭제 성공"); | ||
} | ||
} |
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
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
84 changes: 84 additions & 0 deletions
84
dodam-core/src/main/java/b1nd/dodamcore/recruit/application/RecruitService.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,84 @@ | ||
package b1nd.dodamcore.recruit.application; | ||
|
||
import b1nd.dodamcore.common.util.ModifyUtil; | ||
import b1nd.dodamcore.member.application.MemberSessionHolder; | ||
import b1nd.dodamcore.member.domain.entity.Member; | ||
import b1nd.dodamcore.recruit.application.dto.req.RecruitReq; | ||
import b1nd.dodamcore.recruit.application.dto.res.RecruitPageRes; | ||
import b1nd.dodamcore.recruit.application.dto.res.RecruitRes; | ||
import b1nd.dodamcore.recruit.domain.entity.Recruit; | ||
import b1nd.dodamcore.recruit.domain.exception.RecruitNotFoundException; | ||
import b1nd.dodamcore.recruit.repository.RecruitFileRepository; | ||
import b1nd.dodamcore.recruit.repository.RecruitRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class RecruitService { | ||
|
||
private final RecruitRepository recruitRepository; | ||
private final RecruitFileRepository recruitFileRepository; | ||
private final MemberSessionHolder memberSessionHolder; | ||
|
||
public RecruitPageRes getRecruitsByPaging(int page) { | ||
|
||
Pageable pageRequest = PageRequest.of(page - 1, 10); | ||
Page<Recruit> recruitList = recruitRepository.findAllByOrderByIdDesc(pageRequest); | ||
|
||
int pageNum = recruitList.getTotalPages() - recruitList.getNumber(); | ||
Integer nextPage = pageNum <= 1 ? null : pageNum; | ||
|
||
return RecruitPageRes.of(recruitList, nextPage); | ||
} | ||
|
||
public RecruitRes getRecruitById(int id) { | ||
|
||
Recruit recruit = recruitRepository.findByIdWithJoin(id) | ||
.orElseThrow(RecruitNotFoundException::new); | ||
|
||
return RecruitRes.of(recruit); | ||
} | ||
|
||
@Transactional(rollbackFor = Exception.class) | ||
public void createRecruit(RecruitReq createRecruitReq) { | ||
|
||
Member member = memberSessionHolder.current(); | ||
Recruit recruit = createRecruitReq.mapToRecruit(member); | ||
|
||
recruitRepository.save(recruit); | ||
} | ||
|
||
@Transactional(rollbackFor = Exception.class) | ||
public void modifyRecruit(int id, RecruitReq dto) { | ||
|
||
Recruit recruit = recruitRepository.findById(id) | ||
.orElseThrow(RecruitNotFoundException::new); | ||
|
||
recruitFileRepository.deleteByRecruit_Id(id); | ||
|
||
recruit.updateRecruit( | ||
ModifyUtil.modifyIfNotNull(dto.name(), recruit.getName()), | ||
ModifyUtil.modifyIfNotNull(dto.location(), recruit.getLocation()), | ||
ModifyUtil.modifyIfNotNull(dto.duty(), recruit.getDuty()), | ||
ModifyUtil.modifyIfNotNull(dto.etc(), recruit.getEtc()), | ||
ModifyUtil.modifyIfNotZero(dto.personnel(), recruit.getPersonnel()), | ||
ModifyUtil.modifyIfNotNull(dto.image(), recruit.getImage()), | ||
dto.updateRecruitFile(recruit) | ||
); | ||
} | ||
|
||
@Transactional(rollbackFor = Exception.class) | ||
public void deleteRecruit(int id) { | ||
|
||
Recruit recruit = recruitRepository.findById(id) | ||
.orElseThrow(RecruitNotFoundException::new); | ||
|
||
recruitRepository.delete(recruit); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
dodam-core/src/main/java/b1nd/dodamcore/recruit/application/dto/Pdf.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,16 @@ | ||
package b1nd.dodamcore.recruit.application.dto; | ||
|
||
import b1nd.dodamcore.recruit.domain.entity.RecruitFile; | ||
import jakarta.validation.constraints.NotEmpty; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public record Pdf(@NotEmpty String url, @NotEmpty String name) { | ||
|
||
public static List<Pdf> of(List<RecruitFile> recruitFiles) { | ||
return recruitFiles.stream().map(recruitFile -> | ||
new Pdf(recruitFile.getPdfUrl(), recruitFile.getPdfName()) | ||
).collect(Collectors.toList()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
dodam-core/src/main/java/b1nd/dodamcore/recruit/application/dto/req/RecruitReq.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,47 @@ | ||
package b1nd.dodamcore.recruit.application.dto.req; | ||
|
||
import b1nd.dodamcore.member.domain.entity.Member; | ||
import b1nd.dodamcore.recruit.application.dto.Pdf; | ||
import b1nd.dodamcore.recruit.domain.entity.Recruit; | ||
import b1nd.dodamcore.recruit.domain.entity.RecruitFile; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public record RecruitReq(@NotEmpty String name, @NotEmpty String location, @NotEmpty String duty, | ||
String etc, @Positive @NotNull int personnel, @NotEmpty String image, List<Pdf> pdfs) { | ||
|
||
public Recruit mapToRecruit(Member member) { | ||
Recruit recruit = Recruit.builder() | ||
.writer(member) | ||
.name(name) | ||
.location(location) | ||
.duty(duty) | ||
.etc(etc) | ||
.personnel(personnel) | ||
.image(image) | ||
.build(); | ||
|
||
pdfs.forEach(pdf -> recruit.addRecruitFile( | ||
RecruitFile.builder() | ||
.pdfName(pdf.name()) | ||
.pdfUrl(pdf.url()) | ||
.build() | ||
)); | ||
|
||
return recruit; | ||
} | ||
|
||
public List<RecruitFile> updateRecruitFile(Recruit recruit) { | ||
return pdfs.stream().map(pdf -> | ||
RecruitFile.builder() | ||
.recruit(recruit) | ||
.pdfName(pdf.name()) | ||
.pdfUrl(pdf.url()) | ||
.build() | ||
).collect(Collectors.toList()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
dodam-core/src/main/java/b1nd/dodamcore/recruit/application/dto/res/RecruitPageRes.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,29 @@ | ||
package b1nd.dodamcore.recruit.application.dto.res; | ||
|
||
import b1nd.dodamcore.recruit.domain.entity.Recruit; | ||
import org.springframework.data.domain.Page; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public record RecruitPageRes(List<RecruitListRes> recruitList, Integer nextPage) { | ||
|
||
public static RecruitPageRes of(Page<Recruit> recruitPage, Integer nextPage) { | ||
return new RecruitPageRes(recruitPage.getContent().stream().map(recruit -> | ||
new RecruitListRes( | ||
recruit.getId(), | ||
recruit.getWriter().getName(), | ||
recruit.getName(), | ||
recruit.getLocation(), | ||
recruit.getDuty(), | ||
recruit.getEtc(), | ||
recruit.getPersonnel(), | ||
recruit.getImage() | ||
)).collect(Collectors.toList()), | ||
nextPage); | ||
} | ||
|
||
public record RecruitListRes(int id, String writer, String name, String location, String duty, | ||
String etc, int personnel, String image) { | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
dodam-core/src/main/java/b1nd/dodamcore/recruit/application/dto/res/RecruitRes.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,23 @@ | ||
package b1nd.dodamcore.recruit.application.dto.res; | ||
|
||
import b1nd.dodamcore.recruit.application.dto.Pdf; | ||
import b1nd.dodamcore.recruit.domain.entity.Recruit; | ||
|
||
import java.util.List; | ||
|
||
public record RecruitRes(String writer, String name, String location, String duty, | ||
String etc, int personnel, String image, List<Pdf> pdfs) { | ||
|
||
public static RecruitRes of(Recruit recruit) { | ||
return new RecruitRes( | ||
recruit.getWriter().getName(), | ||
recruit.getName(), | ||
recruit.getLocation(), | ||
recruit.getDuty(), | ||
recruit.getEtc(), | ||
recruit.getPersonnel(), | ||
recruit.getImage(), | ||
Pdf.of(recruit.getRecruitFiles()) | ||
); | ||
} | ||
} |
Oops, something went wrong.