diff --git a/src/main/java/com/waruru/areyouhere/attendee/controller/AttendeeController.java b/src/main/java/com/waruru/areyouhere/attendee/controller/AttendeeController.java index 6853499..28a44a2 100644 --- a/src/main/java/com/waruru/areyouhere/attendee/controller/AttendeeController.java +++ b/src/main/java/com/waruru/areyouhere/attendee/controller/AttendeeController.java @@ -1,5 +1,6 @@ package com.waruru.areyouhere.attendee.controller; +import com.waruru.areyouhere.attendee.dto.request.UpdateAttendeesRequestDto; import com.waruru.areyouhere.attendee.service.dto.AttendeeDetailDto; import com.waruru.areyouhere.attendee.dto.response.ClassAttendeesResponseDto; import com.waruru.areyouhere.attendee.dto.request.DeleteAttendeesRequestDto; @@ -16,6 +17,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -65,5 +67,12 @@ public ResponseEntity checkDuplicate(@RequestBody DuplicateC public ResponseEntity getAttendeeDetail(@RequestParam("attendeeId") Long attendeeId){ return ResponseEntity.ok(attendeeService.getAttendanceCount(attendeeId)); } + + @LoginRequired + @PutMapping + public ResponseEntity update(@RequestBody UpdateAttendeesRequestDto UpdateAttendeesRequestDto){ + attendeeService.updateAll(UpdateAttendeesRequestDto.getCourseId(), UpdateAttendeesRequestDto.getUpdatedAttendees()); + return ResponseEntity.ok().build(); + } } diff --git a/src/main/java/com/waruru/areyouhere/attendee/dto/request/UpdateAttendeesRequestDto.java b/src/main/java/com/waruru/areyouhere/attendee/dto/request/UpdateAttendeesRequestDto.java index 4458b96..03fe96e 100644 --- a/src/main/java/com/waruru/areyouhere/attendee/dto/request/UpdateAttendeesRequestDto.java +++ b/src/main/java/com/waruru/areyouhere/attendee/dto/request/UpdateAttendeesRequestDto.java @@ -2,7 +2,9 @@ import com.waruru.areyouhere.attendee.service.dto.AttendeeInfo; import java.util.List; +import lombok.Getter; +@Getter public class UpdateAttendeesRequestDto { private Long courseId; private List updatedAttendees; diff --git a/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeService.java b/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeService.java index 3dcf51b..2a7767d 100644 --- a/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeService.java +++ b/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeService.java @@ -2,6 +2,7 @@ import com.waruru.areyouhere.attendee.service.dto.AttendeeData; import com.waruru.areyouhere.attendee.service.dto.AttendeeDetailDto; +import com.waruru.areyouhere.attendee.service.dto.AttendeeInfo; import com.waruru.areyouhere.attendee.service.dto.ClassAttendees; import com.waruru.areyouhere.attendee.service.dto.DuplicateAttendees; import com.waruru.areyouhere.attendee.service.dto.SessionAttendees; @@ -24,4 +25,6 @@ public interface AttendeeService { public DuplicateAttendees getDuplicatesAll(Long courseId, List newAttendees); public AttendeeDetailDto getAttendanceCount(Long attendeeId); + + public void updateAll(Long courseId, List updatedAttendees); } diff --git a/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeServiceImpl.java b/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeServiceImpl.java index 3d7ccdc..bb48d38 100644 --- a/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeServiceImpl.java +++ b/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeServiceImpl.java @@ -194,10 +194,21 @@ public AttendeeDetailDto getAttendanceCount(Long attendeeId){ .build(); } + @Override public void updateAll(Long courseId, List updatedAttendees){ List attendees = attendeeRepository.findAttendeesByCourse_Id(courseId); Map attendeeMap = attendees.stream().collect(Collectors.toMap(Attendee::getId, attendee -> attendee)); //TODO: duplicate 처리 + + List attendeeUniqueCheck = updatedAttendees.stream() + .map(attendeeData -> + attendeeData.getName() + (attendeeData.getNote() == null ? "" : attendeeData.getNote()) + ).toList(); + + if(!isUnique(attendeeUniqueCheck, courseId)){ + throw new AttendeesNotUniqueException("참여자 이름이 중복되었습니다."); + } + updatedAttendees.stream() .map(attendee -> attendeeMap.get(attendee.getId())