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

Fix/login #13

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,23 @@ public class SignUpController {
private final AuthService authService;

@Operation(summary = "회원가입")
@PostMapping("/users/signUp")
public ResponseEntity<BaseResponse> userSignUp(@RequestPart (value = "UserSignUpRequest") UserSignUpRequest request, @RequestPart(value = "file", required = false) MultipartFile multipartFile) throws IOException {
@PostMapping(value = "/users/signUp",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<BaseResponse> userSignUp(
@RequestPart (value = "UserSignUpRequest") UserSignUpRequest request,
@RequestPart(value = "file", required = false) MultipartFile multipartFile) throws IOException {
authService.userSignUp(request, multipartFile);
return ResponseEntity.ok(new BaseResponse<>(SUCCESS));
}

@Operation(summary = "소셜 로그인 회원가입")
@PatchMapping("/users/signUp/social")
public ResponseEntity<BaseResponse> userSocialSignUp(@AuthenticationPrincipal UserDetails loginUser,@Valid @RequestPart (value = "SocialSignUpRequest") SocialSignUpRequest socialSignUpRequest, @RequestPart(value = "file", required = false) MultipartFile multipartFile) throws IOException {
@PatchMapping(value = "/users/signUp/social",
consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<BaseResponse> userSocialSignUp(
@AuthenticationPrincipal UserDetails loginUser,
@Valid @RequestPart (value = "SocialSignUpRequest") SocialSignUpRequest socialSignUpRequest,
@RequestPart(value = "file", required = false) MultipartFile multipartFile) throws IOException {

authService.userSocialSignUp(loginUser.getUsername(), socialSignUpRequest, multipartFile);
return ResponseEntity.ok(new BaseResponse<>(SUCCESS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ public void userSignUp(UserSignUpRequest request, MultipartFile multipartFile) t
throw new BadRequestException(ALREADY_EXIST_NICKNAME);
}

String profileImageUrl;
if (multipartFile.isEmpty() || multipartFile == null){
throw new BadRequestException(FILE_NOT_FOUND);
String profileImageUrl = null;
if (multipartFile == null){
// throw new BadRequestException(FILE_NOT_FOUND);
log.info("user profile image is null");
}
else {
profileImageUrl = s3Service.uploadFile(multipartFile);
Expand All @@ -71,9 +72,10 @@ public void userSocialSignUp(String email, SocialSignUpRequest socialSignUpReque
Language language = socialSignUpRequest.language();
Boolean isOptionAgr = socialSignUpRequest.isOptionAgr();

String profileImageUrl;
if (multipartFile.isEmpty() || multipartFile == null){
throw new BadRequestException(FILE_NOT_FOUND);
String profileImageUrl = null;
if (multipartFile == null){
// throw new BadRequestException(FILE_NOT_FOUND);
log.info("user profile image is null");
}
else {
profileImageUrl = s3Service.uploadFile(multipartFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.allo.server.global.component;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.lang.reflect.Type;
import org.springframework.http.MediaType;
import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;

@Component
public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter {

/**
* Converter for support http request with header Content-Type: multipart/form-data
*/
public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) {
super(objectMapper, MediaType.APPLICATION_OCTET_STREAM);
}

@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) {
return false;
}

@Override
protected boolean canWrite(MediaType mediaType) {
return false;
}
}

38 changes: 38 additions & 0 deletions src/main/java/com/allo/server/global/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.allo.server.global.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

@Value("${springdoc.version}")
private String version;

@Bean
public OpenAPI openAPI() {

SecurityScheme securityScheme = new SecurityScheme()
.type(SecurityScheme.Type.HTTP).scheme("Bearer").bearerFormat("JWT")
.in(SecurityScheme.In.HEADER).name("Authorization");
SecurityRequirement securityRequirement = new SecurityRequirement().addList("JWT");

Components components = new Components().addSecuritySchemes("JWT", securityScheme);

Info info = new Info()
.title("Glee API 명세서")
.description("Glee API 명세서입니다.")
.version(version);

return new OpenAPI()
.info(info)
.components(components)
.addSecurityItem(securityRequirement);
}
}