Skip to content

Commit

Permalink
M3-403 Feat : s3 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdals802 committed Oct 16, 2024
1 parent 95c741c commit 595bd3e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,29 @@ public class RankingController {
@GetMapping("/user")
public Response<List<UserRankingResponse>> getAllUserRanking(
@RequestParam(required = false, name = "lookup-date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate lookUpDate) {
return Response.createSuccess(
userRankingService.getCurrentPixelAllUserRankings(lookUpDate)
);
return Response.createSuccess(userRankingService.getCurrentPixelAllUserRankings(lookUpDate));
}

@Operation(summary = "개인전 개인 랭킹 조회", description = "특정 유저의 현재 순위를 반환한다.")
@GetMapping("/user/{userId}")
public Response<UserRankingResponse> getUserRank(
@Parameter(description = "찾고자 하는 userID", required = true)
@PathVariable Long userId,
@RequestParam(required = false, name = "lookup-date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate lookUpDate
) {
return Response.createSuccess(
userRankingService.getUserCurrentPixelRankInfo(userId, lookUpDate));
@Parameter(description = "찾고자 하는 userID", required = true) @PathVariable("userId") Long userId,
@RequestParam(required = false, name = "lookup-date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate lookUpDate) {
return Response.createSuccess(userRankingService.getUserCurrentPixelRankInfo(userId, lookUpDate));
}

@Operation(summary = "그룹 전체 랭킹 조회", description = "현재 그룹들의 차지 중인 픽셀 기준으로 상위 30개의 랭킹을 반환한다.")
@GetMapping("/community")
public Response<List<CommunityRankingResponse>> getAllCommunityRanking(
@RequestParam(required = false, name = "lookup-date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate lookUpDate) {
return Response.createSuccess(
communityRankingService.getCurrentPixelAllUCommunityRankings(lookUpDate)
);
return Response.createSuccess(communityRankingService.getCurrentPixelAllUCommunityRankings(lookUpDate));
}

@Operation(summary = "그룹 별 랭킹 조회", description = "특정 그룹의 현재 순위를 반환한다.")
@GetMapping("/community/{communityId}")
public Response<CommunityRankingResponse> getCommunityRank(
@Parameter(description = "찾고자 하는 communityId", required = true)
@PathVariable Long communityId,
@RequestParam(required = false, name = "lookup-date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate lookUpDate
) {
@Parameter(description = "찾고자 하는 communityId", required = true) @PathVariable("communityId") Long communityId,
@RequestParam(required = false, name = "lookup-date") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate lookUpDate) {
return Response.createSuccess(
communityRankingService.getCommunityCurrentPixelRankInfo(communityId, lookUpDate));
}
Expand Down
22 changes: 7 additions & 15 deletions src/main/java/com/m3pro/groundflip/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,31 @@ public class UserController {
@Operation(summary = "사용자 기본 정보 조회", description = "닉네임, id, 출생년도, 성별, 프로필 사진, 그룹이름, 그룹 id 를 조회 한다.")
@GetMapping("/{userId}")
public Response<UserInfoResponse> getUserInfo(
@Parameter(description = "찾고자 하는 userId", required = true)
@PathVariable("userId") Long userId
) {
@Parameter(description = "찾고자 하는 userId", required = true) @PathVariable("userId") Long userId) {
return Response.createSuccess(userService.getUserInfo(userId));
}

@Operation(summary = "사용자 정보 수정", description = "닉네임, id, 출생년도, 성별, 프로필 사진을 수정한다.")
@PutMapping("/{userId}")
public Response<?> putUserInfo(
@Parameter(description = "찾고자 하는 userId", required = true)
@PathVariable Long userId,
@RequestPart UserInfoRequest userInfoRequest,
@RequestPart(value = "profileImage", required = false) MultipartFile multipartfile
) throws IOException {
@Parameter(description = "찾고자 하는 userId", required = true) @PathVariable("userId") Long userId,
@RequestPart("userInfoRequest") UserInfoRequest userInfoRequest,
@RequestPart(value = "profileImage", required = false) MultipartFile multipartfile) throws IOException {
userService.putUserInfo(userId, userInfoRequest, multipartfile);
return Response.createSuccessWithNoData();
}

@Operation(summary = "사용자 탈퇴", description = "회원을 탈퇴한다.")
@DeleteMapping("/{userId}")
public Response<?> putUserInfo(
@Parameter(description = "찾고자 하는 userId", required = true) @PathVariable Long userId,
@RequestBody UserDeleteRequest userDeleteRequest
) {
public Response<?> putUserInfo(@Parameter(description = "찾고자 하는 userId", required = true) @PathVariable Long userId,
@RequestBody UserDeleteRequest userDeleteRequest) {
userService.deleteUser(userId, userDeleteRequest);
return Response.createSuccessWithNoData();
}

@Operation(summary = "FCM 등록 토큰 등록", description = "푸시 알림을 위한 FCM 등록 토큰을 저장한다.")
@PostMapping("/fcm-token")
public Response<?> postFcmToken(
@RequestBody FcmTokenRequest fcmTokenRequest
) {
public Response<?> postFcmToken(@RequestBody FcmTokenRequest fcmTokenRequest) {
fcmService.registerFcmToken(fcmTokenRequest);
return Response.createSuccessWithNoData();
}
Expand Down
81 changes: 54 additions & 27 deletions src/main/java/com/m3pro/groundflip/util/S3Uploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,68 @@ public class S3Uploader {
@Value("${cloud.aws.s3.bucket}")
private String bucket;

public String uploadFiles(MultipartFile multipartFile, Long userId) throws IOException {
String originalFileName = multipartFile.getOriginalFilename();
String convertedFileName;
// public String uploadFiles(MultipartFile multipartFile, Long userId) throws IOException {
// String originalFileName = multipartFile.getOriginalFilename();
// String convertedFileName;
// String imageUrl = "";
// final String path = bucket.concat("/static");
//
// if (originalFileName != null) {
// convertedFileName = convertFileNameToUuid(originalFileName, userId);
// ObjectMetadata metadata = new ObjectMetadata();
// metadata.setContentLength(multipartFile.getSize());
// metadata.setContentType(multipartFile.getContentType());
//
// amazonS3Client.putObject(path, convertedFileName, multipartFile.getInputStream(), metadata);
// imageUrl = amazonS3Client.getUrl(path, convertedFileName).toString();
// }
// return imageUrl;
// }

// public String uploadCommunityFiles(MultipartFile multipartFile) throws IOException {
// String originalFileName = multipartFile.getOriginalFilename();
// String convertedFileName;
// String imageUrl = "";
// final String path = bucket.concat("/university_logo");
//
// if (originalFileName != null) {
// convertedFileName = convertFileNameToUuid2(originalFileName);
// ObjectMetadata metadata = new ObjectMetadata();
// metadata.setContentLength(multipartFile.getSize());
// metadata.setContentType(multipartFile.getContentType());
//
// amazonS3Client.putObject(path, convertedFileName, multipartFile.getInputStream(), metadata);
// imageUrl = amazonS3Client.getUrl(path, convertedFileName).toString();
// }
//
// return imageUrl;
// }

public String uploadFile(MultipartFile multipartFile, String bucketPath,
String convertedFileName) throws IOException {
String imageUrl = "";
final String path = bucket.concat("/static");
final String path = bucket.concat(bucketPath);

ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(multipartFile.getSize());
metadata.setContentType(multipartFile.getContentType());

if (originalFileName != null) {
convertedFileName = convertFileNameToUuid(originalFileName, userId);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(multipartFile.getSize());
metadata.setContentType(multipartFile.getContentType());
amazonS3Client.putObject(path, convertedFileName, multipartFile.getInputStream(), metadata);
imageUrl = amazonS3Client.getUrl(path, convertedFileName).toString();

amazonS3Client.putObject(path, convertedFileName, multipartFile.getInputStream(), metadata);
imageUrl = amazonS3Client.getUrl(path, convertedFileName).toString();
}
return imageUrl;
}

public String uploadCommunityFiles(MultipartFile multipartFile) throws IOException {
public String uploadFiles(MultipartFile multipartFile, Long userId) throws IOException {
String originalFileName = multipartFile.getOriginalFilename();
String convertedFileName;
String imageUrl = "";
final String path = bucket.concat("/university_logo");

if (originalFileName != null) {
convertedFileName = convertFileNameToUuid2(originalFileName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(multipartFile.getSize());
metadata.setContentType(multipartFile.getContentType());

amazonS3Client.putObject(path, convertedFileName, multipartFile.getInputStream(), metadata);
imageUrl = amazonS3Client.getUrl(path, convertedFileName).toString();
}
String convertedFileName = convertFileNameToUuid(originalFileName, userId);
return uploadFile(multipartFile, "/static", convertedFileName);
}

return imageUrl;
public String uploadCommunityFiles(MultipartFile multipartFile) throws IOException {
String originalFileName = multipartFile.getOriginalFilename();
String convertedFileName = convertFileNameToUuid2(originalFileName);
return uploadFile(multipartFile, "/university_logo", convertedFileName);
}

private String convertFileNameToUuid(String fileName, Long userId) {
Expand Down

0 comments on commit 595bd3e

Please sign in to comment.