-
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 #28 from 9oormthon-univ/feat/point
[FEAT] 스윕페이/포인트 홈 조회 및 카드등록 구현
- Loading branch information
Showing
17 changed files
with
369 additions
and
28 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
48 changes: 48 additions & 0 deletions
48
src/main/java/com/groom/swipo/domain/auth/service/S3Service.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,48 @@ | ||
package com.groom.swipo.domain.auth.service; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.CannedAccessControlList; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.UUID; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.model.ObjectMetadata; | ||
import com.amazonaws.services.s3.model.PutObjectRequest; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.UUID; | ||
|
||
@Service | ||
public class S3Service { | ||
|
||
private final AmazonS3 amazonS3; | ||
|
||
@Value("${cloud.s3.bucket}") | ||
private String bucketName; | ||
|
||
public S3Service(AmazonS3 amazonS3) { | ||
this.amazonS3 = amazonS3; | ||
} | ||
|
||
public String uploadImage(MultipartFile image) { | ||
String fileName = UUID.randomUUID().toString() + "-" + image.getOriginalFilename(); | ||
try (InputStream inputStream = image.getInputStream()) { | ||
ObjectMetadata metadata = new ObjectMetadata(); // 콘텐츠 길이 지정 | ||
metadata.setContentLength(image.getSize()); | ||
|
||
amazonS3.putObject(new PutObjectRequest(bucketName, fileName, inputStream, metadata)); | ||
return amazonS3.getUrl(bucketName, fileName).toString(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("이미지 업로드 중 오류가 발생했습니다.", e); | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/groom/swipo/domain/payment/dto/PaylistInfo.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,25 @@ | ||
package com.groom.swipo.domain.payment.dto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import com.groom.swipo.domain.payment.entity.Paylist; | ||
import com.groom.swipo.domain.store.entity.Store; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record PaylistInfo( | ||
String paylistId, | ||
Integer amount, | ||
String storeName, | ||
LocalDateTime createAt | ||
) { | ||
public static PaylistInfo of(Paylist paylist, Store store){ | ||
return PaylistInfo.builder() | ||
.paylistId(String.valueOf(paylist.getId())) | ||
.amount((int)paylist.getValue()) | ||
.storeName(store.getName()) | ||
.createAt(paylist.getCreatedAt()) | ||
.build(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/groom/swipo/domain/payment/exception/PayNotFoundException.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,13 @@ | ||
package com.groom.swipo.domain.payment.exception; | ||
|
||
import com.groom.swipo.global.error.exception.NotFoundGroupException; | ||
|
||
public class PayNotFoundException extends NotFoundGroupException { | ||
public PayNotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
public PayNotFoundException() { | ||
super("해당 페이를 찾지 못했습니다."); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/groom/swipo/domain/payment/repository/PayRepository.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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package com.groom.swipo.domain.payment.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.groom.swipo.domain.payment.entity.Pay; | ||
import com.groom.swipo.domain.user.entity.User; | ||
|
||
@Repository | ||
public interface PayRepository extends JpaRepository<Pay, Long> { | ||
Optional<Pay> findByUser(User user); | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/groom/swipo/domain/payment/repository/PaylistRepository.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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package com.groom.swipo.domain.payment.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.groom.swipo.domain.payment.entity.Pay; | ||
import com.groom.swipo.domain.payment.entity.Paylist; | ||
|
||
@Repository | ||
public interface PaylistRepository extends JpaRepository<Paylist, Long> { | ||
List<Paylist> findTop5ByPayOrderByCreatedAtDesc(Pay pay); | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/groom/swipo/domain/point/dto/CardInfo.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,22 @@ | ||
package com.groom.swipo.domain.point.dto; | ||
|
||
import com.groom.swipo.domain.point.entity.Card; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record CardInfo( | ||
String cardId, | ||
String region, | ||
Integer point, | ||
String customImage | ||
) { | ||
public static CardInfo from(Card card) { | ||
return CardInfo.builder() | ||
.cardId(String.valueOf(card.getId())) | ||
.region(card.getArea().getRegionName()) | ||
.point(card.getTotalPoint()) | ||
.customImage(card.getCustomImage()) | ||
.build(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/groom/swipo/domain/point/dto/Response/PointHomeResponse.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,26 @@ | ||
package com.groom.swipo.domain.point.dto.Response; | ||
|
||
import java.util.List; | ||
|
||
import com.groom.swipo.domain.payment.dto.PaylistInfo; | ||
import com.groom.swipo.domain.payment.entity.Pay; | ||
import com.groom.swipo.domain.point.dto.CardInfo; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record PointHomeResponse( | ||
Integer balance, // 페이잔액 | ||
Integer totalCards, //사용자가 보유한 모든 지역 카드 수 | ||
List<CardInfo> cards, | ||
List<PaylistInfo> paylistInfos | ||
) { | ||
public static PointHomeResponse of(Pay pay, Integer totalCards, List<CardInfo> cards, List<PaylistInfo> paylistInfos){ | ||
return PointHomeResponse.builder() | ||
.balance(pay.getTotalPay()) | ||
.totalCards(totalCards) | ||
.cards(cards) | ||
.paylistInfos(paylistInfos) | ||
.build(); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/com/groom/swipo/domain/point/exception/DuplicateCardException.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,12 @@ | ||
package com.groom.swipo.domain.point.exception; | ||
|
||
import com.groom.swipo.global.error.exception.ConflictGroupException; | ||
|
||
public class DuplicateCardException extends ConflictGroupException { | ||
public DuplicateCardException(String message) { | ||
super(message); | ||
} | ||
public DuplicateCardException(){ | ||
this("이미 해당 지역카드가 존재합니다."); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/com/groom/swipo/domain/point/exception/InvalidRegionException.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,13 @@ | ||
package com.groom.swipo.domain.point.exception; | ||
|
||
import com.groom.swipo.global.error.exception.InvalidGroupException; | ||
|
||
public class InvalidRegionException extends InvalidGroupException { | ||
|
||
public InvalidRegionException(String message) { | ||
super(message); | ||
} | ||
public InvalidRegionException(){ | ||
this("지역명을 잘못 작성하였거나 유효하지 않는 지역입니다."); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/groom/swipo/domain/point/repository/CardRepository.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 |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package com.groom.swipo.domain.point.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.groom.swipo.domain.point.entity.Card; | ||
import com.groom.swipo.domain.user.entity.User; | ||
import com.groom.swipo.global.common.enums.Area; | ||
|
||
@Repository | ||
public interface CardRepository extends JpaRepository<Card, Long> { | ||
List<Card> findAllByUser(User user); | ||
boolean existsByUserAndArea(User user, Area area); | ||
} |
Oops, something went wrong.