diff --git a/deploy/local.init.sql b/deploy/local.init.sql index eab3437..a467f24 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, 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, 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, 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) 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_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_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_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_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) 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..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.getProfileImgPath() != null) { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).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 616d665..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.getProfileImgPath(); + 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 99472d0..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.getProfileImgPath() != null) { + if (club.getImgUrl() != null) { try { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).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 e0ad228..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.getProfileImgPath(); + 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 eea6115..f92fa0a 100644 --- a/src/main/java/com/example/moim/club/entity/Club.java +++ b/src/main/java/com/example/moim/club/entity/Club.java @@ -6,14 +6,13 @@ 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; import lombok.NoArgsConstructor; import org.springframework.util.StringUtils; -import java.io.File; import java.util.ArrayList; import java.util.List; @@ -39,7 +38,9 @@ public class Club extends BaseEntity { @Enumerated(value = EnumType.STRING) private AgeRange ageRange; private String clubPassword; - private String profileImgPath = "기본 이미지 링크"; + private String imgUrl; // 프론트에 제공할 URL + private String storedImgName; // UUID 로 저장된 이름 + private String originalImgName; // 파일 업로할 때 이름 private String mainUniformColor; private String subUniformColor; @OneToOne(mappedBy = "club") // 검색을 위한 테이블 매핑 @@ -64,7 +65,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(); @@ -79,7 +80,11 @@ public static Club createClub(ClubInput clubInput, String profileImgPath) { throw new ClubControllerAdvice(ResponseCode.CLUB_CHECK_PASSWORD_INCORRECT); } club.clubPassword = clubInput.getClubPassword(); - club.profileImgPath = profileImgPath; + if (fileInfo != null) { + club.imgUrl = fileInfo.getFileUrl(); + club.originalImgName = fileInfo.getOriginalFileName(); + club.storedImgName = fileInfo.getStoredFileName(); + } club.mainUniformColor = clubInput.getMainUniformColor(); club.subUniformColor = clubInput.getSubUniformColor(); club.memberCount = 1; @@ -92,14 +97,14 @@ public Club updateClubSearch(ClubSearch clubSearch) { } public void changeProfileImg(String newImgPath) { - this.profileImgPath = newImgPath; + this.imgUrl = 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(); } @@ -127,11 +132,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.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 dadd38b..080332b 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.getStoredImgName()); + } + 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..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 @@ -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,8 +17,8 @@ import java.io.IOException; @Slf4j -//@Service -//@Profile("!test") +@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..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 @@ -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; @@ -16,7 +17,7 @@ @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..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.getProfileImgPath() != null) { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).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 6381bd7..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.getProfileImgPath() != null) { + if (club.getImgUrl() != null) { try { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).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 1519edd..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.getProfileImgPath() != null) { + if (club.getImgUrl() != null) { try { - this.image = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).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 2007412..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.getProfileImgPath() != null) { - this.profileImg = Base64.getEncoder().encodeToString(new FileUrlResource(club.getProfileImgPath()).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 72ef3f4..d7b6a20 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; @@ -24,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; @@ -48,7 +49,9 @@ 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) 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.imgUrl = 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.imgUrl = 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.imgUrl = 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 9b4dbdd..4897e36 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).clubCheckPassword(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..58fbb76 --- /dev/null +++ b/src/test/java/com/example/moim/global/util/file/service/CloudFileServiceTest.java @@ -0,0 +1,85 @@ +package com.example.moim.global.util.file.service; + +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 lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +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 java.io.IOException; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@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 + 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 a272d37..d4f2c68 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") @@ -163,7 +170,7 @@ void shouldSaveAndSendNotifications() { .clubPassword("password") .clubCheckPassword("password") .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..1f2d8c1 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, 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, 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, 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, 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_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_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_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_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) 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..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,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, 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, 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, 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, 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_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_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_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_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) 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..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,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, 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, 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, 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, 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_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_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_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_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) VALUES (default, null, null, 'STAFF', '2024-12-11', 2, 2, 1, 1);