-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feat : TypedQuery 작성위해 의존추가 * Feat : TypedQuery 작성위해 의존추가 * Feat : DTO 변경 * Feat : 레포지토리 작성 * Feat : 리펙토링 기존 DiaryList 레포지토리의 쿼리 활용 위해 일반적인 쿼리는 분리후 재사용 * Feat : 서비스계층 추가적인 쿼리 작성없이 일기조회 기능 구현 기본적인 기능 구현 * Feat : 컨트롤러 걔층 반환하는 DTO 변경으로인한 수정 소요 * Fix : 쿼리수정 User가 날짜에있으면 조회가 안되는 버그가있어 쿼리 수정 * Fix : findMostActiveSender 매서드 수정 쿼리를 통해 데이터를 먼저 걸러와서, 불필요한 데이터 조회 안함 + 필요없는 조건문 제거 * Fix : findMostActiveSender 수정 MAX를 이용해 Sender 별로 가장 최근값을 비교해 내림차순해서 정렬하게 함
- Loading branch information
Showing
8 changed files
with
92 additions
and
139 deletions.
There are no files selected for viewing
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
18 changes: 0 additions & 18 deletions
18
src/main/java/com/kuit/chatdiary/dto/DateInquiryResponse.java
This file was deleted.
Oops, something went wrong.
67 changes: 0 additions & 67 deletions
67
src/main/java/com/kuit/chatdiary/repository/CalendarInquiryRepository.java
This file was deleted.
Oops, something went wrong.
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
53 changes: 30 additions & 23 deletions
53
src/main/java/com/kuit/chatdiary/service/calendar/CalendarInquiryService.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 |
---|---|---|
@@ -1,43 +1,50 @@ | ||
package com.kuit.chatdiary.service.calendar; | ||
|
||
import com.kuit.chatdiary.domain.Diary; | ||
import com.kuit.chatdiary.domain.Sender; | ||
import com.kuit.chatdiary.dto.CalendarInquiryResponse; | ||
import com.kuit.chatdiary.dto.DateInquiryResponse; | ||
import com.kuit.chatdiary.dto.CalendarInquiryResponseDTO; | ||
import com.kuit.chatdiary.repository.diary.DiaryListRepository; | ||
import com.kuit.chatdiary.repository.statics.SenderRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import com.kuit.chatdiary.repository.CalendarInquiryRepository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.sql.Date; | ||
import java.time.LocalDate; | ||
import java.time.YearMonth; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class CalendarInquiryService { | ||
|
||
private final CalendarInquiryRepository calendarInquiryRepository; | ||
private final DiaryListRepository diaryListRepository; | ||
private final SenderRepository senderRepository; | ||
|
||
public CalendarInquiryService(CalendarInquiryRepository calendarInquiryRepository) { | ||
this.calendarInquiryRepository = calendarInquiryRepository; | ||
public boolean existsDiary(long memberId, java.util.Date diaryDate) { | ||
List<Diary> diaries = diaryListRepository.getDiaries(memberId, diaryDate, diaryDate); | ||
return !diaries.isEmpty(); | ||
} | ||
|
||
public List<DateInquiryResponse> existsChatByMonth(long memberId, YearMonth month) { | ||
Map<LocalDate, List<CalendarInquiryResponse>> chatExistsByMonth = calendarInquiryRepository.existsChatByMonth(memberId, month); | ||
|
||
List<DateInquiryResponse> list = new ArrayList<>(); | ||
/**각 요소들에 대해 반복*/ | ||
for(Map.Entry<LocalDate, List<CalendarInquiryResponse>> entry : chatExistsByMonth.entrySet()) { | ||
List<LocalDate> dates = new ArrayList<>(); | ||
/**키 값 받아서 리스트에 저장*/ | ||
dates.add(entry.getKey()); | ||
DateInquiryResponse response = new DateInquiryResponse(dates, entry.getValue()); | ||
list.add(response); | ||
} | ||
return list; | ||
} | ||
public List<CalendarInquiryResponseDTO> getCalendarInquiryResponses(long memberId, LocalDate startDate, LocalDate endDate) { | ||
List<CalendarInquiryResponseDTO> responses = new ArrayList<>(); | ||
|
||
for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusDays(1)) { | ||
Date diaryDate = Date.valueOf(date); | ||
boolean exists = existsDiary(memberId, diaryDate); | ||
Sender sender = senderRepository.findMostActiveSender(memberId, diaryDate); | ||
responses.add(new CalendarInquiryResponseDTO(diaryDate.toString(), sender, exists)); | ||
} | ||
|
||
return responses; | ||
} | ||
|
||
|
||
} | ||
public List<CalendarInquiryResponseDTO> getCalendarInquiryResponses(long memberId, YearMonth month) { | ||
LocalDate startDate = month.atDay(1); | ||
LocalDate endDate = month.atEndOfMonth(); | ||
return getCalendarInquiryResponses(memberId, startDate, endDate); | ||
} | ||
} |