Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat/#50] 회의 종료시 안건 상태 관리 및 권한 확인 작업 추가 #54

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/dnd/timeet/agenda/domain/Agenda.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

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;
import org.dnd.timeet.agenda.domain.AgendaStatus;
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;
Expand Down Expand Up @@ -49,12 +51,27 @@ 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();
// 회의에서 진행중인 안건들도 모두 종료되도록 하기
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -67,8 +69,10 @@ public ResponseEntity<ApiResult<MeetingCreateResponse>> attendMeeting(
@PatchMapping("/{meeting-id}/end")
@Operation(summary = "회의 종료", description = "회의를 종료한다.")
public ResponseEntity<ApiResult<MeetingReportResponse>> 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);

Expand Down
Loading