-
Notifications
You must be signed in to change notification settings - Fork 5
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
[BE] 행사 참여 인원 이름 변경 기능 구현 #197
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import server.haengdong.application.request.EventAppRequest; | ||
import server.haengdong.application.request.MemberUpdateAppRequest; | ||
import server.haengdong.application.response.ActionAppResponse; | ||
import server.haengdong.application.response.EventAppResponse; | ||
import server.haengdong.application.response.EventDetailAppResponse; | ||
|
@@ -98,4 +99,22 @@ public MembersAppResponse findAllMembers(String token) { | |
|
||
return new MembersAppResponse(memberNames); | ||
} | ||
|
||
@Transactional | ||
public void updateMember(String token, String memberName, MemberUpdateAppRequest request) { | ||
Event event = eventRepository.findByToken(token) | ||
.orElseThrow(() -> new HaengdongException(HaengdongErrorCode.NOT_FOUND_EVENT)); | ||
String updatedMemberName = request.name(); | ||
validateMemberNameUnique(event, updatedMemberName); | ||
|
||
memberActionRepository.findAllByAction_EventAndMemberName(event, memberName) | ||
.forEach(memberAction -> memberAction.updateMemberName(updatedMemberName)); | ||
Comment on lines
+110
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. r: update와 where절로 쿼리 하나로 처리할 수 있을 것 같아요. 지금은 select와 update 쿼리가 n개 발생해요. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 성능을 비교해서 알려주세요. 👍 |
||
} | ||
|
||
private void validateMemberNameUnique(Event event, String updatedMemberName) { | ||
boolean isMemberNameExist = memberActionRepository.existsByAction_EventAndMemberName(event, updatedMemberName); | ||
if (isMemberNameExist) { | ||
throw new HaengdongException(HaengdongErrorCode.DUPLICATED_MEMBER_NAME); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package server.haengdong.application.request; | ||
|
||
public record MemberUpdateAppRequest(String name) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,12 @@ | |
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
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.RestController; | ||
import server.haengdong.application.EventService; | ||
import server.haengdong.presentation.request.EventSaveRequest; | ||
import server.haengdong.presentation.request.MemberUpdateRequest; | ||
import server.haengdong.presentation.response.EventDetailResponse; | ||
import server.haengdong.presentation.response.EventResponse; | ||
import server.haengdong.presentation.response.MembersResponse; | ||
|
@@ -48,4 +50,15 @@ public ResponseEntity<MembersResponse> findAllMembers(@PathVariable("eventId") S | |
|
||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@PutMapping("/api/events/{eventId}/members/{memberName}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a: API 명세대로 잘 구현되었는데요, memberName을 PathVariable 대신에 body에 넣는 것은 어떤가요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나중에는 memberName 대신 memberId를 사용할 것 같아서 현재의 방식을 사용해도 괜찮을 것 같아요. |
||
public ResponseEntity<Void> updateMember( | ||
@PathVariable("eventId") String token, | ||
@PathVariable("memberName") String memberName, | ||
@Valid @RequestBody MemberUpdateRequest request | ||
) { | ||
eventService.updateMember(token, memberName, request.toAppRequest()); | ||
|
||
return ResponseEntity.ok().build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package server.haengdong.presentation.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import server.haengdong.application.request.MemberUpdateAppRequest; | ||
|
||
public record MemberUpdateRequest( | ||
@NotBlank String name | ||
) { | ||
|
||
public MemberUpdateAppRequest toAppRequest() { | ||
return new MemberUpdateAppRequest(name); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a: memberName에 해당하는 멤버가 존재하는지 검증할 필요가 있을지 논의가 필요해요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
필요가 있지 않을까요?