Skip to content

Commit 64d46b1

Browse files
committed
[refector] 리뷰 반영 수정
1 parent 7ca286d commit 64d46b1

4 files changed

Lines changed: 19 additions & 27 deletions

File tree

src/main/java/store/lastdance/controller/calendar/CalendarV2Controller.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public ResponseEntity<ApiResponse<CalendarResponseDTO>> createCalendar(
6565
@GetMapping("/me")
6666
public ResponseEntity<ApiResponse<List<CalendarResponseDTO>>> getMyCalendars(
6767
@RequestParam(required = false, defaultValue = "MONTHLY") String viewType,
68-
@RequestParam(required = false) LocalDateTime dateTime,
68+
@RequestParam(required = false)
69+
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
70+
LocalDateTime dateTime,
6971
@RequestParam(required = false) String type,
7072
@RequestParam(required = false) String category,
7173
@RequestParam(required = false) UUID groupId,
@@ -141,13 +143,10 @@ public ResponseEntity<ApiResponse<CalendarResponseDTO>> updateCalendar(
141143
@DeleteMapping("/{calendarId}")
142144
public ResponseEntity<ApiResponse<Void>> deleteCalendar(
143145
@PathVariable Long calendarId,
144-
@RequestParam(required = false)
145-
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
146-
LocalDateTime instanceDate,
147146
@AuthenticationPrincipal CustomOAuth2User user) {
148147

149148
try {
150-
calendarService.deleteCalendar(calendarId, instanceDate, user.getUserId());
149+
calendarService.deleteCalendar(calendarId, user.getUserId());
151150

152151
return ResponseEntity.ok(ApiResponse.success());
153152

@@ -171,7 +170,9 @@ public ResponseEntity<ApiResponse<Void>> deleteCalendar(
171170
public ResponseEntity<ApiResponse<List<CalendarResponseDTO>>> getGroupCalendars(
172171
@PathVariable UUID groupId,
173172
@RequestParam(required = false, defaultValue = "MONTHLY") String viewType,
174-
@RequestParam(required = false) LocalDateTime dateTime,
173+
@RequestParam(required = false)
174+
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
175+
LocalDateTime dateTime,
175176
@RequestParam(required = false) String type,
176177
@RequestParam(required = false) String category,
177178
@AuthenticationPrincipal CustomOAuth2User user,

src/main/java/store/lastdance/converter/calendar/CalendarConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public CalendarResponseDTO toDto(Calendar calendar, User user, Group group, Stri
5555
.isAllDay(calendar.getIsAllDay())
5656
.type(calendar.getType())
5757
.category(calendar.getCategory())
58-
.groupId(group != null ? group.getGroupId() : null)
58+
.groupId(calendar.getGroup() != null ? calendar.getGroup().getGroupId() : null)
5959
.groupName(groupName)
60-
.userId(user.getUserId())
60+
.userId(calendar.getUser() != null ? calendar.getUser().getUserId() : null)
6161
.repeatType(calendar.getRepeatType())
6262
.repeatEndDate(calendar.getRepeatEndDate())
6363
.createdAt(calendar.getCreatedAt())

src/main/java/store/lastdance/service/calendar/CalendarV2Service.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface CalendarV2Service {
1919

2020
CalendarResponseDTO updateCalendar(Long calendarId, UpdateCalendarRequestDTO request, UUID userId);
2121

22-
void deleteCalendar(Long calendarId, LocalDateTime instanceDate, UUID userId);
22+
void deleteCalendar(Long calendarId, UUID userId);
2323

2424
boolean isGroupMember(UUID groupId, UUID userId);
2525
}

src/main/java/store/lastdance/service/calendar/CalendarV2ServiceImpl.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,13 @@ public List<CalendarResponseDTO> getCalendarsByUser(UUID userId,
8181
User user = userRepository.findByUserId(userId)
8282
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
8383

84-
Group group;
84+
Group group = null;
8585
if (groupId != null){
8686
boolean isMember = isGroupMember(groupId, userId);
8787
CalendarValidator.validateGroupMembership(groupId, isMember);
8888

8989
group = groupRepository.findById(groupId)
9090
.orElseThrow(() -> new CustomException(ErrorCode.GROUP_NOT_FOUND));
91-
} else {
92-
throw new CustomException(ErrorCode.GROUP_NOT_FOUND);
9391
}
9492

9593
if (dateTime == null) {
@@ -142,7 +140,7 @@ public List<CalendarResponseDTO> getCalendarsByUser(UUID userId,
142140
UUID groupID = calendar.getGroup() != null ? calendar.getGroup().getGroupId() : null;
143141
String groupName = finalGroupNameMap.get(groupID);
144142

145-
return calendarConverter.toDto(calendar, user, group, groupName);
143+
return calendarConverter.toDto(calendar, calendar.getUser(), calendar.getGroup(), groupName);
146144
}).toList();
147145

148146
} catch (Exception e) {
@@ -165,7 +163,7 @@ public CalendarResponseDTO getCalendarById(Long calendarId, UUID userId) {
165163
Group calendarGroup = calendar.getGroup();
166164
String groupName = (calendarGroup != null) ? calendarGroup.getGroupName() : null;
167165

168-
return calendarConverter.toDto(calendar, user, calendarGroup, groupName);
166+
return calendarConverter.toDto(calendar, calendar.getUser(), calendarGroup, groupName);
169167
}
170168

171169
@Override
@@ -232,7 +230,7 @@ public CalendarResponseDTO updateCalendar(Long calendarId, UpdateCalendarRequest
232230
Group updatedGroup = updatedCalendar.getGroup();
233231
String groupName = (updatedGroup != null) ? updatedGroup.getGroupName() : null;
234232

235-
return calendarConverter.toDto(calendar, user, updatedGroup, groupName);
233+
return calendarConverter.toDto(updatedCalendar, updatedCalendar.getUser(), updatedGroup, groupName);
236234

237235
} catch (Exception e) {
238236
log.warn("그룹 일정 수정 중 오류 발생: {}", e.getMessage());
@@ -242,7 +240,7 @@ public CalendarResponseDTO updateCalendar(Long calendarId, UpdateCalendarRequest
242240

243241
@Override
244242
@Transactional
245-
public void deleteCalendar(Long calendarId, LocalDateTime instanceDate, UUID userId) {
243+
public void deleteCalendar(Long calendarId, UUID userId) {
246244
try {
247245
Calendar calendar = calendarRepository.findById(calendarId)
248246
.orElseThrow(() -> new CustomException(ErrorCode.CALENDAR_NOT_FOUND));
@@ -415,10 +413,10 @@ private DateRangeDTO calculateDateRange(String viewType, LocalDateTime baseDate)
415413

416414
case "WEEKLY" -> {
417415
LocalDateTime startOfWeek = baseDate.toLocalDate()
418-
.with(DayOfWeek.MONDAY)
416+
.with(java.time.temporal.TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY))
419417
.atStartOfDay();
420418
LocalDateTime endOfWeek = baseDate.toLocalDate()
421-
.with(DayOfWeek.SUNDAY)
419+
.with(java.time.temporal.TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY))
422420
.atTime(23, 59, 59);
423421
yield new DateRangeDTO(startOfWeek, endOfWeek);
424422
}
@@ -427,15 +425,8 @@ private DateRangeDTO calculateDateRange(String viewType, LocalDateTime baseDate)
427425
LocalDate monthStart = baseDate.toLocalDate().withDayOfMonth(1);
428426
LocalDate monthEnd = baseDate.toLocalDate().withDayOfMonth(baseDate.toLocalDate().lengthOfMonth());
429427

430-
LocalDate calendarStart = monthStart.with(DayOfWeek.SUNDAY);
431-
if (calendarStart.isAfter(monthStart)) {
432-
calendarStart = calendarStart.minusWeeks(1);
433-
}
434-
435-
LocalDate calendarEnd = monthEnd.with(DayOfWeek.SATURDAY);
436-
if (calendarEnd.isBefore(monthEnd)) {
437-
calendarEnd = calendarEnd.plusWeeks(1);
438-
}
428+
LocalDate calendarStart = monthStart.with(java.time.temporal.TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY));
429+
LocalDate calendarEnd = monthEnd.with(java.time.temporal.TemporalAdjusters.nextOrSame(DayOfWeek.SATURDAY));
439430

440431
yield new DateRangeDTO(
441432
calendarStart.atStartOfDay(),

0 commit comments

Comments
 (0)