diff --git a/src/main/java/com/finfellows/domain/bookmark/application/BookmarkService.java b/src/main/java/com/finfellows/domain/bookmark/application/BookmarkService.java new file mode 100644 index 0000000..c7cda1e --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/application/BookmarkService.java @@ -0,0 +1,11 @@ +package com.finfellows.domain.bookmark.application; + +import com.finfellows.global.config.security.token.UserPrincipal; +import com.finfellows.global.payload.Message; +import org.springframework.http.ResponseEntity; + +public interface BookmarkService { + Message insert(UserPrincipal userPrincipal, Long id); + + Message delete(UserPrincipal userPrincipal, Long id); +} diff --git a/src/main/java/com/finfellows/domain/bookmark/application/EduContentBookmarkServiceImpl.java b/src/main/java/com/finfellows/domain/bookmark/application/EduContentBookmarkServiceImpl.java new file mode 100644 index 0000000..6844b6f --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/application/EduContentBookmarkServiceImpl.java @@ -0,0 +1,88 @@ +package com.finfellows.domain.bookmark.application; + +import com.finfellows.domain.bookmark.domain.EduContentBookmark; +import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository; +import com.finfellows.domain.bookmark.dto.EduContentBookmarkRes; +import com.finfellows.domain.educontent.domain.EduContent; +import com.finfellows.domain.educontent.domain.repository.EduContentRepository; +import com.finfellows.domain.user.domain.User; +import com.finfellows.domain.user.domain.repository.UserRepository; +import com.finfellows.global.config.security.token.UserPrincipal; +import com.finfellows.global.payload.Message; +import com.finfellows.global.payload.ResponseCustom; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class EduContentBookmarkServiceImpl implements BookmarkService{ + private final EduContentBookmarkRepository eduContentBookmarkRepository; + private final UserRepository userRepository; + private final EduContentRepository eduContentRepository; + @Transactional + @Override + public Message insert(UserPrincipal userPrincipal, Long id) { + Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); + Optional optionalEduContent = eduContentRepository.findById(id); + + User user = optionalUser.get(); + EduContent eduContent = optionalEduContent.get(); + +// if (eduContentBookmarkRepository.findByUserAndEduContent(user, eduContent).isPresent()) { +// return Message.builder() +// .message("이미 즐겨찾기 목록에 존재합니다.") +// .build(); +// } + + EduContentBookmark eduContentBookmark = EduContentBookmark.builder() + .user(user) + .eduContent(eduContent) + .build(); + + eduContentBookmarkRepository.save(eduContentBookmark); + + return Message.builder() + .message("즐겨찾기 추가에 성공했습니다.") + .build(); + + } + + @Transactional + @Override + public Message delete(UserPrincipal userPrincipal, Long id) { + + Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); + Optional optionalEduContent = eduContentRepository.findById(id); + + User user = optionalUser.get(); + EduContent eduContent = optionalEduContent.get(); + + EduContentBookmark eduContentBookmark = eduContentBookmarkRepository.findByUserAndEduContent(user, eduContent).get(); + + eduContentBookmarkRepository.delete(eduContentBookmark); + + + return Message.builder() + .message("즐겨찾기 삭제에 성공했습니다.") + .build(); + } + + public ResponseCustom> findBookmarks(UserPrincipal userPrincipal) { + Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); + + User user = optionalUser.get(); + + List bookmarks = eduContentBookmarkRepository.findAllByUser(user); + + + List eduContentBookmarkResList = EduContentBookmarkRes.toDto(bookmarks); + + + return ResponseCustom.OK(eduContentBookmarkResList); + } +} diff --git a/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java b/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java new file mode 100644 index 0000000..184e01a --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java @@ -0,0 +1,86 @@ +package com.finfellows.domain.bookmark.application; + +import com.finfellows.domain.bookmark.domain.EduContentBookmark; +import com.finfellows.domain.bookmark.domain.FinancialProductBookmark; +import com.finfellows.domain.bookmark.domain.repository.EduContentBookmarkRepository; +import com.finfellows.domain.bookmark.domain.repository.FinancialProductBookmarkRepository; +import com.finfellows.domain.bookmark.dto.EduContentBookmarkRes; +import com.finfellows.domain.product.domain.FinancialProduct; +import com.finfellows.domain.product.domain.repository.FinancialProductRepository; +import com.finfellows.domain.user.domain.User; +import com.finfellows.domain.user.domain.repository.UserRepository; +import com.finfellows.global.config.security.token.UserPrincipal; +import com.finfellows.global.payload.Message; +import com.finfellows.global.payload.ResponseCustom; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class FinancialProductBookmarkServiceImpl implements BookmarkService{ + private final FinancialProductBookmarkRepository financialProductBookmarkRepository; + private final UserRepository userRepository; + private final FinancialProductRepository financialProductRepository; + private final EduContentBookmarkRepository eduContentBookmarkRepository; + + @Transactional + @Override + public Message insert(UserPrincipal userPrincipal, Long id) { + Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); + Optional optionalFinancialProduct = financialProductRepository.findById(id); + + User user = optionalUser.get(); + FinancialProduct financialProduct = optionalFinancialProduct.get(); + + + FinancialProductBookmark financialProductBookmark = FinancialProductBookmark.builder() + .user(user) + .financialProduct(financialProduct) + .build(); + + financialProductBookmarkRepository.save(financialProductBookmark); + + return Message.builder() + .message("즐겨찾기 추가에 성공했습니다.") + .build(); + } + + @Transactional + @Override + public Message delete(UserPrincipal userPrincipal, Long id) { + Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); + Optional optionalFinancialProduct = financialProductRepository.findById(id); + + User user = optionalUser.get(); + FinancialProduct financialProduct = optionalFinancialProduct.get(); + + FinancialProductBookmark financialProductBookmark = financialProductBookmarkRepository.findByUserAndFinancialProduct(user, financialProduct).get(); + + financialProductBookmarkRepository.delete(financialProductBookmark); + + + return Message.builder() + .message("즐겨찾기 삭제에 성공했습니다.") + .build(); + } + + public ResponseCustom> findBookmarks(UserPrincipal userPrincipal) { + Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); + + User user = optionalUser.get(); + + List bookmarks = eduContentBookmarkRepository.findAllByUser(user); + + + List eduContentBookmarkResList = EduContentBookmarkRes.toDto(bookmarks); + + + return ResponseCustom.OK(eduContentBookmarkResList); + } + +} diff --git a/src/main/java/com/finfellows/domain/bookmark/application/PolicyInfoBookmarkServiceImpl.java b/src/main/java/com/finfellows/domain/bookmark/application/PolicyInfoBookmarkServiceImpl.java new file mode 100644 index 0000000..dc32dcc --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/application/PolicyInfoBookmarkServiceImpl.java @@ -0,0 +1,80 @@ +package com.finfellows.domain.bookmark.application; + +import com.finfellows.domain.bookmark.domain.PolicyInfoBookmark; +import com.finfellows.domain.bookmark.domain.repository.PolicyInfoBookmarkRepository; +import com.finfellows.domain.bookmark.dto.PolicyInfoBookmarkRes; +import com.finfellows.domain.policyinfo.domain.PolicyInfo; +import com.finfellows.domain.policyinfo.domain.repository.PolicyInfoRepository; +import com.finfellows.domain.user.domain.User; +import com.finfellows.domain.user.domain.repository.UserRepository; +import com.finfellows.global.config.security.token.UserPrincipal; +import com.finfellows.global.payload.Message; +import com.finfellows.global.payload.ResponseCustom; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class PolicyInfoBookmarkServiceImpl implements BookmarkService { + private final PolicyInfoBookmarkRepository policyInfoBookmarkRepository; + private final UserRepository userRepository; + private final PolicyInfoRepository policyInfoRepository; + + @Transactional + @Override + public Message insert(UserPrincipal userPrincipal, Long id) { + Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); + Optional optionalPolicyInfo = policyInfoRepository.findById(id); + + User user = optionalUser.get(); + PolicyInfo policyInfo = optionalPolicyInfo.get(); + + PolicyInfoBookmark policyInfoBookmark = PolicyInfoBookmark.builder() + .user(user) + .policyInfo(policyInfo) + .build(); + + policyInfoBookmarkRepository.save(policyInfoBookmark); + + + return Message.builder() + .message("즐겨찾기 추가에 성공했습니다.") + .build(); + } + + @Transactional + @Override + public Message delete(UserPrincipal userPrincipal, Long id) { + Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); + Optional optionalPolicyInfo = policyInfoRepository.findById(id); + + User user = optionalUser.get(); + PolicyInfo policyInfo = optionalPolicyInfo.get(); + + PolicyInfoBookmark policyInfoBookmark = policyInfoBookmarkRepository.findByUserAndPolicyInfo(user, policyInfo).get(); + + policyInfoBookmarkRepository.delete(policyInfoBookmark); + + + return Message.builder() + .message("즐겨찾기 삭제에 성공했습니다.") + .build(); + } + + public ResponseCustom findBookmarks(UserPrincipal userPrincipal) { + Optional optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); + + User user = optionalUser.get(); + + List bookmarks = policyInfoBookmarkRepository.findAllByUser(user); + + List policyInfoBookmarkResList = PolicyInfoBookmarkRes.toDto(bookmarks); + + return ResponseCustom.OK(policyInfoBookmarkResList); + } +} diff --git a/src/main/java/com/finfellows/domain/bookmark/domain/EduContentBookmark.java b/src/main/java/com/finfellows/domain/bookmark/domain/EduContentBookmark.java new file mode 100644 index 0000000..c207195 --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/domain/EduContentBookmark.java @@ -0,0 +1,38 @@ +package com.finfellows.domain.bookmark.domain; + +import com.finfellows.domain.common.BaseEntity; +import com.finfellows.domain.educontent.domain.EduContent; +import com.finfellows.domain.user.domain.User; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Where; + +@Entity +@Table(name = "EduContentBookmark") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +@Where(clause = "status = 'ACTIVE'") +public class EduContentBookmark extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", updatable = false) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + // 금융 배우자 id + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "edu_content_id") + private EduContent eduContent; + + @Builder + public EduContentBookmark(User user, EduContent eduContent) { + this.user = user; + this.eduContent = eduContent; + } +} diff --git a/src/main/java/com/finfellows/domain/bookmark/domain/Bookmark.java b/src/main/java/com/finfellows/domain/bookmark/domain/FinancialProductBookmark.java similarity index 57% rename from src/main/java/com/finfellows/domain/bookmark/domain/Bookmark.java rename to src/main/java/com/finfellows/domain/bookmark/domain/FinancialProductBookmark.java index 70daaa8..d8f631c 100644 --- a/src/main/java/com/finfellows/domain/bookmark/domain/Bookmark.java +++ b/src/main/java/com/finfellows/domain/bookmark/domain/FinancialProductBookmark.java @@ -1,9 +1,8 @@ package com.finfellows.domain.bookmark.domain; import com.finfellows.domain.common.BaseEntity; -import com.finfellows.domain.educontent.domain.EduContent; -import com.finfellows.domain.policyinfo.domain.PolicyInfo; import com.finfellows.domain.product.domain.FinancialProduct; +import com.finfellows.domain.user.domain.User; import jakarta.persistence.*; import lombok.AccessLevel; import lombok.Builder; @@ -12,36 +11,28 @@ import org.hibernate.annotations.Where; @Entity -@Table(name = "Bookmark") +@Table(name = "FinancialProductBookmark") @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @Where(clause = "status = 'ACTIVE'") -public class Bookmark extends BaseEntity{ - +public class FinancialProductBookmark extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", updatable = false) private Long id; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + // 금융 뭐하지 id @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "financial_product_id") private FinancialProduct financialProduct; - // 금융 배우자 id - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "edu_content_id") - private EduContent eduContent; - - // 금융 고마워 id - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "policy_info_id") - private PolicyInfo policyInfo; - @Builder - public Bookmark(FinancialProduct financialProduct, EduContent eduContent, PolicyInfo policyInfo) { + public FinancialProductBookmark(User user, FinancialProduct financialProduct) { + this.user = user; this.financialProduct = financialProduct; - this.eduContent = eduContent; - this.policyInfo = policyInfo; } } diff --git a/src/main/java/com/finfellows/domain/bookmark/domain/PolicyInfoBookmark.java b/src/main/java/com/finfellows/domain/bookmark/domain/PolicyInfoBookmark.java new file mode 100644 index 0000000..1ae615d --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/domain/PolicyInfoBookmark.java @@ -0,0 +1,38 @@ +package com.finfellows.domain.bookmark.domain; + +import com.finfellows.domain.common.BaseEntity; +import com.finfellows.domain.policyinfo.domain.PolicyInfo; +import com.finfellows.domain.user.domain.User; +import jakarta.persistence.*; +import lombok.AccessLevel; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.Where; + +@Entity +@Table(name = "PolicyInfoBookmark") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Getter +@Where(clause = "status = 'ACTIVE'") +public class PolicyInfoBookmark extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", updatable = false) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; + + // 금융 고마워 id + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "policy_info_id") + private PolicyInfo policyInfo; + + @Builder + public PolicyInfoBookmark(User user, PolicyInfo policyInfo) { + this.user = user; + this.policyInfo = policyInfo; + } +} diff --git a/src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java b/src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java new file mode 100644 index 0000000..8d147e8 --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/domain/repository/EduContentBookmarkRepository.java @@ -0,0 +1,16 @@ +package com.finfellows.domain.bookmark.domain.repository; + +import com.finfellows.domain.bookmark.domain.EduContentBookmark; +import com.finfellows.domain.bookmark.domain.FinancialProductBookmark; +import com.finfellows.domain.educontent.domain.EduContent; +import com.finfellows.domain.user.domain.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; +import java.util.Optional; + +public interface EduContentBookmarkRepository extends JpaRepository { + Optional findByUserAndEduContent(User user, EduContent eduContent); + + List findAllByUser(User user); +} diff --git a/src/main/java/com/finfellows/domain/bookmark/domain/repository/FinancialProductBookmarkRepository.java b/src/main/java/com/finfellows/domain/bookmark/domain/repository/FinancialProductBookmarkRepository.java new file mode 100644 index 0000000..8046151 --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/domain/repository/FinancialProductBookmarkRepository.java @@ -0,0 +1,17 @@ +package com.finfellows.domain.bookmark.domain.repository; + +import com.finfellows.domain.bookmark.domain.EduContentBookmark; +import com.finfellows.domain.bookmark.domain.FinancialProductBookmark; +import com.finfellows.domain.educontent.domain.EduContent; +import com.finfellows.domain.product.domain.FinancialProduct; +import com.finfellows.domain.user.domain.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; +import java.util.Optional; + +public interface FinancialProductBookmarkRepository extends JpaRepository { + Optional findByUserAndFinancialProduct(User user, FinancialProduct financialProduct); + + List findAllByUser(User user); +} diff --git a/src/main/java/com/finfellows/domain/bookmark/domain/repository/PolicyInfoBookmarkRepository.java b/src/main/java/com/finfellows/domain/bookmark/domain/repository/PolicyInfoBookmarkRepository.java new file mode 100644 index 0000000..bc16014 --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/domain/repository/PolicyInfoBookmarkRepository.java @@ -0,0 +1,17 @@ +package com.finfellows.domain.bookmark.domain.repository; + +import com.finfellows.domain.bookmark.domain.EduContentBookmark; +import com.finfellows.domain.bookmark.domain.PolicyInfoBookmark; +import com.finfellows.domain.educontent.domain.EduContent; +import com.finfellows.domain.policyinfo.domain.PolicyInfo; +import com.finfellows.domain.user.domain.User; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; +import java.util.Optional; + +public interface PolicyInfoBookmarkRepository extends JpaRepository { + Optional findByUserAndPolicyInfo(User user, PolicyInfo policyInfo); + + List findAllByUser(User user); +} diff --git a/src/main/java/com/finfellows/domain/bookmark/dto/BookmarkRes.java b/src/main/java/com/finfellows/domain/bookmark/dto/BookmarkRes.java new file mode 100644 index 0000000..cc8c5ec --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/dto/BookmarkRes.java @@ -0,0 +1,15 @@ +package com.finfellows.domain.bookmark.dto; + +import lombok.Builder; +import lombok.Data; + +@Data +public class BookmarkRes { + private int id; + + + @Builder + public BookmarkRes(int id) { + this.id = id; + } +} diff --git a/src/main/java/com/finfellows/domain/bookmark/dto/EduContentBookmarkRes.java b/src/main/java/com/finfellows/domain/bookmark/dto/EduContentBookmarkRes.java new file mode 100644 index 0000000..414ca2c --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/dto/EduContentBookmarkRes.java @@ -0,0 +1,31 @@ +package com.finfellows.domain.bookmark.dto; + +import com.finfellows.domain.bookmark.domain.EduContentBookmark; +import com.finfellows.domain.educontent.domain.EduContent; +import lombok.Builder; +import lombok.Data; + +import java.util.List; +import java.util.stream.Collectors; + +@Data +public class EduContentBookmarkRes { + private Long id; + private String content; + + @Builder + public EduContentBookmarkRes(Long id, String content) { + this.id = id; + this.content = content; + } + + public static List toDto(List bookmarks) { + return bookmarks.stream() + .map(bookmark -> EduContentBookmarkRes.builder() + .id(bookmark.getEduContent().getId()) + .content(bookmark.getEduContent().getContent()) + .build()) + .collect(Collectors.toList()); + } + +} diff --git a/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java b/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java new file mode 100644 index 0000000..841715c --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/dto/FinancialProductBookmarkRes.java @@ -0,0 +1,47 @@ +package com.finfellows.domain.bookmark.dto; + +import com.finfellows.domain.bookmark.domain.FinancialProductBookmark; +import com.finfellows.domain.product.domain.FinancialProduct; +import lombok.Builder; +import lombok.Data; + +import java.util.List; +import java.util.stream.Collectors; + +@Data +public class FinancialProductBookmarkRes { + private String productName; + private String companyName; + private String maturityInterestRate; + private String specialCondition; + private Integer maxLimit; + private String joinWay; + + @Builder + public FinancialProductBookmarkRes(String productName, String companyName, String maturityInterestRate, String specialCondition, Integer maxLimit, String joinWay) { + this.productName = productName; + this.companyName = companyName; + this.maturityInterestRate = maturityInterestRate; + this.specialCondition = specialCondition; + this.maxLimit = maxLimit; + this.joinWay = joinWay; + } + + + + + + public static List toDto(List bookmarks) { + return bookmarks.stream() + .map(bookmark -> FinancialProductBookmarkRes.builder() + .companyName(bookmark.getFinancialProduct().getCompanyName()) + .productName(bookmark.getFinancialProduct().getProductName()) + .joinWay(bookmark.getFinancialProduct().getJoinWay()) + .maturityInterestRate(bookmark.getFinancialProduct().getMaturityInterestRate()) + .specialCondition(bookmark.getFinancialProduct().getSpecialCondition()) + .maxLimit(bookmark.getFinancialProduct().getMaxLimit()) + .build()) + .collect(Collectors.toList()); + + } +} diff --git a/src/main/java/com/finfellows/domain/bookmark/dto/PolicyInfoBookmarkRes.java b/src/main/java/com/finfellows/domain/bookmark/dto/PolicyInfoBookmarkRes.java new file mode 100644 index 0000000..2cf7064 --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/dto/PolicyInfoBookmarkRes.java @@ -0,0 +1,30 @@ +package com.finfellows.domain.bookmark.dto; + +import com.finfellows.domain.bookmark.domain.PolicyInfoBookmark; +import lombok.Builder; +import lombok.Data; + +import java.util.List; +import java.util.stream.Collectors; + +@Data +public class PolicyInfoBookmarkRes { + private Long id; + private String url; + + + @Builder + public PolicyInfoBookmarkRes(Long id, String url) { + this.id = id; + this.url = url; + } + + public static List toDto(List bookmarks) { + return bookmarks.stream() + .map(bookmark -> PolicyInfoBookmarkRes.builder() + .id(bookmark.getPolicyInfo().getId()) + .url(bookmark.getPolicyInfo().getUrl()) + .build()) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java b/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java new file mode 100644 index 0000000..105a36c --- /dev/null +++ b/src/main/java/com/finfellows/domain/bookmark/presentation/BookmarkController.java @@ -0,0 +1,114 @@ +package com.finfellows.domain.bookmark.presentation; + +import com.finfellows.domain.bookmark.application.EduContentBookmarkServiceImpl; +import com.finfellows.domain.bookmark.application.FinancialProductBookmarkServiceImpl; +import com.finfellows.domain.bookmark.application.PolicyInfoBookmarkServiceImpl; +import com.finfellows.global.config.security.token.CurrentUser; +import com.finfellows.global.config.security.token.UserPrincipal; +import com.finfellows.global.payload.ErrorResponse; +import com.finfellows.global.payload.Message; +import com.finfellows.global.payload.ResponseCustom; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "Bookmark", description = "Bookmark API") +@Slf4j +@RequiredArgsConstructor +@RestController +@RequestMapping("/bookmarks") +public class BookmarkController { + private final EduContentBookmarkServiceImpl eduContentBookmarkService; + private final FinancialProductBookmarkServiceImpl financialProductBookmarkService; + private final PolicyInfoBookmarkServiceImpl policyInfoBookmarkService; + + + @Operation(summary = "금융, 고마워 북마크", description = "금융, 고마워(정책)를 북마크한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "금융, 고마워.(정책) 즐겨찾기 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "금융, 고마워.(정책) 즐겨찾기 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), + }) + @PostMapping("/policy-info/{policy_info_id}") + public ResponseCustom bookmarkPolicyInfo( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, + @Parameter(description = "금융, 고마워(정책) id를 입력해주세요.", required = true) @Valid @PathVariable("policy_info_id") Long policy_info_id + ) { + return ResponseCustom.OK(policyInfoBookmarkService.insert(userPrincipal, policy_info_id)); + } + + @Operation(summary = "금융, 고마워 북마크 삭제", description = "금융, 고마워(정책) 북마크를 삭제한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "금융, 고마워.(정책) 즐겨찾기 삭제 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "금융, 고마워.(정책) 즐겨찾기 삭제 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), + }) + @DeleteMapping("/policy-info/{policy_info_id}") + public ResponseCustom deleteBookmarkPolicyInfo( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, + @Parameter(description = "금융, 고마워(정책) id를 입력해주세요.", required = true) @Valid @PathVariable("policy_info_id") Long policy_info_id + ) { + return ResponseCustom.OK(policyInfoBookmarkService.delete(userPrincipal, policy_info_id)); + } + + @Operation(summary = "금융, 배우자 북마크", description = "금융, 배우자(교육)를 북마크한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "금융, 배우자.(교육) 즐겨찾기 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "금융, 배우자.(교육) 즐겨찾기 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), + }) + @PostMapping("/edu-content/{edu_content_id}") + public ResponseCustom bookmarkEduContent( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, + @Parameter(description = "금융, 배우자(교육) id를 입력해주세요.", required = true) @Valid @PathVariable("edu_content_id") Long edu_content_id + ) { + return ResponseCustom.OK(eduContentBookmarkService.insert(userPrincipal, edu_content_id)); + } + + @Operation(summary = "금융, 배우자 북마크 삭제", description = "금융, 배우자(교육) 북마크를 삭제한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "금융, 배우자(교육). 즐겨찾기 삭제 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "금융, 배우자(교육). 즐겨찾기 삭제 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), + }) + @DeleteMapping("/edu-content/{edu_content_id}") + public ResponseCustom deleteBookmarkEduContent( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, + @Parameter(description = "금융, 배우자(교육) id를 입력해주세요.", required = true) @Valid @PathVariable("edu_content_id") Long edu_content_id + ) { + return ResponseCustom.OK(eduContentBookmarkService.delete(userPrincipal, edu_content_id)); + } + + @Operation(summary = "금융, 뭐하지 북마크", description = "금융, 뭐하지(금융 상품)를 북마크한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "금융, 뭐하지(금융 상품) 즐겨찾기 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "금융, 뭐하지(금융 상품) 즐겨찾기 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), + }) + @PostMapping("/financial-product/{financial_product_id}") + public ResponseCustom bookmarkFinancialProduct( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, + @Parameter(description = "금융, 뭐하지(금융 상품) id를 입력해주세요.", required = true) @Valid @PathVariable("financial_product_id") Long financial_product_id + ) { + return ResponseCustom.OK(financialProductBookmarkService.insert(userPrincipal, financial_product_id)); + } + + @Operation(summary = "금융, 뭐하지 북마크 삭제", description = "금융, 뭐하지(금융 상품) 북마크를 삭제한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "금융, 뭐하지(금융 상품). 즐겨찾기 삭제 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "금융, 뭐하지(금융 상품). 즐겨찾기 삭제 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), + }) + @DeleteMapping("/financial-product/{financial_product_id}") + public ResponseCustom deleteBookmarkFinancialProduct( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal, + @Parameter(description = "금융, 뭐하지(금융 상품) id를 입력해주세요.", required = true) @Valid @PathVariable("financial_product_id") Long financial_product_id + ) { + return ResponseCustom.OK(financialProductBookmarkService.delete(userPrincipal, financial_product_id)); + } + + + +} diff --git a/src/main/java/com/finfellows/domain/product/domain/repository/FinancialProductRepository.java b/src/main/java/com/finfellows/domain/product/domain/repository/FinancialProductRepository.java index 6c94a53..6a26ef5 100644 --- a/src/main/java/com/finfellows/domain/product/domain/repository/FinancialProductRepository.java +++ b/src/main/java/com/finfellows/domain/product/domain/repository/FinancialProductRepository.java @@ -4,4 +4,5 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface FinancialProductRepository extends JpaRepository { + } diff --git a/src/main/java/com/finfellows/domain/user/application/UserService.java b/src/main/java/com/finfellows/domain/user/application/UserService.java index 2d6074d..ea83f17 100644 --- a/src/main/java/com/finfellows/domain/user/application/UserService.java +++ b/src/main/java/com/finfellows/domain/user/application/UserService.java @@ -19,4 +19,5 @@ public class UserService { + } diff --git a/src/main/java/com/finfellows/domain/user/presentation/UserController.java b/src/main/java/com/finfellows/domain/user/presentation/UserController.java index c9e2ffc..e121357 100644 --- a/src/main/java/com/finfellows/domain/user/presentation/UserController.java +++ b/src/main/java/com/finfellows/domain/user/presentation/UserController.java @@ -1,26 +1,74 @@ package com.finfellows.domain.user.presentation; +import com.finfellows.domain.bookmark.application.EduContentBookmarkServiceImpl; +import com.finfellows.domain.bookmark.application.FinancialProductBookmarkServiceImpl; +import com.finfellows.domain.bookmark.application.PolicyInfoBookmarkServiceImpl; import com.finfellows.domain.user.application.UserService; import com.finfellows.domain.user.domain.User; +import com.finfellows.global.config.security.token.CurrentUser; +import com.finfellows.global.config.security.token.UserPrincipal; +import com.finfellows.global.payload.ErrorResponse; import com.finfellows.global.payload.Message; +import com.finfellows.global.payload.ResponseCustom; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; -import org.springframework.web.ErrorResponse; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +@Tag(name = "User", description = "User API") @RestController @RequiredArgsConstructor -@RequestMapping("/api/v1/users") +@RequestMapping("/users") public class UserController { + private final EduContentBookmarkServiceImpl eduContentBookmarkService; + private final FinancialProductBookmarkServiceImpl financialProductBookmarkService; + private final PolicyInfoBookmarkServiceImpl policyInfoBookmarkService; + + + @Operation(summary = "금융, 뭐하지 즐겨찾기 내역 조회", description = "금융, 뭐하지(금융 상품) 즐겨찾기 내역을 조회한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "금융, 뭐하지.(금융 상품) 즐겨찾기 조회 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "금융, 뭐하지.(금융 상품) 즐겨찾기 조회 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), + }) + @GetMapping("/financial-products") + public ResponseCustom getBookmarkedFinancialProducts( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal + ) { + return financialProductBookmarkService.findBookmarks(userPrincipal); + } + + @Operation(summary = "금융, 배우자 즐겨찾기 내역 조회", description = "금융, 배우자(교육) 즐겨찾기 내역을 조회한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "금융, 배우자.(교육) 즐겨찾기 삭제 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "금융, 배우자.(교육) 즐겨찾기 삭제 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), + }) + @GetMapping("/eduContents") + public ResponseCustom getBookmarkedEduContents( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal + ) { + return eduContentBookmarkService.findBookmarks(userPrincipal); + } + + @Operation(summary = "금융, 고마워 즐겨찾기 내역 조회", description = "금융, 고마워(정책) 즐겨찾기 내역을 조회한다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "금융, 고마워.(정책) 즐겨찾기 삭제 성공", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = Message.class) ) } ), + @ApiResponse(responseCode = "400", description = "금융, 고마워.(정책) 즐겨찾기 삭제 실패", content = { @Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class) ) } ), + }) + @GetMapping("/policy-infos") + public ResponseCustom getBookmarkedPolicyInfos( + @Parameter(description = "Accesstoken을 입력해주세요.", required = true) @CurrentUser UserPrincipal userPrincipal + ) { + return policyInfoBookmarkService.findBookmarks(userPrincipal); + } }