Skip to content

Commit b500c49

Browse files
authored
Merge pull request #14 from DevKor-github/dev
feat: patch /participants/{id} 추가
2 parents 56293d0 + a8be9c2 commit b500c49

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/main/java/com/workingdead/meet/controller/ParticipantController.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,25 @@ public ResponseEntity<Void> remove(@PathVariable Long participantId) {
6868
participantService.remove(participantId);
6969
return ResponseEntity.noContent().build();
7070
}
71+
72+
@Operation(
73+
summary = "참여자 정보 수정",
74+
description = "참여자의 displayName 등 기본 정보를 수정합니다."
75+
)
76+
@ApiResponses({
77+
@ApiResponse(responseCode = "200", description = "참여자 수정 성공",
78+
content = @Content(schema = @Schema(implementation = ParticipantDtos.ParticipantRes.class))),
79+
@ApiResponse(responseCode = "404", description = "참여자를 찾을 수 없음", content = @Content)
80+
})
81+
@PatchMapping("/participants/{participantId}")
82+
public ResponseEntity<ParticipantDtos.ParticipantRes> updateParticipant(
83+
@PathVariable Long participantId,
84+
@Valid @RequestBody ParticipantDtos.UpdateParticipantReq request) {
85+
86+
ParticipantDtos.ParticipantRes response =
87+
participantService.updateParticipant(participantId, request);
88+
return ResponseEntity.ok(response);
89+
}
7190

7291
@Operation(
7392
summary = "참여자 목록 조회 (로그인 칩)",

src/main/java/com/workingdead/meet/dto/ParticipantDtos.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
public class ParticipantDtos {
1010
public record CreateParticipantReq(@NotBlank String displayName) {}
11+
public record UpdateParticipantReq(String displayName) {}
1112
public record ParticipantRes(Long id, String displayName,boolean loggedIn // 로그인 상태
1213
) {}
1314

src/main/java/com/workingdead/meet/service/ParticipantService.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ public ParticipantDtos.ParticipantRes add(Long voteId, String displayName) {
3737
return new ParticipantDtos.ParticipantRes(p.getId(), p.getDisplayName(), false);
3838
}
3939

40+
public ParticipantDtos.ParticipantRes updateParticipant(Long participantId, ParticipantDtos.UpdateParticipantReq request) {
41+
Participant participant = participantRepo.findById(participantId)
42+
.orElseThrow(() -> new NoSuchElementException("Participant not found"));
43+
44+
// displayName 수정 (null이 아닌 경우만)
45+
if (request.displayName() != null && !request.displayName().isBlank()) {
46+
participant.setDisplayName(request.displayName());
47+
}
48+
49+
Participant saved = participantRepo.save(participant);
50+
51+
return new ParticipantDtos.ParticipantRes(
52+
saved.getId(),
53+
saved.getDisplayName(),
54+
false
55+
);
56+
}
57+
4058
@Transactional
4159
public ParticipantDtos.ParticipantRes submit(Long participantId) {
4260
Participant participant = participantRepo.findById(participantId)
@@ -204,4 +222,6 @@ public ParticipantDtos.ParticipantChoicesRes getParticipantChoices(Long particip
204222
priorityInfos
205223
);
206224
}
225+
226+
207227
}

0 commit comments

Comments
 (0)