From f7d945ce47a44bd6c44746a011429a3f4938f539 Mon Sep 17 00:00:00 2001 From: SangWoon123 Date: Thu, 22 Aug 2024 20:59:37 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B7=B8=EB=A3=B9=20=ED=94=8C=EB=9E=98?= =?UTF-8?q?=EB=84=88=20=EC=A1=B0=ED=9A=8C=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../planner/controller/GroupPlannerController.java | 12 ++++++++++++ .../planner/repository/PlannerRepository.java | 5 +++++ .../domain/planner/service/GroupPlannerService.java | 13 +++++++++++++ .../dto/response/GroupScheduleResponse.java | 9 +-------- .../dto/response/PersonalScheduleResponse.java | 8 ++------ 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/tukorea/planding/domain/planner/controller/GroupPlannerController.java b/src/main/java/com/tukorea/planding/domain/planner/controller/GroupPlannerController.java index f3d6ad3..4a01f11 100644 --- a/src/main/java/com/tukorea/planding/domain/planner/controller/GroupPlannerController.java +++ b/src/main/java/com/tukorea/planding/domain/planner/controller/GroupPlannerController.java @@ -2,18 +2,24 @@ import com.tukorea.planding.common.CommonResponse; import com.tukorea.planding.common.CommonUtils; +import com.tukorea.planding.domain.planner.dto.GroupPlannerResponse; import com.tukorea.planding.domain.planner.dto.PlannerDeleteRequest; import com.tukorea.planding.domain.planner.dto.PlannerRequest; import com.tukorea.planding.domain.planner.dto.PlannerUpdateRequest; import com.tukorea.planding.domain.planner.service.GroupPlannerService; +import com.tukorea.planding.domain.user.dto.UserInfo; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.messaging.handler.annotation.DestinationVariable; import org.springframework.messaging.handler.annotation.MessageMapping; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.messaging.simp.stomp.StompHeaderAccessor; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; +import java.util.List; + @Tag(name = "GroupPlanner", description = "그룹플래너") @RestController @RequiredArgsConstructor @@ -41,4 +47,10 @@ public CommonResponse updatePlanner(StompHeaderAccessor accessor, @Destinatio String userCode = accessor.getSessionAttributes().get("userCode").toString(); return CommonUtils.success(groupPlannerService.updateGroupPlanner(userCode, groupCode, request)); } + + @Operation(summary = "그룹 스케줄 플래너: 조회") + @GetMapping("/api/v1/group-rooms/{groupCode}/planner/{scheduleId}") + public CommonResponse> getPlannersByGroupRoom(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode, @PathVariable Long scheduleId) { + return CommonUtils.success(groupPlannerService.getPlannersByGroupRoom(userInfo, groupCode, scheduleId)); + } } diff --git a/src/main/java/com/tukorea/planding/domain/planner/repository/PlannerRepository.java b/src/main/java/com/tukorea/planding/domain/planner/repository/PlannerRepository.java index 9367463..6578473 100644 --- a/src/main/java/com/tukorea/planding/domain/planner/repository/PlannerRepository.java +++ b/src/main/java/com/tukorea/planding/domain/planner/repository/PlannerRepository.java @@ -1,7 +1,12 @@ package com.tukorea.planding.domain.planner.repository; import com.tukorea.planding.domain.planner.entity.Planner; +import com.tukorea.planding.domain.schedule.entity.Schedule; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface PlannerRepository extends JpaRepository { + + List findBySchedule(Schedule schedule); } diff --git a/src/main/java/com/tukorea/planding/domain/planner/service/GroupPlannerService.java b/src/main/java/com/tukorea/planding/domain/planner/service/GroupPlannerService.java index 162bd68..6967e32 100644 --- a/src/main/java/com/tukorea/planding/domain/planner/service/GroupPlannerService.java +++ b/src/main/java/com/tukorea/planding/domain/planner/service/GroupPlannerService.java @@ -12,6 +12,7 @@ import com.tukorea.planding.domain.schedule.entity.Action; import com.tukorea.planding.domain.schedule.entity.Schedule; import com.tukorea.planding.domain.schedule.service.ScheduleQueryService; +import com.tukorea.planding.domain.user.dto.UserInfo; import com.tukorea.planding.domain.user.entity.User; import com.tukorea.planding.domain.user.service.UserQueryService; import com.tukorea.planding.global.error.BusinessException; @@ -141,4 +142,16 @@ private void updateUsers(Planner planner, List newUserCodes) { } } } + + public List getPlannersByGroupRoom(UserInfo userInfo, String groupCode, Long scheduleId) { + if (!userGroupQueryService.checkUserAccessToGroupRoom(groupCode, userInfo.getUserCode())) { + throw new BusinessException(ErrorCode.ACCESS_DENIED); + } + Schedule schedule = scheduleQueryService.findScheduleById(scheduleId); + List planners = plannerRepository.findBySchedule(schedule); + + return planners.stream() + .map(GroupPlannerResponse::fromEntity) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/com/tukorea/planding/domain/schedule/dto/response/GroupScheduleResponse.java b/src/main/java/com/tukorea/planding/domain/schedule/dto/response/GroupScheduleResponse.java index c66bf72..0ced7d1 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/dto/response/GroupScheduleResponse.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/dto/response/GroupScheduleResponse.java @@ -1,6 +1,5 @@ package com.tukorea.planding.domain.schedule.dto.response; -import com.tukorea.planding.domain.planner.dto.GroupPlannerResponse; import com.tukorea.planding.domain.schedule.entity.Schedule; import com.tukorea.planding.domain.schedule.entity.ScheduleType; import lombok.Builder; @@ -8,7 +7,6 @@ import java.time.DayOfWeek; import java.time.LocalDate; import java.util.List; -import java.util.stream.Collectors; @Builder public record GroupScheduleResponse( @@ -21,9 +19,7 @@ public record GroupScheduleResponse( DayOfWeek day, ScheduleType type, String groupName, - List userScheduleAttendances, - List planners -) { + List userScheduleAttendances) { public static GroupScheduleResponse from(Schedule schedule, String groupName, List attendances) { return GroupScheduleResponse.builder() .id(schedule.getId()) @@ -36,9 +32,6 @@ public static GroupScheduleResponse from(Schedule schedule, String groupName, Li .type(ScheduleType.GROUP) .groupName(groupName) .userScheduleAttendances(attendances) - .planners(schedule.getPlanners().stream() - .map(GroupPlannerResponse::fromEntity) - .collect(Collectors.toList())) .build(); } } diff --git a/src/main/java/com/tukorea/planding/domain/schedule/dto/response/PersonalScheduleResponse.java b/src/main/java/com/tukorea/planding/domain/schedule/dto/response/PersonalScheduleResponse.java index 2505263..455df5f 100644 --- a/src/main/java/com/tukorea/planding/domain/schedule/dto/response/PersonalScheduleResponse.java +++ b/src/main/java/com/tukorea/planding/domain/schedule/dto/response/PersonalScheduleResponse.java @@ -22,9 +22,8 @@ public record PersonalScheduleResponse( Integer endTime, boolean complete, ScheduleType type, - DayOfWeek day, - List planners -) { + DayOfWeek day + ) { public static PersonalScheduleResponse from(Schedule schedule) { return PersonalScheduleResponse.builder() @@ -37,9 +36,6 @@ public static PersonalScheduleResponse from(Schedule schedule) { .complete(schedule.isComplete()) .day(schedule.getScheduleDate().getDayOfWeek()) .type(ScheduleType.PERSONAL) - .planners(schedule.getPlanners().stream() - .map(PersonalPlannerResponse::fromEntity) - .collect(Collectors.toList())) .build(); }