From 272599ec4230f9125c8f3e7e16e3449e4f02d637 Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Thu, 20 Jul 2023 18:40:33 +0900 Subject: [PATCH 01/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- favor/build.gradle | 3 + .../favor/configuration/S3Configuration.java | 32 +++++++ .../com/favor/favor/photo/FileHandler.java | 94 ------------------- .../favor/favor/photo/PhotoRepository.java | 7 -- .../com/favor/favor/photo/PhotoService.java | 14 --- .../java/com/favor/favor/photo/S3Service.java | 17 ++++ 6 files changed, 52 insertions(+), 115 deletions(-) create mode 100644 favor/src/main/java/com/favor/favor/configuration/S3Configuration.java delete mode 100644 favor/src/main/java/com/favor/favor/photo/FileHandler.java delete mode 100644 favor/src/main/java/com/favor/favor/photo/PhotoRepository.java delete mode 100644 favor/src/main/java/com/favor/favor/photo/PhotoService.java create mode 100644 favor/src/main/java/com/favor/favor/photo/S3Service.java diff --git a/favor/build.gradle b/favor/build.gradle index b1bd9c4..966483d 100644 --- a/favor/build.gradle +++ b/favor/build.gradle @@ -54,6 +54,9 @@ dependencies { implementation("io.sentry:sentry-spring-boot-starter:4.3.0") implementation 'org.springframework:spring-context:5.3.12' + + //AWS S3 + implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4' } tasks.named('test') { diff --git a/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java b/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java new file mode 100644 index 0000000..b38ee1a --- /dev/null +++ b/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java @@ -0,0 +1,32 @@ +package com.favor.favor.configuration; + +import com.amazonaws.auth.AWSCredentials; +import com.amazonaws.auth.AWSStaticCredentialsProvider; +import com.amazonaws.auth.BasicAWSCredentials; +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3ClientBuilder; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class S3Configuration { + + @Value("${cloud.aws.region.static}") + private String region; + + @Value("${cloud.aws.credentials.access-key}") + private String accesskey; + + @Value("${cloud.aws.credentials.secret-key}") + private String secretkey; + + @Bean + public AmazonS3 amazonS3(){ + AWSCredentials awsCredentials = new BasicAWSCredentials(accesskey, secretkey); + return AmazonS3ClientBuilder.standard() + .withRegion(region) + .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) + .build(); + } +} diff --git a/favor/src/main/java/com/favor/favor/photo/FileHandler.java b/favor/src/main/java/com/favor/favor/photo/FileHandler.java deleted file mode 100644 index fcf3f19..0000000 --- a/favor/src/main/java/com/favor/favor/photo/FileHandler.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.favor.favor.photo; - -import org.springframework.stereotype.Component; -import org.springframework.util.ObjectUtils; -import org.springframework.web.multipart.MultipartFile; - -import java.io.File; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -@Component -public class FileHandler { - public List parseFileInfo( - Long photoIdx, - List multipartFiles - ) throws Exception { - - //반환할 파일 리스트 - List fileList = new ArrayList<>(); - - //파일이 빈 것이 들어올 경우 빈 것 반환 - if (multipartFiles.isEmpty()) { - return fileList; - } - //파일 이름을 날짜로 바꾸어서 저장 - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd"); - String current_date = simpleDateFormat.format(new Date()); - - //파일이 빈 것이 들어오면 빈 것 반환 - if (multipartFiles.isEmpty()) { - return fileList; - } - - //프로젝트 폴더 저장 위해 절대경로 설정 (Window 의 Tomcat 은 Temp 파일을 이용한다) - String absolutePath = new File("").getAbsolutePath() + "\\"; - - //경로 지정하고 그곳에다가 저장 - String path = "images/" + current_date; - File file = new File(path); - - //저장할 디렉토리가 존재하지 않을 경우 - if (!file.exists()) { - file.mkdirs(); //상위 디렉토리까지 생성 - } - - //파일 핸들링 시작 - for (MultipartFile multipartFile : multipartFiles) { - //파일이 비어있지 않을 때 작업 시작해야 오류 없음 - if (!multipartFile.isEmpty()) { - //jpeg, png, gif만 처리할 예정 - String contentType = multipartFile.getContentType(); - String originalFileExtension; - - //확장자가 없다면 잘못된 파일 - if (ObjectUtils.isEmpty(contentType)) { - break; - } - else { - if (contentType.contains("image/jpeg")) { - originalFileExtension = ".jpg"; - } else if (contentType.contains("image/png")) { - originalFileExtension = "png"; - } else if (contentType.contains("image/gif")) { - originalFileExtension = "gif"; - } - - //다른 파일명이면 아무것도 하지 않음 - else { - break; - } - } - - //각 이름 겹치면 안되므로 나노 초까지 동원해서 지정 - String new_file_name = System.nanoTime() + originalFileExtension; - - //생성 후 리스트에 추가 - Photo photo = Photo.builder() - .photoIdx(photoIdx) - .originalFileName((multipartFile.getOriginalFilename())) - .storedFileName(path + "/" + new_file_name) - .fileSize(multipartFile.getSize()) - .build(); - fileList.add(photo); - - //저장된 파일로 변경해 이를 보여줌 - file = new File(absolutePath + path + "/" + new_file_name); - multipartFile.transferTo(file); - } - } - return fileList; - } -} diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoRepository.java b/favor/src/main/java/com/favor/favor/photo/PhotoRepository.java deleted file mode 100644 index bd7acd2..0000000 --- a/favor/src/main/java/com/favor/favor/photo/PhotoRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.favor.favor.photo; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface PhotoRepository extends JpaRepository { - Photo findByPhotoNo(Long photoNo); -} diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoService.java b/favor/src/main/java/com/favor/favor/photo/PhotoService.java deleted file mode 100644 index 5d3aa0d..0000000 --- a/favor/src/main/java/com/favor/favor/photo/PhotoService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.favor.favor.photo; - -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -@Service -@RequiredArgsConstructor -public class PhotoService { - - private final PhotoRepository photoRepository; - private final FileHandler fileHandler; - - -} diff --git a/favor/src/main/java/com/favor/favor/photo/S3Service.java b/favor/src/main/java/com/favor/favor/photo/S3Service.java new file mode 100644 index 0000000..ac4ba4d --- /dev/null +++ b/favor/src/main/java/com/favor/favor/photo/S3Service.java @@ -0,0 +1,17 @@ +package com.favor.favor.photo; + +import com.amazonaws.services.s3.AmazonS3; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class S3Service { + @Value("${cloud.aws.s3.bucket") + String bucketName; + + private final AmazonS3 amazonS3; + + public String uploadPhoto() +} From 2b5aedb7e214baef9d6cb1ee13830b258f0e7229 Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Thu, 20 Jul 2023 19:02:20 +0900 Subject: [PATCH 02/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favor/favor/photo/PhotoController.java | 57 +++++++++++++++++++ .../java/com/favor/favor/photo/PhotoDto.java | 18 ++++++ .../java/com/favor/favor/photo/S3Service.java | 34 ++++++++++- 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 favor/src/main/java/com/favor/favor/photo/PhotoController.java create mode 100644 favor/src/main/java/com/favor/favor/photo/PhotoDto.java diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoController.java b/favor/src/main/java/com/favor/favor/photo/PhotoController.java new file mode 100644 index 0000000..d7b9f30 --- /dev/null +++ b/favor/src/main/java/com/favor/favor/photo/PhotoController.java @@ -0,0 +1,57 @@ +package com.favor.favor.photo; + +import com.favor.favor.common.DefaultResponseDto; +import com.favor.favor.gift.GiftResponseDto; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.io.File; +import java.util.List; + +@Api(tags = "Photo") +@RestController +@RequiredArgsConstructor +@RequestMapping("/photos") +public class PhotoController { + + private final S3Service s3Service; + + @ApiOperation("사진 저장") + @ApiResponses(value={ + @ApiResponse(code = 201, + message = "PHOTO_SAVED", + response = GiftResponseDto.class), + @ApiResponse(code = 400, + message = "FIELD_REQUIRED / *_CHARACTER_INVALID / *_LENGTH_INVALID"), + @ApiResponse(code = 404, + message = ""), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @PostMapping + public ResponseEntity> savePhoto( + @ModelAttribute PhotoDto photoDto){ + + StringBuffer sb = new StringBuffer(); + List fileList = photoDto.getFileList(); + for(File file : fileList){ + s3Service.uploadPhoto(file); + } + + String result = sb.toString(); + + return ResponseEntity.status(201) + .body(DefaultResponseDto.builder() + .responseCode("PHOTO_SAVED") + .responseMessage("사진 저장 완료") + .data(result) + .build()); + } +} diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoDto.java b/favor/src/main/java/com/favor/favor/photo/PhotoDto.java new file mode 100644 index 0000000..d56f5ef --- /dev/null +++ b/favor/src/main/java/com/favor/favor/photo/PhotoDto.java @@ -0,0 +1,18 @@ +package com.favor.favor.photo; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public class PhotoDto { + private List fileList = new ArrayList<>(); +} diff --git a/favor/src/main/java/com/favor/favor/photo/S3Service.java b/favor/src/main/java/com/favor/favor/photo/S3Service.java index ac4ba4d..285673a 100644 --- a/favor/src/main/java/com/favor/favor/photo/S3Service.java +++ b/favor/src/main/java/com/favor/favor/photo/S3Service.java @@ -4,14 +4,42 @@ import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.util.UUID; @Service @RequiredArgsConstructor public class S3Service { + @Value("${cloud.aws.s3.bucket") - String bucketName; + private String bucketName; + + private final AmazonS3 s3; + + public String uploadPhoto(File file){ + + String filename = createStoredFileName(file); + String uploadedFileName = putS3(file, filename); + + return uploadedFileName + " 업로드 완료"; + } + + public String putS3(File file, String fileName){ + //multipartFile(X) + s3.putObject(bucketName, fileName, file); + return fileName; + } + + //확장명 제거한 순수한 파일명 반환 + public String createStoredFileName(File file){ + + String originalFileName = file.getName(); - private final AmazonS3 amazonS3; + int extensionIndex = originalFileName.lastIndexOf('.'); + String fileName = originalFileName.substring(extensionIndex); - public String uploadPhoto() + return fileName; + } } From d2d8e360dd13d8d3c951e36fa387ed42eb810f51 Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Thu, 20 Jul 2023 20:14:10 +0900 Subject: [PATCH 03/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- favor/build.gradle | 3 +- .../favor/configuration/S3Configuration.java | 9 +- .../configuration/SecurityConfiguration.java | 3 +- .../java/com/favor/favor/photo/Photo.java | 29 ++++--- .../favor/favor/photo/PhotoController.java | 17 +--- .../java/com/favor/favor/photo/PhotoDto.java | 18 ---- .../com/favor/favor/photo/PhotoService.java | 82 +++++++++++++++++++ .../java/com/favor/favor/photo/S3Service.java | 45 ---------- 8 files changed, 110 insertions(+), 96 deletions(-) delete mode 100644 favor/src/main/java/com/favor/favor/photo/PhotoDto.java create mode 100644 favor/src/main/java/com/favor/favor/photo/PhotoService.java delete mode 100644 favor/src/main/java/com/favor/favor/photo/S3Service.java diff --git a/favor/build.gradle b/favor/build.gradle index 966483d..5d26571 100644 --- a/favor/build.gradle +++ b/favor/build.gradle @@ -56,8 +56,7 @@ dependencies { implementation 'org.springframework:spring-context:5.3.12' //AWS S3 - implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4' -} + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'} tasks.named('test') { useJUnitPlatform() diff --git a/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java b/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java index b38ee1a..b7b8016 100644 --- a/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java +++ b/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java @@ -4,6 +4,7 @@ import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -22,11 +23,11 @@ public class S3Configuration { private String secretkey; @Bean - public AmazonS3 amazonS3(){ - AWSCredentials awsCredentials = new BasicAWSCredentials(accesskey, secretkey); - return AmazonS3ClientBuilder.standard() + public AmazonS3Client amazonS3Client() { + BasicAWSCredentials awsCreds = new BasicAWSCredentials(accesskey, secretkey); + return (AmazonS3Client) AmazonS3ClientBuilder.standard() .withRegion(region) - .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) + .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) .build(); } } diff --git a/favor/src/main/java/com/favor/favor/configuration/SecurityConfiguration.java b/favor/src/main/java/com/favor/favor/configuration/SecurityConfiguration.java index bb42b6e..7039f1a 100644 --- a/favor/src/main/java/com/favor/favor/configuration/SecurityConfiguration.java +++ b/favor/src/main/java/com/favor/favor/configuration/SecurityConfiguration.java @@ -68,7 +68,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws "/favicon.ico", "/users/sign-in", "/users/sign-up", - "/users/profile/**").permitAll() + "/users/profile/**", + "/photos/**").permitAll() .anyRequest().authenticated() diff --git a/favor/src/main/java/com/favor/favor/photo/Photo.java b/favor/src/main/java/com/favor/favor/photo/Photo.java index 3af779e..e6885fc 100644 --- a/favor/src/main/java/com/favor/favor/photo/Photo.java +++ b/favor/src/main/java/com/favor/favor/photo/Photo.java @@ -1,33 +1,36 @@ package com.favor.favor.photo; import com.favor.favor.common.TimeStamped; -import lombok.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import javax.transaction.Transactional; -@Entity @Getter +@Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -@Builder -@Transactional public class Photo extends TimeStamped { - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long photoNo; - - private Long photoIdx; + private Long id; - private String originalFileName; + private String photoUrl; - private String storedFileName; + @Builder + public Photo(String photoUrl) { + this.photoUrl = photoUrl; + } - private long fileSize; + public String getFileName(String fileName){ + int extensionIndex = fileName.lastIndexOf('.'); + String originalFileName = fileName.substring(extensionIndex); + return originalFileName; + } } diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoController.java b/favor/src/main/java/com/favor/favor/photo/PhotoController.java index d7b9f30..f4732ec 100644 --- a/favor/src/main/java/com/favor/favor/photo/PhotoController.java +++ b/favor/src/main/java/com/favor/favor/photo/PhotoController.java @@ -10,17 +10,14 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; - -import java.io.File; -import java.util.List; +import org.springframework.web.multipart.MultipartFile; @Api(tags = "Photo") @RestController @RequiredArgsConstructor @RequestMapping("/photos") public class PhotoController { - - private final S3Service s3Service; + private final PhotoService photoService; @ApiOperation("사진 저장") @ApiResponses(value={ @@ -37,15 +34,9 @@ public class PhotoController { @ResponseStatus(HttpStatus.OK) @PostMapping public ResponseEntity> savePhoto( - @ModelAttribute PhotoDto photoDto){ - - StringBuffer sb = new StringBuffer(); - List fileList = photoDto.getFileList(); - for(File file : fileList){ - s3Service.uploadPhoto(file); - } + @ModelAttribute MultipartFile photo){ - String result = sb.toString(); + Photo result = photoService.savePhoto(photo); return ResponseEntity.status(201) .body(DefaultResponseDto.builder() diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoDto.java b/favor/src/main/java/com/favor/favor/photo/PhotoDto.java deleted file mode 100644 index d56f5ef..0000000 --- a/favor/src/main/java/com/favor/favor/photo/PhotoDto.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.favor.favor.photo; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -@AllArgsConstructor -@NoArgsConstructor -@Getter -@Setter -public class PhotoDto { - private List fileList = new ArrayList<>(); -} diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoService.java b/favor/src/main/java/com/favor/favor/photo/PhotoService.java new file mode 100644 index 0000000..71c6ef4 --- /dev/null +++ b/favor/src/main/java/com/favor/favor/photo/PhotoService.java @@ -0,0 +1,82 @@ +package com.favor.favor.photo; + +import com.amazonaws.services.s3.AmazonS3Client; +import com.amazonaws.services.s3.model.CannedAccessControlList; +import com.amazonaws.services.s3.model.PutObjectRequest; +import com.favor.favor.exception.CustomException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Objects; + +import static com.favor.favor.exception.ExceptionCode.SERVER_ERROR; + +@Service +@RequiredArgsConstructor +public class PhotoService { + private String brandPhotoBucketName = "favor-app-bucket"; + private final AmazonS3Client amazonS3Client; + + /** + * MultipartFile을 File로 전환 | + * MultipartFile을 받아서 File의 형태로 전환하여 반환한다. + */ + private File convertMultiPartToFile(MultipartFile file) throws IOException { + File convertingFile = new File(Objects.requireNonNull(file.getOriginalFilename())); + FileOutputStream fileOutputStream = new FileOutputStream(convertingFile); + fileOutputStream.write(file.getBytes()); + fileOutputStream.close(); + + return convertingFile; + } + + /** + * S3에 파일 저장 | + * 파일을 전환하고 특정 파일 관련된 폴더에 파일을 저장하고 URL을 반환한다. | + * 500(SERVER_ERROR) + */ + public String insertFileToS3(String bucketName, String fileName, MultipartFile file) { + + try { + File convertedFile = convertMultiPartToFile(file); + String uploadingFileName = fileName; + + amazonS3Client.putObject(new PutObjectRequest(bucketName, uploadingFileName, convertedFile) + .withCannedAcl(CannedAccessControlList.PublicRead)); + convertedFile.delete(); + String url = amazonS3Client.getUrl(bucketName, uploadingFileName).toString(); + return url; + } catch (IOException e) { + throw new CustomException(e, SERVER_ERROR); + } + } + + /** + * 브랜드 사진 저장 | + * 500(SERVER_ERROR) + */ + @Transactional + public Photo savePhoto(MultipartFile file) { + + String filename = file.getOriginalFilename(); + Photo photo = new Photo(filename); + String originalFileName = photo.getFileName(filename); + + String brandPhotoUrl = insertFileToS3(brandPhotoBucketName, originalFileName, file); + + try { + photo = Photo.builder() + .photoUrl(brandPhotoUrl) + .build(); + } catch (RuntimeException e) { + throw new CustomException(e, SERVER_ERROR); + } + + return photo; + } +} diff --git a/favor/src/main/java/com/favor/favor/photo/S3Service.java b/favor/src/main/java/com/favor/favor/photo/S3Service.java deleted file mode 100644 index 285673a..0000000 --- a/favor/src/main/java/com/favor/favor/photo/S3Service.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.favor.favor.photo; - -import com.amazonaws.services.s3.AmazonS3; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; - -import java.io.File; -import java.util.UUID; - -@Service -@RequiredArgsConstructor -public class S3Service { - - @Value("${cloud.aws.s3.bucket") - private String bucketName; - - private final AmazonS3 s3; - - public String uploadPhoto(File file){ - - String filename = createStoredFileName(file); - String uploadedFileName = putS3(file, filename); - - return uploadedFileName + " 업로드 완료"; - } - - public String putS3(File file, String fileName){ - //multipartFile(X) - s3.putObject(bucketName, fileName, file); - return fileName; - } - - //확장명 제거한 순수한 파일명 반환 - public String createStoredFileName(File file){ - - String originalFileName = file.getName(); - - int extensionIndex = originalFileName.lastIndexOf('.'); - String fileName = originalFileName.substring(extensionIndex); - - return fileName; - } -} From 39916f70ab898be17bc82d718500e16fe82a3d98 Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Sat, 29 Jul 2023 09:48:26 +0900 Subject: [PATCH 04/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 사진 S3 등록 기능 구현 - 사진 파일 명 입력해 S3 bucket 에서 삭제하는 기능 구현 --- favor/build.gradle | 6 +-- .../java/com/favor/favor/photo/Photo.java | 7 +--- .../favor/favor/photo/PhotoController.java | 27 ++++++++++++ .../com/favor/favor/photo/PhotoService.java | 42 +++++++++++-------- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/favor/build.gradle b/favor/build.gradle index 5d26571..d007527 100644 --- a/favor/build.gradle +++ b/favor/build.gradle @@ -46,9 +46,9 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' // JWT - implementation 'io.jsonwebtoken:jjwt-api:0.11.2' - runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.2' - runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.2' + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5' + runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' //Sentry implementation("io.sentry:sentry-spring-boot-starter:4.3.0") diff --git a/favor/src/main/java/com/favor/favor/photo/Photo.java b/favor/src/main/java/com/favor/favor/photo/Photo.java index e6885fc..ce984a2 100644 --- a/favor/src/main/java/com/favor/favor/photo/Photo.java +++ b/favor/src/main/java/com/favor/favor/photo/Photo.java @@ -10,6 +10,7 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import java.util.UUID; @Getter @Entity @@ -26,11 +27,5 @@ public Photo(String photoUrl) { this.photoUrl = photoUrl; } - public String getFileName(String fileName){ - int extensionIndex = fileName.lastIndexOf('.'); - String originalFileName = fileName.substring(extensionIndex); - - return originalFileName; - } } diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoController.java b/favor/src/main/java/com/favor/favor/photo/PhotoController.java index f4732ec..f7a9009 100644 --- a/favor/src/main/java/com/favor/favor/photo/PhotoController.java +++ b/favor/src/main/java/com/favor/favor/photo/PhotoController.java @@ -45,4 +45,31 @@ public ResponseEntity> savePhoto( .data(result) .build()); } + + @ApiOperation("사진 삭제") + @ApiResponses(value={ + @ApiResponse(code = 201, + message = "PHOTO_REMOVED", + response = GiftResponseDto.class), + @ApiResponse(code = 400, + message = "FIELD_REQUIRED / *_CHARACTER_INVALID / *_LENGTH_INVALID"), + @ApiResponse(code = 404, + message = ""), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @DeleteMapping + public ResponseEntity> deletePhoto( + String filename){ + + photoService.deleteFileFromS3(filename); + + return ResponseEntity.status(201) + .body(DefaultResponseDto.builder() + .responseCode("PHOTO_REMOVED") + .responseMessage("사진 삭제 완료") + .data(null) + .build()); + } } diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoService.java b/favor/src/main/java/com/favor/favor/photo/PhotoService.java index 71c6ef4..3084cd3 100644 --- a/favor/src/main/java/com/favor/favor/photo/PhotoService.java +++ b/favor/src/main/java/com/favor/favor/photo/PhotoService.java @@ -1,5 +1,6 @@ package com.favor.favor.photo; +import com.amazonaws.SdkClientException; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.PutObjectRequest; @@ -13,20 +14,18 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.Objects; +import java.util.UUID; import static com.favor.favor.exception.ExceptionCode.SERVER_ERROR; @Service @RequiredArgsConstructor public class PhotoService { - private String brandPhotoBucketName = "favor-app-bucket"; + private String bucketName = "favor-app-bucket"; private final AmazonS3Client amazonS3Client; - /** - * MultipartFile을 File로 전환 | - * MultipartFile을 받아서 File의 형태로 전환하여 반환한다. - */ - private File convertMultiPartToFile(MultipartFile file) throws IOException { + //MultipartFile을 File로 전환 + private File convertFile(MultipartFile file) throws IOException { File convertingFile = new File(Objects.requireNonNull(file.getOriginalFilename())); FileOutputStream fileOutputStream = new FileOutputStream(convertingFile); fileOutputStream.write(file.getBytes()); @@ -35,15 +34,11 @@ private File convertMultiPartToFile(MultipartFile file) throws IOException { return convertingFile; } - /** - * S3에 파일 저장 | - * 파일을 전환하고 특정 파일 관련된 폴더에 파일을 저장하고 URL을 반환한다. | - * 500(SERVER_ERROR) - */ + //S3에 사진 업로드 public String insertFileToS3(String bucketName, String fileName, MultipartFile file) { try { - File convertedFile = convertMultiPartToFile(file); + File convertedFile = convertFile(file); String uploadingFileName = fileName; amazonS3Client.putObject(new PutObjectRequest(bucketName, uploadingFileName, convertedFile) @@ -56,18 +51,20 @@ public String insertFileToS3(String bucketName, String fileName, MultipartFile f } } - /** - * 브랜드 사진 저장 | - * 500(SERVER_ERROR) - */ + + public String getStoredFileName(String fileName){ + return UUID.randomUUID() + fileName.substring(fileName.lastIndexOf('.')); + } + + //사진 저장 @Transactional public Photo savePhoto(MultipartFile file) { String filename = file.getOriginalFilename(); Photo photo = new Photo(filename); - String originalFileName = photo.getFileName(filename); + String storedFileName = getStoredFileName(filename); - String brandPhotoUrl = insertFileToS3(brandPhotoBucketName, originalFileName, file); + String brandPhotoUrl = insertFileToS3(bucketName, storedFileName, file); try { photo = Photo.builder() @@ -79,4 +76,13 @@ public Photo savePhoto(MultipartFile file) { return photo; } + + //S3 에서 사진 삭제 + public void deleteFileFromS3(String fileName) {; + try { + amazonS3Client.deleteObject(bucketName, fileName); + } catch (SdkClientException e) { + throw new CustomException(e, SERVER_ERROR); + } + } } From afad99d21a584d3c146ebe6393f7ca8b01500f9d Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Thu, 3 Aug 2023 23:01:18 +0900 Subject: [PATCH 05/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favor/configuration/S3Configuration.java | 2 -- .../main/java/com/favor/favor/gift/Gift.java | 3 +++ .../java/com/favor/favor/photo/Photo.java | 1 - .../com/favor/favor/photo/PhotoService.java | 19 ++++++++++++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java b/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java index b7b8016..5c27939 100644 --- a/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java +++ b/favor/src/main/java/com/favor/favor/configuration/S3Configuration.java @@ -1,9 +1,7 @@ package com.favor.favor.configuration; -import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; -import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import org.springframework.beans.factory.annotation.Value; diff --git a/favor/src/main/java/com/favor/favor/gift/Gift.java b/favor/src/main/java/com/favor/favor/gift/Gift.java index b571146..ded8e36 100644 --- a/favor/src/main/java/com/favor/favor/gift/Gift.java +++ b/favor/src/main/java/com/favor/favor/gift/Gift.java @@ -3,6 +3,7 @@ import com.favor.favor.common.enums.Category; import com.favor.favor.common.enums.Emotion; import com.favor.favor.common.TimeStamped; +import com.favor.favor.photo.Photo; import com.favor.favor.user.User; import lombok.*; @@ -23,6 +24,8 @@ public class Gift extends TimeStamped { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long giftNo; +// @OneToMany(mappedBy = "gift", cascade = CascadeType.ALL , orphanRemoval = true) +// private List giftPhotos = new ArrayList<>(); private String giftName; public void setGiftName(String giftName){ this.giftName = giftName; diff --git a/favor/src/main/java/com/favor/favor/photo/Photo.java b/favor/src/main/java/com/favor/favor/photo/Photo.java index ce984a2..2c5d390 100644 --- a/favor/src/main/java/com/favor/favor/photo/Photo.java +++ b/favor/src/main/java/com/favor/favor/photo/Photo.java @@ -10,7 +10,6 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; -import java.util.UUID; @Getter @Entity diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoService.java b/favor/src/main/java/com/favor/favor/photo/PhotoService.java index 3084cd3..3c33740 100644 --- a/favor/src/main/java/com/favor/favor/photo/PhotoService.java +++ b/favor/src/main/java/com/favor/favor/photo/PhotoService.java @@ -51,7 +51,7 @@ public String insertFileToS3(String bucketName, String fileName, MultipartFile f } } - + //사진 저장 이름 생성 public String getStoredFileName(String fileName){ return UUID.randomUUID() + fileName.substring(fileName.lastIndexOf('.')); } @@ -85,4 +85,21 @@ public Photo savePhoto(MultipartFile file) { throw new CustomException(e, SERVER_ERROR); } } + + //fileName 을 fileUrl 로 변경 + public String extractFileUrl(String fileName){ + String baseUrl = "https://favor-app-bucket.s3.ap-northeast-2.amazonaws.com/"; + return baseUrl + fileName; + } + + //fileUrl 에서 fileName 추출 + public static String extractFileName(String url) { + int lastSlashIndex = url.lastIndexOf('/'); + if (lastSlashIndex != -1 && lastSlashIndex < url.length() - 1) { + return url.substring(lastSlashIndex + 1); + } else { + return null; + } + } + } From 4bb4ccb0abf04846719a61c42a007b11c1944129 Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Fri, 4 Aug 2023 00:22:21 +0900 Subject: [PATCH 06/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/favor/favor/photo/PhotoService.java | 39 ++++-- .../main/java/com/favor/favor/user/User.java | 7 ++ .../com/favor/favor/user/UserController.java | 6 +- .../favor/favor/user/UserPhotoController.java | 112 ++++++++++++++++++ .../favor/favor/user/UserPhotoService.java | 47 ++++++++ .../com/favor/favor/user/UserResponseDto.java | 5 + 6 files changed, 205 insertions(+), 11 deletions(-) create mode 100644 favor/src/main/java/com/favor/favor/user/UserPhotoController.java create mode 100644 favor/src/main/java/com/favor/favor/user/UserPhotoService.java diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoService.java b/favor/src/main/java/com/favor/favor/photo/PhotoService.java index 3c33740..c591af4 100644 --- a/favor/src/main/java/com/favor/favor/photo/PhotoService.java +++ b/favor/src/main/java/com/favor/favor/photo/PhotoService.java @@ -55,6 +55,9 @@ public String insertFileToS3(String bucketName, String fileName, MultipartFile f public String getStoredFileName(String fileName){ return UUID.randomUUID() + fileName.substring(fileName.lastIndexOf('.')); } + public String getUserProfileFileName(String fileName){ + return "user_profile/" + UUID.randomUUID()+ fileName.substring(fileName.lastIndexOf('.')); + } //사진 저장 @Transactional @@ -77,8 +80,28 @@ public Photo savePhoto(MultipartFile file) { return photo; } + @Transactional + public Photo saveUserProfilePhoto(MultipartFile file) { + + String filename = file.getOriginalFilename(); + Photo photo = new Photo(filename); + String storedFileName = getUserProfileFileName(filename); + + String brandPhotoUrl = insertFileToS3(bucketName, storedFileName, file); + + try { + photo = Photo.builder() + .photoUrl(brandPhotoUrl) + .build(); + } catch (RuntimeException e) { + throw new CustomException(e, SERVER_ERROR); + } + + return photo; + } + //S3 에서 사진 삭제 - public void deleteFileFromS3(String fileName) {; + public void deleteFileFromS3(String fileName) { try { amazonS3Client.deleteObject(bucketName, fileName); } catch (SdkClientException e) { @@ -87,19 +110,17 @@ public Photo savePhoto(MultipartFile file) { } //fileName 을 fileUrl 로 변경 - public String extractFileUrl(String fileName){ - String baseUrl = "https://favor-app-bucket.s3.ap-northeast-2.amazonaws.com/"; - return baseUrl + fileName; + public String createFileUrl(String fileName){ + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("https://favor-app-bucket.s3.ap-northeast-2.amazonaws.com/") + .append(fileName); + return stringBuilder.toString(); } //fileUrl 에서 fileName 추출 public static String extractFileName(String url) { int lastSlashIndex = url.lastIndexOf('/'); - if (lastSlashIndex != -1 && lastSlashIndex < url.length() - 1) { - return url.substring(lastSlashIndex + 1); - } else { - return null; - } + return url.substring(lastSlashIndex + 1); } } diff --git a/favor/src/main/java/com/favor/favor/user/User.java b/favor/src/main/java/com/favor/favor/user/User.java index 90be46e..c919577 100644 --- a/favor/src/main/java/com/favor/favor/user/User.java +++ b/favor/src/main/java/com/favor/favor/user/User.java @@ -7,6 +7,7 @@ import com.favor.favor.common.TimeStamped; import com.favor.favor.friend.Friend; import com.favor.favor.gift.Gift; +import com.favor.favor.photo.Photo; import com.favor.favor.reminder.Reminder; import lombok.*; import org.springframework.security.core.GrantedAuthority; @@ -77,6 +78,12 @@ public void setFavorList(List favorList) { @OneToMany(mappedBy = "user", orphanRemoval = true) private List friendList = new ArrayList<>(); + @OneToOne(cascade = CascadeType.ALL) + private Photo userPhoto; + public void setUserPhoto(Photo userPhoto) { + this.userPhoto = userPhoto; + } + private Role role; @Override diff --git a/favor/src/main/java/com/favor/favor/user/UserController.java b/favor/src/main/java/com/favor/favor/user/UserController.java index 0cb2402..cae2917 100644 --- a/favor/src/main/java/com/favor/favor/user/UserController.java +++ b/favor/src/main/java/com/favor/favor/user/UserController.java @@ -148,7 +148,8 @@ public ResponseEntity> signIn( @Transactional @GetMapping public ResponseEntity> readUser( - @AuthenticationPrincipal User loginUser){ + @AuthenticationPrincipal User loginUser + ){ Long userNo = loginUser.getUserNo(); @@ -183,7 +184,8 @@ public ResponseEntity> readUser( @PatchMapping public ResponseEntity> updateUser( @AuthenticationPrincipal User loginUser, - @RequestBody @Valid UserUpdateRequestDto userUpdateRequestDto){ + @RequestBody @Valid UserUpdateRequestDto userUpdateRequestDto + ){ Long userNo = loginUser.getUserNo(); diff --git a/favor/src/main/java/com/favor/favor/user/UserPhotoController.java b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java new file mode 100644 index 0000000..6ac1702 --- /dev/null +++ b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java @@ -0,0 +1,112 @@ +package com.favor.favor.user; + +import com.favor.favor.common.DefaultResponseDto; +import com.favor.favor.photo.Photo; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.transaction.Transactional; + +@RestController +@RequestMapping("/userphotos") +@RequiredArgsConstructor +public class UserPhotoController { + private final UserPhotoService userPhotoService; + private final UserService userService; + + @ApiOperation(value = "회원 사진 등록/수정") + @ApiResponses(value={ + @ApiResponse(code = 201, + message = "USER_PHOTO_ADDED/UPDATED", + response = UserResponseDto.class), + @ApiResponse(code = 400, + message = "FIELD_REQUIRED / *_CHARACTER_INVALID / *_LENGTH_INVALID"), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "USER_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.CREATED) + @PostMapping + public ResponseEntity> updateUserPhoto( + @ModelAttribute MultipartFile file, + @AuthenticationPrincipal User loginUser + ) { + Long userNo = loginUser.getUserNo(); + userService.isExistingUserNo(userNo); + + User user = userPhotoService.updateUserPhoto(userNo, file); + UserResponseDto dto = userService.returnUserDto(user); + + return ResponseEntity.status(201) + .body(DefaultResponseDto.builder() + .responseCode("USER_PHOTO_ADDED/UPDATED") + .responseMessage("회원 사진 등록/수정 완료") + .data(dto) + .build()); + } + + @ApiOperation("회원 사진 조회") + @ApiResponses(value={ + @ApiResponse(code = 200, + message = "USER_PHOTO_FOUND", + response = UserResponseDto.class), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "USER_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @Transactional + @GetMapping + public ResponseEntity> getUserPhoto( + @AuthenticationPrincipal User loginUser + ) { + Photo dto = userPhotoService.getUserPhoto(loginUser.getUserNo()); + + return ResponseEntity.status(200) + .body(DefaultResponseDto.builder() + .responseCode("USER_PHOTO_FOUND") + .responseMessage("회원 사진 조회 완료") + .data(dto) + .build()); + } + + @ApiOperation("회원 사진 삭제") + @ApiResponses(value={ + @ApiResponse(code = 200, + message = "USER_PHOTO_DELETED", + response = UserResponseDto.class), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "USER_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @Transactional + @DeleteMapping + public ResponseEntity deleteUserPhoto(@PathVariable Long userNo) { + UserResponseDto dto = userService + .returnUserDto(userPhotoService.deleteUserPhoto(userNo)); + + return ResponseEntity.status(200) + .body(DefaultResponseDto.builder() + .responseCode("USER_PHOTO_DELETED") + .responseMessage("회원 사진 삭제 완료") + .data(dto) + .build()); + } +} \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/user/UserPhotoService.java b/favor/src/main/java/com/favor/favor/user/UserPhotoService.java new file mode 100644 index 0000000..908ae50 --- /dev/null +++ b/favor/src/main/java/com/favor/favor/user/UserPhotoService.java @@ -0,0 +1,47 @@ +package com.favor.favor.user; + +import com.favor.favor.exception.CustomException; +import com.favor.favor.exception.ExceptionCode; +import com.favor.favor.photo.Photo; +import com.favor.favor.photo.PhotoService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.transaction.Transactional; + +@Service +@RequiredArgsConstructor +public class UserPhotoService { + + private final UserRepository userRepository; + private final PhotoService photoService; + private final UserService userService; + + @Transactional + public User updateUserPhoto(Long userNo, MultipartFile file) { + User user = userService.findUserByUserNo(userNo); + if(!(user.getUserPhoto() == null)){ + deleteUserPhoto(userNo); + } + Photo photo = photoService.saveUserProfilePhoto(file); + user.setUserPhoto(photo); + return userRepository.save(user); + } + + public Photo getUserPhoto(Long userNo) { + return userService.findUserByUserNo(userNo).getUserPhoto(); + } + + @Transactional + public User deleteUserPhoto(Long userNo) { + + User user = userService.findUserByUserNo(userNo); + String fileName = photoService.extractFileName(user.getUserPhoto().getPhotoUrl()); + + user.setUserPhoto(null); + photoService.deleteFileFromS3(fileName); + + return userRepository.save(user); + } +} diff --git a/favor/src/main/java/com/favor/favor/user/UserResponseDto.java b/favor/src/main/java/com/favor/favor/user/UserResponseDto.java index ade67f5..89fd0b6 100644 --- a/favor/src/main/java/com/favor/favor/user/UserResponseDto.java +++ b/favor/src/main/java/com/favor/favor/user/UserResponseDto.java @@ -5,6 +5,7 @@ import com.favor.favor.common.enums.Role; import com.favor.favor.friend.FriendResponseDto; import com.favor.favor.gift.GiftResponseDto; +import com.favor.favor.photo.Photo; import com.favor.favor.reminder.ReminderResponseDto; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -54,6 +55,9 @@ public class UserResponseDto { @ApiModelProperty(value = "") private List favorList; + @ApiModelProperty(value = "") + private Photo userPhoto; + @Builder public UserResponseDto(User user, List reminderList, @@ -73,5 +77,6 @@ public UserResponseDto(User user, this.friendList = friendList; this.favorList = favorList; this.anniversaryList = anniversaryList; + this.userPhoto = user.getUserPhoto(); } } From 3474ada52cfcf32c7f72296e2293cd01ea3f5640 Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Sat, 5 Aug 2023 08:32:07 +0900 Subject: [PATCH 07/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favor/favor/exception/ExceptionCode.java | 1 + .../com/favor/favor/photo/PhotoService.java | 99 ++++++------- .../main/java/com/favor/favor/user/User.java | 12 +- .../favor/favor/user/UserPhotoController.java | 135 +++++++++++++++--- .../favor/favor/user/UserPhotoService.java | 134 +++++++++++++++-- .../com/favor/favor/user/UserResponseDto.java | 9 +- 6 files changed, 296 insertions(+), 94 deletions(-) diff --git a/favor/src/main/java/com/favor/favor/exception/ExceptionCode.java b/favor/src/main/java/com/favor/favor/exception/ExceptionCode.java index a435779..c55ea73 100644 --- a/favor/src/main/java/com/favor/favor/exception/ExceptionCode.java +++ b/favor/src/main/java/com/favor/favor/exception/ExceptionCode.java @@ -49,6 +49,7 @@ public enum ExceptionCode { * 404 NOT_FOUND : Resource 를 찾을 수 없음 */ EMAIL_NOT_FOUND(NOT_FOUND, "등록된 이메일이 없습니다."), + FILE_NOT_FOUND(NOT_FOUND, "등록된 파일이 없습니다."), USER_NOT_FOUND(NOT_FOUND, "등록된 회원이 없습니다."), PASSWORD_NOT_FOUND(NOT_FOUND, "비밀번호를 잘못 입력하였습니다."), FRIEND_NOT_FOUND(NOT_FOUND, "등록된 친구가 없습니다."), diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoService.java b/favor/src/main/java/com/favor/favor/photo/PhotoService.java index c591af4..00565be 100644 --- a/favor/src/main/java/com/favor/favor/photo/PhotoService.java +++ b/favor/src/main/java/com/favor/favor/photo/PhotoService.java @@ -5,6 +5,7 @@ import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.PutObjectRequest; import com.favor.favor.exception.CustomException; +import com.favor.favor.user.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -13,9 +14,11 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.net.URL; import java.util.Objects; import java.util.UUID; +import static com.favor.favor.exception.ExceptionCode.FILE_NOT_FOUND; import static com.favor.favor.exception.ExceptionCode.SERVER_ERROR; @Service @@ -24,18 +27,8 @@ public class PhotoService { private String bucketName = "favor-app-bucket"; private final AmazonS3Client amazonS3Client; - //MultipartFile을 File로 전환 - private File convertFile(MultipartFile file) throws IOException { - File convertingFile = new File(Objects.requireNonNull(file.getOriginalFilename())); - FileOutputStream fileOutputStream = new FileOutputStream(convertingFile); - fileOutputStream.write(file.getBytes()); - fileOutputStream.close(); - - return convertingFile; - } - //S3에 사진 업로드 - public String insertFileToS3(String bucketName, String fileName, MultipartFile file) { + public String uploadFileToS3(String fileName, MultipartFile file) { try { File convertedFile = convertFile(file); @@ -51,43 +44,57 @@ public String insertFileToS3(String bucketName, String fileName, MultipartFile f } } - //사진 저장 이름 생성 - public String getStoredFileName(String fileName){ - return UUID.randomUUID() + fileName.substring(fileName.lastIndexOf('.')); + //S3 에서 사진 삭제 + public void deleteFileFromS3(String fileName) { + try { + amazonS3Client.deleteObject(bucketName, fileName); + } catch (SdkClientException e) { + throw new CustomException(e, FILE_NOT_FOUND); + } } - public String getUserProfileFileName(String fileName){ - return "user_profile/" + UUID.randomUUID()+ fileName.substring(fileName.lastIndexOf('.')); + + //fileName -> fileUrl + public String createFileUrl(String fileName){ + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder + .append("https://favor-app-bucket.s3.ap-northeast-2.amazonaws.com/") + .append(fileName); + return stringBuilder.toString(); } - //사진 저장 - @Transactional - public Photo savePhoto(MultipartFile file) { - String filename = file.getOriginalFilename(); - Photo photo = new Photo(filename); - String storedFileName = getStoredFileName(filename); - String brandPhotoUrl = insertFileToS3(bucketName, storedFileName, file); + //MultipartFile을 File로 전환 + private File convertFile(MultipartFile file) throws IOException { + File convertingFile = new File(Objects.requireNonNull(file.getOriginalFilename())); + FileOutputStream fileOutputStream = new FileOutputStream(convertingFile); + fileOutputStream.write(file.getBytes()); + fileOutputStream.close(); - try { - photo = Photo.builder() - .photoUrl(brandPhotoUrl) - .build(); - } catch (RuntimeException e) { - throw new CustomException(e, SERVER_ERROR); - } + return convertingFile; + } - return photo; + + + + + + + //사진 저장 이름 생성 + public String getStoredFileName(String fileName){ + return UUID.randomUUID() + fileName.substring(fileName.lastIndexOf('.')); } + + //사진 저장 @Transactional - public Photo saveUserProfilePhoto(MultipartFile file) { + public Photo savePhoto(MultipartFile file) { String filename = file.getOriginalFilename(); Photo photo = new Photo(filename); - String storedFileName = getUserProfileFileName(filename); + String storedFileName = getStoredFileName(filename); - String brandPhotoUrl = insertFileToS3(bucketName, storedFileName, file); + String brandPhotoUrl = uploadFileToS3(storedFileName, file); try { photo = Photo.builder() @@ -99,28 +106,4 @@ public Photo saveUserProfilePhoto(MultipartFile file) { return photo; } - - //S3 에서 사진 삭제 - public void deleteFileFromS3(String fileName) { - try { - amazonS3Client.deleteObject(bucketName, fileName); - } catch (SdkClientException e) { - throw new CustomException(e, SERVER_ERROR); - } - } - - //fileName 을 fileUrl 로 변경 - public String createFileUrl(String fileName){ - StringBuilder stringBuilder = new StringBuilder(); - stringBuilder.append("https://favor-app-bucket.s3.ap-northeast-2.amazonaws.com/") - .append(fileName); - return stringBuilder.toString(); - } - - //fileUrl 에서 fileName 추출 - public static String extractFileName(String url) { - int lastSlashIndex = url.lastIndexOf('/'); - return url.substring(lastSlashIndex + 1); - } - } diff --git a/favor/src/main/java/com/favor/favor/user/User.java b/favor/src/main/java/com/favor/favor/user/User.java index c919577..79ae47c 100644 --- a/favor/src/main/java/com/favor/favor/user/User.java +++ b/favor/src/main/java/com/favor/favor/user/User.java @@ -79,9 +79,15 @@ public void setFavorList(List favorList) { private List friendList = new ArrayList<>(); @OneToOne(cascade = CascadeType.ALL) - private Photo userPhoto; - public void setUserPhoto(Photo userPhoto) { - this.userPhoto = userPhoto; + private Photo userProfilePhoto; + public void setUserProfilePhoto(Photo userPhoto) { + this.userProfilePhoto = userPhoto; + } + + @OneToOne(cascade = CascadeType.ALL) + private Photo userBackgroundPhoto; + public void setUserBackgroundPhoto(Photo userPhoto) { + this.userBackgroundPhoto = userPhoto; } private Role role; diff --git a/favor/src/main/java/com/favor/favor/user/UserPhotoController.java b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java index 6ac1702..01303ca 100644 --- a/favor/src/main/java/com/favor/favor/user/UserPhotoController.java +++ b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java @@ -2,6 +2,7 @@ import com.favor.favor.common.DefaultResponseDto; import com.favor.favor.photo.Photo; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; @@ -14,6 +15,7 @@ import javax.transaction.Transactional; +@Api(tags = "User-Photo") @RestController @RequestMapping("/userphotos") @RequiredArgsConstructor @@ -21,10 +23,10 @@ public class UserPhotoController { private final UserPhotoService userPhotoService; private final UserService userService; - @ApiOperation(value = "회원 사진 등록/수정") + @ApiOperation(value = "회원 프로필 사진 등록/수정") @ApiResponses(value={ @ApiResponse(code = 201, - message = "USER_PHOTO_ADDED/UPDATED", + message = "USER_PROFILE_PHOTO_ADDED/UPDATED", response = UserResponseDto.class), @ApiResponse(code = 400, message = "FIELD_REQUIRED / *_CHARACTER_INVALID / *_LENGTH_INVALID"), @@ -36,29 +38,29 @@ public class UserPhotoController { message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.CREATED) - @PostMapping - public ResponseEntity> updateUserPhoto( + @PostMapping("/profile") + public ResponseEntity> updateUserProfilePhoto( @ModelAttribute MultipartFile file, @AuthenticationPrincipal User loginUser ) { Long userNo = loginUser.getUserNo(); userService.isExistingUserNo(userNo); - User user = userPhotoService.updateUserPhoto(userNo, file); + User user = userPhotoService.updateUserProfilePhoto(userNo, file); UserResponseDto dto = userService.returnUserDto(user); return ResponseEntity.status(201) .body(DefaultResponseDto.builder() - .responseCode("USER_PHOTO_ADDED/UPDATED") + .responseCode("USER_PROFILE_PHOTO_ADDED/UPDATED") .responseMessage("회원 사진 등록/수정 완료") .data(dto) .build()); } - @ApiOperation("회원 사진 조회") + @ApiOperation("회원 프로필 사진 조회") @ApiResponses(value={ @ApiResponse(code = 200, - message = "USER_PHOTO_FOUND", + message = "USER_PROFILE_PHOTO_FOUND", response = UserResponseDto.class), @ApiResponse(code = 401, message = "UNAUTHORIZED_USER"), @@ -69,24 +71,24 @@ public ResponseEntity> updateUserPhoto( }) @ResponseStatus(HttpStatus.OK) @Transactional - @GetMapping - public ResponseEntity> getUserPhoto( + @GetMapping("/profile") + public ResponseEntity> getUserProfilePhoto( @AuthenticationPrincipal User loginUser ) { - Photo dto = userPhotoService.getUserPhoto(loginUser.getUserNo()); + Photo dto = userPhotoService.getUserProfilePhoto(loginUser.getUserNo()); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() - .responseCode("USER_PHOTO_FOUND") + .responseCode("USER_PROFILE_PHOTO_FOUND") .responseMessage("회원 사진 조회 완료") .data(dto) .build()); } - @ApiOperation("회원 사진 삭제") + @ApiOperation("회원 프로필 사진 삭제") @ApiResponses(value={ @ApiResponse(code = 200, - message = "USER_PHOTO_DELETED", + message = "USER_PROFILE_PHOTO_DELETED", response = UserResponseDto.class), @ApiResponse(code = 401, message = "UNAUTHORIZED_USER"), @@ -97,16 +99,113 @@ public ResponseEntity> getUserPhoto( }) @ResponseStatus(HttpStatus.OK) @Transactional - @DeleteMapping - public ResponseEntity deleteUserPhoto(@PathVariable Long userNo) { + @DeleteMapping("/profile") + public ResponseEntity> deleteUserProfilePhoto( + @AuthenticationPrincipal User loginUser + ) { + Long userNo = loginUser.getUserNo(); + UserResponseDto dto = userService - .returnUserDto(userPhotoService.deleteUserPhoto(userNo)); + .returnUserDto(userPhotoService.deleteUserProfilePhoto(userNo)); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() - .responseCode("USER_PHOTO_DELETED") + .responseCode("USER_PROFILE_PHOTO_DELETED") .responseMessage("회원 사진 삭제 완료") .data(dto) .build()); } + + @ApiOperation(value = "회원 배경 사진 등록/수정") + @ApiResponses(value={ + @ApiResponse(code = 201, + message = "USER_BACKGROUND_PHOTO_ADDED/UPDATED", + response = UserResponseDto.class), + @ApiResponse(code = 400, + message = "FIELD_REQUIRED / *_CHARACTER_INVALID / *_LENGTH_INVALID"), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "USER_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.CREATED) + @PostMapping("/background") + public ResponseEntity> updateUserBackgroundPhoto( + @ModelAttribute MultipartFile file, + @AuthenticationPrincipal User loginUser + ) { + Long userNo = loginUser.getUserNo(); + userService.isExistingUserNo(userNo); + + User user = userPhotoService.updateUserBackgroundPhoto(userNo, file); + UserResponseDto dto = userService.returnUserDto(user); + + return ResponseEntity.status(201) + .body(DefaultResponseDto.builder() + .responseCode("USER_BACKGROUND_PHOTO_ADDED/UPDATED") + .responseMessage("회원 배경 사진 등록/수정 완료") + .data(dto) + .build()); + } + + @ApiOperation("회원 배경 사진 조회") + @ApiResponses(value={ + @ApiResponse(code = 200, + message = "USER_BACKGROUND_PHOTO_FOUND", + response = UserResponseDto.class), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "USER_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @Transactional + @GetMapping("/background") + public ResponseEntity> getUserBackgroundPhoto( + @AuthenticationPrincipal User loginUser + ) { + Photo dto = userPhotoService.getUserBackgroundPhoto(loginUser.getUserNo()); + + return ResponseEntity.status(200) + .body(DefaultResponseDto.builder() + .responseCode("USER_BACKGROUND_PHOTO_FOUND") + .responseMessage("회원 배경 사진 조회 완료") + .data(dto) + .build()); + } + + @ApiOperation("회원 배경 사진 삭제") + @ApiResponses(value={ + @ApiResponse(code = 200, + message = "USER_BACKGROUND_PHOTO_DELETED", + response = UserResponseDto.class), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "USER_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @Transactional + @DeleteMapping("/background") + public ResponseEntity> deleteUserBackgroundPhoto( + @AuthenticationPrincipal User loginUser + ) { + Long userNo = loginUser.getUserNo(); + + UserResponseDto dto = userService + .returnUserDto(userPhotoService.deleteUserBackgroundPhoto(userNo)); + + return ResponseEntity.status(200) + .body(DefaultResponseDto.builder() + .responseCode("USER_BACKGROUND_PHOTO_DELETED") + .responseMessage("회원 배경 사진 삭제 완료") + .data(dto) + .build()); + } } \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/user/UserPhotoService.java b/favor/src/main/java/com/favor/favor/user/UserPhotoService.java index 908ae50..ccba27c 100644 --- a/favor/src/main/java/com/favor/favor/user/UserPhotoService.java +++ b/favor/src/main/java/com/favor/favor/user/UserPhotoService.java @@ -1,7 +1,6 @@ package com.favor.favor.user; import com.favor.favor.exception.CustomException; -import com.favor.favor.exception.ExceptionCode; import com.favor.favor.photo.Photo; import com.favor.favor.photo.PhotoService; import lombok.RequiredArgsConstructor; @@ -9,39 +8,150 @@ import org.springframework.web.multipart.MultipartFile; import javax.transaction.Transactional; +import java.net.URL; +import java.util.UUID; + +import static com.favor.favor.exception.ExceptionCode.SERVER_ERROR; @Service @RequiredArgsConstructor public class UserPhotoService { - private final UserRepository userRepository; private final PhotoService photoService; private final UserService userService; + //유저 프로필사진 등록/수정 @Transactional - public User updateUserPhoto(Long userNo, MultipartFile file) { + public User updateUserProfilePhoto(Long userNo, MultipartFile file) { User user = userService.findUserByUserNo(userNo); - if(!(user.getUserPhoto() == null)){ - deleteUserPhoto(userNo); + if(!(user.getUserProfilePhoto() == null)){ + deleteUserProfilePhoto(userNo); + } + + String filename = file.getOriginalFilename(); + Photo photo = null; + String storedFileName = getUserProfileFileName(filename); + + String photoUrl = photoService.uploadFileToS3(storedFileName, file); + try { + photo = Photo.builder() + .photoUrl(photoUrl) + .build(); + } catch (RuntimeException e) { + throw new CustomException(e, SERVER_ERROR); } - Photo photo = photoService.saveUserProfilePhoto(file); - user.setUserPhoto(photo); + + user.setUserProfilePhoto(photo); return userRepository.save(user); } - public Photo getUserPhoto(Long userNo) { - return userService.findUserByUserNo(userNo).getUserPhoto(); + //유저 프로필사진 조회 + public Photo getUserProfilePhoto(Long userNo) { + return userService.findUserByUserNo(userNo).getUserProfilePhoto(); } + //유저 프로필사진 삭제 @Transactional - public User deleteUserPhoto(Long userNo) { + public User deleteUserProfilePhoto(Long userNo) { User user = userService.findUserByUserNo(userNo); - String fileName = photoService.extractFileName(user.getUserPhoto().getPhotoUrl()); + String fileName = extractProfilePhotoFileName(user); - user.setUserPhoto(null); + user.setUserProfilePhoto(null); photoService.deleteFileFromS3(fileName); return userRepository.save(user); } + + + //유저 배경사진 등록/수정 + @Transactional + public User updateUserBackgroundPhoto(Long userNo, MultipartFile file) { + User user = userService.findUserByUserNo(userNo); + //유저의 배경 사진이 이미 있으면 삭제 + if(!(user.getUserBackgroundPhoto() == null)){ + deleteUserBackgroundPhoto(userNo); + } + String filename = file.getOriginalFilename(); + Photo photo = null; + String storedFileName = getUserBackgroundFileName(filename); + + String photoUrl = photoService.uploadFileToS3(storedFileName, file); + try { + photo = Photo.builder() + .photoUrl(photoUrl) + .build(); + } catch (RuntimeException e) { + throw new CustomException(e, SERVER_ERROR); + } + + user.setUserBackgroundPhoto(photo); + return userRepository.save(user); + } + + //유저 배경사진 조회 + public Photo getUserBackgroundPhoto(Long userNo) { + return userService.findUserByUserNo(userNo).getUserBackgroundPhoto(); + } + + //유저 배경사진 삭제 + @Transactional + public User deleteUserBackgroundPhoto(Long userNo) { + + User user = userService.findUserByUserNo(userNo); + String fileName = extractBackgroundPhotoFileName(user); + + user.setUserBackgroundPhoto(null); + photoService.deleteFileFromS3(fileName); + + return userRepository.save(user); + } + + + + + //유저 프로필 사진 이름 생성 + public String getUserProfileFileName(String fileName){ + return "user_profile/" + UUID.randomUUID()+ fileName.substring(fileName.lastIndexOf('.')); + } + //유저 배경 사진 이름 생성 + public String getUserBackgroundFileName(String fileName){ + return "user_background/" + UUID.randomUUID()+ fileName.substring(fileName.lastIndexOf('.')); + } + + + //유저의 프로필 사진 이름 추출 + public static String extractProfilePhotoFileName(User user) { + String path = null; + + try { + URL url = new URL(user.getUserProfilePhoto().getPhotoUrl()); + path = url.getPath(); + + if (path.startsWith("/")) { + path = path.substring(1); + } + } catch (Exception e) { + throw new CustomException(e, SERVER_ERROR); + } + + return path; + } + //유저의 배경 사진 이름 추출 + public static String extractBackgroundPhotoFileName(User user) { + String path = null; + + try { + URL url = new URL(user.getUserBackgroundPhoto().getPhotoUrl()); + path = url.getPath(); + + if (path.startsWith("/")) { + path = path.substring(1); + } + } catch (Exception e) { + throw new CustomException(e, SERVER_ERROR); + } + + return path; + } } diff --git a/favor/src/main/java/com/favor/favor/user/UserResponseDto.java b/favor/src/main/java/com/favor/favor/user/UserResponseDto.java index 89fd0b6..a3e5d99 100644 --- a/favor/src/main/java/com/favor/favor/user/UserResponseDto.java +++ b/favor/src/main/java/com/favor/favor/user/UserResponseDto.java @@ -4,7 +4,6 @@ import com.favor.favor.common.enums.Favor; import com.favor.favor.common.enums.Role; import com.favor.favor.friend.FriendResponseDto; -import com.favor.favor.gift.GiftResponseDto; import com.favor.favor.photo.Photo; import com.favor.favor.reminder.ReminderResponseDto; import io.swagger.annotations.ApiModelProperty; @@ -56,7 +55,10 @@ public class UserResponseDto { private List favorList; @ApiModelProperty(value = "") - private Photo userPhoto; + private Photo userProfilePhoto; + + @ApiModelProperty(value = "") + private Photo userBackgroundPhoto; @Builder public UserResponseDto(User user, @@ -77,6 +79,7 @@ public UserResponseDto(User user, this.friendList = friendList; this.favorList = favorList; this.anniversaryList = anniversaryList; - this.userPhoto = user.getUserPhoto(); + this.userProfilePhoto = user.getUserProfilePhoto(); + this.userBackgroundPhoto = user.getUserBackgroundPhoto(); } } From 87a1e2540310e5eadfb805d644f7bd0fd47cb46f Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Sat, 5 Aug 2023 11:45:04 +0900 Subject: [PATCH 08/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- favor/src/main/java/com/favor/favor/gift/Gift.java | 2 ++ .../src/main/java/com/favor/favor/user/UserController.java | 7 ++++++- favor/src/main/java/com/favor/favor/user/UserService.java | 1 - 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/favor/src/main/java/com/favor/favor/gift/Gift.java b/favor/src/main/java/com/favor/favor/gift/Gift.java index ded8e36..fa42fab 100644 --- a/favor/src/main/java/com/favor/favor/gift/Gift.java +++ b/favor/src/main/java/com/favor/favor/gift/Gift.java @@ -74,4 +74,6 @@ public void setIsGiven(Boolean isGiven){ public void setFriendNoList(List friendNoList){ this.friendNoList = friendNoList; } + +// @ManyToOne(cascade = Cas) } \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/user/UserController.java b/favor/src/main/java/com/favor/favor/user/UserController.java index cae2917..8ee892c 100644 --- a/favor/src/main/java/com/favor/favor/user/UserController.java +++ b/favor/src/main/java/com/favor/favor/user/UserController.java @@ -25,6 +25,7 @@ @RequiredArgsConstructor public class UserController { private final UserService userService; + private final UserPhotoService userPhotoService; @ApiOperation(value = "회원가입") @ApiResponses(value={ @@ -231,7 +232,11 @@ public ResponseEntity> deleteUser( userService.isExistingUserNo(userNo); - UserResponseDto dto = userService.returnUserDto(loginUser); + User user = userService.findUserByUserNo(userNo); + UserResponseDto dto = userService.returnUserDto(user); + + userPhotoService.deleteUserProfilePhoto(userNo); + userPhotoService.deleteUserBackgroundPhoto(userNo); userService.deleteUser(userNo); diff --git a/favor/src/main/java/com/favor/favor/user/UserService.java b/favor/src/main/java/com/favor/favor/user/UserService.java index b22f9b7..bc4039e 100644 --- a/favor/src/main/java/com/favor/favor/user/UserService.java +++ b/favor/src/main/java/com/favor/favor/user/UserService.java @@ -120,7 +120,6 @@ public User updateUser(User user, UserUpdateRequestDto userUpdateRequestDto){ @Transactional public void deleteUser(Long userNo) { - User user = findUserByUserNo(userNo); friendRepository.deleteFriendsByFriendUserNo(userNo); userRepository.deleteByUserNo(userNo); } From 990ae5bab0b5d0920765c2efe2f9ced7e652ad60 Mon Sep 17 00:00:00 2001 From: Eun Date: Sat, 5 Aug 2023 20:21:13 +0900 Subject: [PATCH 09/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/favor/favor/gift/Gift.java | 9 +- .../com/favor/favor/gift/GiftController.java | 7 +- .../favor/favor/gift/GiftPhotoController.java | 122 ++++++++++++++++++ .../favor/favor/gift/GiftPhotoService.java | 110 ++++++++++++++++ .../com/favor/favor/gift/GiftRequestDto.java | 2 + .../com/favor/favor/gift/GiftResponseDto.java | 4 + .../com/favor/favor/gift/GiftService.java | 42 ++++-- .../java/com/favor/favor/photo/GiftPhoto.java | 30 +++++ .../favor/favor/photo/PhotoController.java | 2 +- .../com/favor/favor/photo/PhotoService.java | 10 +- .../photo/{Photo.java => UserPhoto.java} | 4 +- .../main/java/com/favor/favor/user/User.java | 10 +- .../favor/favor/user/UserPhotoController.java | 6 +- .../favor/favor/user/UserPhotoService.java | 33 ++--- .../com/favor/favor/user/UserResponseDto.java | 10 +- 15 files changed, 348 insertions(+), 53 deletions(-) create mode 100644 favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java create mode 100644 favor/src/main/java/com/favor/favor/gift/GiftPhotoService.java create mode 100644 favor/src/main/java/com/favor/favor/photo/GiftPhoto.java rename favor/src/main/java/com/favor/favor/photo/{Photo.java => UserPhoto.java} (86%) diff --git a/favor/src/main/java/com/favor/favor/gift/Gift.java b/favor/src/main/java/com/favor/favor/gift/Gift.java index fa42fab..3a696da 100644 --- a/favor/src/main/java/com/favor/favor/gift/Gift.java +++ b/favor/src/main/java/com/favor/favor/gift/Gift.java @@ -3,7 +3,7 @@ import com.favor.favor.common.enums.Category; import com.favor.favor.common.enums.Emotion; import com.favor.favor.common.TimeStamped; -import com.favor.favor.photo.Photo; +import com.favor.favor.photo.GiftPhoto; import com.favor.favor.user.User; import lombok.*; @@ -11,6 +11,7 @@ import javax.transaction.Transactional; import java.time.LocalDate; import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; @Entity @@ -75,5 +76,9 @@ public void setFriendNoList(List friendNoList){ this.friendNoList = friendNoList; } -// @ManyToOne(cascade = Cas) + @OneToMany(cascade = CascadeType.ALL) + private List giftPhotoList = new ArrayList<>(); + public void setGiftPhotoList(List giftPhotoList){ + this.giftPhotoList = giftPhotoList; + } } \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/gift/GiftController.java b/favor/src/main/java/com/favor/favor/gift/GiftController.java index 51ff733..1f6b633 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftController.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftController.java @@ -10,6 +10,7 @@ import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -22,7 +23,7 @@ @RestController @RequestMapping("/gifts") @RequiredArgsConstructor -@Log4j2 +@Slf4j public class GiftController { private final GiftService giftService; @@ -181,10 +182,14 @@ public ResponseEntity> deleteGift( giftService.isExistingGiftNo(giftNo); + Gift gift = giftService.findGiftByGiftNo(giftNo); + log.info("[SYSTEM] giftService.findGiftByGiftNo(giftNo) 완료"); GiftResponseDto dto = giftService.returnDto(gift); + log.info("[SYSTEM] giftService.returnDto(gift) 완료"); giftService.deleteGift(giftNo); + log.info("[SYSTEM] giftService.deleteGift(giftNo) 완료"); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() diff --git a/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java b/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java new file mode 100644 index 0000000..f0ca617 --- /dev/null +++ b/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java @@ -0,0 +1,122 @@ +package com.favor.favor.gift; + +import com.favor.favor.common.DefaultResponseDto; +import com.favor.favor.photo.GiftPhoto; +import com.favor.favor.photo.UserPhoto; +import com.favor.favor.user.User; +import com.favor.favor.user.UserPhotoService; +import com.favor.favor.user.UserResponseDto; +import com.favor.favor.user.UserService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +import javax.transaction.Transactional; +import java.util.List; + +@Api(tags = "Gift-Photo") +@RestController +@RequestMapping("/giftphotos") +@RequiredArgsConstructor +public class GiftPhotoController { + private final GiftPhotoService giftPhotoService; + private final GiftService giftService; + + @ApiOperation(value = "선물 사진 추가") + @ApiResponses(value={ + @ApiResponse(code = 201, + message = "GIFT_PHOTO_LIST_ADDED", + response = UserResponseDto.class), + @ApiResponse(code = 400, + message = "FIELD_REQUIRED / *_CHARACTER_INVALID / *_LENGTH_INVALID"), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "GIFT_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.CREATED) + @PostMapping + public ResponseEntity> addGiftPhotoList( + @ModelAttribute MultipartFile file, + Long giftNo + ) { + giftService.isExistingGiftNo(giftNo); + + Gift gift = giftPhotoService.addGiftPhoto(giftNo, file); + + GiftResponseDto dto = giftService.returnDto(gift); + + return ResponseEntity.status(201) + .body(DefaultResponseDto.builder() + .responseCode("GIFT_PHOTO_LIST_ADDED") + .responseMessage("선물 사진 추가") + .data(dto) + .build()); + } + + @ApiOperation("선물 사진 목록 조회") + @ApiResponses(value={ + @ApiResponse(code = 200, + message = "GIFT_PHOTO_LIST_FOUND", + response = UserResponseDto.class), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "GIFT_NOT_FOUND | FILE_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @Transactional + @GetMapping + public ResponseEntity> getUserProfilePhoto(Long giftNo) { + Gift gift = giftService.findGiftByGiftNo(giftNo); + + List dto = giftPhotoService.getGiftPhotoList(giftNo); + + return ResponseEntity.status(200) + .body(DefaultResponseDto.builder() + .responseCode("GIFT_PHOTO_LIST_FOUND") + .responseMessage("선물 사진 목록 조회 완료") + .data(dto) + .build()); + } + + @ApiOperation("선물 사진 삭제") + @ApiResponses(value={ + @ApiResponse(code = 200, + message = "GIFT_PHOTO_DELETED", + response = UserResponseDto.class), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "GIFT_NOT_FOUND | FILE_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @Transactional + @DeleteMapping + public ResponseEntity> deleteUserProfilePhoto( + Long giftNo, String fileUrl) { + + Gift gift = giftPhotoService.deleteGiftPhoto(giftNo, fileUrl); + GiftResponseDto dto = new GiftResponseDto(gift); + + return ResponseEntity.status(200) + .body(DefaultResponseDto.builder() + .responseCode("GIFT_PHOTO_DELETED") + .responseMessage("선물 사진 삭제 완료") + .data(dto) + .build()); + } +} diff --git a/favor/src/main/java/com/favor/favor/gift/GiftPhotoService.java b/favor/src/main/java/com/favor/favor/gift/GiftPhotoService.java new file mode 100644 index 0000000..866890d --- /dev/null +++ b/favor/src/main/java/com/favor/favor/gift/GiftPhotoService.java @@ -0,0 +1,110 @@ +package com.favor.favor.gift; + +import com.favor.favor.exception.CustomException; +import com.favor.favor.photo.GiftPhoto; +import com.favor.favor.photo.PhotoService; +import com.favor.favor.user.User; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.transaction.Transactional; +import java.net.URL; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; + +import static com.favor.favor.exception.ExceptionCode.FILE_NOT_FOUND; +import static com.favor.favor.exception.ExceptionCode.SERVER_ERROR; + +@Service +@RequiredArgsConstructor +public class GiftPhotoService { + private final GiftRepository giftRepository; + private final GiftService giftService; + private final PhotoService photoService; + + //선물 사진 목록에 사진 추가 + @Transactional + public Gift addGiftPhoto(Long giftNo, MultipartFile file){ + Gift gift = giftService.findGiftByGiftNo(giftNo); + List giftPhotoList = gift.getGiftPhotoList(); + + String fileName = file.getOriginalFilename(); + String storedFileName = getGiftFileName(fileName); + + String giftPhotoUrl = photoService.uploadFileToS3(storedFileName, file); + + try{ + GiftPhoto giftPhoto = GiftPhoto.builder() + .photoUrl(giftPhotoUrl) + .build(); + + giftPhotoList.add(giftPhoto); + + }catch(RuntimeException e){ + throw new CustomException(e, SERVER_ERROR); + } + +// for(MultipartFile file : fileList){ +// String fileName = file.getOriginalFilename(); +// String storedFileName = getGiftFileName(fileName); +// +// String giftPhotoUrl = photoService.uploadFileToS3(storedFileName, file); +// try{ +// GiftPhoto giftPhoto = GiftPhoto.builder() +// .photoUrl(giftPhotoUrl) +// .build(); +// +// giftPhotoList.add(giftPhoto); +// +// }catch(RuntimeException e){ +// throw new CustomException(e, SERVER_ERROR); +// } +// } + gift.setGiftPhotoList(giftPhotoList); + return giftRepository.save(gift); + } + + //선물 사진 목록 조회 + public List getGiftPhotoList(Long giftNo){ + return giftService.findGiftByGiftNo(giftNo).getGiftPhotoList(); + } + + //선물 사진 삭제 + public Gift deleteGiftPhoto(Long giftNo, String photoUrl){ + Gift gift = giftService.findGiftByGiftNo(giftNo); + List giftPhotoList = gift.getGiftPhotoList(); + + GiftPhoto temp = null; + + for(GiftPhoto giftPhoto : giftPhotoList){ + if(photoUrl.equals(giftPhoto.getPhotoUrl())){ + temp = giftPhoto; + String fileName = extractGiftPhotoFileName(photoUrl); + photoService.deleteFileFromS3(fileName); + break; + } + } + giftPhotoList.remove(temp); + + return giftRepository.save(gift); + } + + //선물 사진 이름 생성 + public String getGiftFileName(String fileName){ + return "gift/" + UUID.randomUUID()+ fileName.substring(fileName.lastIndexOf('.')); + } + + //선물 사진 이름 추출 + public static String extractGiftPhotoFileName(String photoUrl) { + String fileName; + try { + fileName = photoUrl.substring(photoUrl.indexOf("gift/")); + } catch (Exception e) { + throw new CustomException(e, FILE_NOT_FOUND); + } + + return fileName; + } +} diff --git a/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java b/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java index 156d5f2..ba3d987 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java @@ -10,6 +10,7 @@ import javax.transaction.Transactional; import java.time.LocalDate; +import java.util.ArrayList; import java.util.List; @Getter @@ -53,6 +54,7 @@ public Gift toEntity(User user, LocalDate giftDate){ .isGiven(isGiven) .user(user) .friendNoList(friendNoList) + .giftPhotoList(new ArrayList<>()) .build(); } } \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java index cbcdab3..6e88689 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java @@ -3,6 +3,7 @@ import com.favor.favor.common.enums.Category; import com.favor.favor.common.enums.Emotion; import com.favor.favor.friend.FriendResponseDto; +import com.favor.favor.photo.GiftPhoto; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -33,6 +34,7 @@ public class GiftResponseDto { private List friendList; private LocalDateTime createdAt; private LocalDateTime modifiedAt; + private List giftPhotoList; @Builder @@ -50,6 +52,7 @@ public GiftResponseDto(Gift gift){ this.friendList = new ArrayList<>(); this.createdAt = gift.getCreatedAt(); this.modifiedAt = gift.getModifiedAt(); + this.giftPhotoList = gift.getGiftPhotoList(); log.info("[GiftResponseDto] 실행 완료"); } @Builder @@ -67,6 +70,7 @@ public GiftResponseDto(Gift gift, List friendList){ this.friendList = friendList; this.createdAt = gift.getCreatedAt(); this.modifiedAt = gift.getModifiedAt(); + this.giftPhotoList = gift.getGiftPhotoList(); log.info("[GiftResponseDto] 실행 완료"); } } diff --git a/favor/src/main/java/com/favor/favor/gift/GiftService.java b/favor/src/main/java/com/favor/favor/gift/GiftService.java index e56b5fb..9202ff8 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftService.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftService.java @@ -136,28 +136,46 @@ public Gift findGiftByGiftNo(Long giftNo){ } + @Transactional public GiftResponseDto returnDto(Gift gift){ List friendResponseDtoList = new ArrayList<>(); List friendNoList = gift.getFriendNoList(); List deletedNoList = new ArrayList<>(); - for(Long f : friendNoList){ - Friend friend = null; - try{ - friend = findFriendByFriendNo(f); - }catch(Exception e){ - deletedNoList.add(f); + + for(Long f : new ArrayList<>(friendNoList)){ + if(findFriendByFriendNo(f) == null){ + friendNoList.remove(f); continue; + }else{ + Friend friend = findFriendByFriendNo(f); + friendResponseDtoList.add(new FriendResponseDto(friend)); } - FriendResponseDto dto = new FriendResponseDto(friend); - friendResponseDtoList.add(dto); - } - for(Long f : deletedNoList){ - friendNoList.remove(f); - } + +// Friend friend = null; +// try{ +// friend = findFriendByFriendNo(f); +// }catch(Exception e){ +// throw new CustomException(e, FRIEND_NOT_FOUND); +// deletedNoList.add(f); +// continue; +// } +// FriendResponseDto dto = new FriendResponseDto(friend); +// friendResponseDtoList.add(dto); + } + log.info("[SYSTEM] for(Long f : friendNoList) 완료"); +// +// for(Long f : new ArrayList<>(friendNoList)){ +// friendNoList.remove(f); +// } +// log.info("[SYSTEM] for(Long f : deletedNoList) 완료"); + gift.setFriendNoList(friendNoList); + log.info("[SYSTEM] gift.setFriendNoList(friendNoList) 완료"); + giftRepository.save(gift); + log.info("[SYSTEM] giftRepository.save(gift) 완료"); return new GiftResponseDto(gift, friendResponseDtoList); } diff --git a/favor/src/main/java/com/favor/favor/photo/GiftPhoto.java b/favor/src/main/java/com/favor/favor/photo/GiftPhoto.java new file mode 100644 index 0000000..b567e4e --- /dev/null +++ b/favor/src/main/java/com/favor/favor/photo/GiftPhoto.java @@ -0,0 +1,30 @@ +package com.favor.favor.photo; + +import com.favor.favor.common.TimeStamped; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Getter +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +public class GiftPhoto extends TimeStamped { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String photoUrl; + + @Builder + public GiftPhoto(String photoUrl) { + this.photoUrl = photoUrl; + } + + +} \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoController.java b/favor/src/main/java/com/favor/favor/photo/PhotoController.java index f7a9009..03bab9c 100644 --- a/favor/src/main/java/com/favor/favor/photo/PhotoController.java +++ b/favor/src/main/java/com/favor/favor/photo/PhotoController.java @@ -36,7 +36,7 @@ public class PhotoController { public ResponseEntity> savePhoto( @ModelAttribute MultipartFile photo){ - Photo result = photoService.savePhoto(photo); + UserPhoto result = photoService.savePhoto(photo); return ResponseEntity.status(201) .body(DefaultResponseDto.builder() diff --git a/favor/src/main/java/com/favor/favor/photo/PhotoService.java b/favor/src/main/java/com/favor/favor/photo/PhotoService.java index 00565be..dec534e 100644 --- a/favor/src/main/java/com/favor/favor/photo/PhotoService.java +++ b/favor/src/main/java/com/favor/favor/photo/PhotoService.java @@ -5,7 +5,6 @@ import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.PutObjectRequest; import com.favor.favor.exception.CustomException; -import com.favor.favor.user.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -14,7 +13,6 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.net.URL; import java.util.Objects; import java.util.UUID; @@ -88,22 +86,22 @@ public String getStoredFileName(String fileName){ //사진 저장 @Transactional - public Photo savePhoto(MultipartFile file) { + public UserPhoto savePhoto(MultipartFile file) { String filename = file.getOriginalFilename(); - Photo photo = new Photo(filename); + UserPhoto userPhoto = new UserPhoto(filename); String storedFileName = getStoredFileName(filename); String brandPhotoUrl = uploadFileToS3(storedFileName, file); try { - photo = Photo.builder() + userPhoto = UserPhoto.builder() .photoUrl(brandPhotoUrl) .build(); } catch (RuntimeException e) { throw new CustomException(e, SERVER_ERROR); } - return photo; + return userPhoto; } } diff --git a/favor/src/main/java/com/favor/favor/photo/Photo.java b/favor/src/main/java/com/favor/favor/photo/UserPhoto.java similarity index 86% rename from favor/src/main/java/com/favor/favor/photo/Photo.java rename to favor/src/main/java/com/favor/favor/photo/UserPhoto.java index 2c5d390..08d0966 100644 --- a/favor/src/main/java/com/favor/favor/photo/Photo.java +++ b/favor/src/main/java/com/favor/favor/photo/UserPhoto.java @@ -14,7 +14,7 @@ @Getter @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Photo extends TimeStamped { +public class UserPhoto extends TimeStamped { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -22,7 +22,7 @@ public class Photo extends TimeStamped { private String photoUrl; @Builder - public Photo(String photoUrl) { + public UserPhoto(String photoUrl) { this.photoUrl = photoUrl; } diff --git a/favor/src/main/java/com/favor/favor/user/User.java b/favor/src/main/java/com/favor/favor/user/User.java index 79ae47c..18b57e7 100644 --- a/favor/src/main/java/com/favor/favor/user/User.java +++ b/favor/src/main/java/com/favor/favor/user/User.java @@ -7,7 +7,7 @@ import com.favor.favor.common.TimeStamped; import com.favor.favor.friend.Friend; import com.favor.favor.gift.Gift; -import com.favor.favor.photo.Photo; +import com.favor.favor.photo.UserPhoto; import com.favor.favor.reminder.Reminder; import lombok.*; import org.springframework.security.core.GrantedAuthority; @@ -79,14 +79,14 @@ public void setFavorList(List favorList) { private List friendList = new ArrayList<>(); @OneToOne(cascade = CascadeType.ALL) - private Photo userProfilePhoto; - public void setUserProfilePhoto(Photo userPhoto) { + private UserPhoto userProfilePhoto; + public void setUserProfilePhoto(UserPhoto userPhoto) { this.userProfilePhoto = userPhoto; } @OneToOne(cascade = CascadeType.ALL) - private Photo userBackgroundPhoto; - public void setUserBackgroundPhoto(Photo userPhoto) { + private UserPhoto userBackgroundPhoto; + public void setUserBackgroundPhoto(UserPhoto userPhoto) { this.userBackgroundPhoto = userPhoto; } diff --git a/favor/src/main/java/com/favor/favor/user/UserPhotoController.java b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java index 01303ca..0a120ee 100644 --- a/favor/src/main/java/com/favor/favor/user/UserPhotoController.java +++ b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java @@ -1,7 +1,7 @@ package com.favor.favor.user; import com.favor.favor.common.DefaultResponseDto; -import com.favor.favor.photo.Photo; +import com.favor.favor.photo.UserPhoto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -75,7 +75,7 @@ public ResponseEntity> updateUserProfilePhoto( public ResponseEntity> getUserProfilePhoto( @AuthenticationPrincipal User loginUser ) { - Photo dto = userPhotoService.getUserProfilePhoto(loginUser.getUserNo()); + UserPhoto dto = userPhotoService.getUserProfilePhoto(loginUser.getUserNo()); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -168,7 +168,7 @@ public ResponseEntity> updateUserBackgroundPhoto( public ResponseEntity> getUserBackgroundPhoto( @AuthenticationPrincipal User loginUser ) { - Photo dto = userPhotoService.getUserBackgroundPhoto(loginUser.getUserNo()); + UserPhoto dto = userPhotoService.getUserBackgroundPhoto(loginUser.getUserNo()); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() diff --git a/favor/src/main/java/com/favor/favor/user/UserPhotoService.java b/favor/src/main/java/com/favor/favor/user/UserPhotoService.java index ccba27c..df24384 100644 --- a/favor/src/main/java/com/favor/favor/user/UserPhotoService.java +++ b/favor/src/main/java/com/favor/favor/user/UserPhotoService.java @@ -1,7 +1,7 @@ package com.favor.favor.user; import com.favor.favor.exception.CustomException; -import com.favor.favor.photo.Photo; +import com.favor.favor.photo.UserPhoto; import com.favor.favor.photo.PhotoService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -11,14 +11,15 @@ import java.net.URL; import java.util.UUID; +import static com.favor.favor.exception.ExceptionCode.FILE_NOT_FOUND; import static com.favor.favor.exception.ExceptionCode.SERVER_ERROR; @Service @RequiredArgsConstructor public class UserPhotoService { private final UserRepository userRepository; - private final PhotoService photoService; private final UserService userService; + private final PhotoService photoService; //유저 프로필사진 등록/수정 @Transactional @@ -28,25 +29,25 @@ public User updateUserProfilePhoto(Long userNo, MultipartFile file) { deleteUserProfilePhoto(userNo); } - String filename = file.getOriginalFilename(); - Photo photo = null; - String storedFileName = getUserProfileFileName(filename); + String fileName = file.getOriginalFilename(); + UserPhoto userPhoto = null; + String storedFileName = getUserProfileFileName(fileName); - String photoUrl = photoService.uploadFileToS3(storedFileName, file); + String profilePhotoUrl = photoService.uploadFileToS3(storedFileName, file); try { - photo = Photo.builder() - .photoUrl(photoUrl) + userPhoto = UserPhoto.builder() + .photoUrl(profilePhotoUrl) .build(); } catch (RuntimeException e) { throw new CustomException(e, SERVER_ERROR); } - user.setUserProfilePhoto(photo); + user.setUserProfilePhoto(userPhoto); return userRepository.save(user); } //유저 프로필사진 조회 - public Photo getUserProfilePhoto(Long userNo) { + public UserPhoto getUserProfilePhoto(Long userNo) { return userService.findUserByUserNo(userNo).getUserProfilePhoto(); } @@ -73,24 +74,24 @@ public User updateUserBackgroundPhoto(Long userNo, MultipartFile file) { deleteUserBackgroundPhoto(userNo); } String filename = file.getOriginalFilename(); - Photo photo = null; + UserPhoto userPhoto = null; String storedFileName = getUserBackgroundFileName(filename); - String photoUrl = photoService.uploadFileToS3(storedFileName, file); + String backgroundPhotoUrl = photoService.uploadFileToS3(storedFileName, file); try { - photo = Photo.builder() - .photoUrl(photoUrl) + userPhoto = UserPhoto.builder() + .photoUrl(backgroundPhotoUrl) .build(); } catch (RuntimeException e) { throw new CustomException(e, SERVER_ERROR); } - user.setUserBackgroundPhoto(photo); + user.setUserBackgroundPhoto(userPhoto); return userRepository.save(user); } //유저 배경사진 조회 - public Photo getUserBackgroundPhoto(Long userNo) { + public UserPhoto getUserBackgroundPhoto(Long userNo) { return userService.findUserByUserNo(userNo).getUserBackgroundPhoto(); } diff --git a/favor/src/main/java/com/favor/favor/user/UserResponseDto.java b/favor/src/main/java/com/favor/favor/user/UserResponseDto.java index a3e5d99..d1abf4a 100644 --- a/favor/src/main/java/com/favor/favor/user/UserResponseDto.java +++ b/favor/src/main/java/com/favor/favor/user/UserResponseDto.java @@ -4,7 +4,7 @@ import com.favor.favor.common.enums.Favor; import com.favor.favor.common.enums.Role; import com.favor.favor.friend.FriendResponseDto; -import com.favor.favor.photo.Photo; +import com.favor.favor.photo.UserPhoto; import com.favor.favor.reminder.ReminderResponseDto; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -55,10 +55,10 @@ public class UserResponseDto { private List favorList; @ApiModelProperty(value = "") - private Photo userProfilePhoto; + private UserPhoto userProfileUserPhoto; @ApiModelProperty(value = "") - private Photo userBackgroundPhoto; + private UserPhoto userBackgroundUserPhoto; @Builder public UserResponseDto(User user, @@ -79,7 +79,7 @@ public UserResponseDto(User user, this.friendList = friendList; this.favorList = favorList; this.anniversaryList = anniversaryList; - this.userProfilePhoto = user.getUserProfilePhoto(); - this.userBackgroundPhoto = user.getUserBackgroundPhoto(); + this.userProfileUserPhoto = user.getUserProfilePhoto(); + this.userBackgroundUserPhoto = user.getUserBackgroundPhoto(); } } From d1d9fbbf95a24d8d2dedbcbbdcae9f3a21a74e46 Mon Sep 17 00:00:00 2001 From: eunki96 Date: Fri, 11 Aug 2023 19:04:39 +0900 Subject: [PATCH 10/15] =?UTF-8?q?[Fix]=20AnniversaryCategory=20=EB=94=94?= =?UTF-8?q?=EC=9E=90=EC=9D=B8=20=EB=A7=A4=EC=B9=AD,=20=EC=B9=9C=EA=B5=AC?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20userId=20=EB=88=84=EB=9D=BD=20#68?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favor/favor/anniversary/Anniversary.java | 8 +-- .../anniversary/AnniversaryRequestDto.java | 6 +- .../anniversary/AnniversaryResponseDto.java | 4 +- .../favor/anniversary/AnniversaryService.java | 2 +- .../AnniversaryUpdateRequestDto.java | 6 +- .../common/enums/CategoryAnniversary.java | 57 +++++++++++++++++++ .../{Category.java => CategoryGift.java} | 28 ++++----- .../main/java/com/favor/favor/gift/Gift.java | 15 +++-- .../com/favor/favor/gift/GiftController.java | 38 ++++++++++++- .../com/favor/favor/gift/GiftRequestDto.java | 6 +- .../com/favor/favor/gift/GiftResponseDto.java | 13 +++-- .../com/favor/favor/gift/GiftService.java | 9 ++- .../favor/gift/GiftUpdateRequestDto.java | 4 +- .../com/favor/favor/user/UserController.java | 6 +- .../com/favor/favor/user/UserService.java | 8 +-- 15 files changed, 152 insertions(+), 58 deletions(-) create mode 100644 favor/src/main/java/com/favor/favor/common/enums/CategoryAnniversary.java rename favor/src/main/java/com/favor/favor/common/enums/{Category.java => CategoryGift.java} (56%) diff --git a/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java b/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java index c7dd54c..1791ee2 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java +++ b/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java @@ -1,15 +1,13 @@ package com.favor.favor.anniversary; import com.favor.favor.common.TimeStamped; -import com.favor.favor.common.enums.Category; +import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.user.User; import lombok.*; import javax.persistence.*; import javax.transaction.Transactional; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.List; @Entity @Getter @@ -30,8 +28,8 @@ public class Anniversary extends TimeStamped { public void setAnniversaryDate(LocalDate anniversaryDate){ this.anniversaryDate = anniversaryDate; } private Integer category; - public void setCategory(Category category){ - this.category = category.getType(); + public void setCategory(CategoryGift categoryGift){ + this.category = categoryGift.getType(); } private Boolean isPinned; diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java index 0d00412..09a65be 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java @@ -1,6 +1,6 @@ package com.favor.favor.anniversary; -import com.favor.favor.common.enums.Category; +import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.user.User; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -21,14 +21,14 @@ public class AnniversaryRequestDto { private String anniversaryDate; @ApiModelProperty(position = 3, required = true, value = "종류", example = "생일") - private Category category; + private CategoryGift categoryGift; @Transactional public Anniversary toEntity(User user, LocalDate localDate){ return Anniversary.builder() .anniversaryTitle(anniversaryTitle) .anniversaryDate(localDate) - .category(category.getType()) + .category(categoryGift.getType()) .isPinned(false) .user(user) .build(); diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java index 89803b2..46efb9d 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java @@ -1,12 +1,12 @@ package com.favor.favor.anniversary; +import com.favor.favor.common.enums.CategoryAnniversary; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.List; @Getter @AllArgsConstructor @@ -18,6 +18,7 @@ public class AnniversaryResponseDto { private Long userNo; private LocalDateTime createdAt; private LocalDateTime modifiedAt; + private CategoryAnniversary categoryAnniversary; @Builder public AnniversaryResponseDto(Anniversary anniversary){ @@ -28,5 +29,6 @@ public AnniversaryResponseDto(Anniversary anniversary){ this.userNo = anniversary.getUser().getUserNo(); this.createdAt = anniversary.getCreatedAt(); this.modifiedAt = anniversary.getModifiedAt(); + this.categoryAnniversary = CategoryAnniversary.valueOf(anniversary.getCategory()); } } diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java index 88712bb..dd19309 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java @@ -66,7 +66,7 @@ public void updateAnniversary(AnniversaryUpdateRequestDto dto, Anniversary anniv anniversary.setAnniversaryTitle(dto.getAnniversaryTitle()); LocalDate localDate = returnLocalDate(dto.getAnniversaryDate()); anniversary.setAnniversaryDate(localDate); - anniversary.setCategory(dto.getCategory()); + anniversary.setCategory(dto.getCategoryGift()); anniversaryRepository.save(anniversary); } diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java index f4a695f..ec1c57a 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java @@ -1,13 +1,11 @@ package com.favor.favor.anniversary; -import com.favor.favor.common.enums.Category; +import com.favor.favor.common.enums.CategoryGift; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; -import java.util.List; - @Getter @NoArgsConstructor @@ -21,7 +19,7 @@ public class AnniversaryUpdateRequestDto { private String anniversaryDate; @ApiModelProperty(position = 3, required = true, value = "종류", example = "생일") - private Category category; + private CategoryGift categoryGift; @ApiModelProperty(position = 4, required = true, value = "핀 여부", example = "false") private Boolean isPinned; diff --git a/favor/src/main/java/com/favor/favor/common/enums/CategoryAnniversary.java b/favor/src/main/java/com/favor/favor/common/enums/CategoryAnniversary.java new file mode 100644 index 0000000..63346a3 --- /dev/null +++ b/favor/src/main/java/com/favor/favor/common/enums/CategoryAnniversary.java @@ -0,0 +1,57 @@ +package com.favor.favor.common.enums; + +import lombok.Getter; + +public enum CategoryAnniversary { + 연인(1), + 축하_생일(2), + 졸업(3), + 합격(4), + 입사_승진(5), + 이사_집들이(6), + 출산(7); + + @Getter + Integer type; + + CategoryAnniversary(Integer type){ + this.type = type; + } + + public static CategoryAnniversary validateType(String category){ + try{ + return CategoryAnniversary.valueOf(category); + }catch(IllegalStateException e){ + throw new IllegalArgumentException(); + } + + } + + public static CategoryAnniversary valueOf(Integer type){ + CategoryAnniversary categoryAnniversary = null; + switch (type){ + case 1: + categoryAnniversary = CategoryAnniversary.연인; + break; + case 2: + categoryAnniversary = CategoryAnniversary.축하_생일; + break; + case 3: + categoryAnniversary = CategoryAnniversary.졸업; + break; + case 4: + categoryAnniversary = CategoryAnniversary.합격; + break; + case 5: + categoryAnniversary = CategoryAnniversary.입사_승진; + break; + case 6: + categoryAnniversary = CategoryAnniversary.이사_집들이; + break; + case 7: + categoryAnniversary = CategoryAnniversary.출산; + break; + } + return categoryAnniversary; + } +} diff --git a/favor/src/main/java/com/favor/favor/common/enums/Category.java b/favor/src/main/java/com/favor/favor/common/enums/CategoryGift.java similarity index 56% rename from favor/src/main/java/com/favor/favor/common/enums/Category.java rename to favor/src/main/java/com/favor/favor/common/enums/CategoryGift.java index 2986ec5..762875e 100644 --- a/favor/src/main/java/com/favor/favor/common/enums/Category.java +++ b/favor/src/main/java/com/favor/favor/common/enums/CategoryGift.java @@ -2,7 +2,7 @@ import lombok.Getter; -public enum Category { +public enum CategoryGift { // 가벼운선물, 생일, 집들이, 시험, 승진, 졸업, 기타 가벼운선물(1), 생일(2), @@ -14,46 +14,46 @@ public enum Category { @Getter Integer type; - Category (Integer type){ + CategoryGift(Integer type){ this.type = type; } - public static Category validateType(String category){ + public static CategoryGift validateType(String category){ try{ - return Category.valueOf(category); + return CategoryGift.valueOf(category); }catch(IllegalStateException e){ //커스텀 전 임시 throw new IllegalArgumentException(); } } - public static Category valueOf(Integer type){ - Category category = null; + public static CategoryGift valueOf(Integer type){ + CategoryGift categoryGift = null; switch (type){ case 1: - category = Category.가벼운선물; + categoryGift = CategoryGift.가벼운선물; break; case 2: - category = Category.생일; + categoryGift = CategoryGift.생일; break; case 3: - category = Category.집들이; + categoryGift = CategoryGift.집들이; break; case 4: - category = Category.시험; + categoryGift = CategoryGift.시험; break; case 5: - category = Category.승진; + categoryGift = CategoryGift.승진; break; case 6: - category = Category.졸업; + categoryGift = CategoryGift.졸업; break; case 7: - category = Category.기타; + categoryGift = CategoryGift.기타; break; default: break; } - return category; + return categoryGift; } } diff --git a/favor/src/main/java/com/favor/favor/gift/Gift.java b/favor/src/main/java/com/favor/favor/gift/Gift.java index 3a696da..e1ce006 100644 --- a/favor/src/main/java/com/favor/favor/gift/Gift.java +++ b/favor/src/main/java/com/favor/favor/gift/Gift.java @@ -1,6 +1,6 @@ package com.favor.favor.gift; -import com.favor.favor.common.enums.Category; +import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.common.enums.Emotion; import com.favor.favor.common.TimeStamped; import com.favor.favor.photo.GiftPhoto; @@ -11,7 +11,6 @@ import javax.transaction.Transactional; import java.time.LocalDate; import java.util.ArrayList; -import java.util.LinkedList; import java.util.List; @Entity @@ -43,8 +42,8 @@ public void setGiftMemo(String giftMemo){ } private Integer category; - public void setCategory(Category category){ - this.category = category.getType(); + public void setCategory(CategoryGift categoryGift){ + this.category = categoryGift.getType(); } private Integer emotion; @@ -78,7 +77,13 @@ public void setFriendNoList(List friendNoList){ @OneToMany(cascade = CascadeType.ALL) private List giftPhotoList = new ArrayList<>(); - public void setGiftPhotoList(List giftPhotoList){ + public void setGiftPhotoList(List giftPhotoList) { this.giftPhotoList = giftPhotoList; } + + @ElementCollection + private List tempFriendList; + public void setTempFriendList(List tempFriendList){ + this.tempFriendList = tempFriendList; + } } \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/gift/GiftController.java b/favor/src/main/java/com/favor/favor/gift/GiftController.java index 1f6b633..bcaf0d5 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftController.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftController.java @@ -1,15 +1,12 @@ package com.favor.favor.gift; import com.favor.favor.common.DefaultResponseDto; -import com.favor.favor.friend.FriendResponseDto; import com.favor.favor.user.User; -import com.favor.favor.user.UserResponseDto; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import lombok.RequiredArgsConstructor; -import lombok.extern.log4j.Log4j2; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -129,6 +126,41 @@ public ResponseEntity> updateGift( .build()); } + @ApiOperation("선물 임시친구목록 수정") + @ApiResponses(value={ + @ApiResponse(code = 200, + message = "GIFT_TEMP_FRIEND_LIST_UPDATED", + response = GiftResponseDto.class), + @ApiResponse(code = 401, + message = "UNAUTHORIZED_USER"), + @ApiResponse(code = 404, + message = "GIFT_NOT_FOUND / FRIEND_NOT_FOUND"), + @ApiResponse(code = 500, + message = "SERVER_ERROR") + }) + @ResponseStatus(HttpStatus.OK) + @Transactional + @PatchMapping("/temp-friend-list/{giftNo}") + public ResponseEntity> updateTempFriendListGift( + @PathVariable Long giftNo, + List tempFriendList + ){ + + giftService.isExistingGiftNo(giftNo); + + + Gift gift = giftService.findGiftByGiftNo(giftNo); + giftService.updateTempFriendList(gift, tempFriendList); + GiftResponseDto dto = giftService.returnDto(gift); + + return ResponseEntity.status(200) + .body(DefaultResponseDto.builder() + .responseCode("GIFT_TEMP_FRIEND_LIST_UPDATED") + .responseMessage("선물 임시친구목록 수정 완료") + .data(dto) + .build()); + } + @ApiOperation("선물 핀 여부 수정") @ApiResponses(value={ @ApiResponse(code = 200, diff --git a/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java b/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java index ba3d987..4992230 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java @@ -1,6 +1,6 @@ package com.favor.favor.gift; -import com.favor.favor.common.enums.Category; +import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.common.enums.Emotion; import com.favor.favor.user.User; import io.swagger.annotations.ApiModelProperty; @@ -27,7 +27,7 @@ public class GiftRequestDto { private String giftMemo; @ApiModelProperty(position = 4, required = false, value = "카테고리", example = "생일") - private Category category; + private CategoryGift categoryGift; @ApiModelProperty(position = 5, required = false, value = "감정", example = "기뻐요") private Emotion emotion; @@ -48,7 +48,7 @@ public Gift toEntity(User user, LocalDate giftDate){ .giftName(giftName) .giftDate(giftDate) .giftMemo(giftMemo) - .category(category.getType()) + .category(categoryGift.getType()) .emotion(emotion.getType()) .isPinned(false) .isGiven(isGiven) diff --git a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java index 6e88689..3cb78ee 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java @@ -1,6 +1,6 @@ package com.favor.favor.gift; -import com.favor.favor.common.enums.Category; +import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.common.enums.Emotion; import com.favor.favor.friend.FriendResponseDto; import com.favor.favor.photo.GiftPhoto; @@ -9,11 +9,9 @@ import lombok.Getter; import lombok.extern.log4j.Log4j2; -import javax.annotation.Nullable; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; -import java.util.Date; import java.util.List; @Log4j2 @@ -26,7 +24,7 @@ public class GiftResponseDto { private String giftName; private LocalDate giftDate; private String giftMemo; - private Category category; + private CategoryGift categoryGift; private Emotion emotion; private Boolean isPinned; private Boolean isGiven; @@ -35,6 +33,7 @@ public class GiftResponseDto { private LocalDateTime createdAt; private LocalDateTime modifiedAt; private List giftPhotoList; + private List tempFriendList; @Builder @@ -44,7 +43,7 @@ public GiftResponseDto(Gift gift){ this.giftName = gift.getGiftName(); this.giftDate = gift.getGiftDate(); this.giftMemo = gift.getGiftMemo(); - this.category = Category.valueOf(gift.getCategory()); + this.categoryGift = CategoryGift.valueOf(gift.getCategory()); this.emotion = Emotion.valueOf(gift.getEmotion()); this.isPinned = gift.getIsPinned(); this.isGiven = gift.getIsGiven(); @@ -53,6 +52,7 @@ public GiftResponseDto(Gift gift){ this.createdAt = gift.getCreatedAt(); this.modifiedAt = gift.getModifiedAt(); this.giftPhotoList = gift.getGiftPhotoList(); + this.tempFriendList = gift.getTempFriendList(); log.info("[GiftResponseDto] 실행 완료"); } @Builder @@ -62,7 +62,7 @@ public GiftResponseDto(Gift gift, List friendList){ this.giftName = gift.getGiftName(); this.giftDate = gift.getGiftDate(); this.giftMemo = gift.getGiftMemo(); - this.category = Category.valueOf(gift.getCategory()); + this.categoryGift = CategoryGift.valueOf(gift.getCategory()); this.emotion = Emotion.valueOf(gift.getEmotion()); this.isPinned = gift.getIsPinned(); this.isGiven = gift.getIsGiven(); @@ -71,6 +71,7 @@ public GiftResponseDto(Gift gift, List friendList){ this.createdAt = gift.getCreatedAt(); this.modifiedAt = gift.getModifiedAt(); this.giftPhotoList = gift.getGiftPhotoList(); + this.tempFriendList = gift.getTempFriendList(); log.info("[GiftResponseDto] 실행 완료"); } } diff --git a/favor/src/main/java/com/favor/favor/gift/GiftService.java b/favor/src/main/java/com/favor/favor/gift/GiftService.java index 9202ff8..bb21f0c 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftService.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftService.java @@ -10,7 +10,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import javax.swing.text.html.Option; import javax.transaction.Transactional; import java.time.LocalDate; import java.time.LocalDateTime; @@ -18,7 +17,6 @@ import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.List; -import java.util.Optional; import static com.favor.favor.exception.ExceptionCode.*; @@ -54,7 +52,7 @@ public void addGiftNo(Long giftNo, List friendNoList){ public void updateGift(GiftUpdateRequestDto dto, Gift gift){ gift.setGiftName(dto.getGiftName()); gift.setGiftMemo(dto.getGiftMemo()); - gift.setCategory(dto.getCategory()); + gift.setCategory(dto.getCategoryGift()); gift.setEmotion(dto.getEmotion()); gift.setIsGiven(dto.getIsGiven()); gift.setGiftDate(returnLocalDate(dto.getGiftDate())); @@ -80,6 +78,11 @@ public void updateIsPinned(Gift gift){ giftRepository.save(gift); } + public void updateTempFriendList(Gift gift, List tempFriendList){ + gift.setTempFriendList(tempFriendList); + giftRepository.save(gift); + } + public void deleteGift(Long giftNo){ giftRepository.deleteById(giftNo); } diff --git a/favor/src/main/java/com/favor/favor/gift/GiftUpdateRequestDto.java b/favor/src/main/java/com/favor/favor/gift/GiftUpdateRequestDto.java index c360e40..0409fac 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftUpdateRequestDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftUpdateRequestDto.java @@ -1,6 +1,6 @@ package com.favor.favor.gift; -import com.favor.favor.common.enums.Category; +import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.common.enums.Emotion; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -23,7 +23,7 @@ public class GiftUpdateRequestDto { private String giftMemo; @ApiModelProperty(position = 4, required = false, value = "카데고리", example = "생일") - private Category category; + private CategoryGift categoryGift; @ApiModelProperty(position = 5, required = false, value = "감정", example = "기뻐요") private Emotion emotion; diff --git a/favor/src/main/java/com/favor/favor/user/UserController.java b/favor/src/main/java/com/favor/favor/user/UserController.java index 8ee892c..719a504 100644 --- a/favor/src/main/java/com/favor/favor/user/UserController.java +++ b/favor/src/main/java/com/favor/favor/user/UserController.java @@ -3,7 +3,7 @@ import com.favor.favor.anniversary.AnniversaryResponseDto; import com.favor.favor.common.DefaultResponseDto; -import com.favor.favor.common.enums.Category; +import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.common.enums.Emotion; import com.favor.favor.friend.FriendResponseDto; import com.favor.favor.gift.GiftResponseDto; @@ -518,12 +518,12 @@ public ResponseEntity> readGiftListByName ( @GetMapping("/gifts-by-category/{category}") public ResponseEntity> readGiftListByCategory( @AuthenticationPrincipal User loginUser, - @PathVariable("category") Category category){ + @PathVariable("category") CategoryGift categoryGift){ Long userNo = loginUser.getUserNo(); userService.isExistingUserNo(userNo); - List dto = userService.readGiftListByCategory(userNo, category); + List dto = userService.readGiftListByCategory(userNo, categoryGift); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() diff --git a/favor/src/main/java/com/favor/favor/user/UserService.java b/favor/src/main/java/com/favor/favor/user/UserService.java index bc4039e..bd3499a 100644 --- a/favor/src/main/java/com/favor/favor/user/UserService.java +++ b/favor/src/main/java/com/favor/favor/user/UserService.java @@ -3,7 +3,7 @@ import com.favor.favor.anniversary.Anniversary; import com.favor.favor.anniversary.AnniversaryResponseDto; import com.favor.favor.auth.JwtTokenProvider; -import com.favor.favor.common.enums.Category; +import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.common.enums.Emotion; import com.favor.favor.common.enums.Favor; import com.favor.favor.common.enums.Role; @@ -18,7 +18,6 @@ import com.favor.favor.reminder.ReminderResponseDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.hibernate.Hibernate; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; @@ -27,7 +26,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.Random; import static com.favor.favor.exception.ExceptionCode.*; @@ -220,9 +218,9 @@ public List readGiftListByName(Long userNo, String giftName){ return g_List; } - public List readGiftListByCategory(Long userNo, Category category){ + public List readGiftListByCategory(Long userNo, CategoryGift categoryGift){ User user = findUserByUserNo(userNo); - Integer categoryNo = category.getType(); + Integer categoryNo = categoryGift.getType(); List giftList = giftRepository.findGiftsByUserAndCategory(user, categoryNo); List g_List = new ArrayList<>(); for(Gift gift : giftList){ From 833922735a1fc365b46b80b3b5da4d3e8ea0333d Mon Sep 17 00:00:00 2001 From: eunki96 Date: Fri, 11 Aug 2023 19:54:22 +0900 Subject: [PATCH 11/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favor/favor/friend/FriendResponseDto.java | 5 +++++ .../com/favor/favor/friend/FriendService.java | 2 +- .../src/main/java/com/favor/favor/gift/Gift.java | 6 ++---- .../com/favor/favor/gift/GiftController.java | 4 ++-- .../favor/favor/gift/GiftPhotoController.java | 11 +++-------- .../com/favor/favor/gift/GiftPhotoService.java | 3 --- .../com/favor/favor/gift/GiftRequestDto.java | 11 ++++++++++- .../java/com/favor/favor/gift/GiftService.java | 2 +- .../favor/favor/gift/GiftTempFriendListDto.java | 16 ++++++++++++++++ .../favor/favor/photo/GiftPhotoResponseDto.java | 11 +++++++++++ .../favor/favor/reminder/ReminderController.java | 2 +- .../favor/favor/reminder/ReminderService.java | 4 ++-- .../favor/favor/user/UserPhotoController.java | 4 ++-- 13 files changed, 56 insertions(+), 25 deletions(-) create mode 100644 favor/src/main/java/com/favor/favor/gift/GiftTempFriendListDto.java create mode 100644 favor/src/main/java/com/favor/favor/photo/GiftPhotoResponseDto.java diff --git a/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java b/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java index 58346c0..46a102c 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java @@ -27,6 +27,7 @@ public class FriendResponseDto { private int totalGift; private Long userNo; + private String userId; @Builder public FriendResponseDto(Friend friend){ @@ -40,6 +41,7 @@ public FriendResponseDto(Friend friend){ this.receivedGift = 0; this.totalGift = 0; this.userNo = friend.getFriendUserNo(); + this.userId = ""; } @Builder @@ -54,10 +56,12 @@ public FriendResponseDto(Friend friend, User user){ this.receivedGift = 0; this.totalGift = 0; this.userNo = user.getUserNo(); + this.userId = user.getUserId(); } @Builder public FriendResponseDto(Friend friend, + User user, List reminderList, List favorList, List anniversaryList, @@ -73,5 +77,6 @@ public FriendResponseDto(Friend friend, this.receivedGift = giftInfo.get("received"); this.totalGift = giftInfo.get("total"); this.userNo = friend.getFriendUserNo(); + this.userId = user.getUserId(); } } diff --git a/favor/src/main/java/com/favor/favor/friend/FriendService.java b/favor/src/main/java/com/favor/favor/friend/FriendService.java index 7bd8014..f6ea029 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendService.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendService.java @@ -182,7 +182,7 @@ public FriendResponseDto returnDto(Friend friend){ } HashMap giftInfo = returnGiftInfo(friend.getFriendNo()); - return new FriendResponseDto(friend, reminderDtoList, favorList, anniversaryList, giftInfo); + return new FriendResponseDto(friend, user, reminderDtoList, favorList, anniversaryList, giftInfo); } public HashMap returnGiftInfo(Long friendNo) { diff --git a/favor/src/main/java/com/favor/favor/gift/Gift.java b/favor/src/main/java/com/favor/favor/gift/Gift.java index e1ce006..986e480 100644 --- a/favor/src/main/java/com/favor/favor/gift/Gift.java +++ b/favor/src/main/java/com/favor/favor/gift/Gift.java @@ -24,8 +24,6 @@ public class Gift extends TimeStamped { @GeneratedValue(strategy = GenerationType.IDENTITY) private Long giftNo; -// @OneToMany(mappedBy = "gift", cascade = CascadeType.ALL , orphanRemoval = true) -// private List giftPhotos = new ArrayList<>(); private String giftName; public void setGiftName(String giftName){ this.giftName = giftName; @@ -83,7 +81,7 @@ public void setGiftPhotoList(List giftPhotoList) { @ElementCollection private List tempFriendList; - public void setTempFriendList(List tempFriendList){ - this.tempFriendList = tempFriendList; + public void setTempFriendList(GiftTempFriendListDto tempFriendList){ + this.tempFriendList = tempFriendList.getTempFrindList(); } } \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/gift/GiftController.java b/favor/src/main/java/com/favor/favor/gift/GiftController.java index bcaf0d5..38b8e0a 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftController.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftController.java @@ -143,14 +143,14 @@ public ResponseEntity> updateGift( @PatchMapping("/temp-friend-list/{giftNo}") public ResponseEntity> updateTempFriendListGift( @PathVariable Long giftNo, - List tempFriendList + @RequestBody GiftTempFriendListDto tempFriendListDto ){ giftService.isExistingGiftNo(giftNo); Gift gift = giftService.findGiftByGiftNo(giftNo); - giftService.updateTempFriendList(gift, tempFriendList); + giftService.updateTempFriendList(gift, tempFriendListDto); GiftResponseDto dto = giftService.returnDto(gift); return ResponseEntity.status(200) diff --git a/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java b/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java index f0ca617..2d342b7 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftPhotoController.java @@ -2,11 +2,7 @@ import com.favor.favor.common.DefaultResponseDto; import com.favor.favor.photo.GiftPhoto; -import com.favor.favor.photo.UserPhoto; -import com.favor.favor.user.User; -import com.favor.favor.user.UserPhotoService; import com.favor.favor.user.UserResponseDto; -import com.favor.favor.user.UserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiResponse; @@ -14,7 +10,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -53,7 +48,7 @@ public ResponseEntity> addGiftPhotoList( Gift gift = giftPhotoService.addGiftPhoto(giftNo, file); - GiftResponseDto dto = giftService.returnDto(gift); + List dto = giftPhotoService.getGiftPhotoList(giftNo); return ResponseEntity.status(201) .body(DefaultResponseDto.builder() @@ -109,8 +104,8 @@ public ResponseEntity> getUserProfilePhoto(Long giftN public ResponseEntity> deleteUserProfilePhoto( Long giftNo, String fileUrl) { - Gift gift = giftPhotoService.deleteGiftPhoto(giftNo, fileUrl); - GiftResponseDto dto = new GiftResponseDto(gift); + giftPhotoService.deleteGiftPhoto(giftNo, fileUrl); + List dto = giftPhotoService.getGiftPhotoList(giftNo); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() diff --git a/favor/src/main/java/com/favor/favor/gift/GiftPhotoService.java b/favor/src/main/java/com/favor/favor/gift/GiftPhotoService.java index 866890d..b9ea019 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftPhotoService.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftPhotoService.java @@ -3,14 +3,11 @@ import com.favor.favor.exception.CustomException; import com.favor.favor.photo.GiftPhoto; import com.favor.favor.photo.PhotoService; -import com.favor.favor.user.User; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import javax.transaction.Transactional; -import java.net.URL; -import java.util.LinkedList; import java.util.List; import java.util.UUID; diff --git a/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java b/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java index 4992230..7bef06d 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java @@ -9,6 +9,7 @@ import lombok.NoArgsConstructor; import javax.transaction.Transactional; +import javax.validation.constraints.NotNull; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -18,30 +19,37 @@ @AllArgsConstructor public class GiftRequestDto { @ApiModelProperty(position = 1, required = true, value = "선물이름", example = "선물이름") + @NotNull private String giftName; @ApiModelProperty(position = 2, required = false, value = "선물날짜", example = "1996-02-29") + @NotNull private String giftDate; @ApiModelProperty(position = 3, required = false, value = "선물메모", example = "선물메모") private String giftMemo; @ApiModelProperty(position = 4, required = false, value = "카테고리", example = "생일") + @NotNull private CategoryGift categoryGift; @ApiModelProperty(position = 5, required = false, value = "감정", example = "기뻐요") private Emotion emotion; - @ApiModelProperty(position = 6, required = false, value = "핀 여부", example = "false") + @NotNull private Boolean isPinned; @ApiModelProperty(position = 7, required = false, value = "받은선물 여부", example = "false") + @NotNull private Boolean isGiven; @ApiModelProperty(position = 8, required = false, value = "연관친구 리스트", example = "[1]") private List friendNoList; + @ApiModelProperty(position = 9, required = true, value = "임시친구 리스트", example = "[\"차은우\", \"카리나\"]") + private List tempFriendList; + @Transactional public Gift toEntity(User user, LocalDate giftDate){ return Gift.builder() @@ -55,6 +63,7 @@ public Gift toEntity(User user, LocalDate giftDate){ .user(user) .friendNoList(friendNoList) .giftPhotoList(new ArrayList<>()) + .tempFriendList(tempFriendList) .build(); } } \ No newline at end of file diff --git a/favor/src/main/java/com/favor/favor/gift/GiftService.java b/favor/src/main/java/com/favor/favor/gift/GiftService.java index bb21f0c..34c8aa6 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftService.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftService.java @@ -78,7 +78,7 @@ public void updateIsPinned(Gift gift){ giftRepository.save(gift); } - public void updateTempFriendList(Gift gift, List tempFriendList){ + public void updateTempFriendList(Gift gift, GiftTempFriendListDto tempFriendList){ gift.setTempFriendList(tempFriendList); giftRepository.save(gift); } diff --git a/favor/src/main/java/com/favor/favor/gift/GiftTempFriendListDto.java b/favor/src/main/java/com/favor/favor/gift/GiftTempFriendListDto.java new file mode 100644 index 0000000..b008eab --- /dev/null +++ b/favor/src/main/java/com/favor/favor/gift/GiftTempFriendListDto.java @@ -0,0 +1,16 @@ +package com.favor.favor.gift; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class GiftTempFriendListDto { + @ApiModelProperty(position = 1, required = false, value = "임시 친구 목록", example = "[\"차은우\",\n\"김채원\"]") + private List tempFrindList; +} diff --git a/favor/src/main/java/com/favor/favor/photo/GiftPhotoResponseDto.java b/favor/src/main/java/com/favor/favor/photo/GiftPhotoResponseDto.java new file mode 100644 index 0000000..8ed7b96 --- /dev/null +++ b/favor/src/main/java/com/favor/favor/photo/GiftPhotoResponseDto.java @@ -0,0 +1,11 @@ +package com.favor.favor.photo; + + +import lombok.AllArgsConstructor; + +import java.util.List; + +@AllArgsConstructor +public class GiftPhotoResponseDto { + private List giftPhotoList; +} diff --git a/favor/src/main/java/com/favor/favor/reminder/ReminderController.java b/favor/src/main/java/com/favor/favor/reminder/ReminderController.java index a13207a..a820bfc 100644 --- a/favor/src/main/java/com/favor/favor/reminder/ReminderController.java +++ b/favor/src/main/java/com/favor/favor/reminder/ReminderController.java @@ -148,7 +148,7 @@ public ResponseEntity> updateReminder( reminderService.isExistingFriendNo(friendNo); Reminder reminder = reminderService.findReminderByReminderNo(reminderNo); - reminderService.updateReminder(reminderUpdateRequestDto, reminderNo, friendNo); + reminderService.updateReminder(reminderUpdateRequestDto, reminderNo); ReminderResponseDto dto = reminderService.returnDto(reminder); return ResponseEntity.status(200) diff --git a/favor/src/main/java/com/favor/favor/reminder/ReminderService.java b/favor/src/main/java/com/favor/favor/reminder/ReminderService.java index 72a9d53..821d6bf 100644 --- a/favor/src/main/java/com/favor/favor/reminder/ReminderService.java +++ b/favor/src/main/java/com/favor/favor/reminder/ReminderService.java @@ -51,9 +51,9 @@ public Reminder addReminder(Long userNo, Long anniversaryNo){ return reminderRepository.save(reminder); } - public void updateReminder(ReminderUpdateRequestDto dto, Long reminderNo, Long friendNo){ + public void updateReminder(ReminderUpdateRequestDto dto, Long reminderNo){ Reminder reminder = findReminderByReminderNo(reminderNo); - Friend friend = findFriendByFriendNo(friendNo); + Friend friend = reminder.getFriend(); reminder.setTitle(dto.getTitle()); reminder.setReminderDate(dto.getReminderDate()); diff --git a/favor/src/main/java/com/favor/favor/user/UserPhotoController.java b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java index 0a120ee..381dadf 100644 --- a/favor/src/main/java/com/favor/favor/user/UserPhotoController.java +++ b/favor/src/main/java/com/favor/favor/user/UserPhotoController.java @@ -47,7 +47,7 @@ public ResponseEntity> updateUserProfilePhoto( userService.isExistingUserNo(userNo); User user = userPhotoService.updateUserProfilePhoto(userNo, file); - UserResponseDto dto = userService.returnUserDto(user); + UserPhoto dto = user.getUserProfilePhoto(); return ResponseEntity.status(201) .body(DefaultResponseDto.builder() @@ -140,7 +140,7 @@ public ResponseEntity> updateUserBackgroundPhoto( userService.isExistingUserNo(userNo); User user = userPhotoService.updateUserBackgroundPhoto(userNo, file); - UserResponseDto dto = userService.returnUserDto(user); + UserPhoto dto = user.getUserBackgroundPhoto(); return ResponseEntity.status(201) .body(DefaultResponseDto.builder() From 0a9dbb73fc4827bb7f1db02279539f76e17f0e52 Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Sat, 12 Aug 2023 08:31:58 +0900 Subject: [PATCH 12/15] =?UTF-8?q?[Fix]=20AnniversaryCategory=20=EB=94=94?= =?UTF-8?q?=EC=9E=90=EC=9D=B8=20=EB=A7=A4=EC=B9=AD,=20=EC=B9=9C=EA=B5=AC?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20userId=20=EB=88=84=EB=9D=BD=20#68?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/favor/favor/anniversary/AnniversaryRequestDto.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java index 09a65be..460f0f1 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java @@ -1,5 +1,6 @@ package com.favor.favor.anniversary; +import com.favor.favor.common.enums.CategoryAnniversary; import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.user.User; import io.swagger.annotations.ApiModelProperty; @@ -20,15 +21,15 @@ public class AnniversaryRequestDto { @ApiModelProperty(position = 2, required = true, value = "날짜", example = "1996-02-29") private String anniversaryDate; - @ApiModelProperty(position = 3, required = true, value = "종류", example = "생일") - private CategoryGift categoryGift; + @ApiModelProperty(position = 3, required = true, value = "종류", example = "축하_생일") + private CategoryAnniversary categoryAnniversary; @Transactional public Anniversary toEntity(User user, LocalDate localDate){ return Anniversary.builder() .anniversaryTitle(anniversaryTitle) .anniversaryDate(localDate) - .category(categoryGift.getType()) + .category(categoryAnniversary.getType()) .isPinned(false) .user(user) .build(); From ee524af47bb24ee614be5c2dee3cc0d2f3a12d8e Mon Sep 17 00:00:00 2001 From: Eun Date: Sat, 12 Aug 2023 20:14:07 +0900 Subject: [PATCH 13/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favor/favor/anniversary/Anniversary.java | 5 +- .../favor/anniversary/AnniversaryService.java | 2 +- .../AnniversaryUpdateRequestDto.java | 5 +- .../favor/favor/friend/FriendResponseDto.java | 34 +++++++-- .../com/favor/favor/friend/FriendService.java | 13 ++-- .../main/java/com/favor/favor/gift/Gift.java | 13 ++-- .../com/favor/favor/gift/GiftController.java | 4 +- .../com/favor/favor/gift/GiftResponseDto.java | 2 + .../com/favor/favor/gift/GiftService.java | 76 +++++++++---------- .../com/favor/favor/user/UserService.java | 46 ++++++++++- 10 files changed, 137 insertions(+), 63 deletions(-) diff --git a/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java b/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java index 1791ee2..1527d33 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java +++ b/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java @@ -1,6 +1,7 @@ package com.favor.favor.anniversary; import com.favor.favor.common.TimeStamped; +import com.favor.favor.common.enums.CategoryAnniversary; import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.user.User; import lombok.*; @@ -28,8 +29,8 @@ public class Anniversary extends TimeStamped { public void setAnniversaryDate(LocalDate anniversaryDate){ this.anniversaryDate = anniversaryDate; } private Integer category; - public void setCategory(CategoryGift categoryGift){ - this.category = categoryGift.getType(); + public void setCategory(CategoryAnniversary categoryAnniversary){ + this.category = categoryAnniversary.getType(); } private Boolean isPinned; diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java index dd19309..703b98f 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java @@ -66,7 +66,7 @@ public void updateAnniversary(AnniversaryUpdateRequestDto dto, Anniversary anniv anniversary.setAnniversaryTitle(dto.getAnniversaryTitle()); LocalDate localDate = returnLocalDate(dto.getAnniversaryDate()); anniversary.setAnniversaryDate(localDate); - anniversary.setCategory(dto.getCategoryGift()); + anniversary.setCategory(dto.getCategoryAnniversary()); anniversaryRepository.save(anniversary); } diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java index ec1c57a..83ca475 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java @@ -1,5 +1,6 @@ package com.favor.favor.anniversary; +import com.favor.favor.common.enums.CategoryAnniversary; import com.favor.favor.common.enums.CategoryGift; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -18,8 +19,8 @@ public class AnniversaryUpdateRequestDto { @ApiModelProperty(position = 2, required = true, value = "날짜", example = "1996-02-29") private String anniversaryDate; - @ApiModelProperty(position = 3, required = true, value = "종류", example = "생일") - private CategoryGift categoryGift; + @ApiModelProperty(position = 3, required = true, value = "종류", example = "축하_생일") + private CategoryAnniversary categoryAnniversary; @ApiModelProperty(position = 4, required = true, value = "핀 여부", example = "false") private Boolean isPinned; diff --git a/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java b/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java index 46a102c..207f6a7 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java @@ -27,7 +27,7 @@ public class FriendResponseDto { private int totalGift; private Long userNo; - private String userId; + private String friendId; @Builder public FriendResponseDto(Friend friend){ @@ -41,7 +41,7 @@ public FriendResponseDto(Friend friend){ this.receivedGift = 0; this.totalGift = 0; this.userNo = friend.getFriendUserNo(); - this.userId = ""; + this.friendId = ""; } @Builder @@ -55,8 +55,8 @@ public FriendResponseDto(Friend friend, User user){ this.givenGift = 0; this.receivedGift = 0; this.totalGift = 0; - this.userNo = user.getUserNo(); - this.userId = user.getUserId(); + this.userNo = friend.getFriendUserNo(); + this.friendId = ""; } @Builder @@ -65,7 +65,8 @@ public FriendResponseDto(Friend friend, List reminderList, List favorList, List anniversaryList, - HashMap giftInfo + HashMap giftInfo, + String friendId ){ this.friendNo = friend.getFriendNo(); this.friendName = friend.getFriendName(); @@ -77,6 +78,27 @@ public FriendResponseDto(Friend friend, this.receivedGift = giftInfo.get("received"); this.totalGift = giftInfo.get("total"); this.userNo = friend.getFriendUserNo(); - this.userId = user.getUserId(); + this.friendId = friendId; + } + + @Builder + public FriendResponseDto(Friend friend, + List reminderList, + List favorList, + List anniversaryList, + HashMap giftInfo, + User friendUser + ){ + this.friendNo = friend.getFriendNo(); + this.friendName = friendUser.getUsername(); + this.friendMemo = friend.getFriendMemo(); + this.reminderList = reminderList; + this.favorList = favorList; + this.anniversaryList = anniversaryList; + this.givenGift = giftInfo.get("given"); + this.receivedGift = giftInfo.get("received"); + this.totalGift = giftInfo.get("total"); + this.userNo = friend.getFriendUserNo(); + this.friendId = friendUser.getUserId(); } } diff --git a/favor/src/main/java/com/favor/favor/friend/FriendService.java b/favor/src/main/java/com/favor/favor/friend/FriendService.java index f6ea029..03b08c1 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendService.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendService.java @@ -58,19 +58,19 @@ public void updateMemo(Friend friend, MemoUpdateRequestDto memoUpdateRequestDto) } + //친구 삭제 @Transactional public void deleteFriend(Long friendNo){ Friend friend = findFriendByFriendNo(friendNo); + //친구의 giftNoList List giftNoList = friend.getGiftNoList(); + //선물들의 친구 목록에서 친구 삭제 for(Long g : giftNoList){ Gift gift = findGiftByGiftNo(g); - List friendNoList = gift.getFriendNoList(); - friendNoList.remove(friendNo); - gift.setFriendNoList(friendNoList); + gift.removeFriendNo(friendNo); giftRepository.save(gift); } - friendRepository.deleteById(friendNo); } @@ -166,6 +166,7 @@ public List findReceivedGiftList(Long friendNo){ @Transactional public FriendResponseDto returnDto(Friend friend){ User user = friend.getUser(); + User friendUser = findUserByUserNo(friend.getFriendUserNo()); List reminderList = user.getReminderList(); List reminderDtoList = new ArrayList<>(); @@ -182,7 +183,9 @@ public FriendResponseDto returnDto(Friend friend){ } HashMap giftInfo = returnGiftInfo(friend.getFriendNo()); - return new FriendResponseDto(friend, user, reminderDtoList, favorList, anniversaryList, giftInfo); + String friendId = friendUser.getUserId(); + + return new FriendResponseDto(friend, user, reminderDtoList, favorList, anniversaryList, giftInfo, friendId); } public HashMap returnGiftInfo(Long friendNo) { diff --git a/favor/src/main/java/com/favor/favor/gift/Gift.java b/favor/src/main/java/com/favor/favor/gift/Gift.java index 986e480..2f1b2d3 100644 --- a/favor/src/main/java/com/favor/favor/gift/Gift.java +++ b/favor/src/main/java/com/favor/favor/gift/Gift.java @@ -8,7 +8,6 @@ import lombok.*; import javax.persistence.*; -import javax.transaction.Transactional; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; @@ -18,7 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor @Builder -@Transactional +@ToString public class Gift extends TimeStamped { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -69,12 +68,16 @@ public void setIsGiven(Boolean isGiven){ @Builder.Default @ElementCollection private List friendNoList = new ArrayList<>(); - public void setFriendNoList(List friendNoList){ - this.friendNoList = friendNoList; + public void addFriendNo(Long friendNo){ + friendNoList.add(friendNo); } + public void removeFriendNo(Long friendNo){ + friendNoList.remove(friendNo); + } + @OneToMany(cascade = CascadeType.ALL) - private List giftPhotoList = new ArrayList<>(); + private List giftPhotoList; public void setGiftPhotoList(List giftPhotoList) { this.giftPhotoList = giftPhotoList; } diff --git a/favor/src/main/java/com/favor/favor/gift/GiftController.java b/favor/src/main/java/com/favor/favor/gift/GiftController.java index 38b8e0a..8c7dfb9 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftController.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftController.java @@ -214,11 +214,13 @@ public ResponseEntity> deleteGift( giftService.isExistingGiftNo(giftNo); - Gift gift = giftService.findGiftByGiftNo(giftNo); log.info("[SYSTEM] giftService.findGiftByGiftNo(giftNo) 완료"); + log.info("[SYSTEM] gift = {}", gift); + GiftResponseDto dto = giftService.returnDto(gift); log.info("[SYSTEM] giftService.returnDto(gift) 완료"); + log.info("[SYSTEM] dto = {}", dto); giftService.deleteGift(giftNo); log.info("[SYSTEM] giftService.deleteGift(giftNo) 완료"); diff --git a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java index 3cb78ee..90b0e13 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java @@ -7,6 +7,7 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; +import lombok.ToString; import lombok.extern.log4j.Log4j2; import java.time.LocalDate; @@ -18,6 +19,7 @@ @Getter @AllArgsConstructor @Builder +@ToString public class GiftResponseDto { private Long giftNo; diff --git a/favor/src/main/java/com/favor/favor/gift/GiftService.java b/favor/src/main/java/com/favor/favor/gift/GiftService.java index 34c8aa6..8a44ddb 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftService.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftService.java @@ -30,11 +30,15 @@ public class GiftService { @Transactional public Gift createGift(GiftRequestDto giftRequestDto, Long userNo){ - log.info("[Service] [createGift] 실행"); + log.info("[SERVICE] [createGift] 실행"); User user = findUserByUserNo(userNo); + log.info("[SERVICE] user = {}", user); LocalDate localDate = returnLocalDate(giftRequestDto.getGiftDate()); + log.info("[SERVICE] locaDate = {}", localDate); Gift gift = giftRepository.save(giftRequestDto.toEntity(user, localDate)); + log.info("[SERVICE] gift = {}", gift); addGiftNo(gift.getGiftNo(), gift.getFriendNoList()); + return giftRepository.save(gift); } @Transactional @@ -50,6 +54,7 @@ public void addGiftNo(Long giftNo, List friendNoList){ } public void updateGift(GiftUpdateRequestDto dto, Gift gift){ + //수정된 gift 정보 저장 (친구 목록 제외) gift.setGiftName(dto.getGiftName()); gift.setGiftMemo(dto.getGiftMemo()); gift.setCategory(dto.getCategoryGift()); @@ -60,17 +65,27 @@ public void updateGift(GiftUpdateRequestDto dto, Gift gift){ List existingFriendNoList = gift.getFriendNoList(); List updatedFriendNoList = dto.getFriendNoList(); + //친구 목록 수정 시 + //빠진 친구들의 선물 목록에서 선물 식별자 삭제 for (Long friendNo : existingFriendNoList) { if (!updatedFriendNoList.contains(friendNo)) { Friend friend = findFriendByFriendNo(friendNo); friend.getGiftNoList().remove(gift.getGiftNo()); friendRepository.save(friend); + //선물의 친구 식별자 목록에서 빠진 친구 삭제 + gift.removeFriendNo(friendNo); + } + } + //추가된 친구들의 선물 목록에 선물 식별자 추가 + for (Long friendNo : updatedFriendNoList) { + if (!existingFriendNoList.contains(friendNo)) { + Friend friend = findFriendByFriendNo(friendNo); + friend.getGiftNoList().add(gift.getGiftNo()); + friendRepository.save(friend); + //선물의 친구 식별자 목록에 추가된 친구 추가 + gift.addFriendNo(friendNo); } } - - gift.setFriendNoList(dto.getFriendNoList()); - addGiftNo(gift.getGiftNo(), dto.getFriendNoList()); - giftRepository.save(gift); } public void updateIsPinned(Gift gift){ @@ -84,10 +99,21 @@ public void updateTempFriendList(Gift gift, GiftTempFriendListDto tempFriendList } public void deleteGift(Long giftNo){ + Gift gift = findGiftByGiftNo(giftNo); + log.info("[SERVICE] gift = {}", gift); + List friendNoList = gift.getFriendNoList(); + log.info("[SERVICE] friendNoList = {}", friendNoList); + + //선물 삭제시 선물을 보유하고 있던 유저의 선물 식별자 목록에서 선물 식별자가 사라짐 + for(Long friendNo : friendNoList){ + Friend friend = findFriendByFriendNo(friendNo); + log.info("[SERVICE] friend = {}", friend); + friend.getGiftNoList().remove(giftNo); + } + giftRepository.deleteById(giftNo); } - public List readAll(){ List g_List = new ArrayList<>(); for(Gift gift : giftRepository.findAll()){ @@ -139,43 +165,17 @@ public Gift findGiftByGiftNo(Long giftNo){ } + // Gift만 입력받아도 FriendList 를 가진 responseDTO 를 반환 @Transactional public GiftResponseDto returnDto(Gift gift){ - List friendResponseDtoList = new ArrayList<>(); List friendNoList = gift.getFriendNoList(); - List deletedNoList = new ArrayList<>(); - - - for(Long f : new ArrayList<>(friendNoList)){ - if(findFriendByFriendNo(f) == null){ - friendNoList.remove(f); - continue; - }else{ - Friend friend = findFriendByFriendNo(f); - friendResponseDtoList.add(new FriendResponseDto(friend)); - } + List friendResponseDtoList = new ArrayList<>(); -// Friend friend = null; -// try{ -// friend = findFriendByFriendNo(f); -// }catch(Exception e){ -// throw new CustomException(e, FRIEND_NOT_FOUND); -// deletedNoList.add(f); -// continue; -// } -// FriendResponseDto dto = new FriendResponseDto(friend); -// friendResponseDtoList.add(dto); - } - log.info("[SYSTEM] for(Long f : friendNoList) 완료"); -// -// for(Long f : new ArrayList<>(friendNoList)){ -// friendNoList.remove(f); -// } -// log.info("[SYSTEM] for(Long f : deletedNoList) 완료"); - - gift.setFriendNoList(friendNoList); - log.info("[SYSTEM] gift.setFriendNoList(friendNoList) 완료"); + for(Long friendNo : friendNoList){ + FriendResponseDto friendResponseDto = new FriendResponseDto(findFriendByFriendNo(friendNo)); + friendResponseDtoList.add(friendResponseDto); + } giftRepository.save(gift); log.info("[SYSTEM] giftRepository.save(gift) 완료"); diff --git a/favor/src/main/java/com/favor/favor/user/UserService.java b/favor/src/main/java/com/favor/favor/user/UserService.java index bd3499a..05e4d53 100644 --- a/favor/src/main/java/com/favor/favor/user/UserService.java +++ b/favor/src/main/java/com/favor/favor/user/UserService.java @@ -165,7 +165,7 @@ public List readGiftList(Long userNo){ List friendList = new ArrayList<>(); for(Long f : gift.getFriendNoList()){ Friend friend = findFriendByFriendNo(f); - FriendResponseDto dto = new FriendResponseDto(friend); + FriendResponseDto dto = returnFriendDto(friend); friendList.add(dto); } g_List.add(new GiftResponseDto(gift, friendList)); @@ -173,13 +173,36 @@ public List readGiftList(Long userNo){ return g_List; } + @Transactional + public FriendResponseDto returnFriendDto(Friend friend){ + User user = friend.getUser(); + User friendUser = findUserByUserNo(friend.getFriendUserNo()); + + List reminderList = friendUser.getReminderList(); + List reminderDtoList = new ArrayList<>(); + for(Reminder r : reminderList){ + reminderDtoList.add(new ReminderResponseDto(r)); + } + List favorList = new ArrayList<>(); + for(Integer favorType : friendUser.getFavorList()){ + favorList.add(Favor.valueOf(favorType)); + } + List anniversaryList = new ArrayList<>(); + for(Anniversary a : friendUser.getAnniversaryList()){ + anniversaryList.add(new AnniversaryResponseDto(a)); + } + HashMap giftInfo = returnGiftInfo(friend.getFriendNo()); + + return new FriendResponseDto(friend, reminderDtoList, favorList, anniversaryList, giftInfo, friendUser); + } + @Transactional public List readFriendList(Long userNo){ User user = findUserByUserNo(userNo); List f_List = new ArrayList<>(); for(Friend f : user.getFriendList()){ - User friendUser = findUserByUserNo(userNo); + User friendUser = findUserByUserNo(f.getFriendUserNo()); FriendResponseDto dto = new FriendResponseDto(f, friendUser); f_List.add(dto); } @@ -372,7 +395,7 @@ public List findReceivedGiftList(Long userNo){ List giftResponseDtoList = new ArrayList<>(); for(Gift gift : giftList){ if(!gift.getIsGiven()){ - GiftResponseDto dto = new GiftResponseDto(gift); + GiftResponseDto dto = returnGiftDto(gift); giftResponseDtoList.add(dto); } } @@ -416,6 +439,23 @@ public UserResponseDto returnUserDto(User user){ return dto; } + @Transactional + public GiftResponseDto returnGiftDto(Gift gift){ + + List friendNoList = gift.getFriendNoList(); + List friendResponseDtoList = new ArrayList<>(); + + for(Long friendNo : friendNoList){ + FriendResponseDto friendResponseDto = new FriendResponseDto(findFriendByFriendNo(friendNo)); + friendResponseDtoList.add(friendResponseDto); + } + + giftRepository.save(gift); + log.info("[SYSTEM] giftRepository.save(gift) 완료"); + + return new GiftResponseDto(gift, friendResponseDtoList); + } + public HashMap returnGiftInfo(Long userNo){ User user = findUserByUserNo(userNo); From f05dab21fe614cb7c82aa1b28c40da37d16ab585 Mon Sep 17 00:00:00 2001 From: Eungi Jeong Date: Sat, 19 Aug 2023 11:37:19 +0900 Subject: [PATCH 14/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../favor/favor/friend/FriendResponseDto.java | 64 ++------- .../com/favor/favor/friend/FriendService.java | 14 +- .../favor/favor/friend/FriendSimpleDto.java | 24 ++++ .../com/favor/favor/gift/GiftResponseDto.java | 5 +- .../com/favor/favor/gift/GiftService.java | 9 +- .../com/favor/favor/gift/GiftSimpleDto.java | 27 ++++ .../favor/reminder/ReminderController.java | 5 +- .../favor/reminder/ReminderResponseDto.java | 8 +- .../favor/favor/reminder/ReminderService.java | 14 +- .../favor/reminder/ReminderSimpleDto.java | 28 ++++ .../com/favor/favor/user/UserController.java | 26 ++-- .../com/favor/favor/user/UserResponseDto.java | 10 +- .../com/favor/favor/user/UserService.java | 131 ++++++------------ 13 files changed, 181 insertions(+), 184 deletions(-) create mode 100644 favor/src/main/java/com/favor/favor/friend/FriendSimpleDto.java create mode 100644 favor/src/main/java/com/favor/favor/gift/GiftSimpleDto.java create mode 100644 favor/src/main/java/com/favor/favor/reminder/ReminderSimpleDto.java diff --git a/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java b/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java index 207f6a7..b9e46de 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendResponseDto.java @@ -2,11 +2,12 @@ import com.favor.favor.anniversary.AnniversaryResponseDto; import com.favor.favor.common.enums.Favor; +import com.favor.favor.photo.UserPhoto; import com.favor.favor.reminder.ReminderResponseDto; +import com.favor.favor.reminder.ReminderSimpleDto; import com.favor.favor.user.User; import lombok.*; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -18,7 +19,7 @@ public class FriendResponseDto { private String friendName; private String friendMemo; - private List reminderList; + private List reminderList; private List favorList; private List anniversaryList; @@ -28,48 +29,19 @@ public class FriendResponseDto { private Long userNo; private String friendId; - - @Builder - public FriendResponseDto(Friend friend){ - this.friendNo = friend.getFriendNo(); - this.friendName = friend.getFriendName(); - this.friendMemo = friend.getFriendMemo(); - this.reminderList = new ArrayList<>(); - this.favorList = new ArrayList<>(); - this.anniversaryList = new ArrayList<>(); - this.givenGift = 0; - this.receivedGift = 0; - this.totalGift = 0; - this.userNo = friend.getFriendUserNo(); - this.friendId = ""; - } - - @Builder - public FriendResponseDto(Friend friend, User user){ - this.friendNo = friend.getFriendNo(); - this.friendName = user.getUsername(); - this.friendMemo = friend.getFriendMemo(); - this.reminderList = new ArrayList<>(); - this.favorList = new ArrayList<>(); - this.anniversaryList = new ArrayList<>(); - this.givenGift = 0; - this.receivedGift = 0; - this.totalGift = 0; - this.userNo = friend.getFriendUserNo(); - this.friendId = ""; - } + private UserPhoto photo; @Builder public FriendResponseDto(Friend friend, - User user, - List reminderList, + User friendUser, + List reminderList, List favorList, List anniversaryList, HashMap giftInfo, String friendId ){ this.friendNo = friend.getFriendNo(); - this.friendName = friend.getFriendName(); + this.friendName = friendUser.getName(); this.friendMemo = friend.getFriendMemo(); this.reminderList = reminderList; this.favorList = favorList; @@ -79,26 +51,6 @@ public FriendResponseDto(Friend friend, this.totalGift = giftInfo.get("total"); this.userNo = friend.getFriendUserNo(); this.friendId = friendId; - } - - @Builder - public FriendResponseDto(Friend friend, - List reminderList, - List favorList, - List anniversaryList, - HashMap giftInfo, - User friendUser - ){ - this.friendNo = friend.getFriendNo(); - this.friendName = friendUser.getUsername(); - this.friendMemo = friend.getFriendMemo(); - this.reminderList = reminderList; - this.favorList = favorList; - this.anniversaryList = anniversaryList; - this.givenGift = giftInfo.get("given"); - this.receivedGift = giftInfo.get("received"); - this.totalGift = giftInfo.get("total"); - this.userNo = friend.getFriendUserNo(); - this.friendId = friendUser.getUserId(); + this.photo = friendUser.getUserProfilePhoto(); } } diff --git a/favor/src/main/java/com/favor/favor/friend/FriendService.java b/favor/src/main/java/com/favor/favor/friend/FriendService.java index 03b08c1..22e06f3 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendService.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendService.java @@ -9,6 +9,7 @@ import com.favor.favor.gift.GiftResponseDto; import com.favor.favor.reminder.Reminder; import com.favor.favor.reminder.ReminderResponseDto; +import com.favor.favor.reminder.ReminderSimpleDto; import com.favor.favor.user.User; import com.favor.favor.user.UserRepository; import lombok.RequiredArgsConstructor; @@ -165,27 +166,26 @@ public List findReceivedGiftList(Long friendNo){ //RETURN @Transactional public FriendResponseDto returnDto(Friend friend){ - User user = friend.getUser(); User friendUser = findUserByUserNo(friend.getFriendUserNo()); - List reminderList = user.getReminderList(); - List reminderDtoList = new ArrayList<>(); + List reminderList = friendUser.getReminderList(); + List reminderDtoList = new ArrayList<>(); for(Reminder r : reminderList){ - reminderDtoList.add(new ReminderResponseDto(r)); + reminderDtoList.add(new ReminderSimpleDto(r)); } List favorList = new ArrayList<>(); - for(Integer favorType : user.getFavorList()){ + for(Integer favorType : friendUser.getFavorList()){ favorList.add(Favor.valueOf(favorType)); } List anniversaryList = new ArrayList<>(); - for(Anniversary a : user.getAnniversaryList()){ + for(Anniversary a : friendUser.getAnniversaryList()){ anniversaryList.add(new AnniversaryResponseDto(a)); } HashMap giftInfo = returnGiftInfo(friend.getFriendNo()); String friendId = friendUser.getUserId(); - return new FriendResponseDto(friend, user, reminderDtoList, favorList, anniversaryList, giftInfo, friendId); + return new FriendResponseDto(friend, friendUser, reminderDtoList, favorList, anniversaryList, giftInfo, friendId); } public HashMap returnGiftInfo(Long friendNo) { diff --git a/favor/src/main/java/com/favor/favor/friend/FriendSimpleDto.java b/favor/src/main/java/com/favor/favor/friend/FriendSimpleDto.java new file mode 100644 index 0000000..2b1f007 --- /dev/null +++ b/favor/src/main/java/com/favor/favor/friend/FriendSimpleDto.java @@ -0,0 +1,24 @@ +package com.favor.favor.friend; + +import com.favor.favor.photo.UserPhoto; +import com.favor.favor.user.User; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class FriendSimpleDto { + private Long friendNo; + private String friendName; + private Long userNo; + private String photo; + + @Builder + public FriendSimpleDto(Friend friend, User friendUser, UserPhoto photo){ + this.friendNo = friend.getFriendNo(); + this.friendName = friendUser.getName(); + this.userNo = friend.getFriendUserNo(); + this.photo = photo.getPhotoUrl(); + } +} diff --git a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java index 90b0e13..038b097 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java @@ -3,6 +3,7 @@ import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.common.enums.Emotion; import com.favor.favor.friend.FriendResponseDto; +import com.favor.favor.friend.FriendSimpleDto; import com.favor.favor.photo.GiftPhoto; import lombok.AllArgsConstructor; import lombok.Builder; @@ -31,7 +32,7 @@ public class GiftResponseDto { private Boolean isPinned; private Boolean isGiven; private Long userNo; - private List friendList; + private List friendList; private LocalDateTime createdAt; private LocalDateTime modifiedAt; private List giftPhotoList; @@ -58,7 +59,7 @@ public GiftResponseDto(Gift gift){ log.info("[GiftResponseDto] 실행 완료"); } @Builder - public GiftResponseDto(Gift gift, List friendList){ + public GiftResponseDto(Gift gift, List friendList){ log.info("[GiftResponseDto] 실행"); this.giftNo = gift.getGiftNo(); this.giftName = gift.getGiftName(); diff --git a/favor/src/main/java/com/favor/favor/gift/GiftService.java b/favor/src/main/java/com/favor/favor/gift/GiftService.java index 8a44ddb..95b3375 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftService.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftService.java @@ -4,6 +4,8 @@ import com.favor.favor.friend.Friend; import com.favor.favor.friend.FriendRepository; import com.favor.favor.friend.FriendResponseDto; +import com.favor.favor.friend.FriendSimpleDto; +import com.favor.favor.photo.UserPhoto; import com.favor.favor.user.User; import com.favor.favor.user.UserRepository; import lombok.RequiredArgsConstructor; @@ -170,10 +172,13 @@ public Gift findGiftByGiftNo(Long giftNo){ public GiftResponseDto returnDto(Gift gift){ List friendNoList = gift.getFriendNoList(); - List friendResponseDtoList = new ArrayList<>(); + List friendResponseDtoList = new ArrayList<>(); for(Long friendNo : friendNoList){ - FriendResponseDto friendResponseDto = new FriendResponseDto(findFriendByFriendNo(friendNo)); + Friend friend = findFriendByFriendNo(friendNo); + User friendUser = findUserByUserNo(friend.getFriendUserNo()); + UserPhoto photo = friendUser.getUserProfilePhoto(); + FriendSimpleDto friendResponseDto = new FriendSimpleDto(friend, friendUser, photo); friendResponseDtoList.add(friendResponseDto); } diff --git a/favor/src/main/java/com/favor/favor/gift/GiftSimpleDto.java b/favor/src/main/java/com/favor/favor/gift/GiftSimpleDto.java new file mode 100644 index 0000000..488918b --- /dev/null +++ b/favor/src/main/java/com/favor/favor/gift/GiftSimpleDto.java @@ -0,0 +1,27 @@ +package com.favor.favor.gift; + +import com.favor.favor.photo.GiftPhoto; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; +import java.util.List; + +@Getter +@AllArgsConstructor +@Builder +public class GiftSimpleDto { + private Long giftNo; + private String giftName; + private LocalDate giftDate; + private List photoList; + + @Builder + public GiftSimpleDto(Gift gift){ + this.giftNo = gift.getGiftNo(); + this.giftName = gift.getGiftName(); + this.giftDate = gift.getGiftDate(); + this.photoList = gift.getGiftPhotoList(); + } +} diff --git a/favor/src/main/java/com/favor/favor/reminder/ReminderController.java b/favor/src/main/java/com/favor/favor/reminder/ReminderController.java index a820bfc..cf86194 100644 --- a/favor/src/main/java/com/favor/favor/reminder/ReminderController.java +++ b/favor/src/main/java/com/favor/favor/reminder/ReminderController.java @@ -142,10 +142,9 @@ public ResponseEntity> readReminder( @PatchMapping("/{reminderNo}") public ResponseEntity> updateReminder( @RequestBody ReminderUpdateRequestDto reminderUpdateRequestDto, - @PathVariable Long reminderNo, Long friendNo){ + @PathVariable Long reminderNo){ reminderService.isExistingReminderNo(reminderNo); - reminderService.isExistingFriendNo(friendNo); Reminder reminder = reminderService.findReminderByReminderNo(reminderNo); reminderService.updateReminder(reminderUpdateRequestDto, reminderNo); @@ -207,7 +206,7 @@ public ResponseEntity> deleteReminder( @GetMapping("/admin") public ResponseEntity> readAll(){ - List dto = reminderService.readAll(); + List dto = reminderService.readAll(); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() diff --git a/favor/src/main/java/com/favor/favor/reminder/ReminderResponseDto.java b/favor/src/main/java/com/favor/favor/reminder/ReminderResponseDto.java index 05cfbdb..0f87784 100644 --- a/favor/src/main/java/com/favor/favor/reminder/ReminderResponseDto.java +++ b/favor/src/main/java/com/favor/favor/reminder/ReminderResponseDto.java @@ -1,5 +1,7 @@ package com.favor.favor.reminder; +import com.favor.favor.friend.FriendResponseDto; +import com.favor.favor.friend.FriendSimpleDto; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -21,10 +23,10 @@ public class ReminderResponseDto { private LocalDateTime alarmTime; private Long userNo; - private Long friendNo; + private FriendSimpleDto friendSimpleDto; @Builder - public ReminderResponseDto(Reminder reminder){ + public ReminderResponseDto(Reminder reminder, FriendSimpleDto dto){ this.reminderNo = reminder.getReminderNo(); this.reminderTitle = reminder.getReminderTitle(); this.reminderDate = reminder.getReminderDate(); @@ -32,6 +34,6 @@ public ReminderResponseDto(Reminder reminder){ this.isAlarmSet = reminder.getIsAlarmSet(); this.alarmTime = reminder.getAlarmTime(); this.userNo = reminder.getUser().getUserNo(); - this.friendNo = reminder.getFriend().getFriendNo(); + this.friendSimpleDto = dto; } } diff --git a/favor/src/main/java/com/favor/favor/reminder/ReminderService.java b/favor/src/main/java/com/favor/favor/reminder/ReminderService.java index 821d6bf..338d45e 100644 --- a/favor/src/main/java/com/favor/favor/reminder/ReminderService.java +++ b/favor/src/main/java/com/favor/favor/reminder/ReminderService.java @@ -5,6 +5,8 @@ import com.favor.favor.exception.CustomException; import com.favor.favor.friend.Friend; import com.favor.favor.friend.FriendRepository; +import com.favor.favor.friend.FriendSimpleDto; +import com.favor.favor.photo.UserPhoto; import com.favor.favor.user.User; import com.favor.favor.user.UserRepository; import lombok.RequiredArgsConstructor; @@ -69,10 +71,10 @@ public void deleteReminder(Long reminderNo){ reminderRepository.deleteById(reminderNo); } - public List readAll(){ - List r_List = new ArrayList<>(); + public List readAll(){ + List r_List = new ArrayList<>(); for(Reminder r : reminderRepository.findAll()){ - ReminderResponseDto dto = new ReminderResponseDto(r); + ReminderSimpleDto dto = new ReminderSimpleDto(r); r_List.add(dto); } return r_List; @@ -144,7 +146,11 @@ public Anniversary findAnniversaryByAnniversaryNo(Long anniversaryNo){ public ReminderResponseDto returnDto(Reminder reminder){ - return new ReminderResponseDto(reminder); + Friend friend = reminder.getFriend(); + User friendUser = findUserByUserNo(friend.getFriendUserNo()); + UserPhoto photo = friendUser.getUserProfilePhoto(); + FriendSimpleDto dto = new FriendSimpleDto(friend, friendUser, photo); + return new ReminderResponseDto(reminder, dto); } public LocalDate returnLocalDate(String dateString){ String patternDate = "yyyy-MM-dd"; diff --git a/favor/src/main/java/com/favor/favor/reminder/ReminderSimpleDto.java b/favor/src/main/java/com/favor/favor/reminder/ReminderSimpleDto.java new file mode 100644 index 0000000..2b25689 --- /dev/null +++ b/favor/src/main/java/com/favor/favor/reminder/ReminderSimpleDto.java @@ -0,0 +1,28 @@ +package com.favor.favor.reminder; + +import com.favor.favor.friend.FriendSimpleDto; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; + +@Getter +@AllArgsConstructor +@Builder +public class ReminderSimpleDto { + private final Long reminderNo; + private String reminderTitle; + private LocalDate reminderDate; + private boolean isAlarmSet; + private Long userNo; + + @Builder + public ReminderSimpleDto(Reminder reminder){ + this.reminderNo = reminder.getReminderNo(); + this.reminderTitle = reminder.getReminderTitle(); + this.reminderDate = reminder.getReminderDate(); + this.isAlarmSet = reminder.getIsAlarmSet(); + this.userNo = reminder.getUser().getUserNo(); + } +} diff --git a/favor/src/main/java/com/favor/favor/user/UserController.java b/favor/src/main/java/com/favor/favor/user/UserController.java index 719a504..b6329cc 100644 --- a/favor/src/main/java/com/favor/favor/user/UserController.java +++ b/favor/src/main/java/com/favor/favor/user/UserController.java @@ -6,8 +6,11 @@ import com.favor.favor.common.enums.CategoryGift; import com.favor.favor.common.enums.Emotion; import com.favor.favor.friend.FriendResponseDto; +import com.favor.favor.friend.FriendSimpleDto; import com.favor.favor.gift.GiftResponseDto; +import com.favor.favor.gift.GiftSimpleDto; import com.favor.favor.reminder.ReminderResponseDto; +import com.favor.favor.reminder.ReminderSimpleDto; import io.swagger.annotations.*; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -189,15 +192,10 @@ public ResponseEntity> updateUser( ){ Long userNo = loginUser.getUserNo(); - userService.isExistingUserNo(userNo); - -// ++ User user = userService.findUserByUserNo(userNo); -// userService.updateUser(loginUser, userUpdateRequestDto); userService.updateUser(user, userUpdateRequestDto); -// UserResponseDto dto = userService.returnUserDto(loginUser); UserResponseDto dto = userService.returnUserDto(user); @@ -302,7 +300,7 @@ public ResponseEntity> readReminderList( userService.isExistingUserNo(userNo); - List reminders = userService.readReminderList(userNo); + List reminders = userService.readReminderList(userNo); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -335,7 +333,7 @@ public ResponseEntity> readReminderListByFMonthAndYea userService.isExistingUserNo(userNo); - List dto = userService.readReminderListByFMonthAndYear(userNo, year, month); + List dto = userService.readReminderListByFMonthAndYear(userNo, year, month); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -367,7 +365,7 @@ public ResponseEntity> readGiftList( userService.isExistingUserNo(userNo); - List gifts = userService.readGiftList(userNo); + List gifts = userService.readGiftList(userNo); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -399,7 +397,7 @@ public ResponseEntity> readFriendList( userService.isExistingUserNo(userNo); - List friends = userService.readFriendList(userNo); + List friends = userService.readFriendList(userNo); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -491,7 +489,7 @@ public ResponseEntity> readGiftListByName ( userService.isExistingUserNo(userNo); - List dto = userService.readGiftListByName(userNo, giftName); + List dto = userService.readGiftListByName(userNo, giftName); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -523,7 +521,7 @@ public ResponseEntity> readGiftListByCategory( Long userNo = loginUser.getUserNo(); userService.isExistingUserNo(userNo); - List dto = userService.readGiftListByCategory(userNo, categoryGift); + List dto = userService.readGiftListByCategory(userNo, categoryGift); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -555,7 +553,7 @@ public ResponseEntity> readGiftListByEmotion( userService.isExistingUserNo(userNo); - List dto = userService.readGiftListByEmotion(userNo, emotion); + List dto = userService.readGiftListByEmotion(userNo, emotion); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -612,7 +610,7 @@ public ResponseEntity> readGivenGiftList( Long userNo = loginUser.getUserNo(); userService.isExistingUserNo(userNo); - List dto = userService.findGivenGiftList(userNo); + List dto = userService.findGivenGiftList(userNo); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -640,7 +638,7 @@ public ResponseEntity> readReceivedGiftList( Long userNo = loginUser.getUserNo(); userService.isExistingUserNo(userNo); - List dto = userService.findReceivedGiftList(userNo); + List dto = userService.findReceivedGiftList(userNo); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() diff --git a/favor/src/main/java/com/favor/favor/user/UserResponseDto.java b/favor/src/main/java/com/favor/favor/user/UserResponseDto.java index d1abf4a..c4b286a 100644 --- a/favor/src/main/java/com/favor/favor/user/UserResponseDto.java +++ b/favor/src/main/java/com/favor/favor/user/UserResponseDto.java @@ -4,8 +4,10 @@ import com.favor.favor.common.enums.Favor; import com.favor.favor.common.enums.Role; import com.favor.favor.friend.FriendResponseDto; +import com.favor.favor.friend.FriendSimpleDto; import com.favor.favor.photo.UserPhoto; import com.favor.favor.reminder.ReminderResponseDto; +import com.favor.favor.reminder.ReminderSimpleDto; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Builder; @@ -43,10 +45,10 @@ public class UserResponseDto { private int totalGift; @ApiModelProperty(value = "") - private List reminderList; + private List reminderList; @ApiModelProperty(value = "") - private List friendList; + private List friendList; @ApiModelProperty(value = "") private List anniversaryList; @@ -62,8 +64,8 @@ public class UserResponseDto { @Builder public UserResponseDto(User user, - List reminderList, - List friendList, + List reminderList, + List friendList, List favorList, List anniversaryList, HashMap giftInfo){ diff --git a/favor/src/main/java/com/favor/favor/user/UserService.java b/favor/src/main/java/com/favor/favor/user/UserService.java index 05e4d53..169c467 100644 --- a/favor/src/main/java/com/favor/favor/user/UserService.java +++ b/favor/src/main/java/com/favor/favor/user/UserService.java @@ -11,11 +11,14 @@ import com.favor.favor.friend.Friend; import com.favor.favor.friend.FriendResponseDto; import com.favor.favor.friend.FriendRepository; +import com.favor.favor.friend.FriendSimpleDto; import com.favor.favor.gift.*; import com.favor.favor.gift.GiftResponseDto; +import com.favor.favor.photo.UserPhoto; import com.favor.favor.reminder.Reminder; import com.favor.favor.reminder.ReminderRepository; import com.favor.favor.reminder.ReminderResponseDto; +import com.favor.favor.reminder.ReminderSimpleDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.crypto.password.PasswordEncoder; @@ -99,13 +102,6 @@ public void isRightPassword(String password, User user){ } } - - - @Transactional - public User readUser(Long userNo){ - return findUserByUserNo(userNo); - } - @Transactional public User updateUser(User user, UserUpdateRequestDto userUpdateRequestDto){ user.setName(userUpdateRequestDto.getName()); @@ -133,12 +129,12 @@ public User updatePassword(String email, String password){ @Transactional - public List readReminderList(Long userNo){ + public List readReminderList(Long userNo){ User user = findUserByUserNo(userNo); - List r_List = new ArrayList<>(); + List r_List = new ArrayList<>(); for(Reminder r : user.getReminderList()){ - ReminderResponseDto dto = new ReminderResponseDto(r); + ReminderSimpleDto dto = new ReminderSimpleDto(r); r_List.add(dto); } return r_List; @@ -157,53 +153,24 @@ public List readAnniversaryList(Long userNo){ } @Transactional - public List readGiftList(Long userNo){ + public List readGiftList(Long userNo){ User user = findUserByUserNo(userNo); - List g_List = new ArrayList<>(); + List g_List = new ArrayList<>(); for(Gift gift : user.getGiftList()){ - List friendList = new ArrayList<>(); - for(Long f : gift.getFriendNoList()){ - Friend friend = findFriendByFriendNo(f); - FriendResponseDto dto = returnFriendDto(friend); - friendList.add(dto); - } - g_List.add(new GiftResponseDto(gift, friendList)); + g_List.add(new GiftSimpleDto(gift)); } return g_List; } - @Transactional - public FriendResponseDto returnFriendDto(Friend friend){ - User user = friend.getUser(); - User friendUser = findUserByUserNo(friend.getFriendUserNo()); - - List reminderList = friendUser.getReminderList(); - List reminderDtoList = new ArrayList<>(); - for(Reminder r : reminderList){ - reminderDtoList.add(new ReminderResponseDto(r)); - } - List favorList = new ArrayList<>(); - for(Integer favorType : friendUser.getFavorList()){ - favorList.add(Favor.valueOf(favorType)); - } - List anniversaryList = new ArrayList<>(); - for(Anniversary a : friendUser.getAnniversaryList()){ - anniversaryList.add(new AnniversaryResponseDto(a)); - } - HashMap giftInfo = returnGiftInfo(friend.getFriendNo()); - - return new FriendResponseDto(friend, reminderDtoList, favorList, anniversaryList, giftInfo, friendUser); - } - - @Transactional - public List readFriendList(Long userNo){ + public List readFriendList(Long userNo){ User user = findUserByUserNo(userNo); - List f_List = new ArrayList<>(); + List f_List = new ArrayList<>(); for(Friend f : user.getFriendList()){ User friendUser = findUserByUserNo(f.getFriendUserNo()); - FriendResponseDto dto = new FriendResponseDto(f, friendUser); + UserPhoto photo = friendUser.getUserProfilePhoto(); + FriendSimpleDto dto = new FriendSimpleDto(f, friendUser, photo); f_List.add(dto); } return f_List; @@ -223,56 +190,38 @@ public List readAll(){ - public List readGiftListByName(Long userNo, String giftName){ + public List readGiftListByName(Long userNo, String giftName){ User user = findUserByUserNo(userNo); List giftList = giftRepository.findGiftsByUserAndGiftNameContains(user, giftName); - List g_List = new ArrayList<>(); + List g_List = new ArrayList<>(); for(Gift gift : giftList){ - List friendList = new ArrayList<>(); - for(Long f : gift.getFriendNoList()){ - Friend friend = findFriendByFriendNo(f); - FriendResponseDto dto = new FriendResponseDto(friend); - friendList.add(dto); - } - g_List.add(new GiftResponseDto(gift, friendList)); + g_List.add(new GiftSimpleDto(gift)); } return g_List; } - public List readGiftListByCategory(Long userNo, CategoryGift categoryGift){ + public List readGiftListByCategory(Long userNo, CategoryGift categoryGift){ User user = findUserByUserNo(userNo); Integer categoryNo = categoryGift.getType(); List giftList = giftRepository.findGiftsByUserAndCategory(user, categoryNo); - List g_List = new ArrayList<>(); + List g_List = new ArrayList<>(); for(Gift gift : giftList){ - List friendList = new ArrayList<>(); - for(Long f : gift.getFriendNoList()){ - Friend friend = findFriendByFriendNo(f); - FriendResponseDto dto = new FriendResponseDto(friend); - friendList.add(dto); - } - g_List.add(new GiftResponseDto(gift, friendList)); + g_List.add(new GiftSimpleDto(gift)); } return g_List; } - public List readGiftListByEmotion(Long userNo, Emotion emotion){ + public List readGiftListByEmotion(Long userNo, Emotion emotion){ User user = findUserByUserNo(userNo); Integer emotionNo = emotion.getType(); List giftList = giftRepository.findGiftsByUserAndEmotion(user, emotionNo); - List g_List = new ArrayList<>(); + List g_List = new ArrayList<>(); for(Gift gift : giftList){ - List friendList = new ArrayList<>(); - for(Long f : gift.getFriendNoList()){ - Friend friend = findFriendByFriendNo(f); - FriendResponseDto dto = new FriendResponseDto(friend); - friendList.add(dto); - } - g_List.add(new GiftResponseDto(gift, friendList)); + g_List.add(new GiftSimpleDto(gift)); } return g_List; @@ -352,7 +301,7 @@ public Friend findFriendByFriendNo(Long friendNo){ } return friend; } - public List readReminderListByFMonthAndYear(Long userNo, int year, int month){ + public List readReminderListByFMonthAndYear(Long userNo, int year, int month){ try{ LocalDate.of(year, month, 1); @@ -360,11 +309,11 @@ public List readReminderListByFMonthAndYear(Long userNo, in throw new CustomException(e, DATE_INVALID); } - List reminderDtoList = new ArrayList<>(); + List reminderDtoList = new ArrayList<>(); List reminderList = findReminderListByMonthAndYear(year, month); for(Reminder r : reminderList){ - ReminderResponseDto dto = new ReminderResponseDto(r); + ReminderSimpleDto dto = new ReminderSimpleDto(r); if(dto.getUserNo()==userNo) reminderDtoList.add(dto); } @@ -377,25 +326,25 @@ public List findReminderListByMonthAndYear(int year, int month){ return reminderRepository.findAllByReminderDateBetween(start, end); } - public List findGivenGiftList(Long userNo){ + public List findGivenGiftList(Long userNo){ User user = findUserByUserNo(userNo); List giftList = giftRepository.findGiftsByUser(user); - List giftResponseDtoList = new ArrayList<>(); + List giftResponseDtoList = new ArrayList<>(); for(Gift gift : giftList){ if(gift.getIsGiven()){ - GiftResponseDto dto = new GiftResponseDto(gift); + GiftSimpleDto dto = new GiftSimpleDto(gift); giftResponseDtoList.add(dto); } } return giftResponseDtoList; } - public List findReceivedGiftList(Long userNo){ + public List findReceivedGiftList(Long userNo){ User user = findUserByUserNo(userNo); List giftList = giftRepository.findGiftsByUser(user); - List giftResponseDtoList = new ArrayList<>(); + List giftResponseDtoList = new ArrayList<>(); for(Gift gift : giftList){ if(!gift.getIsGiven()){ - GiftResponseDto dto = returnGiftDto(gift); + GiftSimpleDto dto = new GiftSimpleDto(gift); giftResponseDtoList.add(dto); } } @@ -409,16 +358,17 @@ public List findReceivedGiftList(Long userNo){ @Transactional public UserResponseDto returnUserDto(User user){ - List r_List = new ArrayList<>(); + List r_List = new ArrayList<>(); for(Reminder r : user.getReminderList()){ - ReminderResponseDto dto = new ReminderResponseDto(r); + ReminderSimpleDto dto = new ReminderSimpleDto(r); r_List.add(dto); } - List f_List = new ArrayList<>(); + List f_List = new ArrayList<>(); for(Friend f : user.getFriendList()){ User friendUser = findUserByUserNo(f.getFriendUserNo()); - FriendResponseDto dto = new FriendResponseDto(f, friendUser); + UserPhoto photo = friendUser.getUserProfilePhoto(); + FriendSimpleDto dto = new FriendSimpleDto(f, friendUser, photo); f_List.add(dto); } @@ -443,11 +393,14 @@ public UserResponseDto returnUserDto(User user){ public GiftResponseDto returnGiftDto(Gift gift){ List friendNoList = gift.getFriendNoList(); - List friendResponseDtoList = new ArrayList<>(); + List friendResponseDtoList = new ArrayList<>(); for(Long friendNo : friendNoList){ - FriendResponseDto friendResponseDto = new FriendResponseDto(findFriendByFriendNo(friendNo)); - friendResponseDtoList.add(friendResponseDto); + Friend friend = findFriendByFriendNo(friendNo); + User friendUser = findUserByUserNo(friend.getFriendUserNo()); + UserPhoto photo = friendUser.getUserProfilePhoto(); + FriendSimpleDto dto = new FriendSimpleDto(friend, friendUser, photo); + friendResponseDtoList.add(dto); } giftRepository.save(gift); From 2620d1cfa63b62bbe864bd0863b89885bd8bfa96 Mon Sep 17 00:00:00 2001 From: Eun Date: Sun, 20 Aug 2023 16:03:25 +0900 Subject: [PATCH 15/15] =?UTF-8?q?[Feat]=20AWS=20S3=EB=A5=BC=20=EC=9D=B4?= =?UTF-8?q?=EC=9A=A9=ED=95=9C=20=EC=9D=B4=EB=AF=B8=EC=A7=80=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=97=85=EB=A1=9C=EB=93=9C=20#57?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../favor/favor/anniversary/Anniversary.java | 20 ++++--- .../anniversary/AnniversaryController.java | 6 -- .../anniversary/AnniversaryRequestDto.java | 12 ++-- .../anniversary/AnniversaryResponseDto.java | 6 +- .../favor/anniversary/AnniversaryService.java | 51 ++--------------- .../AnniversaryUpdateRequestDto.java | 5 +- .../common/enums/AnniversaryCategory.java | 57 +++++++++++++++++++ .../common/enums/CategoryAnniversary.java | 57 ------------------- .../{CategoryGift.java => GiftCategory.java} | 28 ++++----- .../favor/favor/friend/FriendController.java | 14 ++--- .../com/favor/favor/friend/FriendService.java | 21 +++---- .../favor/favor/friend/FriendSimpleDto.java | 6 +- .../main/java/com/favor/favor/gift/Gift.java | 11 +++- .../com/favor/favor/gift/GiftController.java | 6 -- .../com/favor/favor/gift/GiftRequestDto.java | 13 +++-- .../com/favor/favor/gift/GiftResponseDto.java | 9 ++- .../com/favor/favor/gift/GiftService.java | 6 +- .../favor/gift/GiftUpdateRequestDto.java | 4 +- .../favor/reminder/ReminderController.java | 4 -- .../com/favor/favor/user/UserController.java | 24 +------- .../com/favor/favor/user/UserService.java | 8 +-- 22 files changed, 149 insertions(+), 221 deletions(-) create mode 100644 favor/src/main/java/com/favor/favor/common/enums/AnniversaryCategory.java delete mode 100644 favor/src/main/java/com/favor/favor/common/enums/CategoryAnniversary.java rename favor/src/main/java/com/favor/favor/common/enums/{CategoryGift.java => GiftCategory.java} (56%) diff --git a/favor/gradle/wrapper/gradle-wrapper.properties b/favor/gradle/wrapper/gradle-wrapper.properties index 070cb70..da1db5f 100644 --- a/favor/gradle/wrapper/gradle-wrapper.properties +++ b/favor/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java b/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java index 1527d33..5a77673 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java +++ b/favor/src/main/java/com/favor/favor/anniversary/Anniversary.java @@ -1,21 +1,17 @@ package com.favor.favor.anniversary; import com.favor.favor.common.TimeStamped; -import com.favor.favor.common.enums.CategoryAnniversary; -import com.favor.favor.common.enums.CategoryGift; +import com.favor.favor.common.enums.AnniversaryCategory; import com.favor.favor.user.User; import lombok.*; import javax.persistence.*; -import javax.transaction.Transactional; import java.time.LocalDate; + @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -@AllArgsConstructor -@Builder -@Transactional public class Anniversary extends TimeStamped { @Id @@ -29,8 +25,8 @@ public class Anniversary extends TimeStamped { public void setAnniversaryDate(LocalDate anniversaryDate){ this.anniversaryDate = anniversaryDate; } private Integer category; - public void setCategory(CategoryAnniversary categoryAnniversary){ - this.category = categoryAnniversary.getType(); + public void setCategory(AnniversaryCategory anniversaryCategory){ + this.category = anniversaryCategory.getType(); } private Boolean isPinned; @@ -40,4 +36,12 @@ public void setCategory(CategoryAnniversary categoryAnniversary){ @JoinColumn(name = "user_user_no") private User user; + @Builder + public Anniversary(String anniversaryTitle, LocalDate anniversaryDate, Integer category, Boolean isPinned, User user) { + this.anniversaryTitle = anniversaryTitle; + this.anniversaryDate = anniversaryDate; + this.category = category; + this.isPinned = isPinned; + this.user = user; + } } diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryController.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryController.java index 37b990c..511184f 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryController.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryController.java @@ -20,7 +20,6 @@ @RestController @RequestMapping("/anniversaries") @RequiredArgsConstructor -@Log4j2 public class AnniversaryController { private final AnniversaryService anniversaryService; @@ -71,7 +70,6 @@ public ResponseEntity> createAnniversary( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/{anniversaryNo}") public ResponseEntity> readAnniversary( @PathVariable Long anniversaryNo){ @@ -101,7 +99,6 @@ public ResponseEntity> readAnniversary( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @PatchMapping("/{anniversaryNo}") public ResponseEntity> updateAnniversary( @RequestBody AnniversaryUpdateRequestDto anniversaryUpdateRequestDto, @@ -134,7 +131,6 @@ public ResponseEntity> updateAnniversary( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @PatchMapping("/pin/{anniversaryNo}") public ResponseEntity> updateIsPinned( @PathVariable Long anniversaryNo){ @@ -166,7 +162,6 @@ public ResponseEntity> updateIsPinned( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @DeleteMapping("/{anniversaryNo}") public ResponseEntity> deleteAnniversary( @PathVariable Long anniversaryNo){ @@ -197,7 +192,6 @@ public ResponseEntity> deleteAnniversary( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/admin") public ResponseEntity> readAll(){ diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java index 460f0f1..dd13d1f 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryRequestDto.java @@ -1,7 +1,6 @@ package com.favor.favor.anniversary; -import com.favor.favor.common.enums.CategoryAnniversary; -import com.favor.favor.common.enums.CategoryGift; +import com.favor.favor.common.enums.AnniversaryCategory; import com.favor.favor.user.User; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -22,16 +21,17 @@ public class AnniversaryRequestDto { private String anniversaryDate; @ApiModelProperty(position = 3, required = true, value = "종류", example = "축하_생일") - private CategoryAnniversary categoryAnniversary; + private AnniversaryCategory anniversaryCategory; @Transactional - public Anniversary toEntity(User user, LocalDate localDate){ + public Anniversary toEntity(String anniversaryTitle, User user){ return Anniversary.builder() .anniversaryTitle(anniversaryTitle) - .anniversaryDate(localDate) - .category(categoryAnniversary.getType()) + .anniversaryDate(LocalDate.parse(anniversaryDate)) + .category(anniversaryCategory.getType()) .isPinned(false) .user(user) .build(); } + } diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java index 46efb9d..55ca4aa 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryResponseDto.java @@ -1,6 +1,6 @@ package com.favor.favor.anniversary; -import com.favor.favor.common.enums.CategoryAnniversary; +import com.favor.favor.common.enums.AnniversaryCategory; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -18,7 +18,7 @@ public class AnniversaryResponseDto { private Long userNo; private LocalDateTime createdAt; private LocalDateTime modifiedAt; - private CategoryAnniversary categoryAnniversary; + private AnniversaryCategory anniversaryCategory; @Builder public AnniversaryResponseDto(Anniversary anniversary){ @@ -29,6 +29,6 @@ public AnniversaryResponseDto(Anniversary anniversary){ this.userNo = anniversary.getUser().getUserNo(); this.createdAt = anniversary.getCreatedAt(); this.modifiedAt = anniversary.getModifiedAt(); - this.categoryAnniversary = CategoryAnniversary.valueOf(anniversary.getCategory()); + this.anniversaryCategory = AnniversaryCategory.valueOf(anniversary.getCategory()); } } diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java index 703b98f..9dd9192 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryService.java @@ -10,8 +10,6 @@ import javax.transaction.Transactional; import java.time.LocalDate; -import java.time.format.DateTimeFormatter; -import java.time.format.DateTimeParseException; import java.util.ArrayList; import java.util.List; @@ -28,45 +26,14 @@ public class AnniversaryService { @Transactional public Anniversary createAnniversary(AnniversaryRequestDto anniversaryRequestDto, Long userNo){ User user = findUserByUserNo(userNo); - LocalDate localDate = returnLocalDate(anniversaryRequestDto.getAnniversaryDate()); - Anniversary anniversary = anniversaryRepository.save(anniversaryRequestDto.toEntity(user, localDate)); + Anniversary anniversary = anniversaryRepository.save(anniversaryRequestDto.toEntity(anniversaryRequestDto.getAnniversaryTitle(), user)); return anniversaryRepository.save(anniversary); } - @Transactional - public void addAnniversaryNo(Long anniversaryNo, List friendNoList){ - for(Long friendNo : friendNoList){ - Friend friend = findFriendByFriendNo(friendNo); - List anniversaryNoList = friend.getAnniversaryNoList(); - - boolean flag = true; - if (anniversaryNoList.contains(anniversaryNo)) { - flag = false; - break; - } - if(flag) anniversaryNoList.add(anniversaryNo); - - friend.setAnniversaryNoList(anniversaryNoList); - } - } - - public Friend findFriendByFriendNo(Long friendNo){ - Friend friend = null; - try{ - friend = friendRepository.findByFriendNo(friendNo).orElseThrow( - () -> new RuntimeException() - ); - } catch (RuntimeException e){ - throw new CustomException(e, FRIEND_NOT_FOUND); - } - return friend; - } - public void updateAnniversary(AnniversaryUpdateRequestDto dto, Anniversary anniversary){ anniversary.setAnniversaryTitle(dto.getAnniversaryTitle()); - LocalDate localDate = returnLocalDate(dto.getAnniversaryDate()); - anniversary.setAnniversaryDate(localDate); - anniversary.setCategory(dto.getCategoryAnniversary()); + anniversary.setAnniversaryDate(LocalDate.parse(dto.getAnniversaryDate())); + anniversary.setCategory(dto.getAnniversaryCategory()); anniversaryRepository.save(anniversary); } @@ -76,6 +43,7 @@ public void updateIsPinned(Anniversary anniversary){ anniversaryRepository.save(anniversary); } + @Transactional public void deleteAnniversary(Long anniversaryNo){ List friendList = findAnniversaryByAnniversaryNo(anniversaryNo).getUser().getFriendList(); for(Friend friend : friendList){ @@ -125,17 +93,6 @@ public Anniversary findAnniversaryByAnniversaryNo(Long anniversaryNo){ public AnniversaryResponseDto returnDto(Anniversary anniversary){ return new AnniversaryResponseDto(anniversary); } - public LocalDate returnLocalDate(String dateString){ - String patternDate = "yyyy-MM-dd"; - try{ - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(patternDate); - LocalDate date = LocalDate.parse(dateString, formatter); - return date; - - } catch(DateTimeParseException e){ - throw new CustomException(e, DATE_INVALID); - } - } public void isExistingAnniversaryNo(Long anniversaryNo){ Boolean isExistingNo = null; diff --git a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java index 83ca475..66eb64f 100644 --- a/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java +++ b/favor/src/main/java/com/favor/favor/anniversary/AnniversaryUpdateRequestDto.java @@ -1,7 +1,6 @@ package com.favor.favor.anniversary; -import com.favor.favor.common.enums.CategoryAnniversary; -import com.favor.favor.common.enums.CategoryGift; +import com.favor.favor.common.enums.AnniversaryCategory; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Getter; @@ -20,7 +19,7 @@ public class AnniversaryUpdateRequestDto { private String anniversaryDate; @ApiModelProperty(position = 3, required = true, value = "종류", example = "축하_생일") - private CategoryAnniversary categoryAnniversary; + private AnniversaryCategory anniversaryCategory; @ApiModelProperty(position = 4, required = true, value = "핀 여부", example = "false") private Boolean isPinned; diff --git a/favor/src/main/java/com/favor/favor/common/enums/AnniversaryCategory.java b/favor/src/main/java/com/favor/favor/common/enums/AnniversaryCategory.java new file mode 100644 index 0000000..26ad13c --- /dev/null +++ b/favor/src/main/java/com/favor/favor/common/enums/AnniversaryCategory.java @@ -0,0 +1,57 @@ +package com.favor.favor.common.enums; + +import lombok.Getter; + +public enum AnniversaryCategory { + 연인(1), + 축하_생일(2), + 졸업(3), + 합격(4), + 입사_승진(5), + 이사_집들이(6), + 출산(7); + + @Getter + Integer type; + + AnniversaryCategory(Integer type){ + this.type = type; + } + + public static AnniversaryCategory validateType(String category){ + try{ + return AnniversaryCategory.valueOf(category); + }catch(IllegalStateException e){ + throw new IllegalArgumentException(); + } + + } + + public static AnniversaryCategory valueOf(Integer type){ + AnniversaryCategory anniversaryCategory = null; + switch (type){ + case 1: + anniversaryCategory = AnniversaryCategory.연인; + break; + case 2: + anniversaryCategory = AnniversaryCategory.축하_생일; + break; + case 3: + anniversaryCategory = AnniversaryCategory.졸업; + break; + case 4: + anniversaryCategory = AnniversaryCategory.합격; + break; + case 5: + anniversaryCategory = AnniversaryCategory.입사_승진; + break; + case 6: + anniversaryCategory = AnniversaryCategory.이사_집들이; + break; + case 7: + anniversaryCategory = AnniversaryCategory.출산; + break; + } + return anniversaryCategory; + } +} diff --git a/favor/src/main/java/com/favor/favor/common/enums/CategoryAnniversary.java b/favor/src/main/java/com/favor/favor/common/enums/CategoryAnniversary.java deleted file mode 100644 index 63346a3..0000000 --- a/favor/src/main/java/com/favor/favor/common/enums/CategoryAnniversary.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.favor.favor.common.enums; - -import lombok.Getter; - -public enum CategoryAnniversary { - 연인(1), - 축하_생일(2), - 졸업(3), - 합격(4), - 입사_승진(5), - 이사_집들이(6), - 출산(7); - - @Getter - Integer type; - - CategoryAnniversary(Integer type){ - this.type = type; - } - - public static CategoryAnniversary validateType(String category){ - try{ - return CategoryAnniversary.valueOf(category); - }catch(IllegalStateException e){ - throw new IllegalArgumentException(); - } - - } - - public static CategoryAnniversary valueOf(Integer type){ - CategoryAnniversary categoryAnniversary = null; - switch (type){ - case 1: - categoryAnniversary = CategoryAnniversary.연인; - break; - case 2: - categoryAnniversary = CategoryAnniversary.축하_생일; - break; - case 3: - categoryAnniversary = CategoryAnniversary.졸업; - break; - case 4: - categoryAnniversary = CategoryAnniversary.합격; - break; - case 5: - categoryAnniversary = CategoryAnniversary.입사_승진; - break; - case 6: - categoryAnniversary = CategoryAnniversary.이사_집들이; - break; - case 7: - categoryAnniversary = CategoryAnniversary.출산; - break; - } - return categoryAnniversary; - } -} diff --git a/favor/src/main/java/com/favor/favor/common/enums/CategoryGift.java b/favor/src/main/java/com/favor/favor/common/enums/GiftCategory.java similarity index 56% rename from favor/src/main/java/com/favor/favor/common/enums/CategoryGift.java rename to favor/src/main/java/com/favor/favor/common/enums/GiftCategory.java index 762875e..5731b5d 100644 --- a/favor/src/main/java/com/favor/favor/common/enums/CategoryGift.java +++ b/favor/src/main/java/com/favor/favor/common/enums/GiftCategory.java @@ -2,7 +2,7 @@ import lombok.Getter; -public enum CategoryGift { +public enum GiftCategory { // 가벼운선물, 생일, 집들이, 시험, 승진, 졸업, 기타 가벼운선물(1), 생일(2), @@ -14,46 +14,46 @@ public enum CategoryGift { @Getter Integer type; - CategoryGift(Integer type){ + GiftCategory(Integer type){ this.type = type; } - public static CategoryGift validateType(String category){ + public static GiftCategory validateType(String category){ try{ - return CategoryGift.valueOf(category); + return GiftCategory.valueOf(category); }catch(IllegalStateException e){ //커스텀 전 임시 throw new IllegalArgumentException(); } } - public static CategoryGift valueOf(Integer type){ - CategoryGift categoryGift = null; + public static GiftCategory valueOf(Integer type){ + GiftCategory giftCategory = null; switch (type){ case 1: - categoryGift = CategoryGift.가벼운선물; + giftCategory = GiftCategory.가벼운선물; break; case 2: - categoryGift = CategoryGift.생일; + giftCategory = GiftCategory.생일; break; case 3: - categoryGift = CategoryGift.집들이; + giftCategory = GiftCategory.집들이; break; case 4: - categoryGift = CategoryGift.시험; + giftCategory = GiftCategory.시험; break; case 5: - categoryGift = CategoryGift.승진; + giftCategory = GiftCategory.승진; break; case 6: - categoryGift = CategoryGift.졸업; + giftCategory = GiftCategory.졸업; break; case 7: - categoryGift = CategoryGift.기타; + giftCategory = GiftCategory.기타; break; default: break; } - return categoryGift; + return giftCategory; } } diff --git a/favor/src/main/java/com/favor/favor/friend/FriendController.java b/favor/src/main/java/com/favor/favor/friend/FriendController.java index 9e6fccb..5daa611 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendController.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendController.java @@ -3,6 +3,7 @@ import com.favor.favor.common.DefaultResponseDto; import com.favor.favor.gift.GiftResponseDto; +import com.favor.favor.gift.GiftSimpleDto; import com.favor.favor.user.User; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -71,7 +72,6 @@ public ResponseEntity> addFriend( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/{friendNo}") public ResponseEntity> readFriend( @PathVariable Long friendNo){ @@ -102,7 +102,6 @@ public ResponseEntity> readFriend( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @PatchMapping("/{friendNo}") public ResponseEntity> updateFriend( @PathVariable Long friendNo, @@ -137,7 +136,6 @@ public ResponseEntity> updateFriend( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @DeleteMapping("/{friendNo}") public ResponseEntity> deleteFriend( @PathVariable Long friendNo){ @@ -167,7 +165,6 @@ public ResponseEntity> deleteFriend( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/admin") public ResponseEntity> readAll(){ @@ -192,12 +189,11 @@ public ResponseEntity> readAll(){ message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/total-gifts/{friendNo}") public ResponseEntity> readTotalGiftList( @PathVariable Long friendNo){ friendService.isExistingFriendNo(friendNo); - List dto = friendService.findGiftListByFriendNo(friendNo); + List dto = friendService.findGiftListByFriendNo(friendNo); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -218,12 +214,11 @@ public ResponseEntity> readTotalGiftList( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/given-gifts/{friendNo}") public ResponseEntity> readGivenGiftList( @PathVariable Long friendNo){ // 유저 입장에서 받은 선물이므로 관련 친구가 준 선물임 friendService.isExistingFriendNo(friendNo); - List dto = friendService.findReceivedGiftList(friendNo); + List dto = friendService.findReceivedGiftList(friendNo); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -244,12 +239,11 @@ public ResponseEntity> readGivenGiftList( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/received-gifts/{friendNo}") public ResponseEntity> readReceivedGiftList( @PathVariable Long friendNo){// 유저 입장에서 준 선물이므로 관련 친구가 받은 선물임 friendService.isExistingFriendNo(friendNo); - List dto = friendService.findGivenGiftList(friendNo); + List dto = friendService.findGivenGiftList(friendNo); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() diff --git a/favor/src/main/java/com/favor/favor/friend/FriendService.java b/favor/src/main/java/com/favor/favor/friend/FriendService.java index 22e06f3..cd4d321 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendService.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendService.java @@ -7,6 +7,7 @@ import com.favor.favor.gift.Gift; import com.favor.favor.gift.GiftRepository; import com.favor.favor.gift.GiftResponseDto; +import com.favor.favor.gift.GiftSimpleDto; import com.favor.favor.reminder.Reminder; import com.favor.favor.reminder.ReminderResponseDto; import com.favor.favor.reminder.ReminderSimpleDto; @@ -45,7 +46,7 @@ public Boolean isDuplicateFriendUser(User user, User friendUser){ Boolean isDuplicate = false; List friendList = user.getFriendList(); for(Friend f : friendList){ - if(f.getFriendUserNo() == friendUser.getUserNo()) { + if(f.getFriendUserNo() == friendUser.getUserNo() || f.getFriendUserNo() == user.getUserNo()) { isDuplicate = true; break; } @@ -130,32 +131,32 @@ public Friend findFriendByFriendNo(Long friendNo){ } return friend; } - public List findGiftListByFriendNo(Long friendNo){ + public List findGiftListByFriendNo(Long friendNo){ List giftList = giftRepository.findGiftsByFriendNoListContains(friendNo); - List giftResponseDtoList = new ArrayList<>(); + List giftResponseDtoList = new ArrayList<>(); for(Gift gift : giftList){ - GiftResponseDto dto = new GiftResponseDto(gift); + GiftSimpleDto dto = new GiftSimpleDto(gift); giftResponseDtoList.add(dto); } return giftResponseDtoList; } - public List findGivenGiftList(Long friendNo){ + public List findGivenGiftList(Long friendNo){ List giftList = giftRepository.findGiftsByFriendNoListContains(friendNo); - List giftResponseDtoList = new ArrayList<>(); + List giftResponseDtoList = new ArrayList<>(); for(Gift gift : giftList){ if(gift.getIsGiven()){ - GiftResponseDto dto = new GiftResponseDto(gift); + GiftSimpleDto dto = new GiftSimpleDto(gift); giftResponseDtoList.add(dto); } } return giftResponseDtoList; } - public List findReceivedGiftList(Long friendNo){ + public List findReceivedGiftList(Long friendNo){ List giftList = giftRepository.findGiftsByFriendNoListContains(friendNo); - List giftResponseDtoList = new ArrayList<>(); + List giftResponseDtoList = new ArrayList<>(); for(Gift gift : giftList){ if(!gift.getIsGiven()){ - GiftResponseDto dto = new GiftResponseDto(gift); + GiftSimpleDto dto = new GiftSimpleDto(gift); giftResponseDtoList.add(dto); } } diff --git a/favor/src/main/java/com/favor/favor/friend/FriendSimpleDto.java b/favor/src/main/java/com/favor/favor/friend/FriendSimpleDto.java index 2b1f007..74de5fd 100644 --- a/favor/src/main/java/com/favor/favor/friend/FriendSimpleDto.java +++ b/favor/src/main/java/com/favor/favor/friend/FriendSimpleDto.java @@ -11,14 +11,12 @@ public class FriendSimpleDto { private Long friendNo; private String friendName; - private Long userNo; - private String photo; + private UserPhoto photo; @Builder public FriendSimpleDto(Friend friend, User friendUser, UserPhoto photo){ this.friendNo = friend.getFriendNo(); this.friendName = friendUser.getName(); - this.userNo = friend.getFriendUserNo(); - this.photo = photo.getPhotoUrl(); + this.photo = photo; } } diff --git a/favor/src/main/java/com/favor/favor/gift/Gift.java b/favor/src/main/java/com/favor/favor/gift/Gift.java index 2f1b2d3..0c5ba88 100644 --- a/favor/src/main/java/com/favor/favor/gift/Gift.java +++ b/favor/src/main/java/com/favor/favor/gift/Gift.java @@ -1,11 +1,12 @@ package com.favor.favor.gift; -import com.favor.favor.common.enums.CategoryGift; +import com.favor.favor.common.enums.GiftCategory; import com.favor.favor.common.enums.Emotion; import com.favor.favor.common.TimeStamped; import com.favor.favor.photo.GiftPhoto; import com.favor.favor.user.User; import lombok.*; +import org.springframework.lang.Nullable; import javax.persistence.*; import java.time.LocalDate; @@ -28,19 +29,21 @@ public void setGiftName(String giftName){ this.giftName = giftName; } + @Nullable private LocalDate giftDate; public void setGiftDate(LocalDate giftDate){ this.giftDate = giftDate; } + @Nullable private String giftMemo; public void setGiftMemo(String giftMemo){ this.giftMemo = giftMemo; } private Integer category; - public void setCategory(CategoryGift categoryGift){ - this.category = categoryGift.getType(); + public void setCategory(GiftCategory giftCategory){ + this.category = giftCategory.getType(); } private Integer emotion; @@ -65,6 +68,7 @@ public void setIsGiven(Boolean isGiven){ private User user; public void setUser(User user) { this.user = user; } + @Nullable @Builder.Default @ElementCollection private List friendNoList = new ArrayList<>(); @@ -82,6 +86,7 @@ public void setGiftPhotoList(List giftPhotoList) { this.giftPhotoList = giftPhotoList; } + @Nullable @ElementCollection private List tempFriendList; public void setTempFriendList(GiftTempFriendListDto tempFriendList){ diff --git a/favor/src/main/java/com/favor/favor/gift/GiftController.java b/favor/src/main/java/com/favor/favor/gift/GiftController.java index 8c7dfb9..4fc2207 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftController.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftController.java @@ -73,7 +73,6 @@ public ResponseEntity> createGift( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/{giftNo}") public ResponseEntity> readGift( @PathVariable Long giftNo){ @@ -105,7 +104,6 @@ public ResponseEntity> readGift( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @PatchMapping("/{giftNo}") public ResponseEntity> updateGift( @RequestBody GiftUpdateRequestDto giftUpdateRequestDto, @@ -139,7 +137,6 @@ public ResponseEntity> updateGift( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @PatchMapping("/temp-friend-list/{giftNo}") public ResponseEntity> updateTempFriendListGift( @PathVariable Long giftNo, @@ -174,7 +171,6 @@ public ResponseEntity> updateTempFriendListGift( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @PatchMapping("/pin/{giftNo}") public ResponseEntity> updateIsPinned( @PathVariable Long giftNo){ @@ -207,7 +203,6 @@ public ResponseEntity> updateIsPinned( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @DeleteMapping("/{giftNo}") public ResponseEntity> deleteGift( @PathVariable Long giftNo){ @@ -244,7 +239,6 @@ public ResponseEntity> deleteGift( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/admin") public ResponseEntity> readAll(){ diff --git a/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java b/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java index 7bef06d..9817e1e 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftRequestDto.java @@ -1,12 +1,13 @@ package com.favor.favor.gift; -import com.favor.favor.common.enums.CategoryGift; +import com.favor.favor.common.enums.GiftCategory; import com.favor.favor.common.enums.Emotion; import com.favor.favor.user.User; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.lang.Nullable; import javax.transaction.Transactional; import javax.validation.constraints.NotNull; @@ -23,15 +24,17 @@ public class GiftRequestDto { private String giftName; @ApiModelProperty(position = 2, required = false, value = "선물날짜", example = "1996-02-29") - @NotNull + @Nullable private String giftDate; + @ApiModelProperty(position = 3, required = false, value = "선물메모", example = "선물메모") + @Nullable private String giftMemo; @ApiModelProperty(position = 4, required = false, value = "카테고리", example = "생일") @NotNull - private CategoryGift categoryGift; + private GiftCategory giftCategory; @ApiModelProperty(position = 5, required = false, value = "감정", example = "기뻐요") private Emotion emotion; @@ -45,9 +48,11 @@ public class GiftRequestDto { private Boolean isGiven; @ApiModelProperty(position = 8, required = false, value = "연관친구 리스트", example = "[1]") + @Nullable private List friendNoList; @ApiModelProperty(position = 9, required = true, value = "임시친구 리스트", example = "[\"차은우\", \"카리나\"]") + @Nullable private List tempFriendList; @Transactional @@ -56,7 +61,7 @@ public Gift toEntity(User user, LocalDate giftDate){ .giftName(giftName) .giftDate(giftDate) .giftMemo(giftMemo) - .category(categoryGift.getType()) + .category(giftCategory.getType()) .emotion(emotion.getType()) .isPinned(false) .isGiven(isGiven) diff --git a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java index 038b097..e2a714d 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftResponseDto.java @@ -1,8 +1,7 @@ package com.favor.favor.gift; -import com.favor.favor.common.enums.CategoryGift; +import com.favor.favor.common.enums.GiftCategory; import com.favor.favor.common.enums.Emotion; -import com.favor.favor.friend.FriendResponseDto; import com.favor.favor.friend.FriendSimpleDto; import com.favor.favor.photo.GiftPhoto; import lombok.AllArgsConstructor; @@ -27,7 +26,7 @@ public class GiftResponseDto { private String giftName; private LocalDate giftDate; private String giftMemo; - private CategoryGift categoryGift; + private GiftCategory giftCategory; private Emotion emotion; private Boolean isPinned; private Boolean isGiven; @@ -46,7 +45,7 @@ public GiftResponseDto(Gift gift){ this.giftName = gift.getGiftName(); this.giftDate = gift.getGiftDate(); this.giftMemo = gift.getGiftMemo(); - this.categoryGift = CategoryGift.valueOf(gift.getCategory()); + this.giftCategory = GiftCategory.valueOf(gift.getCategory()); this.emotion = Emotion.valueOf(gift.getEmotion()); this.isPinned = gift.getIsPinned(); this.isGiven = gift.getIsGiven(); @@ -65,7 +64,7 @@ public GiftResponseDto(Gift gift, List friendList){ this.giftName = gift.getGiftName(); this.giftDate = gift.getGiftDate(); this.giftMemo = gift.getGiftMemo(); - this.categoryGift = CategoryGift.valueOf(gift.getCategory()); + this.giftCategory = GiftCategory.valueOf(gift.getCategory()); this.emotion = Emotion.valueOf(gift.getEmotion()); this.isPinned = gift.getIsPinned(); this.isGiven = gift.getIsGiven(); diff --git a/favor/src/main/java/com/favor/favor/gift/GiftService.java b/favor/src/main/java/com/favor/favor/gift/GiftService.java index 95b3375..e581a39 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftService.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftService.java @@ -3,7 +3,6 @@ import com.favor.favor.exception.CustomException; import com.favor.favor.friend.Friend; import com.favor.favor.friend.FriendRepository; -import com.favor.favor.friend.FriendResponseDto; import com.favor.favor.friend.FriendSimpleDto; import com.favor.favor.photo.UserPhoto; import com.favor.favor.user.User; @@ -55,11 +54,12 @@ public void addGiftNo(Long giftNo, List friendNoList){ } } + @Transactional public void updateGift(GiftUpdateRequestDto dto, Gift gift){ //수정된 gift 정보 저장 (친구 목록 제외) gift.setGiftName(dto.getGiftName()); gift.setGiftMemo(dto.getGiftMemo()); - gift.setCategory(dto.getCategoryGift()); + gift.setCategory(dto.getGiftCategory()); gift.setEmotion(dto.getEmotion()); gift.setIsGiven(dto.getIsGiven()); gift.setGiftDate(returnLocalDate(dto.getGiftDate())); @@ -69,6 +69,7 @@ public void updateGift(GiftUpdateRequestDto dto, Gift gift){ //친구 목록 수정 시 //빠진 친구들의 선물 목록에서 선물 식별자 삭제 + //@Transactional 없는 경우 ConcurrentModificationException 발생 for (Long friendNo : existingFriendNoList) { if (!updatedFriendNoList.contains(friendNo)) { Friend friend = findFriendByFriendNo(friendNo); @@ -90,6 +91,7 @@ public void updateGift(GiftUpdateRequestDto dto, Gift gift){ } giftRepository.save(gift); } + public void updateIsPinned(Gift gift){ gift.setIsPinned(gift.getIsPinned() == true ? false : true); giftRepository.save(gift); diff --git a/favor/src/main/java/com/favor/favor/gift/GiftUpdateRequestDto.java b/favor/src/main/java/com/favor/favor/gift/GiftUpdateRequestDto.java index 0409fac..2846b64 100644 --- a/favor/src/main/java/com/favor/favor/gift/GiftUpdateRequestDto.java +++ b/favor/src/main/java/com/favor/favor/gift/GiftUpdateRequestDto.java @@ -1,6 +1,6 @@ package com.favor.favor.gift; -import com.favor.favor.common.enums.CategoryGift; +import com.favor.favor.common.enums.GiftCategory; import com.favor.favor.common.enums.Emotion; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; @@ -23,7 +23,7 @@ public class GiftUpdateRequestDto { private String giftMemo; @ApiModelProperty(position = 4, required = false, value = "카데고리", example = "생일") - private CategoryGift categoryGift; + private GiftCategory giftCategory; @ApiModelProperty(position = 5, required = false, value = "감정", example = "기뻐요") private Emotion emotion; diff --git a/favor/src/main/java/com/favor/favor/reminder/ReminderController.java b/favor/src/main/java/com/favor/favor/reminder/ReminderController.java index cf86194..0ffb1b3 100644 --- a/favor/src/main/java/com/favor/favor/reminder/ReminderController.java +++ b/favor/src/main/java/com/favor/favor/reminder/ReminderController.java @@ -108,7 +108,6 @@ public ResponseEntity> addReminder( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/{reminderNo}") public ResponseEntity> readReminder( @PathVariable Long reminderNo){ @@ -138,7 +137,6 @@ public ResponseEntity> readReminder( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @PatchMapping("/{reminderNo}") public ResponseEntity> updateReminder( @RequestBody ReminderUpdateRequestDto reminderUpdateRequestDto, @@ -171,7 +169,6 @@ public ResponseEntity> updateReminder( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @DeleteMapping("/{reminderNo}") public ResponseEntity> deleteReminder( @PathVariable Long reminderNo){ @@ -202,7 +199,6 @@ public ResponseEntity> deleteReminder( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/admin") public ResponseEntity> readAll(){ diff --git a/favor/src/main/java/com/favor/favor/user/UserController.java b/favor/src/main/java/com/favor/favor/user/UserController.java index b6329cc..2924ecb 100644 --- a/favor/src/main/java/com/favor/favor/user/UserController.java +++ b/favor/src/main/java/com/favor/favor/user/UserController.java @@ -3,7 +3,7 @@ import com.favor.favor.anniversary.AnniversaryResponseDto; import com.favor.favor.common.DefaultResponseDto; -import com.favor.favor.common.enums.CategoryGift; +import com.favor.favor.common.enums.GiftCategory; import com.favor.favor.common.enums.Emotion; import com.favor.favor.friend.FriendResponseDto; import com.favor.favor.friend.FriendSimpleDto; @@ -18,7 +18,6 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; -import javax.transaction.Transactional; import javax.validation.Valid; import java.util.List; @@ -82,7 +81,6 @@ public ResponseEntity> signUp( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.CREATED) - @Transactional @PatchMapping("/profile") public ResponseEntity> createProfile( @RequestBody @Valid ProfileDto profileDto, @@ -149,7 +147,6 @@ public ResponseEntity> signIn( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping public ResponseEntity> readUser( @AuthenticationPrincipal User loginUser @@ -184,7 +181,6 @@ public ResponseEntity> readUser( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @PatchMapping public ResponseEntity> updateUser( @AuthenticationPrincipal User loginUser, @@ -221,7 +217,6 @@ public ResponseEntity> updateUser( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @DeleteMapping public ResponseEntity> deleteUser( @AuthenticationPrincipal User loginUser){ @@ -259,7 +254,6 @@ public ResponseEntity> deleteUser( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @PatchMapping("/password") public ResponseEntity> updatePassword( @RequestBody @Valid UserUpdatePasswordRequestDto passwordDto){ @@ -291,7 +285,6 @@ public ResponseEntity> updatePassword( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/reminders") public ResponseEntity> readReminderList( @AuthenticationPrincipal User loginUser){ @@ -322,7 +315,6 @@ public ResponseEntity> readReminderList( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/reminders/{year}/{month}") public ResponseEntity> readReminderListByFMonthAndYear( @AuthenticationPrincipal User loginUser, @@ -356,7 +348,6 @@ public ResponseEntity> readReminderListByFMonthAndYea message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/gifts") public ResponseEntity> readGiftList( @AuthenticationPrincipal User loginUser){ @@ -388,7 +379,6 @@ public ResponseEntity> readGiftList( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/friends") public ResponseEntity> readFriendList( @AuthenticationPrincipal User loginUser){ @@ -420,7 +410,6 @@ public ResponseEntity> readFriendList( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/anniversaries") public ResponseEntity> readAnniversaryList( @AuthenticationPrincipal User loginUser){ @@ -451,7 +440,6 @@ public ResponseEntity> readAnniversaryList( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/admin") public ResponseEntity> readAll(){ @@ -479,7 +467,6 @@ public ResponseEntity> readAll(){ message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/gifts-by-name/{giftName}") public ResponseEntity> readGiftListByName ( @AuthenticationPrincipal User loginUser, @@ -512,16 +499,15 @@ public ResponseEntity> readGiftListByName ( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/gifts-by-category/{category}") public ResponseEntity> readGiftListByCategory( @AuthenticationPrincipal User loginUser, - @PathVariable("category") CategoryGift categoryGift){ + @PathVariable("category") GiftCategory giftCategory){ Long userNo = loginUser.getUserNo(); userService.isExistingUserNo(userNo); - List dto = userService.readGiftListByCategory(userNo, categoryGift); + List dto = userService.readGiftListByCategory(userNo, giftCategory); return ResponseEntity.status(200) .body(DefaultResponseDto.builder() @@ -544,7 +530,6 @@ public ResponseEntity> readGiftListByCategory( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/gifts-by-emotion/{emotion}") public ResponseEntity> readGiftListByEmotion( @AuthenticationPrincipal User loginUser, @@ -576,7 +561,6 @@ public ResponseEntity> readGiftListByEmotion( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/{userId}") public ResponseEntity> readUserByUserId( @PathVariable("userId") String userId){ @@ -603,7 +587,6 @@ public ResponseEntity> readUserByUserId( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/gifts-given") public ResponseEntity> readGivenGiftList( @AuthenticationPrincipal User loginUser){ @@ -631,7 +614,6 @@ public ResponseEntity> readGivenGiftList( message = "SERVER_ERROR") }) @ResponseStatus(HttpStatus.OK) - @Transactional @GetMapping("/gifts-received") public ResponseEntity> readReceivedGiftList( @AuthenticationPrincipal User loginUser){ diff --git a/favor/src/main/java/com/favor/favor/user/UserService.java b/favor/src/main/java/com/favor/favor/user/UserService.java index 169c467..d593518 100644 --- a/favor/src/main/java/com/favor/favor/user/UserService.java +++ b/favor/src/main/java/com/favor/favor/user/UserService.java @@ -3,13 +3,12 @@ import com.favor.favor.anniversary.Anniversary; import com.favor.favor.anniversary.AnniversaryResponseDto; import com.favor.favor.auth.JwtTokenProvider; -import com.favor.favor.common.enums.CategoryGift; +import com.favor.favor.common.enums.GiftCategory; import com.favor.favor.common.enums.Emotion; import com.favor.favor.common.enums.Favor; import com.favor.favor.common.enums.Role; import com.favor.favor.exception.CustomException; import com.favor.favor.friend.Friend; -import com.favor.favor.friend.FriendResponseDto; import com.favor.favor.friend.FriendRepository; import com.favor.favor.friend.FriendSimpleDto; import com.favor.favor.gift.*; @@ -17,7 +16,6 @@ import com.favor.favor.photo.UserPhoto; import com.favor.favor.reminder.Reminder; import com.favor.favor.reminder.ReminderRepository; -import com.favor.favor.reminder.ReminderResponseDto; import com.favor.favor.reminder.ReminderSimpleDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -202,9 +200,9 @@ public List readGiftListByName(Long userNo, String giftName){ return g_List; } - public List readGiftListByCategory(Long userNo, CategoryGift categoryGift){ + public List readGiftListByCategory(Long userNo, GiftCategory giftCategory){ User user = findUserByUserNo(userNo); - Integer categoryNo = categoryGift.getType(); + Integer categoryNo = giftCategory.getType(); List giftList = giftRepository.findGiftsByUserAndCategory(user, categoryNo); List g_List = new ArrayList<>(); for(Gift gift : giftList){