-
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
Changes from 6 commits
43b3b40
3c41971
ed84cd4
588edcf
184bd65
d5fed86
2bef2b1
220a59c
4fd28f8
dbcc5ad
8a26d57
785d1d7
7b678f4
f9e5a04
12bfe15
7102615
2237674
99b3c86
19ed32e
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 |
---|---|---|
|
@@ -2,10 +2,12 @@ | |
|
||
import com.woowacourse.moamoa.auth.config.AuthenticationPrincipal; | ||
import com.woowacourse.moamoa.study.service.MyStudyService; | ||
import com.woowacourse.moamoa.study.service.response.MyRoleResponse; | ||
import com.woowacourse.moamoa.study.service.response.MyStudiesResponse; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
@@ -21,4 +23,11 @@ public ResponseEntity<MyStudiesResponse> getMyStudies(@AuthenticationPrincipal L | |
final MyStudiesResponse myStudiesResponse = myStudyService.getStudies(githubId); | ||
return ResponseEntity.ok().body(myStudiesResponse); | ||
} | ||
|
||
@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 commentThe reason will be displayed to describe this comment to others. Learn more. 깰끔 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
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. 좋아요👍 클래스명 수정했습니다. |
||
|
||
MEMBER, NON_MEMBER, OWNER | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,14 @@ | |
import javax.persistence.ElementCollection; | ||
import javax.persistence.Embeddable; | ||
import javax.persistence.JoinColumn; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@Embeddable | ||
@ToString | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Getter | ||
@ToString | ||
public class Participants { | ||
|
||
@Column(name = "current_member_count") | ||
|
@@ -51,6 +53,10 @@ boolean isAlreadyParticipated(Long memberId) { | |
return participants.contains(new Participant(memberId)) || ownerId.equals(memberId); | ||
} | ||
|
||
public boolean isParticipate(Long memberId) { | ||
return participants.contains(new Participant(memberId)); | ||
} | ||
Comment on lines
+56
to
+58
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. 기존에 존재하는 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. 물론 로직 자체로는 문제가 없지만, 해당 사용자가 참여자인지 확인하는 메서드로 분리하는 게 더 명확하다고 생각해서 나누는 게 좋을 것 같아요! 기존의 |
||
|
||
int getSize() { | ||
return size; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.woowacourse.moamoa.study.service.response; | ||
|
||
import com.woowacourse.moamoa.study.domain.MyRole; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
public class MyRoleResponse { | ||
|
||
private MyRole role; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.springframework.http.HttpHeaders.AUTHORIZATION; | ||
import static org.springframework.http.HttpHeaders.CONTENT_TYPE; | ||
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; | ||
|
||
import com.woowacourse.acceptance.AcceptanceTest; | ||
import com.woowacourse.moamoa.auth.service.oauthclient.response.GithubProfileResponse; | ||
|
@@ -103,4 +106,20 @@ void getMyStudies() { | |
.body("studies[0].tags.id", contains(2, 4, 5)) | ||
.body("studies[0].tags.name", contains("4기", "FE", "React")); | ||
} | ||
|
||
@Test | ||
@DisplayName("특정 스터디에서 나의 Role을 확인한다.") | ||
void isMyStudy() { | ||
final String token = getBearerTokenBySignInOrUp(new GithubProfileResponse(4L, "verus", "https://image", "github.com")); | ||
|
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. service에서 테스트하고 있습니다! |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.woowacourse.moamoa.docs; | ||
|
||
import static com.woowacourse.fixtures.AuthFixtures.JWT_토큰; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; | ||
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; | ||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields; | ||
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; | ||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; | ||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import com.woowacourse.moamoa.auth.service.response.TokenResponse; | ||
import com.woowacourse.moamoa.study.domain.MyRole; | ||
import com.woowacourse.moamoa.study.service.response.MyRoleResponse; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.restdocs.payload.JsonFieldType; | ||
|
||
public class MyStudyDocumentationTest extends DocumentationTest { | ||
|
||
@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 commentThe reason will be displayed to describe this comment to others. Learn more. 인수테스트로 문서화하기로 해서 이 테스트는 삭제해도 될 것 같습니다! |
||
} |
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.
추가했습니다! 👍