forked from KNU-HAEDAL/Birthday_Funding_BE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KNU-HAEDAL#1 feat: 기프티콘 및 유저 기프티콘 서비스 제작
- Loading branch information
Showing
3 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
src/main/java/team/haedal/gifticionfunding/service/gifticon/GifticonService.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,55 @@ | ||
package team.haedal.gifticionfunding.service.gifticon; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import team.haedal.gifticionfunding.entity.gifticon.Gifticon; | ||
import team.haedal.gifticionfunding.entity.gifticon.GifticonUpdate; | ||
import team.haedal.gifticionfunding.repository.gifticon.GifticonJpaRepository; | ||
|
||
import java.util.List; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class GifticonService { | ||
|
||
private final GifticonJpaRepository gifticonJpaRepository; | ||
|
||
//상품등록 | ||
@Transactional | ||
public Long registerGifticon(Gifticon gifticon){ | ||
gifticonJpaRepository.save(gifticon); | ||
return gifticon.getId(); | ||
} | ||
|
||
//상품 전체 조회 | ||
public List<Gifticon> findGifticonAll(){ | ||
return gifticonJpaRepository.findAll(); | ||
} | ||
|
||
//상품 상세 조회 | ||
public Gifticon findGifticon(Long gifticonId){ | ||
return gifticonJpaRepository.findById(gifticonId).orElse(null); | ||
} | ||
|
||
//상품 수정 | ||
|
||
@Transactional | ||
public void updateGifticon(Long gifticonId, GifticonUpdate gifticonUpadate){ | ||
Gifticon findGifticon = gifticonJpaRepository.findById(gifticonId).orElse(null); | ||
if(findGifticon == null){ | ||
throw new IllegalArgumentException("해당 상품이 존재하지 않습니다."); | ||
} | ||
findGifticon.updateGifticon(gifticonUpadate); | ||
} | ||
|
||
//상품 삭제 | ||
@Transactional | ||
public void deleteGifticon(Long gifticonId){ | ||
gifticonJpaRepository.deleteById(gifticonId); | ||
} | ||
|
||
} |
117 changes: 117 additions & 0 deletions
117
src/main/java/team/haedal/gifticionfunding/service/gifticon/UserGifticonService.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,117 @@ | ||
package team.haedal.gifticionfunding.service.gifticon; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import team.haedal.gifticionfunding.entity.gifticon.GifticonPurchase; | ||
import team.haedal.gifticionfunding.entity.gifticon.UserGifticon; | ||
import team.haedal.gifticionfunding.entity.user.User; | ||
import team.haedal.gifticionfunding.repository.gifticon.UserGifticonJpaRepository; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class UserGifticonService { | ||
private final UserGifticonJpaRepository userGifticonJpaRepository; | ||
|
||
/** | ||
* 유저기프티콘 전체 조회 | ||
*/ | ||
public List<UserGifticon> findUserGifticonAll() | ||
{ | ||
return userGifticonJpaRepository.findAll(); | ||
} | ||
|
||
/** | ||
* 유저기프티콘 상세 조회 | ||
*/ | ||
public UserGifticon findUserGifticon(Long userGifticonId) | ||
{ | ||
return userGifticonJpaRepository.findById(userGifticonId).orElse(null); | ||
} | ||
|
||
/** | ||
* 유저기프티콘 소유자별 조회 | ||
*/ | ||
public List<UserGifticon> findUserGifticonByOwner(User owner) | ||
{ | ||
return userGifticonJpaRepository.findByOwner(owner); | ||
} | ||
|
||
/** | ||
* 유저기프티콘 구매자별 조회 | ||
*/ | ||
public List<UserGifticon> findUserGifticonByBuyer(User buyer) | ||
{ | ||
return userGifticonJpaRepository.findByBuyer(buyer); | ||
} | ||
|
||
/** | ||
* 유저기프티콘 삭제 | ||
*/ | ||
@Transactional | ||
public void deleteUserGifticon(Long userGifticonId) | ||
{ | ||
userGifticonJpaRepository.deleteById(userGifticonId); | ||
} | ||
|
||
|
||
|
||
|
||
/** | ||
* 기프티콘 구매 | ||
*/ | ||
@Transactional | ||
public Long purchaseGifticon(GifticonPurchase gifticonPurchase) | ||
{ | ||
UserGifticon userGifticon = UserGifticon.purchaseGifticon(gifticonPurchase); | ||
userGifticonJpaRepository.save(userGifticon); | ||
return userGifticon.getId(); | ||
} | ||
|
||
/** | ||
* 기프티콘 사용 | ||
*/ | ||
@Transactional | ||
public void useGifticon(Long userGifticonId) | ||
{ | ||
UserGifticon userGifticon = userGifticonJpaRepository.findById(userGifticonId).orElse(null); | ||
if(userGifticon == null) | ||
{ | ||
throw new IllegalArgumentException("해당 기프티콘이 존재하지 않습니다."); | ||
} | ||
userGifticon.useGifticon(); | ||
} | ||
|
||
/** | ||
* 기프티콘 환불 | ||
*/ | ||
@Transactional | ||
public void refundGifticon(Long userGifticonId) | ||
{ | ||
UserGifticon userGifticon = userGifticonJpaRepository.findById(userGifticonId).orElse(null); | ||
if(userGifticon == null) | ||
{ | ||
throw new IllegalArgumentException("해당 기프티콘이 존재하지 않습니다."); | ||
} | ||
userGifticon.refundGifticon(); | ||
} | ||
|
||
/** | ||
* 기프티콘 소유자 변경 | ||
*/ | ||
@Transactional | ||
public void changeOwner(Long userGifticonId, User owner) | ||
{ | ||
UserGifticon userGifticon = userGifticonJpaRepository.findById(userGifticonId).orElse(null); | ||
if(userGifticon == null) | ||
{ | ||
throw new IllegalArgumentException("해당 기프티콘이 존재하지 않습니다."); | ||
} | ||
userGifticon.changeOwner(owner); | ||
} | ||
|
||
|
||
} |