From 29ae1fae507c12a936d5eff0599ddb2021504f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=EC=A0=95=ED=9B=84?= Date: Wed, 6 Nov 2024 20:25:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20share=20=EA=B8=B0=EB=8A=A5=20+=20error?= =?UTF-8?q?=20=ED=95=B8=EB=93=A4=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/main/resources/application-s3.yml | 15 ----- .../album/presentation/AlbumController.java | 26 +++++++- .../album/adapter/AlbumRegisterAdapter.java | 66 ++++++++++++++++++- .../outbound/entity/album/JpaAlbumShare.java | 30 +++++++++ .../album/AlbumShareRepository.java | 7 ++ 5 files changed, 124 insertions(+), 20 deletions(-) create mode 100644 outbound/src/main/java/com/pocket/outbound/entity/album/JpaAlbumShare.java create mode 100644 outbound/src/main/java/com/pocket/outbound/repository/album/AlbumShareRepository.java diff --git a/core/src/main/resources/application-s3.yml b/core/src/main/resources/application-s3.yml index 7444af2..e69de29 100644 --- a/core/src/main/resources/application-s3.yml +++ b/core/src/main/resources/application-s3.yml @@ -1,15 +0,0 @@ -# S3 -cloud: - aws: - s3: - bucket: imagedata-ec2-pocket4cut - url: https://imagedata-ec2-pocket4cut.s3.ap-northeast-2.amazonaws.com/ - expTime: 900000 # 15분 - credentials: - access-key: AKIA5FTY6F7TUYFDUPFZ - secret-key: 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 - region: - static: ap-northeast-2 - auto: false - stack: - auto: false \ No newline at end of file diff --git a/inbounds/src/main/java/com/pocket/inbounds/album/presentation/AlbumController.java b/inbounds/src/main/java/com/pocket/inbounds/album/presentation/AlbumController.java index 18f54c1..1b2223d 100644 --- a/inbounds/src/main/java/com/pocket/inbounds/album/presentation/AlbumController.java +++ b/inbounds/src/main/java/com/pocket/inbounds/album/presentation/AlbumController.java @@ -4,7 +4,6 @@ import com.pocket.domain.dto.album.*; import com.pocket.domain.dto.user.UserInfoDTO; import com.pocket.domain.usecase.album.*; -import jakarta.persistence.criteria.CriteriaBuilder; import lombok.RequiredArgsConstructor; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @@ -14,7 +13,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/api/v1/album") -public class AlbumController implements AlbumContollerDocs{ +public class AlbumController implements AlbumContollerDocs { private final AlbumRegisterUseCase albumRegisterUseCase; private final AlbumLikeUseCase albumLikeUseCase; @@ -24,6 +23,7 @@ public class AlbumController implements AlbumContollerDocs{ private final AlbumDeleteUseCase albumDeleteUseCase; private final AlbumHashtagUseCase albumHashtagUseCase; private final AlbumFavoriteUseCase albumFavoriteUseCase; + private final AlbumShareUseCase albumShareUseCase; @PostMapping public ApplicationResponse postPhoto( @@ -108,4 +108,26 @@ public ApplicationResponse> getFavoriteAlbums( return ApplicationResponse.ok(response); } + // 공유링크 생성 + @PostMapping("/share") + public ApplicationResponse shareLink( + @AuthenticationPrincipal UserInfoDTO user, + @RequestParam Long albumId + ) { + + Long token = albumShareUseCase.saveShareTable(user.email(), albumId); + return ApplicationResponse.ok("https://pocket4cut.link/page/share?token" + token); + } + + // 공유자 데이터 정보 저장 + @PostMapping("/{token}/saveShare") + public ApplicationResponse saveShareInfos( + @AuthenticationPrincipal UserInfoDTO user, + @PathVariable Long token + ) { + + albumShareUseCase.saveNewData(user.email(), token); + return ApplicationResponse.ok("Saved"); + } + } diff --git a/outbound/src/main/java/com/pocket/outbound/adapter/album/adapter/AlbumRegisterAdapter.java b/outbound/src/main/java/com/pocket/outbound/adapter/album/adapter/AlbumRegisterAdapter.java index 1ab01b7..4e3ac19 100644 --- a/outbound/src/main/java/com/pocket/outbound/adapter/album/adapter/AlbumRegisterAdapter.java +++ b/outbound/src/main/java/com/pocket/outbound/adapter/album/adapter/AlbumRegisterAdapter.java @@ -1,6 +1,10 @@ package com.pocket.outbound.adapter.album.adapter; import com.pocket.core.aop.annotation.AdapterService; +import com.pocket.core.exception.album.AlbumCustomException; +import com.pocket.core.exception.album.AlbumErrorCode; +import com.pocket.core.exception.hashtag.HashTagCustomException; +import com.pocket.core.exception.hashtag.HashTagErrorCode; import com.pocket.core.exception.photobooth.PhotoBoothCustomException; import com.pocket.core.exception.photobooth.PhotoBoothErrorCode; import com.pocket.core.exception.user.UserCustomException; @@ -8,22 +12,27 @@ import com.pocket.domain.dto.album.AlbumRegisterRequestDto; import com.pocket.domain.dto.album.AlbumRegisterResponseDto; import com.pocket.domain.port.album.AlbumRegisterPort; +import com.pocket.domain.port.album.AlbumSharePort; import com.pocket.outbound.adapter.album.mapper.AlbumOutBoundMapper; -import com.pocket.outbound.entity.*; +import com.pocket.outbound.entity.JpaUser; import com.pocket.outbound.entity.album.JpaAlbum; import com.pocket.outbound.entity.album.JpaAlbumHashTag; +import com.pocket.outbound.entity.album.JpaAlbumShare; import com.pocket.outbound.entity.album.JpaHashTag; import com.pocket.outbound.entity.photobooth.JpaPhotoBooth; -import com.pocket.outbound.repository.*; +import com.pocket.outbound.repository.UserRepository; import com.pocket.outbound.repository.album.AlbumHashTagRepository; import com.pocket.outbound.repository.album.AlbumRepository; +import com.pocket.outbound.repository.album.AlbumShareRepository; import com.pocket.outbound.repository.album.HashTagRepository; import com.pocket.outbound.repository.photobooth.PhotoBoothRepository; import lombok.RequiredArgsConstructor; +import java.util.List; + @AdapterService @RequiredArgsConstructor -public class AlbumRegisterAdapter implements AlbumRegisterPort { +public class AlbumRegisterAdapter implements AlbumRegisterPort, AlbumSharePort { private final AlbumRepository albumRepository; private final HashTagRepository hashtagRepository; @@ -31,6 +40,8 @@ public class AlbumRegisterAdapter implements AlbumRegisterPort { private final PhotoBoothRepository photoBoothRepository; private final UserRepository userRepository; private final AlbumOutBoundMapper albumOutBoundMapper; + private final AlbumShareRepository albumShareRepository; + private final AlbumHashTagRepository albumHashTagRepository; @Override public AlbumRegisterResponseDto registerPhoto(AlbumRegisterRequestDto dto, String name) { @@ -72,4 +83,53 @@ public AlbumRegisterResponseDto registerPhoto(AlbumRegisterRequestDto dto, Strin dto.filePath() ); } + + @Override + public Long saveShareTable(String email, Long albumId) { + + JpaAlbum album = albumRepository.findById(albumId).orElseThrow(() -> new AlbumCustomException(AlbumErrorCode.ALBUM_NOT_FOUND)); + JpaUser jpaUser = userRepository.findByUserEmail(email) + .orElseThrow(() -> new UserCustomException(UserErrorCode.NO_USER_INFO)); + + JpaAlbumShare share = JpaAlbumShare.builder() + .album(album) + .user(jpaUser) + .build(); + + final JpaAlbumShare jpaAlbumShare = albumShareRepository.save(share); + return jpaAlbumShare.getId(); + } + + @Override + public void saveNewData(String email, Long token) { + + JpaAlbumShare albumShare = albumShareRepository.findById(token).orElseThrow(() -> new AlbumCustomException(AlbumErrorCode.ALBUM_SHARE_NOT_FOUND)); + JpaUser jpaUser = userRepository.findByUserEmail(email) + .orElseThrow(() -> new UserCustomException(UserErrorCode.NO_USER_INFO)); + + // 앨범 저장 + JpaAlbum album = albumRepository.findById(albumShare.getAlbum().getId()).orElseThrow(() -> new AlbumCustomException(AlbumErrorCode.ALBUM_NOT_FOUND)); + JpaAlbum newAlbum = JpaAlbum.builder() + .image(album.getImage()) + .jpaUser(jpaUser) + .photoBooth(album.getPhotoBooth()) + .isLiked(album.isLiked()) + .memo(album.getMemo()) + .build(); + albumRepository.save(newAlbum); + + // 해시태그들 저장 + List albumHashTagList = albumHashTagRepository.findByJpaAlbum_Id(album.getId()); + + for (JpaAlbumHashTag a : albumHashTagList) { + JpaHashTag hashTag = hashtagRepository.findById(a.getJpaHashtag().getId()).orElseThrow(() -> new HashTagCustomException(HashTagErrorCode.HASHTAG_NOT_FOUND)); + + JpaHashTag newTag = JpaHashTag.builder() + .hashTag(hashTag.getHashTag()) + .jpaUser(jpaUser) + .build(); + + hashtagRepository.save(newTag); + } + } } \ No newline at end of file diff --git a/outbound/src/main/java/com/pocket/outbound/entity/album/JpaAlbumShare.java b/outbound/src/main/java/com/pocket/outbound/entity/album/JpaAlbumShare.java new file mode 100644 index 0000000..72f41a9 --- /dev/null +++ b/outbound/src/main/java/com/pocket/outbound/entity/album/JpaAlbumShare.java @@ -0,0 +1,30 @@ +package com.pocket.outbound.entity.album; + +import com.pocket.outbound.entity.JpaUser; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@Table(name = "SHARE") +@Entity +@Builder +@AllArgsConstructor +public class JpaAlbumShare { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "album_share_id") + private Long id; + + @ManyToOne + @JoinColumn(name = "album_id") + private JpaAlbum album; + + @ManyToOne + @JoinColumn(name = "user_id") + private JpaUser user; +} diff --git a/outbound/src/main/java/com/pocket/outbound/repository/album/AlbumShareRepository.java b/outbound/src/main/java/com/pocket/outbound/repository/album/AlbumShareRepository.java new file mode 100644 index 0000000..8c8a356 --- /dev/null +++ b/outbound/src/main/java/com/pocket/outbound/repository/album/AlbumShareRepository.java @@ -0,0 +1,7 @@ +package com.pocket.outbound.repository.album; + +import com.pocket.outbound.entity.album.JpaAlbumShare; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface AlbumShareRepository extends JpaRepository { +}