Skip to content

Commit

Permalink
!hotfix: inquiry, proposal 전체 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
daeun084 committed Sep 8, 2024
1 parent 33f3a5f commit b42f0ef
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/main/java/FITPET/dev/controller/InquiryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ApiResponse postInquiry(@RequestBody InquiryRequest.InquiryDto inquiryDto
public ApiResponse getInquiries(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "status", required = false) InquiryStatus inquiryStatus,
@RequestParam(name = "status", required = false, defaultValue = "all") String inquiryStatus,
@RequestParam(name = "page", required = false, defaultValue = "0") int page
){
return ApiResponse.SuccessResponse(SuccessStatus.GET_INQUIRY, inquiryService.getInquiries(startDate, endDate, inquiryStatus, page));
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/FITPET/dev/controller/ProposalController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package FITPET.dev.controller;

import FITPET.dev.common.enums.InquiryStatus;
import FITPET.dev.common.enums.ProposalStatus;
import FITPET.dev.common.status.SuccessStatus;
import FITPET.dev.common.response.ApiResponse;
Expand Down Expand Up @@ -33,7 +32,7 @@ public ApiResponse postProposal(@RequestBody ProposalRequest.ProposalDto proposa
public ApiResponse getProposals(
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate,
@RequestParam(name = "status", required = false) ProposalStatus proposalStatus,
@RequestParam(name = "status", required = false, defaultValue = "all") String proposalStatus,
@RequestParam(name = "page", required = false, defaultValue = "0") int page
){
return ApiResponse.SuccessResponse(SuccessStatus.GET_PROPOSAL, proposalService.getProposals(startDate, endDate, proposalStatus, page));
Expand Down
12 changes: 2 additions & 10 deletions src/main/java/FITPET/dev/repository/InquiryRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,16 @@
import org.springframework.data.repository.query.Param;

import java.time.LocalDateTime;
import java.util.List;

public interface InquiryRepository extends JpaRepository<Inquiry, Long> {

@Query("SELECT i FROM Inquiry i " +
"WHERE (:startDate IS NULL OR i.createdAt >= :startDate) " +
"AND (:endDate IS NULL OR i.createdAt <= :endDate) " +
"ORDER BY i.createdAt DESC ")
Page<Inquiry> findByCreatedAtBetween(@Param(value = "startDate") LocalDateTime startDate,
@Param(value = "endDate") LocalDateTime endDate, Pageable pageable);


@Query("SELECT i FROM Inquiry i " +
"WHERE (:startDate IS NULL OR i.createdAt >= :startDate) " +
"AND (:endDate IS NULL OR i.createdAt <= :endDate) " +
"AND (:status IS NULL OR i.status = :status) " +
"ORDER BY i.createdAt DESC ")
Page<Inquiry> findByCreatedAtBetweenAndStatus(@Param(value = "startDate") LocalDateTime startDate,
@Param(value = "endDate") LocalDateTime endDate,
@Param(value = "status") InquiryStatus status,Pageable pageable);
@Param(value = "status") InquiryStatus status,
Pageable pageable);
}
9 changes: 0 additions & 9 deletions src/main/java/FITPET/dev/repository/ProposalRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@
public interface ProposalRepository extends JpaRepository<Proposal, Long> {
List<Proposal> findAllByOrderByCreatedAtDesc();

@Query("SELECT p FROM Proposal p " +
"WHERE (:startDate IS NULL OR p.createdAt >= :startDate) " +
"AND (:endDate IS NULL OR p.createdAt <= :endDate) " +
"ORDER BY p.createdAt DESC ")
Page<Proposal> findByCreatedAtBetween(@Param(value = "startDate") LocalDateTime startDate,
@Param(value = "endDate") LocalDateTime endDate, Pageable pageable
);


@Query("SELECT p FROM Proposal p " +
"WHERE (:startDate IS NULL OR p.createdAt >= :startDate) " +
"AND (:endDate IS NULL OR p.createdAt <= :endDate) " +
Expand Down
13 changes: 3 additions & 10 deletions src/main/java/FITPET/dev/service/InquiryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ public InquiryResponse.InquiryDto postInquiry(InquiryRequest.InquiryDto inquiryD
* @param inquiryStatus
* @return
*/
public InquiryResponse.InquiryPageDto getInquiries(String startDate, String endDate, InquiryStatus inquiryStatus, int page){
public InquiryResponse.InquiryPageDto getInquiries(String startDate, String endDate, String inquiryStatusStr, int page){

InquiryStatus inquiryStatus = inquiryStatusStr.equals("all") ? null : InquiryStatus.valueOf(inquiryStatusStr);

// 날짜 형식 변경
LocalDateTime start = (startDate != null) ? parseDate(startDate, " 00:00:00") : minDateTime;
Expand All @@ -71,12 +73,9 @@ public InquiryResponse.InquiryPageDto getInquiries(String startDate, String endD

Page<Inquiry> inquiryPage = getInquiryListByStatusBetweenDate(start, end, inquiryStatus, pageable);
return InquiryConverter.toInquiryPageDto(inquiryPage);


}



/*
* 1:1 문의 상태 변경
* @param inquiryId
Expand Down Expand Up @@ -112,14 +111,8 @@ public void deleteInquiry(Long inquiryId) {


private Page<Inquiry> getInquiryListByStatusBetweenDate(LocalDateTime start, LocalDateTime end, InquiryStatus inquiryStatus, Pageable pageable) {

if (inquiryStatus == null){
// 특정 기간동안 생성된 inquiry List 최신순 정렬 후 반환
return inquiryRepository.findByCreatedAtBetween(start, end, pageable);
} else {
// 특정 기간동안 생성된 status 정보가 일치하는 inquiry List 최신순 정렬 후 반환
return inquiryRepository.findByCreatedAtBetweenAndStatus(start, end, inquiryStatus, pageable);
}
}

private Inquiry findInquiryById(Long inquiryId) {
Expand Down
16 changes: 3 additions & 13 deletions src/main/java/FITPET/dev/service/ProposalService.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package FITPET.dev.service;

import FITPET.dev.common.enums.InquiryStatus;
import FITPET.dev.common.enums.ProposalStatus;
import FITPET.dev.common.status.ErrorStatus;
import FITPET.dev.common.exception.GeneralException;
import FITPET.dev.converter.ProposalConverter;
import FITPET.dev.converter.ReferSiteConverter;
import FITPET.dev.dto.request.ProposalRequest;
import FITPET.dev.dto.response.ProposalResponse;
import FITPET.dev.dto.response.ReferSiteResponse;
import FITPET.dev.entity.Inquiry;
import FITPET.dev.entity.Proposal;
import FITPET.dev.entity.ReferSite;
import FITPET.dev.repository.ProposalRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand All @@ -23,7 +18,6 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.List;
import java.util.regex.Pattern;

@Service
Expand Down Expand Up @@ -62,7 +56,9 @@ public void postProposal(ProposalRequest.ProposalDto proposalDto){
* @param proposalStatus
* @return
*/
public ProposalResponse.ProposalPageDto getProposals(String startDate, String endDate, ProposalStatus proposalStatus, int page){
public ProposalResponse.ProposalPageDto getProposals(String startDate, String endDate, String proposalStatusStr, int page){

ProposalStatus proposalStatus = proposalStatusStr.equals("all") ? null : ProposalStatus.valueOf(proposalStatusStr);

// 날짜 형식 변경
LocalDateTime start = (startDate != null) ? parseDate(startDate, " 00:00:00") : minDateTime;
Expand Down Expand Up @@ -108,14 +104,8 @@ public void deleteProposal(Long proposalId) {
}

private Page<Proposal> getProposalListByStatusBetweenDate(LocalDateTime start, LocalDateTime end, ProposalStatus proposalStatus, Pageable pageable) {

if (proposalStatus == null){
// 특정 기간동안 생성된 proposal List 최신순 정렬 후 반환
return proposalRepository.findByCreatedAtBetween(start, end, pageable);
} else {
// 특정 기간동안 생성된 status 정보가 일치하는 proposal List 최신순 정렬 후 반환
return proposalRepository.findByCreatedAtBetweenAndStatus(start, end, proposalStatus, pageable);
}
}


Expand Down

0 comments on commit b42f0ef

Please sign in to comment.