Skip to content

Commit

Permalink
refactor: JobPost 기능 추가 및 Entity 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
YooJHyun committed Oct 8, 2024
1 parent e653162 commit 88093d6
Show file tree
Hide file tree
Showing 15 changed files with 389 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,5 @@ public ResponseEntity<Map<String, String>> deleteApply(@Valid @PathVariable("id"
applyService.delete(id);
return ResponseEntity.ok(Map.of("message", "삭제가 완료되었습니다"));
}

}
4 changes: 2 additions & 2 deletions src/main/java/com/prgrms2/java/bitta/apply/dto/ApplyDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

@Builder
@Data
@NoArgsConstructor // 기본 생성자 추가
@AllArgsConstructor // 모든 필드를 받는 생성자 추가
@NoArgsConstructor
@AllArgsConstructor
@Schema(title = "지원서 DTO", description = "지원서 요청 및 응답에 사용하는 DTO입니다.")
public class ApplyDTO {
@Schema(title = "지원서 ID (PK)", description = "지원서의 고유 ID 입니다.", example = "1", minimum = "1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import com.prgrms2.java.bitta.apply.dto.ApplyDTO;
import com.prgrms2.java.bitta.apply.entity.Apply;
import com.prgrms2.java.bitta.jobpost.entity.JobPost;
import com.prgrms2.java.bitta.member.entity.Member;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -25,5 +29,9 @@ public interface ApplyRepository extends JpaRepository<Apply, Long> {
@Query("DELETE FROM Apply a WHERE a.id = :id")
int deleteByIdAndReturnCount(Long id);

Optional<Apply> findByIdAndMember(Long id, Member member);
@Query("SELECT a FROM Apply a WHERE a.id = :id AND a.member = :member")
Optional<ApplyDTO> findByIdAndMember(Long id, Member member);

@Query("SELECT a FROM Apply a WHERE a.jobPost = :jobPost")
List<ApplyDTO> findAllByJobPost(@Param("jobPost") JobPost jobPost);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.prgrms2.java.bitta.apply.service;

import com.prgrms2.java.bitta.apply.dto.ApplyDTO;
import com.prgrms2.java.bitta.apply.entity.Apply;
import com.prgrms2.java.bitta.jobpost.entity.JobPost;
import com.prgrms2.java.bitta.member.entity.Member;
import jakarta.validation.Valid;
import org.springframework.http.ResponseEntity;

import java.util.List;
Expand All @@ -17,4 +20,6 @@ public interface ApplyService {
ApplyDTO read(Long id);

ApplyDTO readByIdAndMember(Long id, Member member);

List<ApplyDTO> getApplyForJobPost(Long jobPostId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import com.prgrms2.java.bitta.apply.entity.Apply;
import com.prgrms2.java.bitta.apply.exception.ApplyException;
import com.prgrms2.java.bitta.apply.repository.ApplyRepository;
import com.prgrms2.java.bitta.jobpost.entity.JobPost;
import com.prgrms2.java.bitta.jobpost.exception.JobPostException;
import com.prgrms2.java.bitta.jobpost.repository.JobPostRepository;
import com.prgrms2.java.bitta.jobpost.util.JobPostProvider;
import com.prgrms2.java.bitta.member.dto.MemberProvider;
import com.prgrms2.java.bitta.member.entity.Member;
Expand All @@ -18,6 +21,7 @@
@RequiredArgsConstructor
public class ApplyServiceImpl implements ApplyService {
private final ApplyRepository applyRepository;
private final JobPostRepository jobPostRepository;
private final MemberProvider memberProvider;
private final JobPostProvider jobPostProvider;

Expand Down Expand Up @@ -62,13 +66,21 @@ public ApplyDTO read(Long id) {
return applyDTO.orElseThrow(ApplyException.NOT_FOUND::get);
}

// 게시글 작성자의 ID 값 가져오는 메서드
@Override
public ApplyDTO readByIdAndMember(Long id, Member member) {
Apply apply = applyRepository.findByIdAndMember(id, member)
.orElseThrow(ApplyException.NOT_FOUND::get);
return entityToDto(apply);
Optional<ApplyDTO> applyDTO = applyRepository.findByIdAndMember(id, member);
return applyDTO.orElseThrow(ApplyException.NOT_FOUND::get);
}

@Override
public List<ApplyDTO> getApplyForJobPost(Long jobPostId) {
JobPost jobPost = jobPostRepository.findById(jobPostId).orElseThrow();

List<ApplyDTO> apply = applyRepository.findAllByJobPost(jobPost);

return apply;
}

private Apply dtoToEntity(ApplyDTO applyDTO) {
return Apply.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.prgrms2.java.bitta.jobpost.controller;

import com.prgrms2.java.bitta.apply.dto.ApplyDTO;
import com.prgrms2.java.bitta.apply.service.ApplyService;
import com.prgrms2.java.bitta.jobpost.dto.JobPostDTO;
import com.prgrms2.java.bitta.global.dto.PageRequestDTO;
import com.prgrms2.java.bitta.jobpost.service.JobPostService;
Expand All @@ -14,20 +16,21 @@
import lombok.extern.log4j.Log4j2;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static com.prgrms2.java.bitta.global.constants.ApiResponses.*;

@Tag(name = "일거리 API 컨트롤러", description = "일거리와 관련된 REST API를 제공하는 컨틀롤러입니다.")
@Tag(name = "일거리 API 컨트롤러", description = "일거리와 관련된 REST API를 제공하는 컨트롤러입니다.")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/job-post")
@Log4j2
public class JobPostController {
private final JobPostService jobPostService;
private final ApplyService applyService;

@Operation(
summary = "전체 일거리 조회",
Expand Down Expand Up @@ -202,4 +205,22 @@ public ResponseEntity<Map<String, String>> deleteJobPost(@Valid @PathVariable("i
jobPostService.remove(id);
return ResponseEntity.ok(Map.of("message", "삭제가 완료되었습니다"));
}

@GetMapping("/member/{memberId}")
public ResponseEntity<Page<JobPostDTO>> getJobPostByMember(@PathVariable Long memberId, @ModelAttribute PageRequestDTO pageRequestDTO) {
Page<JobPostDTO> result = jobPostService.getJobPostByMember(memberId, pageRequestDTO);
return ResponseEntity.ok(result);
}

@GetMapping("/search")
public ResponseEntity<Page<JobPostDTO>> searchJobPost(@RequestParam("keyword") String keyword, @ModelAttribute PageRequestDTO pageRequestDTO) {
Page<JobPostDTO> result = jobPostService.searchJobPosts(keyword, pageRequestDTO);
return ResponseEntity.ok(result);
}

@GetMapping("/{id}/showApply")
public ResponseEntity<List<ApplyDTO>> showApplyForJobPost(@PathVariable("id") Long id) {
List<ApplyDTO> applyList = applyService.getApplyForJobPost(id);
return ResponseEntity.ok(applyList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.prgrms2.java.bitta.jobpost.entity.JobPost;
import com.prgrms2.java.bitta.jobpost.entity.Location;
import com.prgrms2.java.bitta.jobpost.entity.PayStatus;
import com.prgrms2.java.bitta.jobpost.entity.ShootMethod;
import com.prgrms2.java.bitta.member.entity.Member;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
Expand Down Expand Up @@ -48,6 +49,13 @@ public class JobPostDTO {
@Schema(title = "일거리 수정일시", description = "일거리가 수정된 날짜 및 시간입니다.", example = "2023-09-24T14:45:00")
private LocalDateTime updateAt;

@Schema(title = "촬영 방법", description = "일거리의 진행 방식입니다.", example = "FILM")
@NotNull(message = "촬영 방법은 필수적으로 입력해야 합니다")
private ShootMethod shootMethod;

@Schema(title = "오디션일", description = "오디션을 진행하는 날짜입니다.", example = "2023-09-24")
private LocalDate auditionDate;

@Schema(title = "시작일", description = "일이 시작하는 날짜입니다.", example = "2023-09-24")
private LocalDate startDate;

Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/prgrms2/java/bitta/jobpost/entity/JobPost.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ public class JobPost {
@LastModifiedDate
private LocalDateTime updatedAt; // 게시글 수정일자

private LocalDate startDate; // 이벤트의 시작일
private LocalDate endDate; // 이벤트의 종료일
@Enumerated(EnumType.STRING)
private ShootMethod shootMethod; // 촬영 방법

private LocalDate auditionDate; // 오디션 일자

private LocalDate startDate; // 촬영 기간 시작일
private LocalDate endDate; // 촬영 기간 종료일

@Transient
private boolean isClosed; // 게시글의 마감 여부
Expand All @@ -63,6 +68,6 @@ public boolean isClosed() {
}

// 해당 게시글에 대한 신청 목록 가져야함
@OneToMany(mappedBy = "jobPost", cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(mappedBy = "jobPost", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private List<Apply> apply = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.prgrms2.java.bitta.jobpost.entity;

public enum ShootMethod {
FILM, PHOTO
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.prgrms2.java.bitta.jobpost.repository;

import com.prgrms2.java.bitta.apply.dto.ApplyDTO;
import com.prgrms2.java.bitta.jobpost.dto.JobPostDTO;
import com.prgrms2.java.bitta.jobpost.entity.JobPost;
import org.springframework.data.domain.Page;
Expand All @@ -19,8 +20,13 @@ public interface JobPostRepository extends JpaRepository<JobPost, Long> {
@Query("DELETE FROM JobPost j WHERE j.id = :id")
Long deleteByIdAndReturnCount(Long id);


@Query("SELECT j FROM JobPost j ORDER BY 'id' DESC ")
Page<JobPostDTO> getList(Pageable pageable);

@Query("SELECT j FROM JobPost j WHERE j.member.id = :memberId")
Page<JobPostDTO> findJobPostByMember(@Param("memberId") Long memberId, Pageable pageable);

@Query("SELECT j FROM JobPost j WHERE LOWER(j.title) LIKE LOWER(CONCAT('%', :keyword, '%')) OR LOWER(j.description) LIKE LOWER(CONCAT('%', :keyword, '%'))")
Page<JobPostDTO> searchByKeyword(@Param("keyword") String keyword, Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.prgrms2.java.bitta.jobpost.service;

import com.prgrms2.java.bitta.apply.dto.ApplyDTO;
import com.prgrms2.java.bitta.jobpost.dto.JobPostDTO;
import com.prgrms2.java.bitta.global.dto.PageRequestDTO;
import org.springframework.data.domain.Page;

import java.util.List;

public interface JobPostService {
JobPostDTO register(JobPostDTO jobPostDTO);

Expand All @@ -14,5 +17,10 @@ public interface JobPostService {
JobPostDTO modify(JobPostDTO jobPostDTO);

Page<JobPostDTO> getList(PageRequestDTO pageRequestDTO);

Page<JobPostDTO> getJobPostByMember(Long memberId, PageRequestDTO pageRequestDTO);

Page<JobPostDTO> searchJobPosts(String keyword, PageRequestDTO pageRequestDTO);

}

Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package com.prgrms2.java.bitta.jobpost.service;

import com.prgrms2.java.bitta.apply.dto.ApplyDTO;
import com.prgrms2.java.bitta.apply.entity.Apply;
import com.prgrms2.java.bitta.apply.repository.ApplyRepository;
import com.prgrms2.java.bitta.apply.service.ApplyServiceImpl;
import com.prgrms2.java.bitta.apply.util.ApplyProvider;
import com.prgrms2.java.bitta.jobpost.dto.JobPostDTO;
import com.prgrms2.java.bitta.global.dto.PageRequestDTO;
import com.prgrms2.java.bitta.jobpost.entity.JobPost;
import com.prgrms2.java.bitta.jobpost.exception.JobPostException;
import com.prgrms2.java.bitta.jobpost.repository.JobPostRepository;
import com.prgrms2.java.bitta.member.dto.MemberProvider;
import com.prgrms2.java.bitta.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Slf4j
@Service
Expand All @@ -23,6 +31,9 @@ public class JobPostServiceImpl implements JobPostService {
private final JobPostRepository jobPostRepository;
private final MemberProvider memberProvider;
private final ApplyProvider applyProvider;
private final MemberRepository memberRepository;
private final ApplyRepository applyRepository;
private final ApplyServiceImpl applyServiceImpl;

@Override
public Page<JobPostDTO> getList(PageRequestDTO pageRequestDTO) {
Expand Down Expand Up @@ -60,6 +71,7 @@ public JobPostDTO modify(JobPostDTO jobPostDTO) {
jobPost.setDescription(jobPostDTO.getDescription());
jobPost.setLocation(jobPostDTO.getLocation());
jobPost.setPayStatus(jobPostDTO.getPayStatus());
jobPost.setShootMethod(jobPostDTO.getShootMethod());

jobPostRepository.save(jobPost);

Expand All @@ -78,6 +90,21 @@ public void remove(Long id) {
}
}

@Override // 게시자의 다른 글 검색
public Page<JobPostDTO> getJobPostByMember(Long memberId, PageRequestDTO pageRequestDTO) {
Pageable pageable = PageRequest.of(pageRequestDTO.getPage(), pageRequestDTO.getSize());

return jobPostRepository.findJobPostByMember(memberId, pageable);
}

@Override // 특정 키워드를 포함한 게시물 검색
public Page<JobPostDTO> searchJobPosts(String keyword, PageRequestDTO pageRequestDTO) {
Sort sort = Sort.by("id").descending();
Pageable pageable = pageRequestDTO.getPageable(sort);

return jobPostRepository.searchByKeyword(keyword, pageable);
}

private JobPostDTO entityToDto(JobPost jobPost) {
return JobPostDTO.builder()
.id(jobPost.getId())
Expand All @@ -86,6 +113,8 @@ private JobPostDTO entityToDto(JobPost jobPost) {
.location(jobPost.getLocation())
.payStatus(jobPost.getPayStatus())
.isClosed(jobPost.isClosed())
.shootMethod(jobPost.getShootMethod())
.auditionDate(jobPost.getAuditionDate())
.startDate(jobPost.getStartDate())
.endDate(jobPost.getEndDate())
.updateAt(jobPost.getUpdatedAt())
Expand All @@ -101,6 +130,8 @@ private JobPost dtoToEntity(JobPostDTO jobPostDTO) {
.location(jobPostDTO.getLocation())
.payStatus(jobPostDTO.getPayStatus())
.isClosed(jobPostDTO.isClosed())
.shootMethod(jobPostDTO.getShootMethod())
.auditionDate(jobPostDTO.getAuditionDate())
.startDate(jobPostDTO.getStartDate())
.endDate(jobPostDTO.getEndDate())
.updatedAt(jobPostDTO.getUpdateAt())
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ file.root.path = C:\\
# File size restriction
spring.servlet.multipart.max-file-size=25MB
spring.servlet.multipart.max-request-size=50MB
spring.servlet.multipart.max-request-size=50MB

jwt.secret=f7a4066d832529252c4a07bd6e4ecef7aa1cbceef124157ba57ff75adfb8d232
Loading

0 comments on commit 88093d6

Please sign in to comment.