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#65] 안건 순서 수정 기능 개발 #66

Merged
merged 3 commits into from
Feb 21, 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
34 changes: 34 additions & 0 deletions src/main/java/org/dnd/timeet/agenda/application/AgendaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.time.Duration;
import java.time.LocalTime;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.dnd.timeet.agenda.domain.Agenda;
Expand Down Expand Up @@ -35,6 +36,7 @@ public class AgendaService {
private final AgendaRepository agendaRepository;
private final ParticipantRepository participantRepository;

@Transactional
public Long createAgenda(Long meetingId, AgendaCreateRequest createDto, Member member) {
Meeting meeting = meetingRepository.findById(meetingId)
.orElseThrow(() -> new NotFoundError(ErrorCode.RESOURCE_NOT_FOUND,
Expand All @@ -48,6 +50,8 @@ public Long createAgenda(Long meetingId, AgendaCreateRequest createDto, Member m
}

Agenda agenda = createDto.toEntity(meeting);
List<Agenda> agendaList = agendaRepository.findByMeetingId(meetingId);
agenda.setOrderNum(agendaList.size() + 1);
agenda = agendaRepository.save(agenda);

// 회의 시간 추가
Expand Down Expand Up @@ -160,6 +164,36 @@ public AgendaInfoResponse findAgendas(Long meetingId) {
.orElseThrow(() -> new NotFoundError(ErrorCode.RESOURCE_NOT_FOUND,
Collections.singletonMap("MeetingId", "Meeting not found")));
List<Agenda> agendaList = agendaRepository.findByMeetingId(meetingId);
agendaList.sort(Comparator.comparing(Agenda::getOrderNum));
return new AgendaInfoResponse(meeting, agendaList);
}

public AgendaInfoResponse changeAgendaOrder(Long meetingId, List<Long> agendaIds) {
Meeting meeting = meetingRepository.findById(meetingId)
.orElseThrow(() -> new NotFoundError(ErrorCode.RESOURCE_NOT_FOUND,
Collections.singletonMap("MeetingId", "Meeting not found")));
List<Agenda> agendaList = agendaRepository.findByMeetingId(meetingId);

if (agendaList.size() != agendaIds.size()) {
throw new BadRequestError(BadRequestError.ErrorCode.VALIDATION_FAILED,
Collections.singletonMap("AgendaIds", "Agenda Ids size is not matched"));
}
Comment on lines +177 to +180
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예외 처리 다 잘 진행되었네요 :)


if (agendaList.size() != agendaIds.stream().distinct().count()) {
throw new BadRequestError(BadRequestError.ErrorCode.VALIDATION_FAILED,
Collections.singletonMap("AgendaIds", "Agenda Ids are not unique"));
}
Comment on lines +182 to +185
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

예외 처리 좋습니다 👍


for (int i = 0; i < agendaIds.size(); i++) {
Long agendaId = agendaIds.get(i);
Agenda agenda = agendaList.stream()
.filter(a -> a.getId().equals(agendaId))
.findFirst()
.orElseThrow(() -> new NotFoundError(ErrorCode.RESOURCE_NOT_FOUND,
Collections.singletonMap("AgendaId", "Agenda Id " + agendaId + " not found")));
agenda.setOrderNum(i + 1);
}
agendaList.sort(Comparator.comparing(Agenda::getOrderNum));
Comment on lines +187 to +196
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로직 잘 짜여졌네요 !!


return new AgendaInfoResponse(meeting, agendaList);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.dnd.timeet.agenda.dto.AgendaActionResponse;
import org.dnd.timeet.agenda.dto.AgendaCreateRequest;
import org.dnd.timeet.agenda.dto.AgendaInfoResponse;
import org.dnd.timeet.agenda.dto.AgendaOrderRequest;
import org.dnd.timeet.agenda.dto.AgendaPatchRequest;
import org.dnd.timeet.agenda.dto.AgendaPatchResponse;
import org.dnd.timeet.common.security.CustomUserDetails;
Expand Down Expand Up @@ -85,6 +86,16 @@ public ResponseEntity deleteAgenda(
return ResponseEntity.noContent().build();
}

@PatchMapping("/{meeting-id}/agendas/order")
@Operation(summary = "안건 순서 변경", description = "안건의 순서를 변경한다.")
public ResponseEntity<ApiResult<AgendaInfoResponse>> changeAgendaOrder(
@PathVariable("meeting-id") Long meetingId,
@RequestBody @Valid AgendaOrderRequest agendaOrderRequest) {
AgendaInfoResponse agendaInfoResponse = agendaService.changeAgendaOrder(meetingId,
agendaOrderRequest.getAgendaIds());
return ResponseEntity.ok(ApiUtils.success(agendaInfoResponse));
}

@PatchMapping("/{meeting-id}/agendas/{agenda-id}")
@Operation(summary = "안건 수정", description = "지정된 ID에 해당하는 안건을 수정한다.")
public ResponseEntity<ApiResult<AgendaPatchResponse>> deleteAgenda(
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/dnd/timeet/agenda/domain/Agenda.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public Agenda(Meeting meeting, String title, AgendaType type, Duration allocated
this.orderNum = orderNum;
}

public void setOrderNum(Integer orderNum) {
this.orderNum = orderNum;
}

public void start() {
validateTransition(AgendaStatus.PENDING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public AgendaActionResponse(Agenda agenda, Duration currentDuration, Duration re

this.currentDuration = DurationUtils.formatDuration(currentDuration);
this.remainingDuration = DurationUtils.formatDuration(remainingDuration);

this.timestamp = DateTimeUtils.formatLocalDateTime(LocalDateTime.now());
}

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/dnd/timeet/agenda/dto/AgendaOrderRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.dnd.timeet.agenda.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Schema(description = "안건 순서 변경 요청")
@Getter
@Setter
@NoArgsConstructor
public class AgendaOrderRequest {

@Schema(description = "안건 ID 리스트", example = "[2,1,3]")
private List<Long> agendaIds;

}
Loading