Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public CommonResponse<Void> close(@RequestParam LocalDate now, @RequestParam Int

@GetMapping("/meetings")
@Operation(summary = "정기모임 조회")
public CommonResponse<List<MeetingDTO.Info>> getMeetings(@RequestParam(required = false) Integer cardinal) {
List<MeetingDTO.Info> response = meetingUseCase.find(cardinal);
public CommonResponse<MeetingDTO.Infos> getMeetings(@RequestParam(required = false) Integer cardinal) {
MeetingDTO.Infos response = meetingUseCase.find(cardinal);

return CommonResponse.createSuccess(MEETING_FIND_SUCCESS.getMessage(), response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import leets.weeth.domain.schedule.domain.entity.enums.Type;

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

public class MeetingDTO {

Expand Down Expand Up @@ -31,4 +32,10 @@ public record Info(
LocalDateTime start
) {}

public record Infos(
Info thisWeek,
List<Info> meetings
) {}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package leets.weeth.domain.schedule.application.usecase;

import leets.weeth.domain.schedule.application.dto.MeetingDTO;
import leets.weeth.domain.schedule.application.dto.ScheduleDTO;

import java.util.List;
Expand All @@ -11,7 +12,7 @@ public interface MeetingUseCase {

Response find(Long userId, Long eventId);

List<Info> find(Integer cardinal);
MeetingDTO.Infos find(Integer cardinal);

void save(ScheduleDTO.Save dto, Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import leets.weeth.domain.attendance.domain.service.AttendanceGetService;
import leets.weeth.domain.attendance.domain.service.AttendanceSaveService;
import leets.weeth.domain.attendance.domain.service.AttendanceUpdateService;
import leets.weeth.domain.schedule.application.dto.MeetingDTO;
import leets.weeth.domain.schedule.application.dto.ScheduleDTO;
import leets.weeth.domain.schedule.application.mapper.MeetingMapper;
import leets.weeth.domain.schedule.domain.entity.Meeting;
Expand All @@ -24,6 +25,10 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.DayOfWeek;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요기 import문은 왜 들어갔을까요??

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

처음에 기능을 useCaseImpl에 작성을 하고 난 뒤 파일 분리해서 구현하느라 삭제를 깜빡했습니다!
지우겠습니다 👍🏻

import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.Comparator;
import java.util.List;

import static leets.weeth.domain.schedule.application.dto.MeetingDTO.Info;
Expand Down Expand Up @@ -62,20 +67,21 @@ public Response find(Long userId, Long meetingId) {
}

@Override
public List<Info> find(Integer cardinal) {
public MeetingDTO.Infos find(Integer cardinal) {
List<Meeting> meetings;

if (cardinal == null) {
meetings = meetingGetService.findAll();

} else {
meetings = meetingGetService.findMeetingByCardinal(cardinal);

}

return meetings.stream()
.map(mapper::toInfo)
.toList();
Meeting thisWeek = findThisWeek(meetings);
List<Meeting> sorted = sortMeetings(meetings);

return new MeetingDTO.Infos(
thisWeek != null ? mapper.toInfo(thisWeek) : null,
sorted.stream().map(mapper::toInfo).toList());
}

@Override
Expand Down Expand Up @@ -114,4 +120,26 @@ public void delete(Long meetingId) {
attendanceDeleteService.deleteAll(meeting);
meetingDeleteService.delete(meeting);
}

private List<Meeting> sortMeetings(List<Meeting> meetings) {
return meetings.stream()
.sorted(Comparator.comparing(Meeting::getStart).reversed())
.toList();
}


private Meeting findThisWeek(List<Meeting> meetings) {
LocalDate today = LocalDate.now();
LocalDate startOfWeek = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
LocalDate endOfWeek = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));

return meetings.stream()
.filter(m -> {
LocalDate d = m.getStart().toLocalDate();
return !d.isBefore(startOfWeek) && !d.isAfter(endOfWeek);
})
.findFirst()
.orElse(null);
}

}