Skip to content
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] Refactor/#563 RestDocs 응답 오류(500) 해결 및 상태코드 검증 추가 #565

Merged
merged 10 commits into from
Oct 13, 2023
Merged
58 changes: 29 additions & 29 deletions backend/src/docs/asciidoc/admin.adoc
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// == 관리자 기능
//
// === 전체 회원 조회
//
// operation::admin-controller-test/find-all-member-details[snippets='http-request,http-response']
//
// === 회원 상세 조회
//
// operation::admin-controller-test/find-member[snippets='http-request,http-response']
//
// === 회원 차단(삭제)
//
// operation::admin-controller-test/delete-member[snippets='http-request,http-response']
//
// === 토픽 삭제
//
// operation::admin-controller-test/delete-topic[snippets='http-request,http-response']
//
// === 토픽 이미지 삭제
//
// operation::admin-controller-test/delete-topic-image[snippets='http-request,http-response']
//
// === 핀 삭제
//
// operation::admin-controller-test/delete-pin[snippets='http-request,http-response']
//
// === 핀 이미지 삭제
//
// operation::admin-controller-test/delete-pin-image[snippets='http-request,http-response']
== 관리자 기능

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

관리자 기능 rest docs 를 재활성화 시키신 이유는 어짜피 Authorization 이 외부로 드러나 있지 않으니 안전하다고 판단하셔서인가요?

그냥 궁금해서 여쭤봅니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 맞습니다, 그리고 그 외에 지웠던 이유가 잘 기억이 안나서 편의상 다시 추가해보았는데 그럼에도 노출하지 않는게 좋다고 생각하시면 다시 되돌리겠습니다!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 그 때 잠깐 주석처리 했던 이유가, 굳이 admin api 명세를 모두가 볼 수 있도록 공개해야하나? 라는 가벼운 이유 였던 것 같아서 괜찮을 것 같긴합니다.

무엇보다 secret key 가 없다면, admin api 를 사용할 수 없기도 하구요.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데... 집에 벌써 가셨나요? 전광석화 또또이..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 깃허브 모바일 애용자입니다 ^_^

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

킹쩔TV

=== 전체 회원 조회

operation::admin-controller-test/find-all-member-details[snippets='http-request,http-response']

=== 회원 상세 조회

operation::admin-controller-test/find-member[snippets='http-request,http-response']

=== 회원 차단(삭제)

operation::admin-controller-test/delete-member[snippets='http-request,http-response']

=== 토픽 삭제

operation::admin-controller-test/delete-topic[snippets='http-request,http-response']

=== 토픽 이미지 삭제

operation::admin-controller-test/delete-topic-image[snippets='http-request,http-response']

=== 핀 삭제

operation::admin-controller-test/delete-pin[snippets='http-request,http-response']

=== 핀 이미지 삭제

operation::admin-controller-test/delete-pin-image[snippets='http-request,http-response']
4 changes: 0 additions & 4 deletions backend/src/docs/asciidoc/pin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ operation::pin-controller-test/add[snippets='http-request,http-response']

operation::pin-controller-test/update[snippets='http-request,http-response']

=== 핀 삭제

operation::pin-controller-test/delete[snippets='http-request,http-response']

=== 핀 이미지 추가

operation::pin-controller-test/add-image[snippets='http-request,http-response']
Expand Down
4 changes: 0 additions & 4 deletions backend/src/docs/asciidoc/topic.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,3 @@ operation::topic-controller-test/copy-pin[snippets='http-request,http-response']

operation::topic-controller-test/update[snippets='http-request,http-response']

=== 토픽 삭제

operation::topic-controller-test/delete[snippets='http-request,http-response']

Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ public List<TopicResponse> findAllTopicsInBookmark(AuthMember authMember) {
.toList();
}

private List<Topic> findTopicsInAtlas(Member member) {
return member.getAtlantes()
.stream()
.map(Atlas::getTopic)
.toList();
}

private boolean isInAtlas(Long memberId, Long topicId) {
return atlasRepository.existsByMemberIdAndTopicId(memberId, topicId);
}
Expand All @@ -98,6 +91,13 @@ public List<TopicResponse> findAllTopicsInAtlas(AuthMember authMember) {
.toList();
}

private List<Topic> findTopicsInAtlas(Member member) {
return member.getAtlantes()
.stream()
.map(Atlas::getTopic)
.toList();
}

