This repository has been archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from FinFellows/develop
[FEAT]: User, Bookmark 기능 API 배포
- Loading branch information
Showing
18 changed files
with
689 additions
and
20 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/main/java/com/finfellows/domain/bookmark/application/BookmarkService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/java/com/finfellows/domain/bookmark/application/EduContentBookmarkServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<User> optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); | ||
Optional<EduContent> 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<User> optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); | ||
Optional<EduContent> 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<List<EduContentBookmarkRes>> findBookmarks(UserPrincipal userPrincipal) { | ||
Optional<User> optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); | ||
|
||
User user = optionalUser.get(); | ||
|
||
List<EduContentBookmark> bookmarks = eduContentBookmarkRepository.findAllByUser(user); | ||
|
||
|
||
List<EduContentBookmarkRes> eduContentBookmarkResList = EduContentBookmarkRes.toDto(bookmarks); | ||
|
||
|
||
return ResponseCustom.OK(eduContentBookmarkResList); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
.../java/com/finfellows/domain/bookmark/application/FinancialProductBookmarkServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<User> optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); | ||
Optional<FinancialProduct> 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<User> optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); | ||
Optional<FinancialProduct> 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<List<EduContentBookmarkRes>> findBookmarks(UserPrincipal userPrincipal) { | ||
Optional<User> optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); | ||
|
||
User user = optionalUser.get(); | ||
|
||
List<EduContentBookmark> bookmarks = eduContentBookmarkRepository.findAllByUser(user); | ||
|
||
|
||
List<EduContentBookmarkRes> eduContentBookmarkResList = EduContentBookmarkRes.toDto(bookmarks); | ||
|
||
|
||
return ResponseCustom.OK(eduContentBookmarkResList); | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/finfellows/domain/bookmark/application/PolicyInfoBookmarkServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<User> optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); | ||
Optional<PolicyInfo> 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<User> optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); | ||
Optional<PolicyInfo> 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<User> optionalUser = userRepository.findByEmail(userPrincipal.getEmail()); | ||
|
||
User user = optionalUser.get(); | ||
|
||
List<PolicyInfoBookmark> bookmarks = policyInfoBookmarkRepository.findAllByUser(user); | ||
|
||
List<PolicyInfoBookmarkRes> policyInfoBookmarkResList = PolicyInfoBookmarkRes.toDto(bookmarks); | ||
|
||
return ResponseCustom.OK(policyInfoBookmarkResList); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/finfellows/domain/bookmark/domain/EduContentBookmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.