From 69a710b7917957276cc320737a8d71afc1e3eb2d Mon Sep 17 00:00:00 2001 From: jungyoeal Date: Fri, 27 Sep 2024 11:40:11 +0900 Subject: [PATCH 01/24] =?UTF-8?q?=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EB=A7=8C=ED=95=A8=20=EC=9D=B4=EC=99=B8=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=EB=8A=94=20=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../prgrms2/java/bitta/scoutRequest/entity/ScoutRequest.java | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/java/com/prgrms2/java/bitta/scoutRequest/entity/ScoutRequest.java diff --git a/src/main/java/com/prgrms2/java/bitta/scoutRequest/entity/ScoutRequest.java b/src/main/java/com/prgrms2/java/bitta/scoutRequest/entity/ScoutRequest.java new file mode 100644 index 0000000..deb5b5a --- /dev/null +++ b/src/main/java/com/prgrms2/java/bitta/scoutRequest/entity/ScoutRequest.java @@ -0,0 +1,2 @@ +package com.prgrms2.java.bitta.scoutRequest.entity;public class ScoutRequest { +} From 96ceac25f43a77f3fd77d9a431728e3dd0ce0261 Mon Sep 17 00:00:00 2001 From: juwon-code Date: Thu, 26 Sep 2024 17:52:12 +0900 Subject: [PATCH 02/24] =?UTF-8?q?rename:=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=20=ED=8C=A8=ED=82=A4=EC=A7=80=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=ED=98=BC=EB=8F=99=EB=90=98=EB=8A=94=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=EA=B0=80=20=EC=9E=88=EC=96=B4?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95=ED=95=A9=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - xenum -> 각 도메인의 entity로 이동 - security 패키지를 삭제하고, token과 global 패키지로 분리 - global/exception -> 각 도메인의 exception으로 이동 --- .../bitta/{ => global}/config/CustomSecurityConfig.java | 4 ++-- .../java/bitta/{ => global}/config/JpaAuditConfig.java | 2 +- .../java/com/prgrms2/java/bitta/jobpost/dto/JobPostDTO.java | 4 ++-- .../java/com/prgrms2/java/bitta/jobpost/entity/JobPost.java | 2 -- .../java/bitta/{xenum => jobpost/entity}/Location.java | 2 +- .../java/bitta/{xenum => jobpost/entity}/PayStatus.java | 2 +- .../{security => token/controller}/TokenController.java | 4 ++-- .../bitta/{security => token}/filter/JWTCheckFilter.java | 6 +++--- .../java/bitta/{security => token}/util/JWTUtil.java | 2 +- .../{ => user/controller}/advice/TokenControllerAdvice.java | 4 ++-- src/main/java/com/prgrms2/java/bitta/user/dto/UserDTO.java | 2 +- .../{security/auth => user/entity}/CustomUserPrincipal.java | 3 +-- .../com/prgrms2/java/bitta/{xenum => user/entity}/Role.java | 2 +- src/main/java/com/prgrms2/java/bitta/user/entity/User.java | 1 - .../java/bitta/{gobal => user}/exception/UserException.java | 2 +- .../bitta/{gobal => user}/exception/UserTaskException.java | 2 +- .../com/prgrms2/java/bitta/user/service/UserService.java | 2 +- .../prgrms2/java/bitta/repository/UserRepositoryTest.java | 2 +- 18 files changed, 22 insertions(+), 26 deletions(-) rename src/main/java/com/prgrms2/java/bitta/{ => global}/config/CustomSecurityConfig.java (96%) rename src/main/java/com/prgrms2/java/bitta/{ => global}/config/JpaAuditConfig.java (81%) rename src/main/java/com/prgrms2/java/bitta/{xenum => jobpost/entity}/Location.java (79%) rename src/main/java/com/prgrms2/java/bitta/{xenum => jobpost/entity}/PayStatus.java (62%) rename src/main/java/com/prgrms2/java/bitta/{security => token/controller}/TokenController.java (98%) rename src/main/java/com/prgrms2/java/bitta/{security => token}/filter/JWTCheckFilter.java (96%) rename src/main/java/com/prgrms2/java/bitta/{security => token}/util/JWTUtil.java (97%) rename src/main/java/com/prgrms2/java/bitta/{ => user/controller}/advice/TokenControllerAdvice.java (89%) rename src/main/java/com/prgrms2/java/bitta/{security/auth => user/entity}/CustomUserPrincipal.java (84%) rename src/main/java/com/prgrms2/java/bitta/{xenum => user/entity}/Role.java (56%) rename src/main/java/com/prgrms2/java/bitta/{gobal => user}/exception/UserException.java (89%) rename src/main/java/com/prgrms2/java/bitta/{gobal => user}/exception/UserTaskException.java (80%) diff --git a/src/main/java/com/prgrms2/java/bitta/config/CustomSecurityConfig.java b/src/main/java/com/prgrms2/java/bitta/global/config/CustomSecurityConfig.java similarity index 96% rename from src/main/java/com/prgrms2/java/bitta/config/CustomSecurityConfig.java rename to src/main/java/com/prgrms2/java/bitta/global/config/CustomSecurityConfig.java index 45429f3..d3d2d51 100644 --- a/src/main/java/com/prgrms2/java/bitta/config/CustomSecurityConfig.java +++ b/src/main/java/com/prgrms2/java/bitta/global/config/CustomSecurityConfig.java @@ -1,6 +1,6 @@ -package com.prgrms2.java.bitta.config; +package com.prgrms2.java.bitta.global.config; -import com.prgrms2.java.bitta.security.filter.JWTCheckFilter; +import com.prgrms2.java.bitta.token.filter.JWTCheckFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/prgrms2/java/bitta/config/JpaAuditConfig.java b/src/main/java/com/prgrms2/java/bitta/global/config/JpaAuditConfig.java similarity index 81% rename from src/main/java/com/prgrms2/java/bitta/config/JpaAuditConfig.java rename to src/main/java/com/prgrms2/java/bitta/global/config/JpaAuditConfig.java index 080f4d9..4ab2545 100644 --- a/src/main/java/com/prgrms2/java/bitta/config/JpaAuditConfig.java +++ b/src/main/java/com/prgrms2/java/bitta/global/config/JpaAuditConfig.java @@ -1,4 +1,4 @@ -package com.prgrms2.java.bitta.config; +package com.prgrms2.java.bitta.global.config; import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; diff --git a/src/main/java/com/prgrms2/java/bitta/jobpost/dto/JobPostDTO.java b/src/main/java/com/prgrms2/java/bitta/jobpost/dto/JobPostDTO.java index ee02e7b..5bf6f92 100644 --- a/src/main/java/com/prgrms2/java/bitta/jobpost/dto/JobPostDTO.java +++ b/src/main/java/com/prgrms2/java/bitta/jobpost/dto/JobPostDTO.java @@ -1,8 +1,8 @@ package com.prgrms2.java.bitta.jobpost.dto; import com.prgrms2.java.bitta.jobpost.entity.JobPost; -import com.prgrms2.java.bitta.xenum.Location; -import com.prgrms2.java.bitta.xenum.PayStatus; +import com.prgrms2.java.bitta.jobpost.entity.Location; +import com.prgrms2.java.bitta.jobpost.entity.PayStatus; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/prgrms2/java/bitta/jobpost/entity/JobPost.java b/src/main/java/com/prgrms2/java/bitta/jobpost/entity/JobPost.java index 7bcfc42..50a1891 100644 --- a/src/main/java/com/prgrms2/java/bitta/jobpost/entity/JobPost.java +++ b/src/main/java/com/prgrms2/java/bitta/jobpost/entity/JobPost.java @@ -1,7 +1,5 @@ package com.prgrms2.java.bitta.jobpost.entity; -import com.prgrms2.java.bitta.xenum.Location; -import com.prgrms2.java.bitta.xenum.PayStatus; import com.prgrms2.java.bitta.application.entity.PostApplication; import com.prgrms2.java.bitta.user.entity.User; import jakarta.persistence.*; diff --git a/src/main/java/com/prgrms2/java/bitta/xenum/Location.java b/src/main/java/com/prgrms2/java/bitta/jobpost/entity/Location.java similarity index 79% rename from src/main/java/com/prgrms2/java/bitta/xenum/Location.java rename to src/main/java/com/prgrms2/java/bitta/jobpost/entity/Location.java index d812eed..25e8665 100644 --- a/src/main/java/com/prgrms2/java/bitta/xenum/Location.java +++ b/src/main/java/com/prgrms2/java/bitta/jobpost/entity/Location.java @@ -1,4 +1,4 @@ -package com.prgrms2.java.bitta.xenum; +package com.prgrms2.java.bitta.jobpost.entity; public enum Location { SEOUL, BUSAN, INCHEON, DAEJEON, diff --git a/src/main/java/com/prgrms2/java/bitta/xenum/PayStatus.java b/src/main/java/com/prgrms2/java/bitta/jobpost/entity/PayStatus.java similarity index 62% rename from src/main/java/com/prgrms2/java/bitta/xenum/PayStatus.java rename to src/main/java/com/prgrms2/java/bitta/jobpost/entity/PayStatus.java index e4c7f91..e8c1d2a 100644 --- a/src/main/java/com/prgrms2/java/bitta/xenum/PayStatus.java +++ b/src/main/java/com/prgrms2/java/bitta/jobpost/entity/PayStatus.java @@ -1,4 +1,4 @@ -package com.prgrms2.java.bitta.xenum; +package com.prgrms2.java.bitta.jobpost.entity; public enum PayStatus { FREE, PAID // 모집 방식 (무급, 유급) diff --git a/src/main/java/com/prgrms2/java/bitta/security/TokenController.java b/src/main/java/com/prgrms2/java/bitta/token/controller/TokenController.java similarity index 98% rename from src/main/java/com/prgrms2/java/bitta/security/TokenController.java rename to src/main/java/com/prgrms2/java/bitta/token/controller/TokenController.java index aef5532..decbc7f 100644 --- a/src/main/java/com/prgrms2/java/bitta/security/TokenController.java +++ b/src/main/java/com/prgrms2/java/bitta/token/controller/TokenController.java @@ -1,7 +1,7 @@ -package com.prgrms2.java.bitta.security; +package com.prgrms2.java.bitta.token.controller; import com.prgrms2.java.bitta.user.dto.UserDTO; -import com.prgrms2.java.bitta.security.util.JWTUtil; +import com.prgrms2.java.bitta.token.util.JWTUtil; import com.prgrms2.java.bitta.user.service.UserService; import io.jsonwebtoken.ExpiredJwtException; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/prgrms2/java/bitta/security/filter/JWTCheckFilter.java b/src/main/java/com/prgrms2/java/bitta/token/filter/JWTCheckFilter.java similarity index 96% rename from src/main/java/com/prgrms2/java/bitta/security/filter/JWTCheckFilter.java rename to src/main/java/com/prgrms2/java/bitta/token/filter/JWTCheckFilter.java index 3d50e3d..bec9ecb 100644 --- a/src/main/java/com/prgrms2/java/bitta/security/filter/JWTCheckFilter.java +++ b/src/main/java/com/prgrms2/java/bitta/token/filter/JWTCheckFilter.java @@ -1,8 +1,8 @@ -package com.prgrms2.java.bitta.security.filter; +package com.prgrms2.java.bitta.token.filter; -import com.prgrms2.java.bitta.security.auth.CustomUserPrincipal; -import com.prgrms2.java.bitta.security.util.JWTUtil; +import com.prgrms2.java.bitta.user.entity.CustomUserPrincipal; +import com.prgrms2.java.bitta.token.util.JWTUtil; import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; diff --git a/src/main/java/com/prgrms2/java/bitta/security/util/JWTUtil.java b/src/main/java/com/prgrms2/java/bitta/token/util/JWTUtil.java similarity index 97% rename from src/main/java/com/prgrms2/java/bitta/security/util/JWTUtil.java rename to src/main/java/com/prgrms2/java/bitta/token/util/JWTUtil.java index 4ed27df..891bd0f 100644 --- a/src/main/java/com/prgrms2/java/bitta/security/util/JWTUtil.java +++ b/src/main/java/com/prgrms2/java/bitta/token/util/JWTUtil.java @@ -1,4 +1,4 @@ -package com.prgrms2.java.bitta.security.util; +package com.prgrms2.java.bitta.token.util; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; diff --git a/src/main/java/com/prgrms2/java/bitta/advice/TokenControllerAdvice.java b/src/main/java/com/prgrms2/java/bitta/user/controller/advice/TokenControllerAdvice.java similarity index 89% rename from src/main/java/com/prgrms2/java/bitta/advice/TokenControllerAdvice.java rename to src/main/java/com/prgrms2/java/bitta/user/controller/advice/TokenControllerAdvice.java index a7d9d51..b9359c1 100644 --- a/src/main/java/com/prgrms2/java/bitta/advice/TokenControllerAdvice.java +++ b/src/main/java/com/prgrms2/java/bitta/user/controller/advice/TokenControllerAdvice.java @@ -1,6 +1,6 @@ -package com.prgrms2.java.bitta.advice; +package com.prgrms2.java.bitta.user.controller.advice; -import com.prgrms2.java.bitta.gobal.exception.UserTaskException; +import com.prgrms2.java.bitta.user.exception.UserTaskException; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.authorization.AuthorizationDeniedException; diff --git a/src/main/java/com/prgrms2/java/bitta/user/dto/UserDTO.java b/src/main/java/com/prgrms2/java/bitta/user/dto/UserDTO.java index d72ca31..9d4e2d8 100644 --- a/src/main/java/com/prgrms2/java/bitta/user/dto/UserDTO.java +++ b/src/main/java/com/prgrms2/java/bitta/user/dto/UserDTO.java @@ -1,6 +1,6 @@ package com.prgrms2.java.bitta.user.dto; -import com.prgrms2.java.bitta.xenum.Role; +import com.prgrms2.java.bitta.user.entity.Role; import com.prgrms2.java.bitta.user.entity.User; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/prgrms2/java/bitta/security/auth/CustomUserPrincipal.java b/src/main/java/com/prgrms2/java/bitta/user/entity/CustomUserPrincipal.java similarity index 84% rename from src/main/java/com/prgrms2/java/bitta/security/auth/CustomUserPrincipal.java rename to src/main/java/com/prgrms2/java/bitta/user/entity/CustomUserPrincipal.java index 7fe3f27..5082e3f 100644 --- a/src/main/java/com/prgrms2/java/bitta/security/auth/CustomUserPrincipal.java +++ b/src/main/java/com/prgrms2/java/bitta/user/entity/CustomUserPrincipal.java @@ -1,4 +1,4 @@ -package com.prgrms2.java.bitta.security.auth; +package com.prgrms2.java.bitta.user.entity; import lombok.RequiredArgsConstructor; @@ -8,7 +8,6 @@ public class CustomUserPrincipal implements Principal { private final String email; - @Override public String getName() { return email; diff --git a/src/main/java/com/prgrms2/java/bitta/xenum/Role.java b/src/main/java/com/prgrms2/java/bitta/user/entity/Role.java similarity index 56% rename from src/main/java/com/prgrms2/java/bitta/xenum/Role.java rename to src/main/java/com/prgrms2/java/bitta/user/entity/Role.java index d64227b..424ac1f 100644 --- a/src/main/java/com/prgrms2/java/bitta/xenum/Role.java +++ b/src/main/java/com/prgrms2/java/bitta/user/entity/Role.java @@ -1,4 +1,4 @@ -package com.prgrms2.java.bitta.xenum; +package com.prgrms2.java.bitta.user.entity; public enum Role { Actor, diff --git a/src/main/java/com/prgrms2/java/bitta/user/entity/User.java b/src/main/java/com/prgrms2/java/bitta/user/entity/User.java index 44a1ae6..95b8525 100644 --- a/src/main/java/com/prgrms2/java/bitta/user/entity/User.java +++ b/src/main/java/com/prgrms2/java/bitta/user/entity/User.java @@ -1,7 +1,6 @@ package com.prgrms2.java.bitta.user.entity; -import com.prgrms2.java.bitta.xenum.Role; import jakarta.persistence.*; import lombok.*; import org.springframework.data.annotation.CreatedDate; diff --git a/src/main/java/com/prgrms2/java/bitta/gobal/exception/UserException.java b/src/main/java/com/prgrms2/java/bitta/user/exception/UserException.java similarity index 89% rename from src/main/java/com/prgrms2/java/bitta/gobal/exception/UserException.java rename to src/main/java/com/prgrms2/java/bitta/user/exception/UserException.java index bf184c7..53dabed 100644 --- a/src/main/java/com/prgrms2/java/bitta/gobal/exception/UserException.java +++ b/src/main/java/com/prgrms2/java/bitta/user/exception/UserException.java @@ -1,4 +1,4 @@ -package com.prgrms2.java.bitta.gobal.exception; +package com.prgrms2.java.bitta.user.exception; public enum UserException { NOT_FOUND("NOT_FOUND", 404), diff --git a/src/main/java/com/prgrms2/java/bitta/gobal/exception/UserTaskException.java b/src/main/java/com/prgrms2/java/bitta/user/exception/UserTaskException.java similarity index 80% rename from src/main/java/com/prgrms2/java/bitta/gobal/exception/UserTaskException.java rename to src/main/java/com/prgrms2/java/bitta/user/exception/UserTaskException.java index 1ee22bc..af751eb 100644 --- a/src/main/java/com/prgrms2/java/bitta/gobal/exception/UserTaskException.java +++ b/src/main/java/com/prgrms2/java/bitta/user/exception/UserTaskException.java @@ -1,4 +1,4 @@ -package com.prgrms2.java.bitta.gobal.exception; +package com.prgrms2.java.bitta.user.exception; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/prgrms2/java/bitta/user/service/UserService.java b/src/main/java/com/prgrms2/java/bitta/user/service/UserService.java index e1e7c25..298dacf 100644 --- a/src/main/java/com/prgrms2/java/bitta/user/service/UserService.java +++ b/src/main/java/com/prgrms2/java/bitta/user/service/UserService.java @@ -2,7 +2,7 @@ import com.prgrms2.java.bitta.user.dto.UserDTO; import com.prgrms2.java.bitta.user.entity.User; -import com.prgrms2.java.bitta.gobal.exception.UserException; +import com.prgrms2.java.bitta.user.exception.UserException; import com.prgrms2.java.bitta.user.repository.UserRepository; import lombok.RequiredArgsConstructor; import lombok.extern.log4j.Log4j2; diff --git a/src/test/java/com/prgrms2/java/bitta/repository/UserRepositoryTest.java b/src/test/java/com/prgrms2/java/bitta/repository/UserRepositoryTest.java index 259f544..6ba8984 100644 --- a/src/test/java/com/prgrms2/java/bitta/repository/UserRepositoryTest.java +++ b/src/test/java/com/prgrms2/java/bitta/repository/UserRepositoryTest.java @@ -1,7 +1,7 @@ package com.prgrms2.java.bitta.repository; import com.prgrms2.java.bitta.user.repository.UserRepository; -import com.prgrms2.java.bitta.xenum.Role; +import com.prgrms2.java.bitta.user.entity.Role; import com.prgrms2.java.bitta.user.entity.User; import lombok.extern.log4j.Log4j2; import org.junit.jupiter.api.Test; From da4239cfb5289fc976cb0962f40aa23bbcc40a12 Mon Sep 17 00:00:00 2001 From: ghtndl Date: Fri, 27 Sep 2024 10:26:31 +0900 Subject: [PATCH 03/24] user entity modified --- .../application/entity/PostApplication.java | 3 -- .../bitta/feed/controller/FeedController.java | 14 ++++----- .../feed/dto/{FeedDto.java => FeedDTO.java} | 6 +--- .../java/bitta/feed/service/FeedService.java | 16 +++++----- .../bitta/feed/service/FeedServiceImpl.java | 10 +++--- .../prgrms2/java/bitta/user/dto/UserDTO.java | 17 +++++++++- .../prgrms2/java/bitta/user/entity/User.java | 31 +++++++++++++++++++ .../java/bitta/user/service/UserService.java | 4 +++ 8 files changed, 72 insertions(+), 29 deletions(-) rename src/main/java/com/prgrms2/java/bitta/feed/dto/{FeedDto.java => FeedDTO.java} (91%) diff --git a/src/main/java/com/prgrms2/java/bitta/application/entity/PostApplication.java b/src/main/java/com/prgrms2/java/bitta/application/entity/PostApplication.java index e7cdd0c..911fc3f 100644 --- a/src/main/java/com/prgrms2/java/bitta/application/entity/PostApplication.java +++ b/src/main/java/com/prgrms2/java/bitta/application/entity/PostApplication.java @@ -36,9 +36,6 @@ public class PostApplication { @JoinColumn(name = "user_id", nullable = false) private User user; - // User의 Feed 목록도 가져옴 (1:N 관계) - @OneToMany(mappedBy = "user", fetch = FetchType.LAZY) - private List feeds; @CreatedDate private LocalDateTime appliedAt; diff --git a/src/main/java/com/prgrms2/java/bitta/feed/controller/FeedController.java b/src/main/java/com/prgrms2/java/bitta/feed/controller/FeedController.java index 4e0f1be..fd01235 100644 --- a/src/main/java/com/prgrms2/java/bitta/feed/controller/FeedController.java +++ b/src/main/java/com/prgrms2/java/bitta/feed/controller/FeedController.java @@ -1,6 +1,6 @@ package com.prgrms2.java.bitta.feed.controller; -import com.prgrms2.java.bitta.feed.dto.FeedDto; +import com.prgrms2.java.bitta.feed.dto.FeedDTO; import com.prgrms2.java.bitta.feed.service.FeedService; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; @@ -17,18 +17,18 @@ public class FeedController { @GetMapping public ResponseEntity getFeed() { - List feedDtoList = feedService.readAll(); + List feedDTOList = feedService.readAll(); - if (feedDtoList.isEmpty()) { + if (feedDTOList.isEmpty()) { return ResponseEntity.noContent().build(); } - return ResponseEntity.ok(feedDtoList); + return ResponseEntity.ok(feedDTOList); } @GetMapping("/{id}") public ResponseEntity getFeedById(@PathVariable("id") Long feedId) { - Optional feedDto = feedService.read(feedId); + Optional feedDto = feedService.read(feedId); if (feedDto.isEmpty()) { return ResponseEntity.notFound().build(); @@ -38,7 +38,7 @@ public ResponseEntity getFeedById(@PathVariable("id") Long feedId) { } @PostMapping - public ResponseEntity createFeed(@RequestBody FeedDto feedDto) { + public ResponseEntity createFeed(@RequestBody FeedDTO feedDto) { if (feedDto == null) { return ResponseEntity.badRequest().build(); } @@ -47,7 +47,7 @@ public ResponseEntity createFeed(@RequestBody FeedDto feedDto) { } @PutMapping("/{id}") - public ResponseEntity modifyFeed(@PathVariable("id") Long feedId, @RequestBody FeedDto feedDto) { + public ResponseEntity modifyFeed(@PathVariable("id") Long feedId, @RequestBody FeedDTO feedDto) { if (feedDto == null) { return ResponseEntity.badRequest().build(); } diff --git a/src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDto.java b/src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDTO.java similarity index 91% rename from src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDto.java rename to src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDTO.java index ffbef44..0d0a0c9 100644 --- a/src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDto.java +++ b/src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDTO.java @@ -7,14 +7,10 @@ @Data @Builder -public class FeedDto { +public class FeedDTO { private Long feedId; - private String title; - private String content; - private Long userId; - private LocalDateTime createdAt; } diff --git a/src/main/java/com/prgrms2/java/bitta/feed/service/FeedService.java b/src/main/java/com/prgrms2/java/bitta/feed/service/FeedService.java index 66b04f6..702a30e 100644 --- a/src/main/java/com/prgrms2/java/bitta/feed/service/FeedService.java +++ b/src/main/java/com/prgrms2/java/bitta/feed/service/FeedService.java @@ -1,23 +1,23 @@ package com.prgrms2.java.bitta.feed.service; -import com.prgrms2.java.bitta.feed.dto.FeedDto; +import com.prgrms2.java.bitta.feed.dto.FeedDTO; import com.prgrms2.java.bitta.feed.entity.Feed; import java.util.List; import java.util.Optional; public interface FeedService { - Optional read(Long id); + Optional read(Long id); - List readAll(); + List readAll(); - String insert(FeedDto feedDto); + String insert(FeedDTO feedDto); - Optional update(FeedDto feedDto); + Optional update(FeedDTO feedDto); boolean delete(Long id); - default Feed dtoToEntity(FeedDto feedDto) { + default Feed dtoToEntity(FeedDTO feedDto) { // 회원 아이디는 UserService 에서 할당해야 합니다. return Feed.builder() .feedId(feedDto.getFeedId()) @@ -27,8 +27,8 @@ default Feed dtoToEntity(FeedDto feedDto) { .build(); } - default FeedDto entityToDto(Feed feed) { - return FeedDto.builder() + default FeedDTO entityToDto(Feed feed) { + return FeedDTO.builder() .feedId(feed.getFeedId()) .title(feed.getTitle()) .content(feed.getContent()) diff --git a/src/main/java/com/prgrms2/java/bitta/feed/service/FeedServiceImpl.java b/src/main/java/com/prgrms2/java/bitta/feed/service/FeedServiceImpl.java index 070a2dc..519c64f 100644 --- a/src/main/java/com/prgrms2/java/bitta/feed/service/FeedServiceImpl.java +++ b/src/main/java/com/prgrms2/java/bitta/feed/service/FeedServiceImpl.java @@ -1,6 +1,6 @@ package com.prgrms2.java.bitta.feed.service; -import com.prgrms2.java.bitta.feed.dto.FeedDto; +import com.prgrms2.java.bitta.feed.dto.FeedDTO; import org.springframework.stereotype.Service; import java.util.List; @@ -9,22 +9,22 @@ @Service public class FeedServiceImpl implements FeedService { @Override - public Optional read(Long id) { + public Optional read(Long id) { return null; } @Override - public List readAll() { + public List readAll() { return null; } @Override - public String insert(FeedDto feedDto) { + public String insert(FeedDTO feedDto) { return null; } @Override - public Optional update(FeedDto feedDto) { + public Optional update(FeedDTO feedDto) { return Optional.empty(); } diff --git a/src/main/java/com/prgrms2/java/bitta/user/dto/UserDTO.java b/src/main/java/com/prgrms2/java/bitta/user/dto/UserDTO.java index 9d4e2d8..4eefd6a 100644 --- a/src/main/java/com/prgrms2/java/bitta/user/dto/UserDTO.java +++ b/src/main/java/com/prgrms2/java/bitta/user/dto/UserDTO.java @@ -1,5 +1,6 @@ package com.prgrms2.java.bitta.user.dto; +import com.prgrms2.java.bitta.feed.dto.FeedDTO; import com.prgrms2.java.bitta.user.entity.Role; import com.prgrms2.java.bitta.user.entity.User; import lombok.AllArgsConstructor; @@ -9,7 +10,9 @@ import java.time.LocalDateTime; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Data @Builder @@ -26,6 +29,10 @@ public class UserDTO { private String profilePicture; private LocalDateTime createdAt; + // 추가된 필드 + private List feeds; + //private List postApplications; + public UserDTO(User user) { this.userId = user.getUserId(); this.username = user.getUsername(); @@ -35,9 +42,17 @@ public UserDTO(User user) { this.role = user.getRole(); this.profilePicture = user.getProfilePicture(); this.createdAt = user.getCreatedAt(); + + // Feed와 PostApplication 정보도 가져옴 +// this.feeds = user.getFeeds().stream() +// .map(FeedDTO::new) +// .collect(Collectors.toList()); +// this.postApplications = user.getPostApplications().stream() +// .map(PostApplicationDTO::new) +// .collect(Collectors.toList()); } - //JWT + // JWT public Map getPayload() { Map payloadMap = new HashMap<>(); payloadMap.put("userId", userId); diff --git a/src/main/java/com/prgrms2/java/bitta/user/entity/User.java b/src/main/java/com/prgrms2/java/bitta/user/entity/User.java index 95b8525..5075574 100644 --- a/src/main/java/com/prgrms2/java/bitta/user/entity/User.java +++ b/src/main/java/com/prgrms2/java/bitta/user/entity/User.java @@ -1,12 +1,16 @@ package com.prgrms2.java.bitta.user.entity; +import com.prgrms2.java.bitta.application.entity.PostApplication; +import com.prgrms2.java.bitta.feed.entity.Feed; import jakarta.persistence.*; import lombok.*; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; @Entity @AllArgsConstructor @@ -38,6 +42,13 @@ public class User { @CreatedDate private LocalDateTime createdAt; + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List feeds = new ArrayList<>(); + + @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List postApplications = new ArrayList<>(); + + public void changeUsername(String username) { this.username = username; } @@ -61,4 +72,24 @@ public void changeProfilePicture(String profilePicture) { public void changeRole(Role role) { this.role = role; } + + public void addFeed(Feed feed) { + this.feeds.add(feed); + feed.setUser(this); // 양방향 연관관계 설정 + } + + public void removeFeed(Feed feed) { + this.feeds.remove(feed); + feed.setUser(null); // 연관관계 해제 + } + + public void addPostApplication(PostApplication postApplication) { + this.postApplications.add(postApplication); + postApplication.setUser(this); // 양방향 연관관계 설정 + } + + public void removePostApplication(PostApplication postApplication) { + this.postApplications.remove(postApplication); + postApplication.setUser(null); // 연관관계 해제 + } } diff --git a/src/main/java/com/prgrms2/java/bitta/user/service/UserService.java b/src/main/java/com/prgrms2/java/bitta/user/service/UserService.java index 298dacf..3795068 100644 --- a/src/main/java/com/prgrms2/java/bitta/user/service/UserService.java +++ b/src/main/java/com/prgrms2/java/bitta/user/service/UserService.java @@ -35,4 +35,8 @@ public UserDTO read(String email) { /**단순 조회 로직*/ User user = foundUser.orElseThrow(UserException.BAD_CREDENTIALS::get); return new UserDTO(user); } + + public UserDTO register(UserDTO userDTO) { + + } } From 149dd973391aeaada01e2b306a48a15a2c42b444 Mon Sep 17 00:00:00 2001 From: Preta3418 Date: Fri, 27 Sep 2024 12:12:47 +0900 Subject: [PATCH 04/24] service --- .../bitta/feed/service/FeedServiceImpl.java | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/prgrms2/java/bitta/feed/service/FeedServiceImpl.java b/src/main/java/com/prgrms2/java/bitta/feed/service/FeedServiceImpl.java index 519c64f..a7fe148 100644 --- a/src/main/java/com/prgrms2/java/bitta/feed/service/FeedServiceImpl.java +++ b/src/main/java/com/prgrms2/java/bitta/feed/service/FeedServiceImpl.java @@ -1,35 +1,72 @@ package com.prgrms2.java.bitta.feed.service; import com.prgrms2.java.bitta.feed.dto.FeedDTO; +import com.prgrms2.java.bitta.feed.entity.Feed; +import com.prgrms2.java.bitta.feed.repository.FeedRepository; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; @Service public class FeedServiceImpl implements FeedService { + + private final FeedRepository feedRepository; + + // Constructor for dependency injection + public FeedServiceImpl(FeedRepository feedRepository) { + this.feedRepository = feedRepository; + } + @Override + @Transactional(readOnly = true) public Optional read(Long id) { - return null; + return feedRepository.findById(id).map(this::entityToDto); // Ensure consistent method reference } @Override + @Transactional(readOnly = true) public List readAll() { - return null; + return feedRepository.findAll().stream() + .map(this::entityToDto) // Consistent method reference + .collect(Collectors.toList()); } @Override - public String insert(FeedDTO feedDto) { - return null; + @Transactional + public String insert(FeedDTO feedDTO) { + Feed feed = dtoToEntity(feedDTO); + feedRepository.save(feed); + return "Feed created successfully"; } @Override - public Optional update(FeedDTO feedDto) { + @Transactional + public Optional update(FeedDTO feedDTO) { + Optional feedOpt = feedRepository.findById(feedDTO.getFeedId()); + + if (feedOpt.isPresent()) { + Feed feed = feedOpt.get(); + feed.setTitle(feedDTO.getTitle()); + feed.setContent(feedDTO.getContent()); + feedRepository.save(feed); + return Optional.of(entityToDto(feed)); + } + return Optional.empty(); } @Override + @Transactional public boolean delete(Long id) { + if (feedRepository.existsById(id)) { + feedRepository.deleteById(id); + return true; + } return false; } -} + + +} \ No newline at end of file From acb6bd7be50cfc161cec21347409c47a308d7809 Mon Sep 17 00:00:00 2001 From: juwon-code Date: Fri, 4 Oct 2024 20:54:22 +0900 Subject: [PATCH 05/24] =?UTF-8?q?remove:=20=EC=82=AC=EC=A7=84=20=EB=B0=8F?= =?UTF-8?q?=20=EC=98=81=EC=83=81=20=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=20=EC=82=AC=EC=A7=84=20=EB=B0=8F=20=EC=98=81?= =?UTF-8?q?=EC=83=81=20=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=EB=A5=BC=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=ED=95=A9=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to: #75 --- .../java/bitta/photo/entity/Photo.java | 35 ----------- .../photo/repository/PhotoRepository.java | 17 ----- .../bitta/photo/service/PhotoService.java | 14 ----- .../bitta/photo/service/PhotoServiceImpl.java | 63 ------------------- .../java/bitta/video/entity/Video.java | 38 ----------- .../video/repository/VideoRepository.java | 17 ----- .../bitta/video/service/VideoService.java | 15 ----- .../bitta/video/service/VideoServiceImpl.java | 63 ------------------- 8 files changed, 262 deletions(-) delete mode 100644 src/main/java/com/prgrms2/java/bitta/photo/entity/Photo.java delete mode 100644 src/main/java/com/prgrms2/java/bitta/photo/repository/PhotoRepository.java delete mode 100644 src/main/java/com/prgrms2/java/bitta/photo/service/PhotoService.java delete mode 100644 src/main/java/com/prgrms2/java/bitta/photo/service/PhotoServiceImpl.java delete mode 100644 src/main/java/com/prgrms2/java/bitta/video/entity/Video.java delete mode 100644 src/main/java/com/prgrms2/java/bitta/video/repository/VideoRepository.java delete mode 100644 src/main/java/com/prgrms2/java/bitta/video/service/VideoService.java delete mode 100644 src/main/java/com/prgrms2/java/bitta/video/service/VideoServiceImpl.java diff --git a/src/main/java/com/prgrms2/java/bitta/photo/entity/Photo.java b/src/main/java/com/prgrms2/java/bitta/photo/entity/Photo.java deleted file mode 100644 index cadab1b..0000000 --- a/src/main/java/com/prgrms2/java/bitta/photo/entity/Photo.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.prgrms2.java.bitta.photo.entity; - -import com.prgrms2.java.bitta.member.entity.Member; -import com.prgrms2.java.bitta.feed.entity.Feed; -import jakarta.persistence.*; -import lombok.*; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import java.time.LocalDateTime; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -@Entity -@EntityListeners(AuditingEntityListener.class) -public class Photo { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Setter(AccessLevel.NONE) - private Long photoId; - - private Long fileSize; - - private String photoUrl; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "feed_id") - private Feed feed; - - @CreatedDate - @Column(updatable = false) - private LocalDateTime uploadedAt; -} diff --git a/src/main/java/com/prgrms2/java/bitta/photo/repository/PhotoRepository.java b/src/main/java/com/prgrms2/java/bitta/photo/repository/PhotoRepository.java deleted file mode 100644 index ef69426..0000000 --- a/src/main/java/com/prgrms2/java/bitta/photo/repository/PhotoRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.prgrms2.java.bitta.photo.repository; - -import com.prgrms2.java.bitta.photo.entity.Photo; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface PhotoRepository extends JpaRepository { - @Query("SELECT p.photoUrl FROM Photo p WHERE p.feed.id = :feedId") - List findPhotoUrlByFeedId(@Param("feedId") Long feedId); - - void deleteByPhotoUrl(String photoUrl); -} diff --git a/src/main/java/com/prgrms2/java/bitta/photo/service/PhotoService.java b/src/main/java/com/prgrms2/java/bitta/photo/service/PhotoService.java deleted file mode 100644 index 3c59283..0000000 --- a/src/main/java/com/prgrms2/java/bitta/photo/service/PhotoService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.prgrms2.java.bitta.photo.service; - -import com.prgrms2.java.bitta.photo.entity.Photo; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; - -public interface PhotoService { - Photo upload(MultipartFile file) throws IOException; - - void delete(String filepath); - - void delete(Long feedId); -} diff --git a/src/main/java/com/prgrms2/java/bitta/photo/service/PhotoServiceImpl.java b/src/main/java/com/prgrms2/java/bitta/photo/service/PhotoServiceImpl.java deleted file mode 100644 index b5bdfd2..0000000 --- a/src/main/java/com/prgrms2/java/bitta/photo/service/PhotoServiceImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.prgrms2.java.bitta.photo.service; - -import com.prgrms2.java.bitta.photo.entity.Photo; -import com.prgrms2.java.bitta.photo.repository.PhotoRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.UUID; - -@Service -@RequiredArgsConstructor -public class PhotoServiceImpl implements PhotoService{ - private final PhotoRepository photoRepository; - - @Value("${file.root.path}") - private String fileRootPath; - - @Override - @Transactional - public Photo upload(MultipartFile file) throws IOException { - String filename = UUID.randomUUID() + "_" + file.getOriginalFilename(); - String filepath = fileRootPath + "uploads/photos/" + filename; - - file.transferTo(new File(filepath)); - - return Photo.builder() - .photoUrl(filepath) - .fileSize(file.getSize()) - .build(); - } - - @Override - @Transactional - public void delete(String filepath) { - File file = new File(filepath); - - if (file.delete()) { - photoRepository.deleteByPhotoUrl(filepath); - } else { - throw new NoSuchElementException(); - } - } - - @Override - public void delete(Long feedId) { - List photoUrls = photoRepository.findPhotoUrlByFeedId(feedId); - - photoUrls.forEach(url -> { - File file = new File(url); - - if (file.exists()) { - file.delete(); - } - }); - } -} diff --git a/src/main/java/com/prgrms2/java/bitta/video/entity/Video.java b/src/main/java/com/prgrms2/java/bitta/video/entity/Video.java deleted file mode 100644 index a250403..0000000 --- a/src/main/java/com/prgrms2/java/bitta/video/entity/Video.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.prgrms2.java.bitta.video.entity; - -import com.prgrms2.java.bitta.feed.entity.Feed; -import com.prgrms2.java.bitta.member.entity.Member; -import jakarta.persistence.*; -import lombok.*; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import java.time.LocalDateTime; - -@Data -@NoArgsConstructor -@AllArgsConstructor -@Builder -@Entity -@EntityListeners(AuditingEntityListener.class) -public class Video { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Setter(AccessLevel.NONE) - private Long videoId; - - private String title; - - private Long fileSize; - - private String videoUrl; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "feed_id") - private Feed feed; - - @CreatedDate - @Column(updatable = false) - private LocalDateTime uploadedAt; - -} diff --git a/src/main/java/com/prgrms2/java/bitta/video/repository/VideoRepository.java b/src/main/java/com/prgrms2/java/bitta/video/repository/VideoRepository.java deleted file mode 100644 index 733f868..0000000 --- a/src/main/java/com/prgrms2/java/bitta/video/repository/VideoRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.prgrms2.java.bitta.video.repository; - -import com.prgrms2.java.bitta.video.entity.Video; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; - -import java.util.List; - -@Repository -public interface VideoRepository extends JpaRepository { - @Query("SELECT v.videoUrl FROM Video v WHERE v.feed.id = :feedId") - List findVideoUrlByFeedId(@Param("feedId") Long feedId); - - void deleteByVideoUrl(String videoUrl); -} diff --git a/src/main/java/com/prgrms2/java/bitta/video/service/VideoService.java b/src/main/java/com/prgrms2/java/bitta/video/service/VideoService.java deleted file mode 100644 index 4f07e84..0000000 --- a/src/main/java/com/prgrms2/java/bitta/video/service/VideoService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.prgrms2.java.bitta.video.service; - -import com.prgrms2.java.bitta.video.entity.Video; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; - -public interface VideoService { - Video upload(MultipartFile file) throws IOException; - - void delete(String filepath); - - void delete(Long feedId); -} - diff --git a/src/main/java/com/prgrms2/java/bitta/video/service/VideoServiceImpl.java b/src/main/java/com/prgrms2/java/bitta/video/service/VideoServiceImpl.java deleted file mode 100644 index a852327..0000000 --- a/src/main/java/com/prgrms2/java/bitta/video/service/VideoServiceImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.prgrms2.java.bitta.video.service; - -import com.prgrms2.java.bitta.video.entity.Video; -import com.prgrms2.java.bitta.video.repository.VideoRepository; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.UUID; - -@Service -@RequiredArgsConstructor -public class VideoServiceImpl implements VideoService { - private final VideoRepository videoRepository; - - @Value("${file.root.path}") - private String fileRootPath; - - @Override - @Transactional - public Video upload(MultipartFile file) throws IOException { - String filename = UUID.randomUUID() + "_" + file.getOriginalFilename(); - String filepath = fileRootPath + "uploads/videos/" + filename; - - file.transferTo(new File(filepath)); - - return Video.builder() - .videoUrl(filepath) - .fileSize(file.getSize()) - .build(); - } - - @Override - @Transactional - public void delete(String filepath) { - File file = new File(filepath); - - if (file.delete()) { - videoRepository.deleteByVideoUrl(filepath); - } else { - throw new NoSuchElementException(); - } - } - - @Override - public void delete(Long feedId) { - List videoUrls = videoRepository.findVideoUrlByFeedId(feedId); - - videoUrls.forEach(url -> { - File file = new File(url); - - if (file.exists()) { - file.delete(); - } - }); - } -} From 22af62f9f2e3b168ae7acc1385b151103305547c Mon Sep 17 00:00:00 2001 From: juwon-code Date: Mon, 7 Oct 2024 00:05:11 +0900 Subject: [PATCH 06/24] =?UTF-8?q?feat:=20=EB=AF=B8=EB=94=94=EC=96=B4=20?= =?UTF-8?q?=ED=86=B5=ED=95=A9=20=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EC=82=AC=EC=A7=84=EA=B3=BC=20=EB=B9=84?= =?UTF-8?q?=EB=94=94=EC=98=A4=EB=A5=BC=20=ED=86=B5=ED=95=A9=ED=95=9C=20?= =?UTF-8?q?=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=EB=A5=BC=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=ED=95=A9=EB=8B=88=EB=8B=A4.=20-=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EB=8B=B4=EC=9D=84=20=EB=AF=B8?= =?UTF-8?q?=EB=94=94=EC=96=B4=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EB=B0=8F=20?= =?UTF-8?q?DTO=20=EC=B6=94=EA=B0=80=20-=20=EB=AF=B8=EB=94=94=EC=96=B4=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=98=A4=EB=A5=98=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20-=20DB=EC=99=80=20=ED=86=B5=EC=8B=A0?= =?UTF-8?q?=ED=95=A0=20=EB=AF=B8=EB=94=94=EC=96=B4=20=EB=A0=88=ED=8F=AC?= =?UTF-8?q?=EC=A7=80=ED=86=A0=EB=A6=AC=20=EC=B6=94=EA=B0=80=20-=20?= =?UTF-8?q?=ED=94=BC=EB=93=9C=20=EC=84=9C=EB=B9=84=EC=8A=A4=EC=99=80=20?= =?UTF-8?q?=EC=97=B0=EB=8F=99=EB=90=98=EB=8A=94=20=EB=AF=B8=EB=94=94?= =?UTF-8?q?=EC=96=B4=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to: #75 --- .../java/bitta/media/dto/MediaDto.java | 51 ++++++ .../java/bitta/media/entity/Media.java | 50 ++++++ .../bitta/media/entity/MediaCategory.java | 5 + .../media/exception/MediaFileException.java | 17 ++ .../exception/MediaFileTaskException.java | 11 ++ .../media/repository/MediaRepository.java | 15 ++ .../bitta/media/service/MediaService.java | 19 +++ .../bitta/media/service/MediaServiceImpl.java | 149 ++++++++++++++++++ 8 files changed, 317 insertions(+) create mode 100644 src/main/java/com/prgrms2/java/bitta/media/dto/MediaDto.java create mode 100644 src/main/java/com/prgrms2/java/bitta/media/entity/Media.java create mode 100644 src/main/java/com/prgrms2/java/bitta/media/entity/MediaCategory.java create mode 100644 src/main/java/com/prgrms2/java/bitta/media/exception/MediaFileException.java create mode 100644 src/main/java/com/prgrms2/java/bitta/media/exception/MediaFileTaskException.java create mode 100644 src/main/java/com/prgrms2/java/bitta/media/repository/MediaRepository.java create mode 100644 src/main/java/com/prgrms2/java/bitta/media/service/MediaService.java create mode 100644 src/main/java/com/prgrms2/java/bitta/media/service/MediaServiceImpl.java diff --git a/src/main/java/com/prgrms2/java/bitta/media/dto/MediaDto.java b/src/main/java/com/prgrms2/java/bitta/media/dto/MediaDto.java new file mode 100644 index 0000000..64a48c9 --- /dev/null +++ b/src/main/java/com/prgrms2/java/bitta/media/dto/MediaDto.java @@ -0,0 +1,51 @@ +package com.prgrms2.java.bitta.media.dto; + +import com.prgrms2.java.bitta.media.entity.MediaCategory; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@Schema(title = "미디어 DTO", description = "미디어 파일의 요청 및 응답에 사용하는 DTO입니다.") +public class MediaDto { + @Schema(title = "미디어 ID (PK)", description = "미디어 파일의 고유 ID 입니다.") + @Min(value = 1, message = "ID는 0 또는 음수가 될 수 없습니다.") + private Long id; + + @Schema(title = "파일명", description = "UUID로 이루어진 파일명 입니다.", example = "ef30982a-67e5-4d41-bb34-e05e82798076") + @NotBlank(message = "파일명은 비우거나, 공백이 될 수 없습니다.") + @Size(min = 1, max = 36, message = "파일명은 1 ~ 36자 이하여야 합니다.") + private String filename; + + @Schema(title = "확장자", description = "파일의 확장자 입니다.", example = ".jpg") + @NotBlank(message = "확장자는 비우거나, 공백이 될 수 없습니다.") + private String extension; + + @Schema(title = "파일 크기", description = "파일의 크기입니다.", example = "2048") + @Min(value = 0, message = "파일 크기는 음수가 될 수 없습니다.") + @Builder.Default + private Long size = 0L; + + @Schema(title = "파일 타입", description = "파일의 타입입니다.", example = "IMAGE") + private MediaCategory type; + + @Schema(title = "피드 ID (FK)", description = "피드의 ID입니다.") + @Min(value = 1, message = "ID는 0 또는 음수가 될 수 없습니다.") + private Long feedId; + + @Schema(title = "파일 저장일시", description = "파일이 저장된 날짜 및 시간입니다.", example = "2023-09-24T14:45:00") + private LocalDateTime createdAt; + + @Schema(title = "파일 수정일시", description = "파일이 수정된 날짜 및 시간입니다.", example = "2023-09-24T14:45:00") + private LocalDateTime updatedAt; +} \ No newline at end of file diff --git a/src/main/java/com/prgrms2/java/bitta/media/entity/Media.java b/src/main/java/com/prgrms2/java/bitta/media/entity/Media.java new file mode 100644 index 0000000..03b6826 --- /dev/null +++ b/src/main/java/com/prgrms2/java/bitta/media/entity/Media.java @@ -0,0 +1,50 @@ +package com.prgrms2.java.bitta.media.entity; + +import com.prgrms2.java.bitta.feed.entity.Feed; +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.ColumnDefault; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import java.time.LocalDateTime; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Entity +@EntityListeners(AuditingEntityListener.class) +public class Media { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Setter(AccessLevel.NONE) + private Long id; + + @Column(length = 36, unique = true, nullable = false) + private String filename; + + @Column(nullable = false) + private String extension; + + @Column(nullable = false) + @ColumnDefault("0") + private Long size; + + @Column(nullable = false) + @Enumerated(EnumType.STRING) + private MediaCategory type; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "feed_id") + private Feed feed; + + @CreatedDate + @Column(updatable = false, nullable = false) + private LocalDateTime createdAt; + + @LastModifiedDate + @Column(nullable = false) + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/prgrms2/java/bitta/media/entity/MediaCategory.java b/src/main/java/com/prgrms2/java/bitta/media/entity/MediaCategory.java new file mode 100644 index 0000000..2f558a9 --- /dev/null +++ b/src/main/java/com/prgrms2/java/bitta/media/entity/MediaCategory.java @@ -0,0 +1,5 @@ +package com.prgrms2.java.bitta.media.entity; + +public enum MediaCategory { + IMAGE, VIDEO, PROFILE +} diff --git a/src/main/java/com/prgrms2/java/bitta/media/exception/MediaFileException.java b/src/main/java/com/prgrms2/java/bitta/media/exception/MediaFileException.java new file mode 100644 index 0000000..95b06ba --- /dev/null +++ b/src/main/java/com/prgrms2/java/bitta/media/exception/MediaFileException.java @@ -0,0 +1,17 @@ +package com.prgrms2.java.bitta.media.exception; + +public enum MediaFileException { + NOT_FOUND(404, "해당 파일은 존재하지 않습니다."), + INTERNAL_ERROR(500, "파일 처리에 실패했습니다."), + INVALID_FORMAT(500, "올바르지 않은 파일 포맷입니다."); + + private MediaFileTaskException mediaFileTaskException; + + MediaFileException(int code, String message) { + mediaFileTaskException = new MediaFileTaskException(code, message); + } + + public MediaFileTaskException get() { + return mediaFileTaskException; + } +} diff --git a/src/main/java/com/prgrms2/java/bitta/media/exception/MediaFileTaskException.java b/src/main/java/com/prgrms2/java/bitta/media/exception/MediaFileTaskException.java new file mode 100644 index 0000000..59f6497 --- /dev/null +++ b/src/main/java/com/prgrms2/java/bitta/media/exception/MediaFileTaskException.java @@ -0,0 +1,11 @@ +package com.prgrms2.java.bitta.media.exception; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter +public class MediaFileTaskException extends RuntimeException { + private int code; + private String message; +} diff --git a/src/main/java/com/prgrms2/java/bitta/media/repository/MediaRepository.java b/src/main/java/com/prgrms2/java/bitta/media/repository/MediaRepository.java new file mode 100644 index 0000000..0986fbb --- /dev/null +++ b/src/main/java/com/prgrms2/java/bitta/media/repository/MediaRepository.java @@ -0,0 +1,15 @@ +package com.prgrms2.java.bitta.media.repository; + +import com.prgrms2.java.bitta.media.entity.Media; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface MediaRepository extends JpaRepository { + @Query("SELECT m FROM Media m WHERE m.feed.id = :feedId") + List findAllByFeedId(@Param("feedId") Long feedId); +} diff --git a/src/main/java/com/prgrms2/java/bitta/media/service/MediaService.java b/src/main/java/com/prgrms2/java/bitta/media/service/MediaService.java new file mode 100644 index 0000000..7d8f08c --- /dev/null +++ b/src/main/java/com/prgrms2/java/bitta/media/service/MediaService.java @@ -0,0 +1,19 @@ +package com.prgrms2.java.bitta.media.service; + +import com.prgrms2.java.bitta.media.dto.MediaDto; +import com.prgrms2.java.bitta.media.entity.Media; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + +public interface MediaService { + void upload(List files, Long feedId); + + void delete(List mediaDtos); + + void delete(Long feedId); + + List convertDTOs(List mediaDTOs); + + List convertEntities(List medias); +} \ No newline at end of file diff --git a/src/main/java/com/prgrms2/java/bitta/media/service/MediaServiceImpl.java b/src/main/java/com/prgrms2/java/bitta/media/service/MediaServiceImpl.java new file mode 100644 index 0000000..db8d685 --- /dev/null +++ b/src/main/java/com/prgrms2/java/bitta/media/service/MediaServiceImpl.java @@ -0,0 +1,149 @@ +package com.prgrms2.java.bitta.media.service; + +import com.prgrms2.java.bitta.feed.entity.Feed; +import com.prgrms2.java.bitta.feed.service.FeedProvider; +import com.prgrms2.java.bitta.media.dto.MediaDto; +import com.prgrms2.java.bitta.media.entity.MediaCategory; +import com.prgrms2.java.bitta.media.entity.Media; +import com.prgrms2.java.bitta.media.exception.MediaFileException; +import com.prgrms2.java.bitta.media.repository.MediaRepository; + +import lombok.RequiredArgsConstructor; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +@Service +@RequiredArgsConstructor +public class MediaServiceImpl implements MediaService { + private final MediaRepository mediaRepository; + + private final FeedProvider feedProvider; + + @Value("${file.root.path}") + private String rootPath; + + @Override + public void upload(List files, Long feedId) { + List categories = checkFileType(files); + List media = new ArrayList<>(); + Feed feed = feedProvider.getById(feedId); + + for (int i = 0; i < files.size(); i++) { + MultipartFile file = files.get(i); + + String filename = UUID.randomUUID().toString(); + String extension = "." + StringUtils.getFilenameExtension(file.getOriginalFilename()); + + try { + file.transferTo(new File(rootPath + filename + extension)); + } catch (IOException e) { + throw MediaFileException.INTERNAL_ERROR.get(); + } + + media.add(Media.builder() + .filename(filename) + .extension(extension) + .size(file.getSize()) + .type(categories.get(i)) + .feed(feed) + .build()); + } + + mediaRepository.saveAll(media); + } + + @Override + public void delete(List mediaDtos) { + mediaDtos.forEach(dto -> { + String filepath = rootPath + dto.getFilename() + dto.getExtension(); + + File file = new File(filepath); + + if (file.exists()) { + file.delete(); + } else { + throw MediaFileException.NOT_FOUND.get(); + } + }); + } + + @Override + public void delete(Long feedId) { + List medias = mediaRepository.findAllByFeedId(feedId); + + medias.forEach(media -> { + String filepath = rootPath + media.getFilename() + media.getExtension(); + + File file = new File(filepath); + + if (file.exists()) { + file.delete(); + } else { + throw MediaFileException.NOT_FOUND.get(); + } + }); + } + + private List checkFileType(List files) { + List categories = new ArrayList<>(); + + files.forEach(file -> { + String contentType = file.getContentType(); + + if (contentType.startsWith("image/")) { + categories.add(MediaCategory.IMAGE); + } else if (contentType.startsWith("video/")) { + categories.add(MediaCategory.VIDEO); + } else { + throw MediaFileException.INVALID_FORMAT.get(); + } + }); + + return categories; + } + + @Override + public List convertDTOs(List mediaDTOs) { + return mediaDTOs.stream().map(this::dtoToEntity).toList(); + } + + @Override + public List convertEntities(List medias) { + return medias.stream().map(this::entityToDto).toList(); + } + + private Media dtoToEntity(MediaDto mediaDto) { + return Media.builder() + .id(mediaDto.getId()) + .filename(mediaDto.getFilename()) + .extension(mediaDto.getExtension()) + .size(mediaDto.getSize()) + .type(mediaDto.getType()) + .feed(feedProvider.getById(mediaDto.getFeedId())) + .createdAt(mediaDto.getCreatedAt()) + .updatedAt(mediaDto.getUpdatedAt()) + .build(); + } + + private MediaDto entityToDto(Media media) { + return MediaDto.builder() + .id(media.getId()) + .filename(media.getFilename()) + .extension(media.getExtension()) + .size(media.getSize()) + .type(media.getType()) + .feedId(media.getFeed().getId()) + .createdAt(media.getCreatedAt()) + .updatedAt(media.getUpdatedAt()) + .build(); + } +} From 51c0f122cc708da98930a844dd8dd3d533595c37 Mon Sep 17 00:00:00 2001 From: juwon-code Date: Mon, 7 Oct 2024 00:55:45 +0900 Subject: [PATCH 07/24] =?UTF-8?q?feat:=20=ED=94=BC=EB=93=9C=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80=20=EB=B0=8F?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20-=20=ED=94=BC?= =?UTF-8?q?=EB=93=9C=20=EC=A1=B0=ED=9A=8C=20=EC=98=B5=EC=85=98=20=EB=B0=8F?= =?UTF-8?q?=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=84=A4=EC=9D=B4=EC=85=98=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20-=20=EA=B2=80=EC=A6=9D=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=A0=9C=EA=B1=B0=20?= =?UTF-8?q?=EB=B0=8F=20=EC=A3=BC=EC=84=9D=20=EB=B3=80=EA=B2=BD=20-=20?= =?UTF-8?q?=EC=8A=A4=EC=9B=A8=EA=B1=B0=20JSON=20=EC=9D=91=EB=8B=B5=20?= =?UTF-8?q?=EC=98=88=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to: #75 --- .../bitta/feed/controller/FeedController.java | 39 +++++-- .../prgrms2/java/bitta/feed/dto/FeedDTO.java | 17 ++- .../prgrms2/java/bitta/feed/entity/Feed.java | 24 +---- .../bitta/feed/repository/FeedRepository.java | 18 +++- .../java/bitta/feed/service/FeedProvider.java | 18 ++++ .../java/bitta/feed/service/FeedService.java | 11 +- .../bitta/feed/service/FeedServiceImpl.java | 100 ++++++------------ .../bitta/global/constants/ApiResponses.java | 4 +- .../bitta/media/service/MediaServiceImpl.java | 6 +- 9 files changed, 117 insertions(+), 120 deletions(-) create mode 100644 src/main/java/com/prgrms2/java/bitta/feed/service/FeedProvider.java diff --git a/src/main/java/com/prgrms2/java/bitta/feed/controller/FeedController.java b/src/main/java/com/prgrms2/java/bitta/feed/controller/FeedController.java index 31a320d..2871a69 100644 --- a/src/main/java/com/prgrms2/java/bitta/feed/controller/FeedController.java +++ b/src/main/java/com/prgrms2/java/bitta/feed/controller/FeedController.java @@ -2,8 +2,10 @@ import com.prgrms2.java.bitta.feed.dto.FeedDTO; import com.prgrms2.java.bitta.feed.service.FeedService; +import com.prgrms2.java.bitta.media.dto.MediaDto; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; @@ -11,6 +13,8 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.Min; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; @@ -31,8 +35,8 @@ public class FeedController { private final FeedService feedService; @Operation( - summary = "전체 피드 조회", - description = "전체 피드를 조회합니다.", + summary = "피드 목록 조회", + description = "페이지와 사이즈를 조건으로 피드 목록을 조회합니다.", responses = { @ApiResponse( responseCode = "200", @@ -52,11 +56,32 @@ public class FeedController { ) } ) + @Parameters({ + @Parameter( + name = "page", + description = "피드 페이지 번호", + required = true, + example = "0", + schema = @Schema(type = "integer", defaultValue = "0", minimum = "0") + ), + @Parameter( + name = "size", + description = "피드 페이지 크기", + required = true, + example = "10", + schema = @Schema(type = "integer", defaultValue = "10", minimum = "1") + ) + }) @GetMapping - public ResponseEntity getFeed() { + public ResponseEntity getFeeds(@RequestParam(required = false, defaultValue = "0", value = "page") int page + , @RequestParam(required = false, defaultValue = "10", value = "size") int size + , @RequestParam(required = false, value = "username") String username + , @RequestParam(required = false, value = "title") String title) { + Pageable pageable = PageRequest.of(page, size); + return ResponseEntity.ok( - Map.of("message", "피드를 성공적으로 조회했습니다.", "result", feedService.readAll()) - ); + Map.of("message", "피드를 성공적으로 조회했습니다." + , "result", feedService.readAll(pageable, username, title))); } @Operation( @@ -204,10 +229,10 @@ public ResponseEntity createFeed(@RequestPart(value = "feed") @Valid FeedDTO ) @PutMapping(value = "/{id}", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public ResponseEntity modifyFeed(@PathVariable("id") @Min(1) Long id, @RequestPart("feed") @Valid FeedDTO feedDTO - , @RequestPart("filesToUpload") List filesToUpload, @RequestPart("filepathsToDelete") List filepathsToDelete) { + , @RequestPart("filesToUpload") List filesToUpload, @RequestPart("filesToDelete") List filesToDelete) { feedDTO.setId(id); - feedService.update(feedDTO, filesToUpload, filepathsToDelete); + feedService.update(feedDTO, filesToUpload, filesToDelete); return ResponseEntity.ok().body(Map.of("message", "피드가 수정되었습니다.")); } diff --git a/src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDTO.java b/src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDTO.java index 02a03d0..4ffdbd8 100644 --- a/src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDTO.java +++ b/src/main/java/com/prgrms2/java/bitta/feed/dto/FeedDTO.java @@ -1,5 +1,6 @@ package com.prgrms2.java.bitta.feed.dto; +import com.prgrms2.java.bitta.media.dto.MediaDto; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.*; import lombok.AllArgsConstructor; @@ -17,11 +18,11 @@ @Schema(title = "피드 DTO", description = "피드의 요청 및 응답에 사용하는 DTO입니다.") public class FeedDTO { @Schema(title = "피드 ID (PK)", description = "피드의 고유 ID 입니다.", example = "1", minimum = "1") - @Min(value = 1, message = "ID는 음수가 될 수 없습니다.") + @Min(value = 1, message = "ID는 0 또는 음수가 될 수 없습니다.") private Long id; @Schema(title = "피드 제목", description = "피드 제목입니다.", example = "Feed Title", minimum = "1", maximum = "50") - @NotBlank(message = "제목은 비워둘 수 없습니다.") + @NotBlank(message = "제목은 비우거나, 공백이 될 수 없습니다.") @Size(min = 1, max = 50, message = "제목은 1 ~ 50자 이하여야 합니다.") private String title; @@ -31,17 +32,13 @@ public class FeedDTO { private String content = ""; @Schema(title = "회원 ID (FK)", description = "회원의 고유 ID 입니다.", example = "1", minimum = "1") - @Min(value = 1, message = "ID는 음수가 될 수 없습니다.") + @Min(value = 1, message = "ID는 0 또는 음수가 될 수 없습니다.") @NotNull(message = "회원 ID는 누락될 수 없습니다.") private Long memberId; @Schema(title = "피드 생성일시", description = "피드가 생성된 날짜 및 시간입니다.", example = "2023-09-24T14:45:00") - @PastOrPresent(message = "생성일자는 현재 시점 혹은 이전이어야 합니다.") private LocalDateTime createdAt; - @Schema(title = "사진 URL 목록", description = "피드에 포함된 사진 URL 목록입니다.", example = "[\"IMAGE_URL_1\", \"IMAGE_URL_2\"]") - private List photoUrls; - - @Schema(title = "영상 URL 목록", description = "피드에 포함된 영상 URL 목록입니다.", example = "[\"VIDEO_URL_1\", \"VIDEO_URL_2\"]") - private List videoUrls; -} + @Schema(title = "미디어 파일 목록", description = "피드에 포함된 사진 및 영상 목록입니다.") + private List medias; +} \ No newline at end of file diff --git a/src/main/java/com/prgrms2/java/bitta/feed/entity/Feed.java b/src/main/java/com/prgrms2/java/bitta/feed/entity/Feed.java index a34de4e..18c08d9 100644 --- a/src/main/java/com/prgrms2/java/bitta/feed/entity/Feed.java +++ b/src/main/java/com/prgrms2/java/bitta/feed/entity/Feed.java @@ -1,8 +1,7 @@ package com.prgrms2.java.bitta.feed.entity; +import com.prgrms2.java.bitta.media.entity.Media; import com.prgrms2.java.bitta.member.entity.Member; -import com.prgrms2.java.bitta.photo.entity.Photo; -import com.prgrms2.java.bitta.video.entity.Video; import jakarta.persistence.*; import lombok.*; import org.springframework.data.annotation.CreatedDate; @@ -41,24 +40,9 @@ public class Feed { @Builder.Default @OneToMany(mappedBy = "feed", cascade = CascadeType.ALL, orphanRemoval = true) - private List photos = new ArrayList<>(); + private List medias = new ArrayList<>(); - @Builder.Default - @OneToMany(mappedBy = "feed", cascade = CascadeType.ALL, orphanRemoval = true) - private List