Skip to content

Commit

Permalink
[fix] 구글 로그인 response 수정 #27
Browse files Browse the repository at this point in the history
  • Loading branch information
kryptonite43 committed Mar 24, 2023
1 parent 6cede96 commit c5956bc
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/main/java/com/SollutionChallenge/HighLight/Page/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class Page {

private static Page createPage(Long id, File fileId) {
Page page = new Page();
page.id=id;
page.fileId=fileId;
return new Page();
page.id = id;
page.fileId = fileId;
return page;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.SollutionChallenge.HighLight.Page;

public class PageController {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.SollutionChallenge.HighLight.auth;

import com.SollutionChallenge.HighLight.common.ApiResponse;
import com.SollutionChallenge.HighLight.common.Success;
import com.SollutionChallenge.HighLight.dto.TokenDto;
import com.SollutionChallenge.HighLight.service.AuthService;
import lombok.RequiredArgsConstructor;
Expand All @@ -20,28 +18,16 @@ public class GoogleController {
@Autowired
AuthService authService;

/* ResponseEntity 사용해서 헤더에 status code 담는 버전 */
@PostMapping(value = "/login")
public ApiResponse googleLogin(@RequestBody GoogleLoginResponse googleLoginResponse) throws IOException {
public ResponseEntity<TokenDto> googleLogin(@RequestBody GoogleLoginResponse googleLoginResponse) throws IOException {
String accessToken = googleLoginResponse.getAccess_token();
String idToken = googleLoginResponse.getId_token();
System.out.println(accessToken);
System.out.println("========== user's accessToken: " + accessToken + " ==========");

return ApiResponse.successCode(Success.CREATE_USER_SUCCESS, authService.googleLogin(accessToken));
return ResponseEntity
.status(HttpStatus.OK)
.body(authService.googleLogin(accessToken));
}
/* ResponseEntity 사용해서 헤더에 status code 담는 버전 */
// @PostMapping(value = "/login")
// public ResponseEntity<TokenDto> googleLogin(@RequestBody GoogleLoginResponse googleLoginResponse) throws IOException {
// HttpHeaders headers = new HttpHeaders();
// headers.set("Status-Code", String.valueOf(HttpStatus.OK));
//
// String accessToken = googleLoginResponse.getAccess_token();
// String idToken = googleLoginResponse.getId_token();
// System.out.println(accessToken);
//
// return ResponseEntity
// .status(HttpStatus.OK)
// .headers(headers)
// .body(authService.googleLogin(accessToken));
// }

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.SollutionChallenge.HighLight.controller;

import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.storage.Storage;
import com.SollutionChallenge.HighLight.dto.UploadReqDto;
import lombok.RequiredArgsConstructor;
Expand All @@ -10,7 +9,6 @@
import org.springframework.web.bind.annotation.*;
import com.SollutionChallenge.HighLight.service.GCSService;

import java.io.FileInputStream;
import java.io.IOException;

@RestController
Expand All @@ -23,11 +21,9 @@ public class GCSController {


@PostMapping("/upload")
public ResponseEntity<Void> uploadNewImage(UploadReqDto dto) throws IOException {

gcsService.uploadNewImage(dto);

return new ResponseEntity(HttpStatus.OK);
public ResponseEntity<Void> uploadNewFile(UploadReqDto dto) throws IOException {
gcsService.uploadNewFile(dto);
return new ResponseEntity<>(HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
@Builder
public class UploadReqDto {
private String userName;
private MultipartFile image;
private MultipartFile uploadedfile;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@ public class GCSService {
@Value("${spring.cloud.gcp.storage.bucket}")
private String bucketName;

public void uploadNewImage(UploadReqDto dto) throws IOException {
public void uploadNewFile(UploadReqDto dto) throws IOException {
String uuid = UUID.randomUUID().toString(); // Google Cloud Storage에 저장될 파일 이름
String ext = dto.getImage().getContentType(); // 파일의 형식 ex) JPG
String ext = dto.getUploadedfile().getContentType(); // 파일의 형식 ex) JPG

// Cloud에 이미지 업로드
BlobInfo blobInfo = storage.create(
BlobInfo.newBuilder(bucketName, uuid)
.setContentType(ext)
.build(),
dto.getImage().getInputStream()
dto.getUploadedfile().getInputStream()
);



}


Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ spring.servlet.multipart.maxRequestSize=100MB
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.format_sql=true
#spring.jpa.properties.hibernate.format_sql=true

logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type=trace
spring.h2.console.enabled=true
Expand Down

0 comments on commit c5956bc

Please sign in to comment.