Skip to content

Commit

Permalink
Merge pull request #97 from prgrms-be-devcourse/dev/refactor/jobpost/#64
Browse files Browse the repository at this point in the history


pullrequest: JobPost 기능 추가 및 Apply 수정
  • Loading branch information
YooJHyun authored Oct 8, 2024
2 parents 3d68e6d + caf53c6 commit dfb7c1a
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 131 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,6 +2,7 @@

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.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -25,5 +26,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
Expand Up @@ -2,8 +2,6 @@

import com.prgrms2.java.bitta.apply.dto.ApplyDTO;
import com.prgrms2.java.bitta.member.entity.Member;
import org.springframework.http.ResponseEntity;

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

Expand All @@ -17,4 +15,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,8 @@
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.repository.JobPostRepository;
import com.prgrms2.java.bitta.jobpost.util.JobPostProvider;
import com.prgrms2.java.bitta.member.entity.Member;
import com.prgrms2.java.bitta.member.service.MemberProvider;
Expand All @@ -18,6 +20,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 +65,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,6 +1,5 @@
package com.prgrms2.java.bitta.apply.util;

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 lombok.RequiredArgsConstructor;
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;

//LIST A

Expand Down Expand Up @@ -208,4 +211,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);
}
}
11 changes: 8 additions & 3 deletions src/main/java/com/prgrms2/java/bitta/jobpost/dto/JobPostDTO.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.prgrms2.java.bitta.jobpost.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
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.member.entity.Member;
import com.prgrms2.java.bitta.jobpost.entity.ShootMethod;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -48,6 +46,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 @@ -52,8 +52,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 @@ -67,6 +72,6 @@ public boolean isClosed() {
private Media media;

// 해당 게시글에 대한 신청 목록 가져야함
@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
Expand Up @@ -19,8 +19,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
Expand Up @@ -14,5 +14,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
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -60,6 +61,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 +80,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 +103,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 +120,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
7 changes: 7 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

logging.level.org.springframework.security.web=TRACE

# File root path
file.root.path = C:\\
# File size restriction
spring.servlet.multipart.max-file-size=25MB
spring.servlet.multipart.max-request-size=50MB
Loading

0 comments on commit dfb7c1a

Please sign in to comment.