From 9d03825b18280d704cb33a17c20443e4de5e1b21 Mon Sep 17 00:00:00 2001 From: 5nam Date: Wed, 7 May 2025 16:43:38 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor(#34):=20fileService=20AWS=20S3=20?= =?UTF-8?q?=EC=97=B0=EB=8F=99=20-=20fileService=20upload=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=20FileInfo=20=EA=B0=9D=EC=B2=B4=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=20-=20Club,=20User=20=EC=9D=98=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20imgUrl,=20originalImg?= =?UTF-8?q?Name,=20storedImgName(=EC=82=AD=EC=A0=9C=ED=95=A0=20=EB=95=8C?= =?UTF-8?q?=20=EC=93=B0=EC=9D=B4=EB=8A=94=20=EA=B0=92,=20test/aaaa-aaaa-aa?= =?UTF-8?q?aa.jpg)=20=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/local.init.sql | 28 +++--- .../moim/club/dto/response/ClubOutput.java | 4 +- .../club/dto/response/ClubSaveOutput.java | 2 +- .../club/dto/response/ClubSearchOutput.java | 4 +- .../club/dto/response/ClubUpdateOutput.java | 2 +- .../com/example/moim/club/entity/Club.java | 27 +++--- .../club/service/ClubCommandServiceImpl.java | 4 + .../global/util/file/config/AwsS3Config.java | 2 - .../moim/global/util/file/model/AwsS3.java | 14 --- .../moim/global/util/file/model/FileInfo.java | 19 ++++ .../util/file/service/AwsS3FileService.java | 33 ++++--- .../global/util/file/service/FileService.java | 3 +- .../util/file/service/LocalFileService.java | 15 ++-- .../global/util/uuid/SystemUuidHolder.java | 2 +- .../moim/global/util/uuid/TestUuidHolder.java | 11 +++ .../com/example/moim/main/dto/MainOutput.java | 4 +- .../main/dto/RecommendClubListOutput.java | 4 +- .../moim/match/dto/NearClubsOutput.java | 4 +- .../example/moim/user/dto/MyClubOutput.java | 4 +- .../com/example/moim/user/entity/User.java | 36 +++++--- .../moim/user/service/UserService.java | 3 + .../repository/ClubRepositoryImplTest.java | 11 ++- .../file/service/CloudFileServiceTest.java | 89 +++++++++++++++++++ .../file/service/LocalFileServiceTest.java | 27 +++--- .../service/NotificationServiceTest.java | 9 +- src/test/resources/application.properties | 3 +- .../sql/comment-repository-test-data.sql | 28 +++--- .../schedule-vote-repository-test-data.sql | 28 +++--- .../sql/user-club-repository-test-data.sql | 28 +++--- 29 files changed, 307 insertions(+), 141 deletions(-) delete mode 100644 src/main/java/com/example/moim/global/util/file/model/AwsS3.java create mode 100644 src/main/java/com/example/moim/global/util/file/model/FileInfo.java create mode 100644 src/main/java/com/example/moim/global/util/uuid/TestUuidHolder.java create mode 100644 src/test/java/com/example/moim/global/util/file/service/CloudFileServiceTest.java diff --git a/deploy/local.init.sql b/deploy/local.init.sql index eab3437..f473ee6 100644 --- a/deploy/local.init.sql +++ b/deploy/local.init.sql @@ -1,9 +1,9 @@ -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, 2, 'sub_uniform_color', 'title nothing', '한양대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, 2, 'sub_uniform_color', 'titlenothing', '서울대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, null, 2, 'sub_uniform_color', 'title nothing', '연세대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '한양대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '서울대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '연세대학교'); INSERT INTO CLUB_SEARCH (CLUB_ID, CREATED_DATE, UPDATED_DATE, TITLE_NO_SPACE, INTRO_NO_SPACE, EXP_NO_SPACE, ALL_FIELDS_CONCAT) VALUES (1, null, null, 'titlenothing', 'introduction', 'explanation', 'titlenothing|introduction|explanation'); @@ -12,14 +12,14 @@ VALUES (2, null, null, 'titlenothing', 'introduction', 'explanation', 'titlenoth INSERT INTO CLUB_SEARCH (CLUB_ID, CREATED_DATE, UPDATED_DATE, TITLE_NO_SPACE, INTRO_NO_SPACE, EXP_NO_SPACE, ALL_FIELDS_CONCAT) VALUES (3, null, null, 'titlenothing', 'introduction', 'explanation', 'titlenothing|introduction|explanation'); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); INSERT INTO user_club (id, created_date, updated_date, club_role, join_date, match_count, schedule_count, club_id, user_id) VALUES (default, null, null, 'STAFF', '2024-12-11', 2, 2, 1, 1); diff --git a/src/main/java/com/example/moim/club/dto/response/ClubOutput.java b/src/main/java/com/example/moim/club/dto/response/ClubOutput.java index 76e7175..e0a2878 100644 --- a/src/main/java/com/example/moim/club/dto/response/ClubOutput.java +++ b/src/main/java/com/example/moim/club/dto/response/ClubOutput.java @@ -48,8 +48,8 @@ public ClubOutput(Club club, List userList, ClubRole clubRole) { this.mainUniformColor = club.getMainUniformColor(); this.subUniformColor = club.getSubUniformColor(); try { - if (club.getProfileImgPath() != null) { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).getContentAsByteArray()); + if (club.getImageUrl() != null) { + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/com/example/moim/club/dto/response/ClubSaveOutput.java b/src/main/java/com/example/moim/club/dto/response/ClubSaveOutput.java index 616d665..ebe57c4 100644 --- a/src/main/java/com/example/moim/club/dto/response/ClubSaveOutput.java +++ b/src/main/java/com/example/moim/club/dto/response/ClubSaveOutput.java @@ -31,7 +31,7 @@ public ClubSaveOutput(Club club, List userList) { this.title = club.getTitle(); this.explanation = club.getExplanation(); this.introduction = club.getIntroduction(); - this.profileImg = club.getProfileImgPath(); + this.profileImg = club.getImageUrl(); this.clubCategory = club.getClubCategory().getKoreanName(); this.university = club.getUniversity(); this.gender = club.getGender().getKoreanName(); diff --git a/src/main/java/com/example/moim/club/dto/response/ClubSearchOutput.java b/src/main/java/com/example/moim/club/dto/response/ClubSearchOutput.java index 99472d0..c165d31 100644 --- a/src/main/java/com/example/moim/club/dto/response/ClubSearchOutput.java +++ b/src/main/java/com/example/moim/club/dto/response/ClubSearchOutput.java @@ -22,9 +22,9 @@ public ClubSearchOutput(Club club) { this.title = club.getTitle(); this.explanation = club.getExplanation(); this.memberCount = club.getMemberCount(); - if (club.getProfileImgPath() != null) { + if (club.getImageUrl() != null) { try { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).getContentAsByteArray()); + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/example/moim/club/dto/response/ClubUpdateOutput.java b/src/main/java/com/example/moim/club/dto/response/ClubUpdateOutput.java index e0ad228..a8b7649 100644 --- a/src/main/java/com/example/moim/club/dto/response/ClubUpdateOutput.java +++ b/src/main/java/com/example/moim/club/dto/response/ClubUpdateOutput.java @@ -29,7 +29,7 @@ public ClubUpdateOutput(Club club, List userList) { this.title = club.getTitle(); this.explanation = club.getExplanation(); this.introduction = club.getIntroduction(); - this.profileImg = club.getProfileImgPath(); + this.profileImg = club.getImageUrl(); this.clubCategory = club.getClubCategory().getKoreanName(); this.university = club.getUniversity(); this.gender = club.getGender().getKoreanName(); diff --git a/src/main/java/com/example/moim/club/entity/Club.java b/src/main/java/com/example/moim/club/entity/Club.java index f175777..c9d3260 100644 --- a/src/main/java/com/example/moim/club/entity/Club.java +++ b/src/main/java/com/example/moim/club/entity/Club.java @@ -6,7 +6,7 @@ import com.example.moim.global.entity.BaseEntity; import com.example.moim.global.enums.*; import com.example.moim.global.exception.ResponseCode; -import com.example.moim.global.util.TextUtils; +import com.example.moim.global.util.file.model.FileInfo; import com.example.moim.match.entity.Match; import jakarta.persistence.*; import lombok.Getter; @@ -39,7 +39,9 @@ public class Club extends BaseEntity { @Enumerated(value = EnumType.STRING) private AgeRange ageRange; private String clubPassword; - private String profileImgPath = "기본 이미지 링크"; + private String imageUrl; // 프론트에 제공할 URL + private String storedImageName; // UUID 로 저장된 이름 + private String originalImageName; // 파일 업로할 때 이름 private String mainUniformColor; private String subUniformColor; @OneToOne(mappedBy = "club") // 검색을 위한 테이블 매핑 @@ -64,7 +66,7 @@ public class Club extends BaseEntity { /** * TODO : university 는 없을 수도 있으므로, null 일 경우를 처리해주기 */ - public static Club createClub(ClubInput clubInput, String profileImgPath) { + public static Club createClub(ClubInput clubInput, FileInfo fileInfo) { Club club = new Club(); club.title = clubInput.getTitle(); club.explanation = clubInput.getExplanation(); @@ -76,7 +78,11 @@ public static Club createClub(ClubInput clubInput, String profileImgPath) { club.sportsType = SportsType.fromKoreanName(clubInput.getSportsType()).get(); club.ageRange = AgeRange.fromKoreanName(clubInput.getAgeRange()).get(); club.clubPassword = clubInput.getClubPassword(); - club.profileImgPath = profileImgPath; + if (fileInfo != null) { + club.imageUrl = fileInfo.getFileUrl(); + club.originalImageName = fileInfo.getOriginalFileName(); + club.storedImageName = fileInfo.getStoredFileName(); + } club.mainUniformColor = clubInput.getMainUniformColor(); club.subUniformColor = clubInput.getSubUniformColor(); club.memberCount = 1; @@ -89,14 +95,14 @@ public Club updateClubSearch(ClubSearch clubSearch) { } public void changeProfileImg(String newImgPath) { - this.profileImgPath = newImgPath; + this.imageUrl = newImgPath; } public void plusMemberCount() { memberCount++; } - public void updateClub(ClubUpdateInput clubUpdateInput, String profileImgPath) { + public void updateClub(ClubUpdateInput clubUpdateInput, FileInfo fileInfo) { if (StringUtils.hasText(clubUpdateInput.getTitle())) { this.title = clubUpdateInput.getTitle(); } @@ -124,11 +130,10 @@ public void updateClub(ClubUpdateInput clubUpdateInput, String profileImgPath) { if (StringUtils.hasText(clubUpdateInput.getSportsType())) { this.sportsType = SportsType.fromKoreanName(clubUpdateInput.getSportsType()).orElseThrow(() -> new ClubControllerAdvice(ResponseCode.INVALID_SPORTS_TYPE)); } - if (StringUtils.hasText(profileImgPath)) { - if (StringUtils.hasText(this.profileImgPath)) { - new File(this.profileImgPath).delete(); - } - this.profileImgPath = profileImgPath; + if (fileInfo != null) { + this.imageUrl = fileInfo.getFileUrl(); + this.originalImageName = fileInfo.getOriginalFileName(); + this.storedImageName = fileInfo.getStoredFileName(); } } diff --git a/src/main/java/com/example/moim/club/service/ClubCommandServiceImpl.java b/src/main/java/com/example/moim/club/service/ClubCommandServiceImpl.java index 88cbcc6..3429784 100644 --- a/src/main/java/com/example/moim/club/service/ClubCommandServiceImpl.java +++ b/src/main/java/com/example/moim/club/service/ClubCommandServiceImpl.java @@ -64,6 +64,10 @@ public ClubUpdateOutput updateClub(User user, ClubUpdateInput clubUpdateInput, L throw new ClubControllerAdvice(ResponseCode.CLUB_PASSWORD_INCORRECT); } + if (clubUpdateInput.getProfileImg() != null) { + fileService.remove(club.getStoredImageName()); + } + club.updateClub(clubUpdateInput, fileService.upload(clubUpdateInput.getProfileImg(), "/club-profile")); // 검색 정보 동기화를 위한 처리 club.getClubSearch().updateFrom(club); diff --git a/src/main/java/com/example/moim/global/util/file/config/AwsS3Config.java b/src/main/java/com/example/moim/global/util/file/config/AwsS3Config.java index 855a783..8d6bd04 100644 --- a/src/main/java/com/example/moim/global/util/file/config/AwsS3Config.java +++ b/src/main/java/com/example/moim/global/util/file/config/AwsS3Config.java @@ -8,10 +8,8 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; @Slf4j -@Profile("!test") @Configuration public class AwsS3Config { diff --git a/src/main/java/com/example/moim/global/util/file/model/AwsS3.java b/src/main/java/com/example/moim/global/util/file/model/AwsS3.java deleted file mode 100644 index b20b378..0000000 --- a/src/main/java/com/example/moim/global/util/file/model/AwsS3.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.example.moim.global.util.file.model; - -import lombok.*; - -@Builder -@Getter @Setter -@NoArgsConstructor -@AllArgsConstructor -public class AwsS3 { - - private String key; - private String path; - -} diff --git a/src/main/java/com/example/moim/global/util/file/model/FileInfo.java b/src/main/java/com/example/moim/global/util/file/model/FileInfo.java new file mode 100644 index 0000000..93a1f07 --- /dev/null +++ b/src/main/java/com/example/moim/global/util/file/model/FileInfo.java @@ -0,0 +1,19 @@ +package com.example.moim.global.util.file.model; + +import lombok.Builder; +import lombok.Data; + +@Data +public class FileInfo { + + private String originalFileName; + private String storedFileName; + private String fileUrl; + + @Builder + public FileInfo(String originalFileName, String storedFileName, String fileUrl, String contentType, long size) { + this.originalFileName = originalFileName; + this.storedFileName = storedFileName; + this.fileUrl = fileUrl; + } +} diff --git a/src/main/java/com/example/moim/global/util/file/service/AwsS3FileService.java b/src/main/java/com/example/moim/global/util/file/service/AwsS3FileService.java index e381bb5..98d75bb 100644 --- a/src/main/java/com/example/moim/global/util/file/service/AwsS3FileService.java +++ b/src/main/java/com/example/moim/global/util/file/service/AwsS3FileService.java @@ -1,12 +1,11 @@ package com.example.moim.global.util.file.service; import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; import com.example.moim.global.exception.ResponseCode; -import com.example.moim.global.util.file.model.AwsS3; import com.example.moim.global.util.file.exception.advice.AwsS3ControllerAdvice; +import com.example.moim.global.util.file.model.FileInfo; import com.example.moim.global.util.uuid.UuidHolder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -18,7 +17,7 @@ import java.io.IOException; @Slf4j -//@Service +@Service //@Profile("!test") @RequiredArgsConstructor public class AwsS3FileService implements FileService { @@ -29,11 +28,18 @@ public class AwsS3FileService implements FileService { @Value("${cloud.aws.s3.bucket}") private String bucket; - public String upload(MultipartFile multipartFile, String directoryName) { + public FileInfo upload(MultipartFile multipartFile, String directoryName) { // 확장자 가져오기 String originalFilename = multipartFile.getOriginalFilename(); - String extension = originalFilename.substring(originalFilename.lastIndexOf(".")); + + int dotIndex = originalFilename.lastIndexOf("."); + + if (dotIndex == -1 || dotIndex == originalFilename.length() - 1) { + throw new AwsS3ControllerAdvice(ResponseCode.FILE_CONTENT_TYPE_NOT_IMAGE); + } + + String extension = originalFilename.substring(dotIndex); String fileName = uuidHolder.randomUuid() + extension; String key = directoryName + "/" + fileName; @@ -46,8 +52,7 @@ public String upload(MultipartFile multipartFile, String directoryName) { try { // 파일 업로드 - PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, multipartFile.getInputStream(), metadata) - .withCannedAcl(CannedAccessControlList.PublicRead); // Public Read 권한 설정 + PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, multipartFile.getInputStream(), metadata); // Public Read 권한 설정 amazonS3.putObject(putObjectRequest); } catch (IOException e) { throw new AwsS3ControllerAdvice(ResponseCode.S3_UPLOAD_FAIL); @@ -56,13 +61,11 @@ public String upload(MultipartFile multipartFile, String directoryName) { String path = amazonS3.getUrl(bucket, key).toString(); log.info("upload path : {}", path); - AwsS3 result = AwsS3 - .builder() - .key(key) - .path(path) + return FileInfo.builder() + .fileUrl(path) + .originalFileName(originalFilename) + .storedFileName(key) .build(); - - return result.getPath(); } public void remove(String path) { @@ -75,4 +78,8 @@ public void remove(String path) { } + public boolean doesObjectExist(String objectName) { + return amazonS3.doesObjectExist(bucket, objectName); + } + } diff --git a/src/main/java/com/example/moim/global/util/file/service/FileService.java b/src/main/java/com/example/moim/global/util/file/service/FileService.java index 7b0fda3..a5da6f1 100644 --- a/src/main/java/com/example/moim/global/util/file/service/FileService.java +++ b/src/main/java/com/example/moim/global/util/file/service/FileService.java @@ -1,10 +1,11 @@ package com.example.moim.global.util.file.service; +import com.example.moim.global.util.file.model.FileInfo; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; public interface FileService { - String upload(MultipartFile multipartFile, String directoryName) throws IOException; + FileInfo upload(MultipartFile multipartFile, String directoryName) throws IOException; void remove(String path); } diff --git a/src/main/java/com/example/moim/global/util/file/service/LocalFileService.java b/src/main/java/com/example/moim/global/util/file/service/LocalFileService.java index a0d0c0c..534726f 100644 --- a/src/main/java/com/example/moim/global/util/file/service/LocalFileService.java +++ b/src/main/java/com/example/moim/global/util/file/service/LocalFileService.java @@ -2,6 +2,7 @@ import com.example.moim.global.exception.ResponseCode; import com.example.moim.global.util.file.exception.advice.LocalFileControllerAdvice; +import com.example.moim.global.util.file.model.FileInfo; import com.example.moim.global.util.uuid.UuidHolder; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -14,9 +15,9 @@ import java.io.FileOutputStream; import java.io.IOException; -@Service +//@Service @Slf4j -//@Profile("test") +@Profile("!test") @RequiredArgsConstructor public class LocalFileService implements FileService { @@ -27,7 +28,7 @@ public class LocalFileService implements FileService { private final UuidHolder uuidHolder; @Override - public String upload(MultipartFile multipartFile, String directoryName) throws IOException { + public FileInfo upload(MultipartFile multipartFile, String directoryName) throws IOException { String originalFileName = multipartFile.getOriginalFilename(); String mimeType = multipartFile.getContentType(); @@ -61,7 +62,11 @@ public String upload(MultipartFile multipartFile, String directoryName) throws I } } - return file.getPath(); + return FileInfo.builder() + .fileUrl(file.getPath()) + .originalFileName(originalFileName) + .storedFileName(randomFileName) + .build(); } private boolean fileTypeCheck(String mimeType) { @@ -70,7 +75,7 @@ private boolean fileTypeCheck(String mimeType) { @Override public void remove(String path) { - File file = new File(path); + File file = new File(fileUploadDir + path); file.delete(); } diff --git a/src/main/java/com/example/moim/global/util/uuid/SystemUuidHolder.java b/src/main/java/com/example/moim/global/util/uuid/SystemUuidHolder.java index b7d4841..cc0f312 100644 --- a/src/main/java/com/example/moim/global/util/uuid/SystemUuidHolder.java +++ b/src/main/java/com/example/moim/global/util/uuid/SystemUuidHolder.java @@ -7,7 +7,7 @@ import java.util.UUID; @Slf4j -//@Profile("!test") +@Profile("!test") @Component public class SystemUuidHolder implements UuidHolder { @Override diff --git a/src/main/java/com/example/moim/global/util/uuid/TestUuidHolder.java b/src/main/java/com/example/moim/global/util/uuid/TestUuidHolder.java new file mode 100644 index 0000000..78bb78d --- /dev/null +++ b/src/main/java/com/example/moim/global/util/uuid/TestUuidHolder.java @@ -0,0 +1,11 @@ +package com.example.moim.global.util.uuid; + +import org.springframework.stereotype.Component; + +@Component +public class TestUuidHolder implements UuidHolder { + @Override + public String randomUuid() { + return "aaaa-aaaa-aaaa"; + } +} diff --git a/src/main/java/com/example/moim/main/dto/MainOutput.java b/src/main/java/com/example/moim/main/dto/MainOutput.java index f0fb08e..ef00ecb 100644 --- a/src/main/java/com/example/moim/main/dto/MainOutput.java +++ b/src/main/java/com/example/moim/main/dto/MainOutput.java @@ -22,8 +22,8 @@ public MainOutput(Club club, List scheduleList) { this.title = club.getTitle(); this.explanation = club.getExplanation(); try { - if (club.getProfileImgPath() != null) { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).getContentAsByteArray()); + if (club.getImageUrl() != null) { + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/com/example/moim/main/dto/RecommendClubListOutput.java b/src/main/java/com/example/moim/main/dto/RecommendClubListOutput.java index 6381bd7..ac9e8ef 100644 --- a/src/main/java/com/example/moim/main/dto/RecommendClubListOutput.java +++ b/src/main/java/com/example/moim/main/dto/RecommendClubListOutput.java @@ -20,9 +20,9 @@ public RecommendClubListOutput(Club club) { this.title = club.getTitle(); this.explanation = club.getExplanation(); this.memberCount = club.getMemberCount(); - if (club.getProfileImgPath() != null) { + if (club.getImageUrl() != null) { try { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).getContentAsByteArray()); + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/example/moim/match/dto/NearClubsOutput.java b/src/main/java/com/example/moim/match/dto/NearClubsOutput.java index 1519edd..8a7f41d 100644 --- a/src/main/java/com/example/moim/match/dto/NearClubsOutput.java +++ b/src/main/java/com/example/moim/match/dto/NearClubsOutput.java @@ -14,9 +14,9 @@ public class NearClubsOutput { public NearClubsOutput(Club club) { this.title = club.getTitle(); - if (club.getProfileImgPath() != null) { + if (club.getImageUrl() != null) { try { - this.image = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).getContentAsByteArray()); + this.image = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/example/moim/user/dto/MyClubOutput.java b/src/main/java/com/example/moim/user/dto/MyClubOutput.java index 2007412..08a625d 100644 --- a/src/main/java/com/example/moim/user/dto/MyClubOutput.java +++ b/src/main/java/com/example/moim/user/dto/MyClubOutput.java @@ -20,8 +20,8 @@ public MyClubOutput(Club club) { this.clubName = club.getTitle(); this.explanation = club.getExplanation(); try { - if (club.getProfileImgPath() != null) { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).getContentAsByteArray()); + if (club.getImageUrl() != null) { + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/com/example/moim/user/entity/User.java b/src/main/java/com/example/moim/user/entity/User.java index 72ef3f4..a0c0ba5 100644 --- a/src/main/java/com/example/moim/user/entity/User.java +++ b/src/main/java/com/example/moim/user/entity/User.java @@ -6,6 +6,7 @@ import com.example.moim.global.enums.Gender; import com.example.moim.global.enums.Position; import com.example.moim.global.exception.ResponseCode; +import com.example.moim.global.util.file.model.FileInfo; import com.example.moim.notification.entity.NotificationEntity; import com.example.moim.user.dto.GoogleUserSignup; import com.example.moim.user.dto.KakaoUserSignup; @@ -49,6 +50,8 @@ public class User extends BaseEntity { private Gender gender; private String phone; private String imgPath; + private String originalImgName; + private String storedImgName; @Enumerated(EnumType.STRING) private Role role; @Enumerated(EnumType.STRING) @@ -71,7 +74,7 @@ public class User extends BaseEntity { @Builder public User(String email, String password, String name, String birthday, Gender gender, String phone, - String imgPath, + FileInfo fileInfo, Role role, ActivityArea activityArea, int height, int weight, String mainFoot, Position mainPosition, Position subPosition, String refreshToken, String fcmToken, List userClub, List notifications) { @@ -81,7 +84,15 @@ public User(String email, String password, String name, String birthday, Gender this.birthday = birthday; this.gender = gender; this.phone = phone; - this.imgPath = imgPath; + /** + * CHECK: 여기 파일 서비스 구조 고쳐지면서, 변경된 코드입니다! + */ + if (fileInfo != null) { + this.imgPath = fileInfo.getFileUrl(); + this.originalImgName = fileInfo.getOriginalFileName(); + this.storedImgName = fileInfo.getStoredFileName(); + } + this.role = role; this.activityArea = activityArea; this.height = height; @@ -141,11 +152,14 @@ public static User createNaverUser(NaverUserSignup naverUserSignup) { return user; } - public void fillUserInfo(SocialSignupInput socialSignupInput, String imgPath) { + public void fillUserInfo(SocialSignupInput socialSignupInput, FileInfo fileInfo) { this.name = socialSignupInput.getName(); this.birthday = socialSignupInput.getBirthday(); this.phone = socialSignupInput.getPhone(); - this.imgPath = imgPath; + /** + * CHECK: 여기 파일 서비스 구조 고쳐지면서, 변경된 코드입니다! + */ + this.imgPath = fileInfo.getFileUrl(); // this.gender = Gender.from(socialSignupInput.getGender()); this.gender = Gender.fromKoreanName(socialSignupInput.getGender()) .orElseThrow(() -> new UserControllerAdvice(ResponseCode.INVALID_GENDER)); @@ -160,7 +174,7 @@ public void fillUserInfo(SocialSignupInput socialSignupInput, String imgPath) { } } - public void updateUserInfo(UserUpdateInput userUpdateInput, String imgPath) { + public void updateUserInfo(UserUpdateInput userUpdateInput, FileInfo fileInfo) { if (userUpdateInput.getName() != null && !userUpdateInput.getName().isBlank()) { this.name = userUpdateInput.getName(); } @@ -170,11 +184,13 @@ public void updateUserInfo(UserUpdateInput userUpdateInput, String imgPath) { if (userUpdateInput.getPhone() != null && !userUpdateInput.getPhone().isBlank()) { this.phone = userUpdateInput.getPhone(); } - if (imgPath != null) { - if (this.imgPath != null) { - new File(this.imgPath).delete(); - } - this.imgPath = imgPath; + /** + * CHECK: 여기 파일 서비스 구조 고쳐지면서, 변경된 코드입니다! + */ + if (fileInfo != null) { + this.imgPath = fileInfo.getFileUrl(); + this.storedImgName = fileInfo.getStoredFileName(); + this.originalImgName = fileInfo.getOriginalFileName(); } if (userUpdateInput.getGender() != null && !userUpdateInput.getGender().isBlank()) { this.gender = Gender.fromKoreanName(userUpdateInput.getGender()) diff --git a/src/main/java/com/example/moim/user/service/UserService.java b/src/main/java/com/example/moim/user/service/UserService.java index 3e22aa2..56618f4 100644 --- a/src/main/java/com/example/moim/user/service/UserService.java +++ b/src/main/java/com/example/moim/user/service/UserService.java @@ -66,6 +66,9 @@ public void saveUserInfo(User loginUser, SocialSignupInput socialSignupInput) th @Transactional public void updateUserInfo(User loginUser, UserUpdateInput userUpdateInput) throws IOException { User user = userRepository.findById(loginUser.getId()).get(); + if (userUpdateInput.getImg() != null) { + fileService.remove(user.getStoredImgName()); + } user.updateUserInfo(userUpdateInput, fileService.upload(userUpdateInput.getImg(), "/user_profile")); } diff --git a/src/test/java/com/example/moim/club/repository/ClubRepositoryImplTest.java b/src/test/java/com/example/moim/club/repository/ClubRepositoryImplTest.java index 2133b77..de13437 100644 --- a/src/test/java/com/example/moim/club/repository/ClubRepositoryImplTest.java +++ b/src/test/java/com/example/moim/club/repository/ClubRepositoryImplTest.java @@ -5,6 +5,7 @@ import com.example.moim.club.entity.*; import com.example.moim.global.enums.*; import com.example.moim.global.util.TextUtils; +import com.example.moim.global.util.file.model.FileInfo; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -55,8 +56,14 @@ void init() { .university(university).gender(gender.getKoreanName()).activityArea(activityArea.getKoreanName()).ageRange(ageRange.getKoreanName()).sportsType(sportsType.getKoreanName()) .clubPassword(clubPassword).profileImg(profileImg).mainUniformColor(mainUniformColor).subUniformColor(subUniformColor).build(); - Club savedClub = clubRepository.save(Club.createClub(clubInput, "/club")); - Club savedClub2 = clubRepository.save(Club.createClub(clubInput2, "/club")); + FileInfo fileInfo = FileInfo.builder() + .fileUrl("fileUrl") + .originalFileName("originalFileName.jpg") + .storedFileName("test/aaaa-aaaa-aaaa.jpg") + .build(); + + Club savedClub = clubRepository.save(Club.createClub(clubInput, fileInfo)); + Club savedClub2 = clubRepository.save(Club.createClub(clubInput2, fileInfo)); ClubSearch clubSearch = ClubSearch.builder() .club(savedClub) diff --git a/src/test/java/com/example/moim/global/util/file/service/CloudFileServiceTest.java b/src/test/java/com/example/moim/global/util/file/service/CloudFileServiceTest.java new file mode 100644 index 0000000..bda1394 --- /dev/null +++ b/src/test/java/com/example/moim/global/util/file/service/CloudFileServiceTest.java @@ -0,0 +1,89 @@ +package com.example.moim.global.util.file.service; + +import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; +import com.amazonaws.regions.Regions; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import com.example.moim.global.exception.ResponseCode; +import com.example.moim.global.util.file.exception.advice.AwsS3ControllerAdvice; +import com.example.moim.global.util.file.model.FileInfo; +import com.example.moim.global.util.uuid.UuidHolder; +import com.example.moim.schedule.exception.advice.ScheduleControllerAdvice; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.util.ReflectionTestUtils; + +import java.io.File; +import java.io.IOException; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.when; + +@Slf4j +@SpringBootTest +class CloudFileServiceTest { + + @Autowired + private AwsS3FileService fileService; + + @Value("${cloud.aws.s3.bucket}") + String bucket; + + @Test + void upload() throws IOException { + //given + MockMultipartFile mockMultipartFile = new MockMultipartFile("name", "originalName.jpg", "image/png", "ddd".getBytes()); + + log.debug("originalName = {}", mockMultipartFile.getOriginalFilename()); + + //when + FileInfo fileInfo = fileService.upload(mockMultipartFile, "test"); + + //then + assertThat(fileInfo.getFileUrl()).contains("/test"); + assertThat(fileService.doesObjectExist("test/aaaa-aaaa-aaaa.jpg")).isTrue(); + + fileService.remove(fileInfo.getStoredFileName()); + } + + @Test + void upload_wrong_file_type() throws IOException { + //given + MockMultipartFile mockMultipartFile = new MockMultipartFile("name", "originalName", "image/png", "ddd".getBytes()); + + log.debug("originalName = {}", mockMultipartFile.getOriginalFilename()); + + //when + //then + Exception exception = assertThrows(AwsS3ControllerAdvice.class, () -> { + fileService.upload(mockMultipartFile, "test"); + }); + assertThat(exception.getMessage()).isEqualTo(ResponseCode.FILE_CONTENT_TYPE_NOT_IMAGE.getMessage()); + } + + @Test + void remove() throws IOException { + //given + MockMultipartFile mockMultipartFile = new MockMultipartFile("delete file", "delete_originalName.jpg", "image/png", "delete".getBytes()); + + FileInfo fileInfo = fileService.upload(mockMultipartFile, "test"); + + //when + fileService.remove(fileInfo.getStoredFileName()); + + //then + assertThat(fileService.doesObjectExist(fileInfo.getStoredFileName())).isFalse(); + + } +} \ No newline at end of file diff --git a/src/test/java/com/example/moim/global/util/file/service/LocalFileServiceTest.java b/src/test/java/com/example/moim/global/util/file/service/LocalFileServiceTest.java index 4e3ab92..f14aa31 100644 --- a/src/test/java/com/example/moim/global/util/file/service/LocalFileServiceTest.java +++ b/src/test/java/com/example/moim/global/util/file/service/LocalFileServiceTest.java @@ -1,6 +1,8 @@ package com.example.moim.global.util.file.service; +import com.example.moim.global.util.file.model.FileInfo; import com.example.moim.global.util.uuid.UuidHolder; +import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -16,6 +18,7 @@ import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.Mockito.when; +@Slf4j @ExtendWith(MockitoExtension.class) class LocalFileServiceTest { @@ -32,20 +35,24 @@ void setUp() { @Test void upload() throws IOException { //given - MockMultipartFile mockMultipartFile = new MockMultipartFile("name", "originalName", "image/png", "ddd".getBytes()); + MockMultipartFile mockMultipartFile = new MockMultipartFile("name", "originalName.jpg", "image/png", "ddd".getBytes()); //when when(testUuidHolder.randomUuid()).thenReturn("aaaa-aaaa-aaaa"); //then - String filePath = localFileService.upload(mockMultipartFile, "/test"); + FileInfo fileInfo = localFileService.upload(mockMultipartFile, "/test"); - assertThat(filePath).contains("/test"); - assertThat(filePath).contains("aaaa-aaaa-aaaa"); - assertThat(filePath).contains("originalName"); - assertThat(new File(filePath).exists()).isTrue(); + log.info("fileUrl : {}", fileInfo.getFileUrl()); + log.info("originalName : {}", fileInfo.getOriginalFileName()); + log.info("storedName : {}", fileInfo.getStoredFileName()); - localFileService.remove(filePath); + assertThat(fileInfo.getFileUrl()).contains("/test"); + assertThat(fileInfo.getStoredFileName()).contains("aaaa-aaaa-aaaa"); + assertThat(fileInfo.getOriginalFileName()).contains("originalName.jpg"); + assertThat(new File(fileInfo.getFileUrl()).exists()).isTrue(); + + localFileService.remove(fileInfo.getStoredFileName()); } @Test @@ -53,12 +60,12 @@ void remove() throws IOException { //given MockMultipartFile mockMultipartFile = new MockMultipartFile("delete file", "delete originalName", "image/png", "delete".getBytes()); when(testUuidHolder.randomUuid()).thenReturn("aaaa-aaaa-aaaa"); - String filePath = localFileService.upload(mockMultipartFile, "/test"); + FileInfo fileInfo = localFileService.upload(mockMultipartFile, "/test"); //when - localFileService.remove(filePath); + localFileService.remove(fileInfo.getStoredFileName()); //then - assertThat(new File(filePath).exists()).isFalse(); + assertThat(new File(fileInfo.getStoredFileName()).exists()).isFalse(); } } \ No newline at end of file diff --git a/src/test/java/com/example/moim/notification/service/NotificationServiceTest.java b/src/test/java/com/example/moim/notification/service/NotificationServiceTest.java index 16a694a..4b38dcb 100644 --- a/src/test/java/com/example/moim/notification/service/NotificationServiceTest.java +++ b/src/test/java/com/example/moim/notification/service/NotificationServiceTest.java @@ -10,6 +10,7 @@ import com.example.moim.club.dto.request.ClubInput; import com.example.moim.club.entity.Club; +import com.example.moim.global.util.file.model.FileInfo; import com.example.moim.notification.dto.ClubJoinEvent; import com.example.moim.notification.dto.NotificationExistOutput; import com.example.moim.notification.dto.NotificationOutput; @@ -141,6 +142,12 @@ void shouldDeleteNotificationById() { @DisplayName("알림을 저장하고 전송한다") void shouldSaveAndSendNotifications() { // given + FileInfo fileInfo = FileInfo.builder() + .fileUrl("fileUrl") + .originalFileName("originalFileName.jpg") + .storedFileName("test/aaaa-aaaa-aaaa.jpg") + .build(); + User targetUser = User.createUser( SignupInput.builder() .phone("010-1234-5678") @@ -161,7 +168,7 @@ void shouldSaveAndSendNotifications() { .sportsType("축구") .ageRange("20대") .build() - , "path/to/image" + , fileInfo ); NotificationEntity n1 = NotificationEntity.create(targetUser diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index b2d2a5a..c7ae262 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -1 +1,2 @@ -spring.profiles.active=test \ No newline at end of file +#spring.profiles.active= +spring.profiles.include=test, s3 \ No newline at end of file diff --git a/src/test/resources/sql/comment-repository-test-data.sql b/src/test/resources/sql/comment-repository-test-data.sql index 02d19cd..8e110ce 100644 --- a/src/test/resources/sql/comment-repository-test-data.sql +++ b/src/test/resources/sql/comment-repository-test-data.sql @@ -1,21 +1,21 @@ --ALTER TABLE USERS DROP CONSTRAINT CONSTRAINT_4; --ALTER TABLE USERS DROP CONSTRAINT CONSTRAINT_4D4; -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, 'profile_img_path', 2, 'sub_uniform_color', 'title', '한양대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, 'profile_img_path', 2, 'sub_uniform_color', 'title', '서울대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, 'profile_img_path', 2, 'sub_uniform_color', 'title', '연세대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '한양대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '서울대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '연세대학교'); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, 'img_path', 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, 'img_path', 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, 'img_path', 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, 'img_path', 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); INSERT INTO user_club (id, created_date, updated_date, club_role, join_date, match_count, schedule_count, club_id, user_id) VALUES (default, null, null, 'STAFF', '2024-12-11', 2, 2, 1, 1); diff --git a/src/test/resources/sql/schedule-vote-repository-test-data.sql b/src/test/resources/sql/schedule-vote-repository-test-data.sql index d3b8158..c7a9457 100644 --- a/src/test/resources/sql/schedule-vote-repository-test-data.sql +++ b/src/test/resources/sql/schedule-vote-repository-test-data.sql @@ -1,18 +1,18 @@ -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, 'profile_img_path', 2, 'sub_uniform_color', 'title', '한양대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, 'profile_img_path', 2, 'sub_uniform_color', 'title', '서울대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, 'profile_img_path', 2, 'sub_uniform_color', 'title', '연세대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '한양대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '서울대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '연세대학교'); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, 'img_path', 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, 'img_path', 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, 'img_path', 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, 'img_path', 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); INSERT INTO user_club (id, created_date, updated_date, club_role, join_date, match_count, schedule_count, club_id, user_id) VALUES (default, null, null, 'STAFF', '2024-12-11', 2, 2, 1, 1); diff --git a/src/test/resources/sql/user-club-repository-test-data.sql b/src/test/resources/sql/user-club-repository-test-data.sql index 0c90d45..3029ba3 100644 --- a/src/test/resources/sql/user-club-repository-test-data.sql +++ b/src/test/resources/sql/user-club-repository-test-data.sql @@ -1,21 +1,21 @@ --ALTER TABLE USERS DROP CONSTRAINT CONSTRAINT_4; --ALTER TABLE USERS DROP CONSTRAINT CONSTRAINT_4D4; -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, 'profile_img_path', 2, 'sub_uniform_color', 'title', '한양대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, 'profile_img_path', 2, 'sub_uniform_color', 'title', '서울대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, profile_img_path, schedule_count, sub_uniform_color, title, university) -VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, 'profile_img_path', 2, 'sub_uniform_color', 'title', '연세대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '한양대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '서울대학교'); +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '연세대학교'); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, 'img_path', 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, 'img_path', 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, 'img_path', 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) -VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, 'img_path', 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); INSERT INTO user_club (id, created_date, updated_date, club_role, join_date, match_count, schedule_count, club_id, user_id) VALUES (default, null, null, 'STAFF', '2024-12-11', 2, 2, 1, 1); From d230ae5e9b5ebfb14916ed0b0edb040cde8ff1c5 Mon Sep 17 00:00:00 2001 From: 5nam Date: Wed, 7 May 2025 17:04:29 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor(#34):=20img=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EC=BB=AC=EB=9F=BC=EB=AA=85=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/local.init.sql | 14 ++++++------- .../moim/club/dto/response/ClubOutput.java | 4 ++-- .../club/dto/response/ClubSaveOutput.java | 2 +- .../club/dto/response/ClubSearchOutput.java | 4 ++-- .../club/dto/response/ClubUpdateOutput.java | 2 +- .../club/dto/response/UserClubOutput.java | 4 ++-- .../com/example/moim/club/entity/Club.java | 21 +++++++++---------- .../club/service/ClubCommandServiceImpl.java | 2 +- .../com/example/moim/main/dto/MainOutput.java | 4 ++-- .../main/dto/RecommendClubListOutput.java | 4 ++-- .../moim/match/dto/NearClubsOutput.java | 4 ++-- .../moim/schedule/dto/ScheduleUserOutput.java | 4 ++-- .../example/moim/user/dto/LoginOutput.java | 4 ++-- .../example/moim/user/dto/MyClubOutput.java | 4 ++-- .../com/example/moim/user/dto/UserOutput.java | 5 ++--- .../com/example/moim/user/entity/User.java | 12 +++++------ .../sql/comment-repository-test-data.sql | 14 ++++++------- .../schedule-vote-repository-test-data.sql | 14 ++++++------- .../sql/user-club-repository-test-data.sql | 14 ++++++------- 19 files changed, 67 insertions(+), 69 deletions(-) diff --git a/deploy/local.init.sql b/deploy/local.init.sql index f473ee6..a467f24 100644 --- a/deploy/local.init.sql +++ b/deploy/local.init.sql @@ -1,8 +1,8 @@ -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '한양대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '서울대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '연세대학교'); INSERT INTO CLUB_SEARCH (CLUB_ID, CREATED_DATE, UPDATED_DATE, TITLE_NO_SPACE, INTRO_NO_SPACE, EXP_NO_SPACE, ALL_FIELDS_CONCAT) @@ -12,13 +12,13 @@ VALUES (2, null, null, 'titlenothing', 'introduction', 'explanation', 'titlenoth INSERT INTO CLUB_SEARCH (CLUB_ID, CREATED_DATE, UPDATED_DATE, TITLE_NO_SPACE, INTRO_NO_SPACE, EXP_NO_SPACE, ALL_FIELDS_CONCAT) VALUES (3, null, null, 'titlenothing', 'introduction', 'explanation', 'titlenothing|introduction|explanation'); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); INSERT INTO user_club (id, created_date, updated_date, club_role, join_date, match_count, schedule_count, club_id, user_id) diff --git a/src/main/java/com/example/moim/club/dto/response/ClubOutput.java b/src/main/java/com/example/moim/club/dto/response/ClubOutput.java index e0a2878..284038b 100644 --- a/src/main/java/com/example/moim/club/dto/response/ClubOutput.java +++ b/src/main/java/com/example/moim/club/dto/response/ClubOutput.java @@ -48,8 +48,8 @@ public ClubOutput(Club club, List userList, ClubRole clubRole) { this.mainUniformColor = club.getMainUniformColor(); this.subUniformColor = club.getSubUniformColor(); try { - if (club.getImageUrl() != null) { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); + if (club.getImgUrl() != null) { + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImgUrl()).getContentAsByteArray()); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/com/example/moim/club/dto/response/ClubSaveOutput.java b/src/main/java/com/example/moim/club/dto/response/ClubSaveOutput.java index ebe57c4..c2bd858 100644 --- a/src/main/java/com/example/moim/club/dto/response/ClubSaveOutput.java +++ b/src/main/java/com/example/moim/club/dto/response/ClubSaveOutput.java @@ -31,7 +31,7 @@ public ClubSaveOutput(Club club, List userList) { this.title = club.getTitle(); this.explanation = club.getExplanation(); this.introduction = club.getIntroduction(); - this.profileImg = club.getImageUrl(); + this.profileImg = club.getImgUrl(); this.clubCategory = club.getClubCategory().getKoreanName(); this.university = club.getUniversity(); this.gender = club.getGender().getKoreanName(); diff --git a/src/main/java/com/example/moim/club/dto/response/ClubSearchOutput.java b/src/main/java/com/example/moim/club/dto/response/ClubSearchOutput.java index c165d31..c6e885c 100644 --- a/src/main/java/com/example/moim/club/dto/response/ClubSearchOutput.java +++ b/src/main/java/com/example/moim/club/dto/response/ClubSearchOutput.java @@ -22,9 +22,9 @@ public ClubSearchOutput(Club club) { this.title = club.getTitle(); this.explanation = club.getExplanation(); this.memberCount = club.getMemberCount(); - if (club.getImageUrl() != null) { + if (club.getImgUrl() != null) { try { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImgUrl()).getContentAsByteArray()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/example/moim/club/dto/response/ClubUpdateOutput.java b/src/main/java/com/example/moim/club/dto/response/ClubUpdateOutput.java index a8b7649..aa19b09 100644 --- a/src/main/java/com/example/moim/club/dto/response/ClubUpdateOutput.java +++ b/src/main/java/com/example/moim/club/dto/response/ClubUpdateOutput.java @@ -29,7 +29,7 @@ public ClubUpdateOutput(Club club, List userList) { this.title = club.getTitle(); this.explanation = club.getExplanation(); this.introduction = club.getIntroduction(); - this.profileImg = club.getImageUrl(); + this.profileImg = club.getImgUrl(); this.clubCategory = club.getClubCategory().getKoreanName(); this.university = club.getUniversity(); this.gender = club.getGender().getKoreanName(); diff --git a/src/main/java/com/example/moim/club/dto/response/UserClubOutput.java b/src/main/java/com/example/moim/club/dto/response/UserClubOutput.java index bf2ba66..b739a83 100644 --- a/src/main/java/com/example/moim/club/dto/response/UserClubOutput.java +++ b/src/main/java/com/example/moim/club/dto/response/UserClubOutput.java @@ -28,9 +28,9 @@ public UserClubOutput(UserClub userClub) { this.clubRole = userClub.getClubRole().getKoreanName(); this.joinDate = userClub.getJoinDate(); this.birthday = userClub.getUser().getBirthday(); - if (StringUtils.hasText(userClub.getUser().getImgPath())) { + if (StringUtils.hasText(userClub.getUser().getImgUrl())) { try { - this.img = Base64.getEncoder().encodeToString(new FileUrlResource(userClub.getUser().getImgPath()).getContentAsByteArray()); + this.img = Base64.getEncoder().encodeToString(new FileUrlResource(userClub.getUser().getImgUrl()).getContentAsByteArray()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/example/moim/club/entity/Club.java b/src/main/java/com/example/moim/club/entity/Club.java index c9d3260..3bd712e 100644 --- a/src/main/java/com/example/moim/club/entity/Club.java +++ b/src/main/java/com/example/moim/club/entity/Club.java @@ -13,7 +13,6 @@ import lombok.NoArgsConstructor; import org.springframework.util.StringUtils; -import java.io.File; import java.util.ArrayList; import java.util.List; @@ -39,9 +38,9 @@ public class Club extends BaseEntity { @Enumerated(value = EnumType.STRING) private AgeRange ageRange; private String clubPassword; - private String imageUrl; // 프론트에 제공할 URL - private String storedImageName; // UUID 로 저장된 이름 - private String originalImageName; // 파일 업로할 때 이름 + private String imgUrl; // 프론트에 제공할 URL + private String storedImgName; // UUID 로 저장된 이름 + private String originalImgName; // 파일 업로할 때 이름 private String mainUniformColor; private String subUniformColor; @OneToOne(mappedBy = "club") // 검색을 위한 테이블 매핑 @@ -79,9 +78,9 @@ public static Club createClub(ClubInput clubInput, FileInfo fileInfo) { club.ageRange = AgeRange.fromKoreanName(clubInput.getAgeRange()).get(); club.clubPassword = clubInput.getClubPassword(); if (fileInfo != null) { - club.imageUrl = fileInfo.getFileUrl(); - club.originalImageName = fileInfo.getOriginalFileName(); - club.storedImageName = fileInfo.getStoredFileName(); + club.imgUrl = fileInfo.getFileUrl(); + club.originalImgName = fileInfo.getOriginalFileName(); + club.storedImgName = fileInfo.getStoredFileName(); } club.mainUniformColor = clubInput.getMainUniformColor(); club.subUniformColor = clubInput.getSubUniformColor(); @@ -95,7 +94,7 @@ public Club updateClubSearch(ClubSearch clubSearch) { } public void changeProfileImg(String newImgPath) { - this.imageUrl = newImgPath; + this.imgUrl = newImgPath; } public void plusMemberCount() { @@ -131,9 +130,9 @@ public void updateClub(ClubUpdateInput clubUpdateInput, FileInfo fileInfo) { this.sportsType = SportsType.fromKoreanName(clubUpdateInput.getSportsType()).orElseThrow(() -> new ClubControllerAdvice(ResponseCode.INVALID_SPORTS_TYPE)); } if (fileInfo != null) { - this.imageUrl = fileInfo.getFileUrl(); - this.originalImageName = fileInfo.getOriginalFileName(); - this.storedImageName = fileInfo.getStoredFileName(); + this.imgUrl = fileInfo.getFileUrl(); + this.originalImgName = fileInfo.getOriginalFileName(); + this.storedImgName = fileInfo.getStoredFileName(); } } diff --git a/src/main/java/com/example/moim/club/service/ClubCommandServiceImpl.java b/src/main/java/com/example/moim/club/service/ClubCommandServiceImpl.java index 3429784..d85bf2a 100644 --- a/src/main/java/com/example/moim/club/service/ClubCommandServiceImpl.java +++ b/src/main/java/com/example/moim/club/service/ClubCommandServiceImpl.java @@ -65,7 +65,7 @@ public ClubUpdateOutput updateClub(User user, ClubUpdateInput clubUpdateInput, L } if (clubUpdateInput.getProfileImg() != null) { - fileService.remove(club.getStoredImageName()); + fileService.remove(club.getStoredImgName()); } club.updateClub(clubUpdateInput, fileService.upload(clubUpdateInput.getProfileImg(), "/club-profile")); diff --git a/src/main/java/com/example/moim/main/dto/MainOutput.java b/src/main/java/com/example/moim/main/dto/MainOutput.java index ef00ecb..d798ad1 100644 --- a/src/main/java/com/example/moim/main/dto/MainOutput.java +++ b/src/main/java/com/example/moim/main/dto/MainOutput.java @@ -22,8 +22,8 @@ public MainOutput(Club club, List scheduleList) { this.title = club.getTitle(); this.explanation = club.getExplanation(); try { - if (club.getImageUrl() != null) { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); + if (club.getImgUrl() != null) { + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImgUrl()).getContentAsByteArray()); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/com/example/moim/main/dto/RecommendClubListOutput.java b/src/main/java/com/example/moim/main/dto/RecommendClubListOutput.java index ac9e8ef..b192872 100644 --- a/src/main/java/com/example/moim/main/dto/RecommendClubListOutput.java +++ b/src/main/java/com/example/moim/main/dto/RecommendClubListOutput.java @@ -20,9 +20,9 @@ public RecommendClubListOutput(Club club) { this.title = club.getTitle(); this.explanation = club.getExplanation(); this.memberCount = club.getMemberCount(); - if (club.getImageUrl() != null) { + if (club.getImgUrl() != null) { try { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImgUrl()).getContentAsByteArray()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/example/moim/match/dto/NearClubsOutput.java b/src/main/java/com/example/moim/match/dto/NearClubsOutput.java index 8a7f41d..9690b39 100644 --- a/src/main/java/com/example/moim/match/dto/NearClubsOutput.java +++ b/src/main/java/com/example/moim/match/dto/NearClubsOutput.java @@ -14,9 +14,9 @@ public class NearClubsOutput { public NearClubsOutput(Club club) { this.title = club.getTitle(); - if (club.getImageUrl() != null) { + if (club.getImgUrl() != null) { try { - this.image = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); + this.image = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImgUrl()).getContentAsByteArray()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/example/moim/schedule/dto/ScheduleUserOutput.java b/src/main/java/com/example/moim/schedule/dto/ScheduleUserOutput.java index b474c78..6e5123b 100644 --- a/src/main/java/com/example/moim/schedule/dto/ScheduleUserOutput.java +++ b/src/main/java/com/example/moim/schedule/dto/ScheduleUserOutput.java @@ -15,9 +15,9 @@ public class ScheduleUserOutput { public ScheduleUserOutput(ScheduleVote scheduleVote) { this.name = scheduleVote.getUser().getName(); - if (scheduleVote.getUser().getImgPath() != null) { + if (scheduleVote.getUser().getImgUrl() != null) { try { - this.img = Base64.getEncoder().encodeToString(new FileUrlResource(scheduleVote.getUser().getImgPath()).getContentAsByteArray()); + this.img = Base64.getEncoder().encodeToString(new FileUrlResource(scheduleVote.getUser().getImgUrl()).getContentAsByteArray()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/example/moim/user/dto/LoginOutput.java b/src/main/java/com/example/moim/user/dto/LoginOutput.java index b4bb9c0..aa1f958 100644 --- a/src/main/java/com/example/moim/user/dto/LoginOutput.java +++ b/src/main/java/com/example/moim/user/dto/LoginOutput.java @@ -28,7 +28,7 @@ public LoginOutput(User user, String accessToken) { this.gender = user.getGender().getKoreanName(); this.phone = user.getPhone(); this.activityArea = user.getActivityArea().getKoreanName(); - this.img = user.getImgPath();//base64인코딩 해야함 + this.img = user.getImgUrl();//base64인코딩 해야함 this.accessToken = accessToken; this.refreshToken = user.getRefreshToken(); } @@ -42,7 +42,7 @@ public LoginOutput(User user, String accessToken, Boolean hasClub) { } this.phone = user.getPhone(); this.activityArea = user.getActivityArea().getKoreanName(); - this.img = user.getImgPath();//base64인코딩 해야함 + this.img = user.getImgUrl();//base64인코딩 해야함 this.height = user.getHeight(); this.weight = user.getWeight(); this.mainFoot = user.getMainFoot(); diff --git a/src/main/java/com/example/moim/user/dto/MyClubOutput.java b/src/main/java/com/example/moim/user/dto/MyClubOutput.java index 08a625d..de64ca7 100644 --- a/src/main/java/com/example/moim/user/dto/MyClubOutput.java +++ b/src/main/java/com/example/moim/user/dto/MyClubOutput.java @@ -20,8 +20,8 @@ public MyClubOutput(Club club) { this.clubName = club.getTitle(); this.explanation = club.getExplanation(); try { - if (club.getImageUrl() != null) { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImageUrl()).getContentAsByteArray()); + if (club.getImgUrl() != null) { + this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getImgUrl()).getContentAsByteArray()); } } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/com/example/moim/user/dto/UserOutput.java b/src/main/java/com/example/moim/user/dto/UserOutput.java index a2e94f9..57fe95d 100644 --- a/src/main/java/com/example/moim/user/dto/UserOutput.java +++ b/src/main/java/com/example/moim/user/dto/UserOutput.java @@ -1,6 +1,5 @@ package com.example.moim.user.dto; -import com.example.moim.global.enums.Gender; import com.example.moim.user.entity.User; import lombok.Data; import org.springframework.core.io.FileUrlResource; @@ -31,9 +30,9 @@ public UserOutput(User user, Boolean hasClub) { this.gender = user.getGender().getKoreanName(); this.phone = user.getPhone(); this.hasClub = hasClub; - if (user.getImgPath() != null) { + if (user.getImgUrl() != null) { try { - this.img = Base64.getEncoder().encodeToString(new FileUrlResource(user.getImgPath()).getContentAsByteArray()); + this.img = Base64.getEncoder().encodeToString(new FileUrlResource(user.getImgUrl()).getContentAsByteArray()); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/example/moim/user/entity/User.java b/src/main/java/com/example/moim/user/entity/User.java index a0c0ba5..d7b6a20 100644 --- a/src/main/java/com/example/moim/user/entity/User.java +++ b/src/main/java/com/example/moim/user/entity/User.java @@ -25,10 +25,10 @@ import jakarta.persistence.Id; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import java.io.File; + import java.util.ArrayList; import java.util.List; -import lombok.AllArgsConstructor; + import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @@ -49,7 +49,7 @@ public class User extends BaseEntity { @Enumerated(EnumType.STRING) private Gender gender; private String phone; - private String imgPath; + private String imgUrl; private String originalImgName; private String storedImgName; @Enumerated(EnumType.STRING) @@ -88,7 +88,7 @@ public User(String email, String password, String name, String birthday, Gender * CHECK: 여기 파일 서비스 구조 고쳐지면서, 변경된 코드입니다! */ if (fileInfo != null) { - this.imgPath = fileInfo.getFileUrl(); + this.imgUrl = fileInfo.getFileUrl(); this.originalImgName = fileInfo.getOriginalFileName(); this.storedImgName = fileInfo.getStoredFileName(); } @@ -159,7 +159,7 @@ public void fillUserInfo(SocialSignupInput socialSignupInput, FileInfo fileInfo) /** * CHECK: 여기 파일 서비스 구조 고쳐지면서, 변경된 코드입니다! */ - this.imgPath = fileInfo.getFileUrl(); + this.imgUrl = fileInfo.getFileUrl(); // this.gender = Gender.from(socialSignupInput.getGender()); this.gender = Gender.fromKoreanName(socialSignupInput.getGender()) .orElseThrow(() -> new UserControllerAdvice(ResponseCode.INVALID_GENDER)); @@ -188,7 +188,7 @@ public void updateUserInfo(UserUpdateInput userUpdateInput, FileInfo fileInfo) { * CHECK: 여기 파일 서비스 구조 고쳐지면서, 변경된 코드입니다! */ if (fileInfo != null) { - this.imgPath = fileInfo.getFileUrl(); + this.imgUrl = fileInfo.getFileUrl(); this.storedImgName = fileInfo.getStoredFileName(); this.originalImgName = fileInfo.getOriginalFileName(); } diff --git a/src/test/resources/sql/comment-repository-test-data.sql b/src/test/resources/sql/comment-repository-test-data.sql index 8e110ce..1f2d8c1 100644 --- a/src/test/resources/sql/comment-repository-test-data.sql +++ b/src/test/resources/sql/comment-repository-test-data.sql @@ -1,20 +1,20 @@ --ALTER TABLE USERS DROP CONSTRAINT CONSTRAINT_4; --ALTER TABLE USERS DROP CONSTRAINT CONSTRAINT_4D4; -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '한양대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '서울대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '연세대학교'); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); INSERT INTO user_club (id, created_date, updated_date, club_role, join_date, match_count, schedule_count, club_id, user_id) diff --git a/src/test/resources/sql/schedule-vote-repository-test-data.sql b/src/test/resources/sql/schedule-vote-repository-test-data.sql index c7a9457..4c9cd33 100644 --- a/src/test/resources/sql/schedule-vote-repository-test-data.sql +++ b/src/test/resources/sql/schedule-vote-repository-test-data.sql @@ -1,17 +1,17 @@ -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '한양대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '서울대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '연세대학교'); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); INSERT INTO user_club (id, created_date, updated_date, club_role, join_date, match_count, schedule_count, club_id, user_id) diff --git a/src/test/resources/sql/user-club-repository-test-data.sql b/src/test/resources/sql/user-club-repository-test-data.sql index 3029ba3..2413962 100644 --- a/src/test/resources/sql/user-club-repository-test-data.sql +++ b/src/test/resources/sql/user-club-repository-test-data.sql @@ -1,20 +1,20 @@ --ALTER TABLE USERS DROP CONSTRAINT CONSTRAINT_4; --ALTER TABLE USERS DROP CONSTRAINT CONSTRAINT_4D4; -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'MAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '한양대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'SEOUL', 'TWENTIES', 'SCHOOL_GROUP', 'club_password', 'explanation', 'WOMAN', 'introduction', 'SOCCER', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '서울대학교'); -INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, image_url, stored_image_name, original_image_name, schedule_count, sub_uniform_color, title, university) +INSERT INTO club (id, created_date, updated_date, activity_area, age_range, club_category, club_password, explanation, gender, introduction, sports_type, main_uniform_color, match_count, member_count, img_url, original_img_name, stored_img_name, schedule_count, sub_uniform_color, title, university) VALUES (default, null, null, 'GYEONGGI', 'THIRTIES', 'SOCIAL_GROUP', 'club_password', 'explanation', 'UNISEX', 'introduction', 'FUTSAL', 'main_uniform_color', 2, 5, null, null, null, 2, 'sub_uniform_color', 'title', '연세대학교'); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'RIGHT', 'ST', 'name', 'password', 'phone', 'refresh_token123456', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'SEOUL', 'birthday', 'email', 'fcm_token', 'WOMAN', 180, null, null, null, 'LEFT', 'LM', 'name', 'password', 'phone', 'refresh_token12345678', 'USER', 'ST', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'RIGHT', 'GK', 'name', 'password', 'phone', 'refresh_token123456789', 'USER', 'LM', 70); -INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_path, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) +INSERT INTO users (user_id, created_date, updated_date, activity_area, birthday, email, fcm_token, gender, height, img_url, original_img_name, stored_img_name, main_foot, main_position, name, password, phone, refresh_token, role, sub_position, weight) VALUES (default, null, null, 'GYEONGGI', 'birthday', 'email', 'fcm_token', 'MAN', 180, null, null, null, 'BOTH', 'MANAGER', 'name', 'password', 'phone', 'refresh_token12345678910', 'USER', 'GK', 70); INSERT INTO user_club (id, created_date, updated_date, club_role, join_date, match_count, schedule_count, club_id, user_id) From 60f393b72c2ace94736b195500f82a3c24752c28 Mon Sep 17 00:00:00 2001 From: 5nam Date: Mon, 26 May 2025 23:47:14 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat(#34):=20Profile=20=EC=95=A0=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=B6=94=EA=B0=80=EB=A1=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=EC=99=80=20=EC=9A=B4=EC=98=81?= =?UTF-8?q?=EC=9A=A9=20=ED=8C=8C=EC=9D=BC=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EB=82=98=EB=88=94.=20CouldFileServiceTest=20=EB=8A=94=20@Disab?= =?UTF-8?q?led=20=EC=B2=98=EB=A6=AC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/file/service/AwsS3FileService.java | 2 +- .../util/file/service/LocalFileService.java | 4 ++-- .../file/service/CloudFileServiceTest.java | 24 ++++++++----------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/example/moim/global/util/file/service/AwsS3FileService.java b/src/main/java/com/example/moim/global/util/file/service/AwsS3FileService.java index 98d75bb..5dd2bdf 100644 --- a/src/main/java/com/example/moim/global/util/file/service/AwsS3FileService.java +++ b/src/main/java/com/example/moim/global/util/file/service/AwsS3FileService.java @@ -18,7 +18,7 @@ @Slf4j @Service -//@Profile("!test") +@Profile("!test") @RequiredArgsConstructor public class AwsS3FileService implements FileService { diff --git a/src/main/java/com/example/moim/global/util/file/service/LocalFileService.java b/src/main/java/com/example/moim/global/util/file/service/LocalFileService.java index 534726f..fa508ea 100644 --- a/src/main/java/com/example/moim/global/util/file/service/LocalFileService.java +++ b/src/main/java/com/example/moim/global/util/file/service/LocalFileService.java @@ -15,9 +15,9 @@ import java.io.FileOutputStream; import java.io.IOException; -//@Service +@Service @Slf4j -@Profile("!test") +@Profile("test") @RequiredArgsConstructor public class LocalFileService implements FileService { diff --git a/src/test/java/com/example/moim/global/util/file/service/CloudFileServiceTest.java b/src/test/java/com/example/moim/global/util/file/service/CloudFileServiceTest.java index bda1394..58fbb76 100644 --- a/src/test/java/com/example/moim/global/util/file/service/CloudFileServiceTest.java +++ b/src/test/java/com/example/moim/global/util/file/service/CloudFileServiceTest.java @@ -1,45 +1,41 @@ package com.example.moim.global.util.file.service; -import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; -import com.amazonaws.regions.Regions; -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.example.moim.global.exception.ResponseCode; import com.example.moim.global.util.file.exception.advice.AwsS3ControllerAdvice; import com.example.moim.global.util.file.model.FileInfo; -import com.example.moim.global.util.uuid.UuidHolder; -import com.example.moim.schedule.exception.advice.ScheduleControllerAdvice; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.util.ReflectionTestUtils; -import java.io.File; import java.io.IOException; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.when; @Slf4j +@Disabled("S3 환경에서만 실행 가능. 활성화 시 프로파일 필요") @SpringBootTest class CloudFileServiceTest { @Autowired + private ApplicationContext context; + private AwsS3FileService fileService; @Value("${cloud.aws.s3.bucket}") String bucket; + @BeforeEach + void setUp() { + fileService = context.getBean(AwsS3FileService.class); + } + @Test void upload() throws IOException { //given