-
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] issue187: 특정 스터디에서 나의 role을 확인하는 API 생성 #193
Conversation
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.
린론! 코드 잘봤어요! 혹시 구현중이신건가요? 몇가지 코멘트 남겼어요!
@@ -18,4 +20,10 @@ public class AuthController { | |||
public ResponseEntity<TokenResponse> login(@RequestParam final String code) { | |||
return ResponseEntity.ok().body(authService.createToken(code)); | |||
} | |||
|
|||
@GetMapping("/api/auth/role") |
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.
음 저는 특정 스터디에서 내 역할을 보는 API가 auth쪽에 있는게 어색하다고 느껴지는데요.
린론은 왜 auth에다 하셨나요?
auth는 정말 소셜로그인이나 회원가입 같은 인증관련 API만 두는거라고 생각하고 있어서 더 어색하다 느껴지는 것 같네요
auth에서 studyId를 받는건 더더욱 어색하구요!
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.
명세 변경전에 있던 코드라서, 현재 /api/members/me/role?study-id={studyId}
로 변경됐습니다 ~
|
||
@GetMapping("/api/auth/role") | ||
public ResponseEntity<Void> getStudyRole( | ||
@AuthenticationPrincipal Long githubId, @RequestParam(name = "study-id") Long studyId) { |
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.
어? studyId는 URI에 없는데 어디서 가져오는건가요?
@GetMapping("/api/auth/role") | ||
public ResponseEntity<Void> getStudyRole( | ||
@AuthenticationPrincipal Long githubId, @RequestParam(name = "study-id") Long studyId) { | ||
return ResponseEntity.ok().build(); |
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.
그냥 ok만 넘겨주네요
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.
린론!! 구현 깔끔하게 잘 해주셨네요..!!
몇가지 의견 남겨봅니다!😁
@GetMapping("/api/members/me/role") | ||
public ResponseEntity<MyRoleResponse> getMyRoleInStudy( | ||
@AuthenticationPrincipal Long githubId, @RequestParam(name = "study-id") Long studyId | ||
) { | ||
return ResponseEntity.ok().body(myStudyService.findMyRoleInStudy(githubId, studyId)); |
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.
깰끔
@@ -0,0 +1,6 @@ | |||
package com.woowacourse.moamoa.study.domain; | |||
|
|||
public enum MyRole { |
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.
MemberRole
가 더 명시적일 것 같습니다!
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.
좋아요👍 클래스명 수정했습니다.
public boolean isParticipate(Long memberId) { | ||
return participants.contains(new Participant(memberId)); | ||
} |
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.
기존에 존재하는 isAlreadyParticipated
메소드를 활용해도 Service 로직에 이상이 없을 것 같아요!
(owner 를 먼저 검사하고 있어서)
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.
물론 로직 자체로는 문제가 없지만, 해당 사용자가 참여자인지 확인하는 메서드로 분리하는 게 더 명확하다고 생각해서 나누는 게 좋을 것 같아요! 기존의 isAlreadyParticipated
의 메서드명 때문에 헷갈릴 것 같아서요!
@DisplayName("스터디에서 사용자의 역할을 조회한다.") | ||
@Test | ||
void getMyRoleInStudy() throws Exception { | ||
given(myStudyService.findMyRoleInStudy(any(), any())).willReturn(new MyRoleResponse(MyRole.MEMBER)); | ||
|
||
mockMvc.perform(get("/api/members/me/role") | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer " + JWT_토큰) | ||
.queryParam("study-id", "3") | ||
.contentType(MediaType.APPLICATION_JSON_VALUE) | ||
.accept(MediaType.APPLICATION_JSON)) | ||
.andDo(document("members/me/role", | ||
requestHeaders( | ||
headerWithName("Authorization").description( | ||
"Bearer Token")), | ||
requestParameters(parameterWithName("study-id").description("스터디 ID")), | ||
responseFields(fieldWithPath("role").type(JsonFieldType.STRING).description("해당 스터디에서 사용자의 역할")))) | ||
.andDo(print()) | ||
.andExpect(status().isOk()); | ||
} |
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.
인수테스트로 문서화하기로 해서 이 테스트는 삭제해도 될 것 같습니다!
RestAssured.given().log().all() | ||
.header(CONTENT_TYPE, APPLICATION_JSON_VALUE) | ||
.header(AUTHORIZATION, token) | ||
.queryParam("study-id", 7) | ||
.when() | ||
.get("/api/members/me/role") | ||
.then().log().all() | ||
.statusCode(HttpStatus.OK.value()) | ||
.body("role", is("OWNER")); | ||
} |
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.
OWNER 이외에 NON_MEMBER 나 MEMBER 등의 테스트 케이스도 추가해주면 좋을 것 같아요!! (꼭 인수테스트에서 할 필요는 없을 것 같구...)
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.
service에서 테스트하고 있습니다!
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.
린론 구현한 코드 확인했습니다!
}) | ||
@ExtendWith(RestDocumentationExtension.class) | ||
@Import(JwtTokenProvider.class) | ||
public class DocumentationTest { |
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.
이 클래스 MockMvc에서 RestAssured로 변경하면서 사라졌습니다!
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.
RestAssured
로 추가했습니다 ~
|
||
@GetMapping("/api/members/me/role") | ||
public ResponseEntity<MyRoleResponse> getMyRoleInStudy( | ||
@AuthenticationPrincipal Long githubId, @RequestParam(name = "study-id") Long studyId |
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.
final이 빠졌어요..!
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.
추가했습니다! 👍
|
||
@WebMvcTest(controllers = MyStudyController.class) | ||
@Import(JwtTokenProvider.class) | ||
public class BadRequestMyMyRoleWebMvcTest { |
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.
study Id가 String인 경우 400 예외를 확인하는 테스트 추가 부탁드려요~
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.
추가했습니다 ~ :D
@Import({JwtTokenProvider.class}) | ||
class UnauthorizedMyStudyControllerTest { | ||
@Import(JwtTokenProvider.class) | ||
class UnauthorizedMyStudyWebMvcTest { |
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.
/api/members/me/role에 대한 테스트도 추가 부탁드려요~
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.
인증 테스트 추가했습니다 ~
final Participants participants = study.getParticipants(); | ||
return getMyRoleResponse(member, participants); | ||
} | ||
|
||
private MyRoleResponse getMyRoleResponse(final Member member, final Participants participants) { | ||
if (Objects.equals(participants.getOwnerId(), member.getId())) { | ||
return new MyRoleResponse(MemberRole.OWNER); | ||
} | ||
if (participants.isParticipate(member.getId())) { | ||
return new MyRoleResponse(MemberRole.MEMBER); | ||
} | ||
return new MyRoleResponse(MemberRole.NON_MEMBER); | ||
} |
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.
final Participants participants = study.getParticipants(); | |
return getMyRoleResponse(member, participants); | |
} | |
private MyRoleResponse getMyRoleResponse(final Member member, final Participants participants) { | |
if (Objects.equals(participants.getOwnerId(), member.getId())) { | |
return new MyRoleResponse(MemberRole.OWNER); | |
} | |
if (participants.isParticipate(member.getId())) { | |
return new MyRoleResponse(MemberRole.MEMBER); | |
} | |
return new MyRoleResponse(MemberRole.NON_MEMBER); | |
} | |
Role role = study.getRole(member.getId()); | |
return new MyRoleResponse(role); |
이런 식으로 메시지를 날리면 좋을 것 같아요
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.
그리고 Domain에 단위 테스트를 만들면 좋을 것 같아요.
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.
로직 이동하고 단위 테스트 생성했습니다 ~
요약
특정 스터디에서 나의 role을 확인하는 API를 생성한다.
세부사항
close #187