Skip to content

Commit

Permalink
feat: 참가자 수정 API
Browse files Browse the repository at this point in the history
  • Loading branch information
SHEOMM committed Mar 30, 2024
1 parent c414bb6 commit 1f0036c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -65,5 +67,12 @@ public ResponseEntity<DuplicateAttendees> checkDuplicate(@RequestBody DuplicateC
public ResponseEntity<AttendeeDetailDto> getAttendeeDetail(@RequestParam("attendeeId") Long attendeeId){
return ResponseEntity.ok(attendeeService.getAttendanceCount(attendeeId));
}

@LoginRequired
@PutMapping
public ResponseEntity<HttpStatus> update(@RequestBody UpdateAttendeesRequestDto UpdateAttendeesRequestDto){
attendeeService.updateAll(UpdateAttendeesRequestDto.getCourseId(), UpdateAttendeesRequestDto.getUpdatedAttendees());
return ResponseEntity.ok().build();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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<AttendeeInfo> updatedAttendees;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,4 +25,6 @@ public interface AttendeeService {
public DuplicateAttendees getDuplicatesAll(Long courseId, List<String> newAttendees);

public AttendeeDetailDto getAttendanceCount(Long attendeeId);

public void updateAll(Long courseId, List<AttendeeInfo> updatedAttendees);
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,21 @@ public AttendeeDetailDto getAttendanceCount(Long attendeeId){
.build();
}

@Override
public void updateAll(Long courseId, List<AttendeeInfo> updatedAttendees){
List<Attendee> attendees = attendeeRepository.findAttendeesByCourse_Id(courseId);
Map<Long, Attendee> attendeeMap = attendees.stream().collect(Collectors.toMap(Attendee::getId, attendee -> attendee));
//TODO: duplicate 처리

List<String> 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())
Expand Down

0 comments on commit 1f0036c

Please sign in to comment.