Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions deploy/local.init.sql
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public ClubOutput(Club club, List<UserClubOutput> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ClubSaveOutput(Club club, List<UserClubOutput> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ClubUpdateOutput(Club club, List<UserClubOutput> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
28 changes: 16 additions & 12 deletions src/main/java/com/example/moim/club/entity/Club.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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") // 검색을 위한 테이블 매핑
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,8 +17,8 @@
import java.io.IOException;

@Slf4j
//@Service
//@Profile("!test")
@Service
@Profile("!test")
@RequiredArgsConstructor
public class AwsS3FileService implements FileService {

Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -75,4 +78,8 @@ public void remove(String path) {

}

public boolean doesObjectExist(String objectName) {
return amazonS3.doesObjectExist(bucket, objectName);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
Loading