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(); }