Skip to content

Commit

Permalink
fix: 그룹 플래너 조회 API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
SangWoon123 committed Aug 22, 2024
1 parent 8fb9eb3 commit f7d945c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<List<GroupPlannerResponse>> getPlannersByGroupRoom(@AuthenticationPrincipal UserInfo userInfo, @PathVariable String groupCode, @PathVariable Long scheduleId) {
return CommonUtils.success(groupPlannerService.getPlannersByGroupRoom(userInfo, groupCode, scheduleId));
}
}
Original file line number Diff line number Diff line change
@@ -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<Planner, Long> {

List<Planner> findBySchedule(Schedule schedule);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -141,4 +142,16 @@ private void updateUsers(Planner planner, List<String> newUserCodes) {
}
}
}

public List<GroupPlannerResponse> 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<Planner> planners = plannerRepository.findBySchedule(schedule);

return planners.stream()
.map(GroupPlannerResponse::fromEntity)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

@Builder
public record GroupScheduleResponse(
Expand All @@ -21,9 +19,7 @@ public record GroupScheduleResponse(
DayOfWeek day,
ScheduleType type,
String groupName,
List<UserScheduleAttendance> userScheduleAttendances,
List<GroupPlannerResponse> planners
) {
List<UserScheduleAttendance> userScheduleAttendances) {
public static GroupScheduleResponse from(Schedule schedule, String groupName, List<UserScheduleAttendance> attendances) {
return GroupScheduleResponse.builder()
.id(schedule.getId())
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ public record PersonalScheduleResponse(
Integer endTime,
boolean complete,
ScheduleType type,
DayOfWeek day,
List<PersonalPlannerResponse> planners
) {
DayOfWeek day
) {

public static PersonalScheduleResponse from(Schedule schedule) {
return PersonalScheduleResponse.builder()
Expand All @@ -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();
}

Expand Down

0 comments on commit f7d945c

Please sign in to comment.