private boolean isInBookmark(Long memberId, Long topicId) {
return bookmarkRepository.existsByMemberIdAndTopicId(memberId, topicId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public ResponseEntity<Void> update(
.build();
}

@Deprecated(since = "2023.10.10 (이미지 삭제 로직 불완전, 사용되지 않는 API)")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

최근들어 Deprecated 를 아주 야무지게 쓰시는군요 멋집니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 나중에 보면 힘들거가타서여.. 근데 이것도 부채네요!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그래도 이렇게 붙여주신 덕분에 추후에 볼 때 편할 것 같네요!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪭

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🪭 이거 무슨 이모지져? 저는 안보임..
image

@LoginRequired
@DeleteMapping("/{pinId}")
public ResponseEntity<Void> delete(AuthMember member, @PathVariable Long pinId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ public ResponseEntity<Void> mergeAndCreate(
.build();
}

@LoginRequired
@PutMapping("/{topicId}")
public ResponseEntity<Void> update(
AuthMember member,
@PathVariable Long topicId,
@RequestBody TopicUpdateRequest request
) {
topicCommandService.updateTopicInfo(member, topicId, request);

return ResponseEntity.ok().build();
}

@LoginRequired
@PostMapping("/{topicId}/copy")
public ResponseEntity<Void> copyPin(
Expand Down Expand Up @@ -127,26 +139,14 @@ public ResponseEntity<List<TopicResponse>> findAllByOrderByUpdatedAtDesc(AuthMem
return ResponseEntity.ok(responses);
}

@LoginRequired
@PutMapping("/{topicId}")
public ResponseEntity<Void> update(
AuthMember member,
@PathVariable Long topicId,
@RequestBody TopicUpdateRequest request
) {
topicCommandService.updateTopicInfo(member, topicId, request);

return ResponseEntity.ok().build();
}

@GetMapping("/bests")
public ResponseEntity<List<TopicResponse>> findAllBestTopics(AuthMember authMember) {
List<TopicResponse> responses = topicQueryService.findAllBestTopics(authMember);

return ResponseEntity.ok(responses);
}

@Deprecated(since = "2023.10.06")
@Deprecated(since = "2023.10.06 (연관관계 삭제 불완전, 사용되지 않는 API)")
@LoginRequired
@DeleteMapping("/{topicId}")
public ResponseEntity<Void> delete(AuthMember member, @PathVariable Long topicId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

class AdminControllerTest extends RestDocsIntegration {

Expand Down Expand Up @@ -74,7 +75,7 @@ class AdminControllerTest extends RestDocsIntegration {
private AdminAuthInterceptor adminAuthInterceptor;

@BeforeEach
void setAll() throws Exception {
void setAll() {
given(adminAuthInterceptor.preHandle(any(), any(), any())).willReturn(true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿굿

}

Expand All @@ -88,10 +89,10 @@ void findAllMemberDetails() throws Exception {

given(adminQueryService.findAllMemberDetails()).willReturn(response);

mockMvc.perform(
MockMvcRequestBuilders.get("/admin/members")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
mockMvc.perform(MockMvcRequestBuilders.get("/admin/members")
.header(AUTHORIZATION, "testKey"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andDo(restDocs.document());
}

@DisplayName("멤버 상세 조회")
Expand All @@ -109,64 +110,64 @@ void findMember() throws Exception {

given(adminQueryService.findMemberDetail(any())).willReturn(response);

mockMvc.perform(
MockMvcRequestBuilders.get("/admin/members/1")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
mockMvc.perform(MockMvcRequestBuilders.get("/admin/members/1")
.header(AUTHORIZATION, "testKey"))
.andExpect(MockMvcResultMatchers.status().isOk())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

.andDo(restDocs.document());
}

@DisplayName("멤버 차단(블랙리스트)")
@Test
void deleteMember() throws Exception {
doNothing().when(adminCommandService).blockMember(any());

mockMvc.perform(
MockMvcRequestBuilders.delete("/admin/members/1")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/members/1")
.header(AUTHORIZATION, "testKey"))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andDo(restDocs.document());
}

@DisplayName("토픽 삭제")
@Test
void deleteTopic() throws Exception {
doNothing().when(adminCommandService).deleteTopic(any());

mockMvc.perform(
MockMvcRequestBuilders.delete("/admin/topics/1")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/topics/1")
.header(AUTHORIZATION, "testKey"))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andDo(restDocs.document());
}

@DisplayName("토픽 이미지 삭제")
@Test
void deleteTopicImage() throws Exception {
doNothing().when(adminCommandService).deleteTopicImage(any());

mockMvc.perform(
MockMvcRequestBuilders.delete("/admin/topics/1/images")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/topics/1/images")
.header(AUTHORIZATION, "testKey"))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andDo(restDocs.document());
}

@DisplayName("핀 삭제")
@Test
void deletePin() throws Exception {
doNothing().when(adminCommandService).deletePin(any());

mockMvc.perform(
MockMvcRequestBuilders.delete("/admin/pins/1")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/pins/1")
.header(AUTHORIZATION, "testKey"))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andDo(restDocs.document());
}

@DisplayName("토픽 이미지 삭제")
@Test
void deletePinImage() throws Exception {
doNothing().when(adminCommandService).deletePinImage(any());

mockMvc.perform(
MockMvcRequestBuilders.delete("/admin/pins/images/1")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
mockMvc.perform(MockMvcRequestBuilders.delete("/admin/pins/images/1")
.header(AUTHORIZATION, "testKey"))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andDo(restDocs.document());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;

class AtlasControllerTest extends RestDocsIntegration {

Expand All @@ -23,10 +24,10 @@ void addTopicToAtlas() throws Exception {
doNothing().when(atlasCommandService).addTopic(any(), any());

// then
mockMvc.perform(
MockMvcRequestBuilders.post("/atlas/topics?id=1")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
mockMvc.perform(MockMvcRequestBuilders.post("/atlas/topics?id=1")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L)))
.andExpect(MockMvcResultMatchers.status().isCreated())
.andDo(restDocs.document());
}

@Test
Expand All @@ -35,10 +36,10 @@ void removeTopicFromAtlas() throws Exception {
doNothing().when(atlasCommandService).removeTopic(any(), any());

// then
mockMvc.perform(
MockMvcRequestBuilders.delete("/atlas/topics?id=1")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L))
).andDo(restDocs.document());
mockMvc.perform(MockMvcRequestBuilders.delete("/atlas/topics?id=1")
.header(AUTHORIZATION, testAuthHeaderProvider.createAuthHeaderById(1L)))
.andExpect(MockMvcResultMatchers.status().isNoContent())
.andDo(restDocs.document());
}

}
Loading
Loading