From bb481135ff0dc18d4fbc753ada584dc4814702bd Mon Sep 17 00:00:00 2001 From: Mint Date: Mon, 19 Feb 2024 15:04:29 +0900 Subject: [PATCH 1/2] [#51] feat: Automate agenda item status update on meeting conclusion --- .../dnd/timeet/agenda/application/AgendaService.java | 2 +- src/main/java/org/dnd/timeet/agenda/domain/Agenda.java | 2 +- .../dnd/timeet/meeting/application/MeetingService.java | 10 ++++++++++ .../timeet/meeting/controller/MeetingController.java | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dnd/timeet/agenda/application/AgendaService.java b/src/main/java/org/dnd/timeet/agenda/application/AgendaService.java index 0eca384..d4a9e67 100644 --- a/src/main/java/org/dnd/timeet/agenda/application/AgendaService.java +++ b/src/main/java/org/dnd/timeet/agenda/application/AgendaService.java @@ -99,7 +99,7 @@ public void cancelAgenda(Long meetingId, Long agendaId) { Agenda agenda = agendaRepository.findByIdAndMeetingId(agendaId, meetingId) .orElseThrow(() -> new NotFoundError(ErrorCode.RESOURCE_NOT_FOUND, Collections.singletonMap("AgendaId", "Agenda not found"))); - agenda.delete(); + agenda.cancel(); } diff --git a/src/main/java/org/dnd/timeet/agenda/domain/Agenda.java b/src/main/java/org/dnd/timeet/agenda/domain/Agenda.java index 0f18649..2c50b4f 100644 --- a/src/main/java/org/dnd/timeet/agenda/domain/Agenda.java +++ b/src/main/java/org/dnd/timeet/agenda/domain/Agenda.java @@ -153,7 +153,7 @@ private void validateTransition(AgendaStatus... validPreviousStatuses) { Collections.singletonMap("AgendaStatus", "Invalid status transition")); } - public void cancelAgenda() { + public void cancel() { this.status = AgendaStatus.CANCELED; this.delete(); } diff --git a/src/main/java/org/dnd/timeet/meeting/application/MeetingService.java b/src/main/java/org/dnd/timeet/meeting/application/MeetingService.java index 2eddba0..0bc42f2 100644 --- a/src/main/java/org/dnd/timeet/meeting/application/MeetingService.java +++ b/src/main/java/org/dnd/timeet/meeting/application/MeetingService.java @@ -55,6 +55,16 @@ public void endMeeting(Long meetingId) { Collections.singletonMap("MeetingId", "Meeting not found"))); meeting.endMeeting(); + // 회의에서 진행중인 안건들도 모두 종료되도록 하기 + agendaRepository.findByMeetingId(meetingId) + .forEach(agenda -> { + if (agenda.getStatus().equals(AgendaStatus.INPROGRESS) || + agenda.getStatus().equals(AgendaStatus.PAUSED)) { + agenda.complete(); + } else if (agenda.getStatus().equals(AgendaStatus.PENDING)) { + agenda.cancel(); + } + }); } public Meeting addParticipantToMeeting(Long meetingId, Member member) { diff --git a/src/main/java/org/dnd/timeet/meeting/controller/MeetingController.java b/src/main/java/org/dnd/timeet/meeting/controller/MeetingController.java index 3845e24..d80ee7e 100644 --- a/src/main/java/org/dnd/timeet/meeting/controller/MeetingController.java +++ b/src/main/java/org/dnd/timeet/meeting/controller/MeetingController.java @@ -69,6 +69,7 @@ public ResponseEntity> attendMeeting( public ResponseEntity> closeMeeting( @PathVariable("meeting-id") Long meetingId) { meetingService.endMeeting(meetingId); + MeetingReportInfoResponse meetingReportInfoResponse = meetingService.createReport(meetingId); MeetingReportResponse meetingReportResponse = new MeetingReportResponse(meetingReportInfoResponse); From b76fcc1d70623c6ed2c6dced9d595b012bf4235b Mon Sep 17 00:00:00 2001 From: Mint Date: Mon, 19 Feb 2024 15:19:19 +0900 Subject: [PATCH 2/2] [#51] feat: Restrict meeting conclustion privileges to the host --- .../org/dnd/timeet/common/exception/ForbiddenError.java | 5 ++--- .../dnd/timeet/meeting/application/MeetingService.java | 9 ++++++++- .../dnd/timeet/meeting/controller/MeetingController.java | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/dnd/timeet/common/exception/ForbiddenError.java b/src/main/java/org/dnd/timeet/common/exception/ForbiddenError.java index db8a3a4..d23f647 100644 --- a/src/main/java/org/dnd/timeet/common/exception/ForbiddenError.java +++ b/src/main/java/org/dnd/timeet/common/exception/ForbiddenError.java @@ -1,13 +1,12 @@ package org.dnd.timeet.common.exception; +import java.util.Map; import lombok.Getter; import org.springframework.http.HttpStatus; -import java.util.Map; - /** - * HTTP 상태 코드 403 (Forbidden) : 금지됨 인증은 되었지만, 리소스에 접근할 권한이 없을때 발생합니다. + * HTTP 상태 코드 403 (Forbidden) : 금지됨. 인증은 되었지만, 리소스에 접근할 권한이 없을때 발생합니다. */ @Getter public class ForbiddenError extends ApiException { diff --git a/src/main/java/org/dnd/timeet/meeting/application/MeetingService.java b/src/main/java/org/dnd/timeet/meeting/application/MeetingService.java index 0bc42f2..5dac305 100644 --- a/src/main/java/org/dnd/timeet/meeting/application/MeetingService.java +++ b/src/main/java/org/dnd/timeet/meeting/application/MeetingService.java @@ -5,6 +5,7 @@ import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.dnd.timeet.agenda.domain.AgendaRepository; @@ -12,6 +13,7 @@ import org.dnd.timeet.agenda.domain.AgendaType; import org.dnd.timeet.agenda.dto.AgendaReportInfoResponse; import org.dnd.timeet.common.exception.BadRequestError; +import org.dnd.timeet.common.exception.ForbiddenError; import org.dnd.timeet.common.exception.NotFoundError; import org.dnd.timeet.common.exception.NotFoundError.ErrorCode; import org.dnd.timeet.meeting.domain.Meeting; @@ -49,10 +51,15 @@ public Meeting createMeeting(MeetingCreateRequest createDto, Member member) { return meeting; } - public void endMeeting(Long meetingId) { + public void endMeeting(Long meetingId, Long memberId) { Meeting meeting = meetingRepository.findById(meetingId) .orElseThrow(() -> new NotFoundError(NotFoundError.ErrorCode.RESOURCE_NOT_FOUND, Collections.singletonMap("MeetingId", "Meeting not found"))); + // 회의의 방장인지 확인 + if (!Objects.equals(meeting.getHostMember().getId(), memberId)) { + throw new ForbiddenError(ForbiddenError.ErrorCode.ROLE_BASED_ACCESS_ERROR, + Collections.singletonMap("MemberId", "Member is not the host of the meeting")); + } meeting.endMeeting(); // 회의에서 진행중인 안건들도 모두 종료되도록 하기 diff --git a/src/main/java/org/dnd/timeet/meeting/controller/MeetingController.java b/src/main/java/org/dnd/timeet/meeting/controller/MeetingController.java index d80ee7e..0a5d2d9 100644 --- a/src/main/java/org/dnd/timeet/meeting/controller/MeetingController.java +++ b/src/main/java/org/dnd/timeet/meeting/controller/MeetingController.java @@ -7,6 +7,7 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.dnd.timeet.common.security.CustomUserDetails; +import org.dnd.timeet.common.security.annotation.ReqUser; import org.dnd.timeet.common.utils.ApiUtils; import org.dnd.timeet.common.utils.ApiUtils.ApiResult; import org.dnd.timeet.meeting.application.MeetingService; @@ -17,6 +18,7 @@ import org.dnd.timeet.meeting.dto.MeetingRemainingTimeResponse; import org.dnd.timeet.meeting.dto.MeetingReportInfoResponse; import org.dnd.timeet.meeting.dto.MeetingReportResponse; +import org.dnd.timeet.member.domain.Member; import org.dnd.timeet.member.dto.MemberInfoListResponse; import org.dnd.timeet.member.dto.MemberInfoResponse; import org.springframework.http.ResponseEntity; @@ -67,8 +69,9 @@ public ResponseEntity> attendMeeting( @PatchMapping("/{meeting-id}/end") @Operation(summary = "회의 종료", description = "회의를 종료한다.") public ResponseEntity> closeMeeting( - @PathVariable("meeting-id") Long meetingId) { - meetingService.endMeeting(meetingId); + @PathVariable("meeting-id") Long meetingId, + @ReqUser Member member) { + meetingService.endMeeting(meetingId, member.getId()); MeetingReportInfoResponse meetingReportInfoResponse = meetingService.createReport(meetingId); MeetingReportResponse meetingReportResponse = new MeetingReportResponse(meetingReportInfoResponse);