Skip to content

Commit

Permalink
fix: 그룹스케줄, 개인스케줄 request 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
SangWoon123 committed May 31, 2024
1 parent a4cf802 commit 2d4437f
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.tukorea.planding.common.CommonResponse;
import com.tukorea.planding.common.CommonUtils;
import com.tukorea.planding.domain.schedule.dto.request.GroupScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.response.GroupScheduleResponse;
import com.tukorea.planding.domain.schedule.service.GroupScheduleService;
import com.tukorea.planding.domain.schedule.dto.request.ScheduleRequest;
Expand Down Expand Up @@ -51,8 +52,8 @@ public CommonResponse<GroupScheduleResponse> getGroupSchedule(@PathVariable Long

@Operation(summary = "그룹 스케줄: 스케줄 수정")
@PatchMapping("/api/v1/group-rooms/{groupRoomId}/{scheduleId}")
public CommonResponse<ScheduleResponse> updateScheduleByGroupRoom(@PathVariable Long groupRoomId, @PathVariable Long scheduleId, @RequestBody ScheduleRequest scheduleRequest, @AuthenticationPrincipal UserInfo userInfo) {
ScheduleResponse scheduleResponse = groupScheduleService.updateScheduleByGroupRoom(groupRoomId, scheduleId, scheduleRequest, userInfo);
public CommonResponse<ScheduleResponse> updateScheduleByGroupRoom(@PathVariable Long groupRoomId, @PathVariable Long scheduleId, @RequestBody GroupScheduleRequest groupScheduleRequest, @AuthenticationPrincipal UserInfo userInfo) {
ScheduleResponse scheduleResponse = groupScheduleService.updateScheduleByGroupRoom(groupRoomId, scheduleId, groupScheduleRequest, userInfo);
return CommonUtils.success(scheduleResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.tukorea.planding.common.CommonResponse;
import com.tukorea.planding.common.CommonUtils;
import com.tukorea.planding.domain.schedule.dto.request.PersonalScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.response.PersonalScheduleResponse;
import com.tukorea.planding.domain.schedule.service.PersonalScheduleService;
import com.tukorea.planding.domain.user.dto.UserInfo;
Expand Down Expand Up @@ -36,8 +37,8 @@ public CommonResponse<List<ScheduleResponse>> getWeekSchedule(@AuthenticationPri

@Operation(summary = "개인 스케줄: 생성")
@PostMapping()
public CommonResponse<PersonalScheduleResponse> createSchedule(@AuthenticationPrincipal UserInfo userInfo, @RequestBody ScheduleRequest scheduleRequest) {
PersonalScheduleResponse response = personalScheduleService.createSchedule(userInfo, scheduleRequest);
public CommonResponse<PersonalScheduleResponse> createSchedule(@AuthenticationPrincipal UserInfo userInfo, @RequestBody PersonalScheduleRequest personalScheduleRequest) {
PersonalScheduleResponse response = personalScheduleService.createSchedule(userInfo, personalScheduleRequest);
return CommonUtils.success(response);
}

Expand All @@ -58,8 +59,8 @@ public CommonResponse<PersonalScheduleResponse> getScheduleById(@PathVariable(na
//TODO 아직 요구사항 미정
@Operation(summary = "개인 스케줄: 제목,내용,시작시간,끝낼시간 항목 수정")
@PatchMapping("/{schedule_id}")
public CommonResponse<PersonalScheduleResponse> updateSchedule(@PathVariable(name = "schedule_id") Long id, @RequestBody ScheduleRequest scheduleRequest, @AuthenticationPrincipal UserInfo userInfo) {
PersonalScheduleResponse scheduleResponse = personalScheduleService.updateSchedule(id, scheduleRequest, userInfo);
public CommonResponse<PersonalScheduleResponse> updateSchedule(@PathVariable(name = "schedule_id") Long id, @RequestBody PersonalScheduleRequest personalScheduleRequest, @AuthenticationPrincipal UserInfo userInfo) {
PersonalScheduleResponse scheduleResponse = personalScheduleService.updateSchedule(id, personalScheduleRequest, userInfo);
return CommonUtils.success(scheduleResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record GroupScheduleRequest(
String title,
String content,
LocalDate scheduleDate,
LocalTime startTime,
LocalTime endTime
Integer startTime,
Integer endTime
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.tukorea.planding.domain.schedule.dto.request;

import lombok.Builder;

import java.time.LocalDate;

@Builder
public record PersonalScheduleRequest(
String title,
String content,
LocalDate scheduleDate,
Integer startTime,
Integer endTime
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.tukorea.planding.domain.notify.dto.NotificationScheduleRequest;
import com.tukorea.planding.domain.notify.entity.NotificationType;
import com.tukorea.planding.domain.notify.service.NotificationService;
import com.tukorea.planding.domain.schedule.dto.request.GroupScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.request.ScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.response.GroupScheduleResponse;
import com.tukorea.planding.domain.schedule.dto.response.ScheduleResponse;
Expand Down Expand Up @@ -97,11 +98,11 @@ public List<GroupScheduleResponse> getSchedulesByGroupRoom(Long groupRoomId, Use
.collect(Collectors.toList());
}

public ScheduleResponse updateScheduleByGroupRoom(Long groupRoomId, Long scheduleId, ScheduleRequest scheduleRequest, UserInfo userInfo) {
public ScheduleResponse updateScheduleByGroupRoom(Long groupRoomId, Long scheduleId, GroupScheduleRequest groupScheduleRequest, UserInfo userInfo) {
checkUserAccessToGroupRoom(groupRoomId, userInfo.getUserCode());

Schedule schedule = scheduleQueryService.findScheduleById(scheduleId);
schedule.update(scheduleRequest.title(), scheduleRequest.content(), scheduleRequest.startTime(), scheduleRequest.endTime());
schedule.update(groupScheduleRequest.title(), groupScheduleRequest.content(), groupScheduleRequest.startTime(), groupScheduleRequest.endTime());

return ScheduleResponse.from(schedule);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tukorea.planding.domain.schedule.service;

import com.tukorea.planding.domain.schedule.dto.request.PersonalScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.request.ScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.response.PersonalScheduleResponse;
import com.tukorea.planding.domain.schedule.dto.response.ScheduleResponse;
Expand Down Expand Up @@ -42,7 +43,7 @@ public List<ScheduleResponse> getAllSchedule(UserInfo userInfo, int weekOffset)
.collect(Collectors.toList());
}

public PersonalScheduleResponse createSchedule(UserInfo userInfo, ScheduleRequest scheduleRequest) {
public PersonalScheduleResponse createSchedule(UserInfo userInfo, PersonalScheduleRequest personalScheduleRequest) {
User user = userQueryService.getUserByUserCode(userInfo.getUserCode());

// 개인 스케줄 생성
Expand All @@ -52,11 +53,11 @@ public PersonalScheduleResponse createSchedule(UserInfo userInfo, ScheduleReques

Schedule newSchedule = Schedule.builder()
.personalSchedule(personalSchedule)
.title(scheduleRequest.title())
.content(scheduleRequest.content())
.scheduleDate(scheduleRequest.scheduleDate())
.startTime(scheduleRequest.startTime())
.endTime(scheduleRequest.endTime())
.title(personalScheduleRequest.title())
.content(personalScheduleRequest.content())
.scheduleDate(personalScheduleRequest.scheduleDate())
.startTime(personalScheduleRequest.startTime())
.endTime(personalScheduleRequest.endTime())
.isComplete(false)
.type(ScheduleType.PERSONAL)
.build();
Expand Down Expand Up @@ -85,7 +86,7 @@ public void deleteSchedule(UserInfo userInfo, Long scheduleId) {
}


public PersonalScheduleResponse updateSchedule(Long scheduleId, ScheduleRequest scheduleRequest, UserInfo userInfo) {
public PersonalScheduleResponse updateSchedule(Long scheduleId, PersonalScheduleRequest scheduleRequest, UserInfo userInfo) {
Schedule schedule = scheduleQueryService.findScheduleById(scheduleId);
schedule.getPersonalSchedule().checkOwnership(userInfo.getId());
schedule.update(scheduleRequest.title(), scheduleRequest.content(), scheduleRequest.startTime(), scheduleRequest.endTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tukorea.planding.domain.schedule.controller.PersonalScheduleController;
import com.tukorea.planding.domain.schedule.dto.request.PersonalScheduleRequest;
import com.tukorea.planding.domain.user.mapper.UserMapper;
import com.tukorea.planding.global.config.security.SecurityConfig;
import com.tukorea.planding.global.config.security.jwt.JwtAuthenticationFilter;
Expand Down Expand Up @@ -54,7 +55,7 @@ void createSchedule() throws Exception{
.email("test")
.build();

ScheduleRequest schedule = ScheduleRequest.builder()
PersonalScheduleRequest schedule = PersonalScheduleRequest.builder()
.title("test")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tukorea.planding.domain.schedule.controller.PersonalScheduleController;
import com.tukorea.planding.domain.schedule.dto.request.PersonalScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.request.ScheduleRequest;
import com.tukorea.planding.domain.schedule.service.PersonalScheduleService;
import com.tukorea.planding.domain.user.entity.User;
Expand Down Expand Up @@ -54,7 +55,7 @@ void createSchedule() throws Exception {
.email("test")
.build();

ScheduleRequest schedule = ScheduleRequest.builder()
PersonalScheduleRequest schedule = PersonalScheduleRequest.builder()
.title("test")
.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.tukorea.planding.domain.schedule.service;

import com.tukorea.planding.domain.schedule.dto.request.PersonalScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.request.ScheduleRequest;
import com.tukorea.planding.domain.schedule.dto.response.PersonalScheduleResponse;
import com.tukorea.planding.domain.schedule.dto.response.ScheduleResponse;
Expand Down Expand Up @@ -54,16 +55,16 @@ class PersonalScheduleServiceTest {
private User testUser;
private Schedule schedule;
private PersonalSchedule personalSchedule;
private ScheduleRequest scheduleRequest;
private PersonalScheduleRequest scheduleRequest;


@BeforeEach
void setUp() {
testUser = new User("test", "profile", "username", Role.USER, SocialType.KAKAO, null, "#test"); // 테스트용 사용자 정보 초기화
ReflectionTestUtils.setField(testUser, "id", 1L);
personalSchedule = new PersonalSchedule(testUser);
schedule = new Schedule("title", "content", LocalDate.now(), LocalTime.of(9, 0), LocalTime.of(10, 0), true, ScheduleType.PERSONAL, personalSchedule, null);
scheduleRequest = new ScheduleRequest(1L, "title", "content", LocalDate.now(), LocalTime.of(9, 0), LocalTime.of(10, 0));
schedule = new Schedule("title", "content", LocalDate.now(), 9, 10, true, ScheduleType.PERSONAL, personalSchedule, null);
scheduleRequest = new PersonalScheduleRequest("title", "content", LocalDate.now(), 9, 10);
}


Expand Down Expand Up @@ -111,6 +112,6 @@ void setUp() {
@Test
public void update_스케줄수정시_endTime이startTime보다작을때() {
//given
assertThrows(IllegalArgumentException.class, () -> schedule.update(null, null, LocalTime.of(10, 0), LocalTime.of(9, 10)));
assertThrows(IllegalArgumentException.class, () -> schedule.update(null, null, 10, 9));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.tukorea.planding.domain.schedule.controller.PersonalScheduleController;
import com.tukorea.planding.domain.schedule.dto.request.PersonalScheduleRequest;
import com.tukorea.planding.domain.user.mapper.UserMapper;
import com.tukorea.planding.global.config.security.SecurityConfig;
import com.tukorea.planding.global.config.security.jwt.JwtAuthenticationFilter;
Expand Down Expand Up @@ -54,7 +55,7 @@ void createSchedule() throws Exception{
.email("test")
.build();

ScheduleRequest schedule = ScheduleRequest.builder()
PersonalScheduleRequest schedule = PersonalScheduleRequest.builder()
.title("test")
.build();

Expand Down

0 comments on commit 2d4437f

Please sign in to comment.