Skip to content

Commit

Permalink
[BE] API 문서 고도화 (컨트롤러 테스트)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinwook94 committed Oct 19, 2023
1 parent 4b51222 commit 0d850cf
Show file tree
Hide file tree
Showing 18 changed files with 993 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,4 @@ public ResponseEntity<Void> addStacks(@RequestBody List<StackRequest> requests)
return ResponseEntity.ok().build();
}

@PostMapping("/language")
public ResponseEntity<Void> addLanguage(@RequestParam String name, @RequestParam String icon) {
stackService.addLanguage(name, icon);
return ResponseEntity.ok().build();
}

@DeleteMapping("/language")
public ResponseEntity<Void> removeLanguage(@RequestParam String name) {
stackService.removeLanguage(name);
return ResponseEntity.ok().build();
}

@PostMapping("/framework")
public ResponseEntity<Void> addFramework(@RequestParam String name, @RequestParam String icon) {
stackService.addFramework(name, icon);
return ResponseEntity.ok().build();
}

@DeleteMapping("/framework")
public ResponseEntity<Void> removeFramework(@RequestParam String name) {
stackService.removeFramework(name);
return ResponseEntity.ok().build();
}

}
35 changes: 0 additions & 35 deletions backend/src/main/java/com/bootme/stack/service/StackService.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,36 +57,6 @@ public void addStacks(List<StackRequest> requests) {
}
}

@Transactional
public void addLanguage(String name, String icon) {
validateDuplicate(name);
Stack stack = new Stack(name, LANGUAGE, icon);
stackRepository.save(stack);
languages.add(name);
}

@Transactional
public void removeLanguage(String name) {
Stack stack = getStackByNameAndType(name, LANGUAGE);
stackRepository.delete(stack);
languages.remove(name);
}

@Transactional
public void addFramework(String name, String icon) {
validateDuplicate(name);
Stack stack = new Stack(name, FRAMEWORK, icon);
stackRepository.save(stack);
frameworks.add(name);
}

@Transactional
public void removeFramework(String name) {
Stack stack = getStackByNameAndType(name, FRAMEWORK);
stackRepository.delete(stack);
frameworks.remove(name);
}

@Transactional(readOnly = true)
public List<StackResponse> findAllStacks() {
return stackRepository.findAll().stream()
Expand All @@ -100,11 +70,6 @@ public Stack getStackByName(String name) {
.orElseThrow(() -> new ResourceNotFoundException(NOT_FOUND_STACK, name));
}

private Stack getStackByNameAndType(String name, String type) {
return stackRepository.findByNameAndType(name, type)
.orElseThrow(() -> new ResourceNotFoundException(NOT_FOUND_STACK, name));
}

private void validateDuplicate(String name){
boolean isExist = stackRepository.existsByName(name);
if(isExist){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.bootme.common.exception.TokenParseException;
import com.bootme.common.exception.AuthenticationException;
import com.bootme.util.ControllerTest;
import com.epages.restdocs.apispec.ResourceSnippetParameters;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand All @@ -15,13 +16,15 @@

import static com.bootme.common.exception.ErrorType.*;
import static com.bootme.util.fixture.AuthFixture.*;
import static com.epages.restdocs.apispec.ResourceDocumentation.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willDoNothing;
import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -53,7 +56,22 @@ void login_success() throws Exception {
perform.andDo(print())
.andDo(document("auth/login/success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())));
preprocessResponse(prettyPrint()),
resource(ResourceSnippetParameters.builder()
.summary("구글, 카카오 로그인")
.description("구글, 카카오 로그인 (OpenID Connect)")
.requestHeaders(
headerWithName("Authorization").description("ID Token")
)
.responseFields(
fieldWithPath("memberId").description("멤버 ID"),
fieldWithPath("email").description("이메일"),
fieldWithPath("nickname").description("닉네임"),
fieldWithPath("profileImage").description("프로필 사진"),
fieldWithPath("job").description("직업")
)
.build())
));
}

@Test
Expand Down Expand Up @@ -215,7 +233,22 @@ void naverLogin_success() throws Exception {
perform.andDo(print())
.andDo(document("auth/login/naver/success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())));
preprocessResponse(prettyPrint()),
resource(ResourceSnippetParameters.builder()
.summary("네이버 로그인")
.description("네이버 로그인 (OAuth 2.0)")
.requestFields(
fieldWithPath("url").description("네이버 OAuth URL")
)
.responseFields(
fieldWithPath("memberId").description("멤버 ID"),
fieldWithPath("email").description("이메일"),
fieldWithPath("nickname").description("닉네임"),
fieldWithPath("profileImage").description("프로필 사진"),
fieldWithPath("job").description("직")
)
.build())
));
}

@Test
Expand All @@ -231,7 +264,12 @@ void logout() throws Exception {
perform.andDo(print())
.andDo(document("auth/logout/success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())));
preprocessResponse(prettyPrint()),
resource(ResourceSnippetParameters.builder()
.summary("로그아웃")
.description("로그아웃")
.build())
));
}

@Test
Expand All @@ -257,7 +295,35 @@ void getSecrets_success() throws Exception {
perform.andDo(print())
.andDo(document("auth/secrets/success",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())));
preprocessResponse(prettyPrint()),
resource(ResourceSnippetParameters.builder()
.summary("시크릿 요청")
.description("AWS Secrets Manager 저장된 시크릿 값 요청. (소셜 로그인 위한 API Key 등)")
.requestHeaders(
headerWithName("Bootme_Secret").description("JWT 검증 목적"),
headerWithName("Origin").description("허용된 origin 인지 검증 목적")
)
.responseFields(
fieldWithPath("apiUrl").description("bootme 서버 URL"),
fieldWithPath("googleClientId").description("googleClientId"),
fieldWithPath("googleIssuer").description("googleIssuer"),
fieldWithPath("googleAudience").description("googleAudience"),
fieldWithPath("naverClientId").description("naverClientId"),
fieldWithPath("naverClientSecret").description("naverClientSecret"),
fieldWithPath("naverIssuer").description("naverIssuer"),
fieldWithPath("naverAudience").description("naverAudience"),
fieldWithPath("naverSigningKey").description("naverSigningKey"),
fieldWithPath("kakaoRestApiKey").description("kakaoRestApiKey"),
fieldWithPath("kakaoClientSecret").description("kakaoClientSecret"),
fieldWithPath("kakaoIssuer").description("kakaoIssuer"),
fieldWithPath("kakaoAudience").description("kakaoAudience"),
fieldWithPath("kakaoJavascriptKey").description("kakaoJavascriptKey"),
fieldWithPath("bootmeIssuer").description("bootmeIssuer"),
fieldWithPath("bootmeAudience").description("bootmeAudience"),
fieldWithPath("bootmeSigningKey").description("bootmeSigningKey")
)
.build())
));
}

}

0 comments on commit 0d850cf

Please sign in to comment.