Skip to content

Commit

Permalink
jwt project swagger add
Browse files Browse the repository at this point in the history
  • Loading branch information
Jupiter-J committed Apr 25, 2022
1 parent ebedf7c commit 3e5101e
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
11 changes: 7 additions & 4 deletions server/JWT_momo/ReadMeServer.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@

### 2022-04-20 개발상황
* CORS 에러 해결
* (프론트 요구사항) Topic Entity CreateAt 추가
* Topic Entity CreateAt 추가 (프론트님 요구사항)
* Topic CRUD 서버 업데이트

### 2022-04-21 개발상황
* User CRUD API 생성
* Post CRUD API 생성
* Swagger 적용
* (프론트 요구사항) POST CRUD 수정 + DB변경
* POST CRUD 수정 + DB변경 (프론트님 요구사항)

### 2022-04-22 개발상황
* 회원가입 API 구현 (test Project)
* CORS 에러 해결 2
* 로그인 API 테스트

### 2022-04-23 개발상황
* 나의 게시글 확인 기능 API 생성

### 2022-04-24 개발상황
* swagger 명세서 업데이트
* swagger 명세서 업데이트
* 데이터베이스 초기 데이터 삽입 (기획자님 요구사항)
* JWT 토큰 로그인 회원가입 구현


---
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.sideproject.momo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;


@EnableSwagger2
@Configuration
public class SwaggerConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.OAS_30) // open api spec 3.0
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(this.apiInfo())
;
}

private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("MoMo Project API")
.description("모모 프로젝트의 API를 정리합니다")
.version("1.0")
.build();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ protected void configure(HttpSecurity http) throws Exception {
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests() // /와 /auth/** 경로는 인증 안해도 됨.
.antMatchers("/", "/auth/**").permitAll()
.antMatchers("/", "/auth/**",
"/v3/api-docs/**", "/swagger*/**").permitAll()
.anyRequest() // /와 /auth/**이외의 모든 경로는 인증 해야됨.
.authenticated();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.sideproject.momo.model.JwtUserDTO;
import dev.sideproject.momo.security.TokenProvider;
import dev.sideproject.momo.service.JwtUserService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
Expand All @@ -31,6 +32,7 @@ public class JwtUserController {


@PostMapping("/signup")
@ApiOperation(value = "회원가입", notes = "email, username, password 필요")
public ResponseEntity<?> registerUser(@RequestBody JwtUserDTO userDTO) {
try {
// 리퀘스트를 이용해 저장할 유저 만들기
Expand Down Expand Up @@ -58,6 +60,7 @@ public ResponseEntity<?> registerUser(@RequestBody JwtUserDTO userDTO) {
}

@PostMapping("/signin")
@ApiOperation(value = "회원가입", notes = "email, username, password 필요")
public ResponseEntity<?> authenticate(@RequestBody JwtUserDTO userDTO) {
JwtUserEntity user = userService.getByCredentials(userDTO.getEmail(), userDTO.getPassword(), passwordEncoder);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.sideproject.momo.model;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -10,9 +11,19 @@
@NoArgsConstructor
@AllArgsConstructor
public class JwtUserDTO {

@ApiModelProperty(value = "토큰" , example = "회원가입시에는 null")
private String token;

@ApiModelProperty(value = "이메일" , example = "ta@naveer.com")
private String email;

@ApiModelProperty(value = "성명", example = "짱구")
private String username;

@ApiModelProperty(value = "비밀번호", example = "password")
private String password;

@ApiModelProperty(value = "고유 id")
private String id;
}

0 comments on commit 3e5101e

Please sign in to comment.