Skip to content

Commit 7fe7981

Browse files
authored
Merge pull request #148 from prgrms-web-devcourse-final-project/feature/EA3-112-calender
[EA3-112] fix: 날짜별 조회 날짜 계산 로직 수정 및 일정 등록 시 Id 값 반환
2 parents f8c1910 + 1016648 commit 7fe7981

File tree

8 files changed

+24
-28
lines changed

8 files changed

+24
-28
lines changed

src/main/java/grep/neogul_coder/domain/calender/controller/PersonalCalendarController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public class PersonalCalendarController implements PersonalCalendarSpecification
2020

2121
// 사용자 개인 일정 등록 API
2222
@PostMapping
23-
public ApiResponse<Void> create(
23+
public ApiResponse<Long> create(
2424
@PathVariable("userId") Long userId,
2525
@Valid @RequestBody PersonalCalendarRequest request) {
26-
personalCalendarService.create(userId, request);
27-
return ApiResponse.noContent();
26+
Long calendarId = personalCalendarService.create(userId, request);
27+
return ApiResponse.success(calendarId); // 생성된 일정 ID 반환
2828
}
2929

3030
// 사용자 개인 일정 전체 조회 API

src/main/java/grep/neogul_coder/domain/calender/controller/PersonalCalendarSpecification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public interface PersonalCalendarSpecification {
2020
summary = "개인 일정 생성",
2121
description = "사용자의 개인 일정을 생성합니다.\n\n예: `/api/users/{userId}/calendar`"
2222
)
23-
ApiResponse<Void> create(
23+
ApiResponse<Long> create(
2424
@Parameter(name = "userId", description = "사용자 ID", required = true, in = ParameterIn.PATH)
2525
@PathVariable("userId") Long userId,
2626
@RequestBody PersonalCalendarRequest request

src/main/java/grep/neogul_coder/domain/calender/controller/TeamCalendarController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public class TeamCalendarController implements TeamCalendarSpecification {
2323

2424
// 팀 일정 생성
2525
@PostMapping
26-
public ApiResponse<Void> create(
26+
public ApiResponse<Long> create(
2727
@AuthenticationPrincipal(expression = "userId") Long userId, // 인증된 사용자의 ID를 자동 주입받음
2828
@PathVariable("studyId") Long studyId,
2929
@Valid @RequestBody TeamCalendarRequest request
3030
) {
31-
teamCalendarService.create(studyId, userId, request);
32-
return ApiResponse.noContent();
31+
Long calendarId = teamCalendarService.create(studyId, userId, request);
32+
return ApiResponse.success(calendarId); // 생성된 일정 ID 반환
3333
}
3434

3535
// 전체 일정 조회 API

src/main/java/grep/neogul_coder/domain/calender/controller/TeamCalendarSpecification.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ApiResponse<List<TeamCalendarResponse>> findByDate(
4848
description = "특정 팀 ID에 새로운 일정을 생성합니다.\n\n" +
4949
"예: `/api/teams/{studyId}/calendar`"
5050
)
51-
ApiResponse<Void> create(
51+
ApiResponse<Long> create(
5252
@Parameter(hidden = true) @AuthenticationPrincipal Long userId,
5353
@Parameter(name = "studyId", description = "일정을 생성할 팀 ID", required = true, in = ParameterIn.PATH)
5454
@PathVariable("studyId") Long studyId,

src/main/java/grep/neogul_coder/domain/calender/repository/PersonalCalendarQueryRepository.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,10 @@ public class PersonalCalendarQueryRepository {
2020

2121
private final JPAQueryFactory queryFactory;
2222

23-
public List<PersonalCalendar> findByUserIdAndDate(Long userId, LocalDate date) {
23+
public List<PersonalCalendar> findByUserIdAndDate(Long userId, LocalDateTime start, LocalDateTime end) {
2424
// Q타입 : 쿼리DSL 에서 사용하는 엔티티 기반 쿼리 클래스
2525
QPersonalCalendar pc = QPersonalCalendar.personalCalendar;
2626

27-
// 조회 기준 : 하루의 시작과 끝 시간
28-
LocalDateTime start = date.atStartOfDay(); // 00:00:00
29-
LocalDateTime end = date.atTime(LocalTime.MAX); // 23:59:59.999
30-
3127
// 쿼리 실행:
3228
// 해당 유저의 일정 중
3329
// 시작 시간 <= 당일 끝시간 이고
@@ -38,7 +34,7 @@ public List<PersonalCalendar> findByUserIdAndDate(Long userId, LocalDate date) {
3834
.where(
3935
pc.userId.eq(userId),
4036
pc.activated.eq(true),
41-
calendar.scheduledStart.loe(end),
37+
calendar.scheduledStart.lt(end),
4238
calendar.scheduledEnd.goe(start)
4339
)
4440
.fetch();

src/main/java/grep/neogul_coder/domain/calender/repository/TeamCalendarQueryRepository.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ public class TeamCalendarQueryRepository {
2020

2121
private final JPAQueryFactory queryFactory;
2222

23-
public List<TeamCalendar> findByStudyIdAndDate(Long studyId, LocalDate date) {
23+
public List<TeamCalendar> findByStudyIdAndDate(Long studyId, LocalDateTime start, LocalDateTime end) {
2424
// 쿼리DSL용 Q타입: 팀 캘린더
2525
QTeamCalendar tc = QTeamCalendar.teamCalendar;
2626

27-
LocalDateTime start = date.atStartOfDay(); // 00:00:00
28-
LocalDateTime end = date.atTime(LocalTime.MAX); // 23:59:59.999...
29-
3027
// 쿼리:
3128
// - 해당 studyId인 팀 일정 중
3229
// - 일정 시작이 하루 끝 이전
@@ -37,7 +34,7 @@ public List<TeamCalendar> findByStudyIdAndDate(Long studyId, LocalDate date) {
3734
.where(
3835
tc.studyId.eq(studyId),
3936
tc.activated.eq(true),
40-
calendar.scheduledStart.loe(end),
37+
calendar.scheduledStart.lt(end),
4138
calendar.scheduledEnd.goe(start)
4239
)
4340
.fetch();

src/main/java/grep/neogul_coder/domain/calender/service/PersonalCalendarService.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@ public List<PersonalCalendarResponse> findAll(Long userId) {
4545
// 특정 날짜의 일정 필터링해서 조회
4646
public List<PersonalCalendarResponse> findByDate(Long userId, LocalDate date) {
4747
User user = userService.get(userId);
48-
49-
LocalDateTime startOfDay = date.atStartOfDay(); // 00:00:00
50-
LocalDateTime endOfDay = date.atTime(LocalTime.MAX); // 23:59:59.999999999
48+
LocalDateTime start = date.atStartOfDay(); // 2025-07-23 00:00
49+
LocalDateTime end = date.plusDays(1).atStartOfDay(); // 2025-07-24 00:00
5150

5251
return personalCalendarQueryRepository
53-
.findByUserIdAndDate(userId, date).stream()
52+
.findByUserIdAndDate(userId, start, end).stream()
5453
.map(pc -> PersonalCalendarResponse.from(pc, user))
5554
.toList();
5655
}
5756

5857
// 개인 일정 생성
5958
@Transactional
60-
public void create(Long userId, PersonalCalendarRequest request) {
59+
public Long create(Long userId, PersonalCalendarRequest request) {
6160
// 필수 필드 입력 안할 시 유효성 예외 발생
6261
validateRequiredFields(request); // 메서드로 분리
6362

6463
Calendar calendar = request.toCalendar();
6564
PersonalCalendar personalCalendar = new PersonalCalendar(userId, calendar);
6665
personalCalendarRepository.save(personalCalendar);
66+
return calendar.getId();
6767
}
6868

6969
// 개인 일정 수정

src/main/java/grep/neogul_coder/domain/calender/service/TeamCalendarService.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ public List<TeamCalendarResponse> findAll(Long studyId) {
4545
}
4646

4747
public List<TeamCalendarResponse> findByDate(Long studyId, LocalDate date) {
48-
LocalDateTime startOfDay = date.atStartOfDay();
49-
LocalDateTime endOfDay = date.atTime(LocalTime.MAX); // 23:59:59.999..
48+
49+
LocalDateTime start = date.atStartOfDay();
50+
LocalDateTime end = date.plusDays(1).atStartOfDay();
5051

5152
return teamCalendarQueryRepository
52-
.findByStudyIdAndDate(studyId, date).stream()
53+
.findByStudyIdAndDate(studyId, start, end).stream()
5354
.map(tc -> {
5455
User user = userService.get(tc.getUserId());
5556
return TeamCalendarResponse.from(tc, user);
@@ -58,12 +59,14 @@ public List<TeamCalendarResponse> findByDate(Long studyId, LocalDate date) {
5859
}
5960

6061
@Transactional
61-
public void create(Long studyId, Long userId, TeamCalendarRequest request) {
62+
public Long create(Long studyId, Long userId, TeamCalendarRequest request) {
6263
validateRequest(request);
6364

6465
Calendar calendar = request.toCalendar();
6566
TeamCalendar teamCalendar = new TeamCalendar(studyId, userId, calendar);
6667
teamCalendarRepository.save(teamCalendar);
68+
69+
return calendar.getId();
6770
}
6871

6972
@Transactional

0 commit comments

Comments
 (0)