Skip to content

Commit

Permalink
Merge pull request #28 from 9oormthon-univ/feat/point
Browse files Browse the repository at this point in the history
[FEAT] 스윕페이/포인트 홈 조회 및 카드등록 구현
  • Loading branch information
kduoh99 authored Nov 22, 2024
2 parents 1d37dc3 + 80bec94 commit ad11637
Show file tree
Hide file tree
Showing 17 changed files with 369 additions and 28 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ dependencies {

// 휴대폰 인증 API (nurigo)
implementation 'net.nurigo:sdk:4.3.0'

// S3
implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4'
}

// iamport
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/groom/swipo/domain/auth/service/S3Service.java
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 src/main/java/com/groom/swipo/domain/payment/dto/PaylistInfo.java
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();
}
}
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("해당 페이를 찾지 못했습니다.");
}
}
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);
}
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.groom.swipo.domain.point.dto.Request.SwipstoneSwapRequest;
import com.groom.swipo.domain.point.dto.Response.PointHomeResponse;
import com.groom.swipo.domain.point.dto.Response.SwipstoneResponse;
import com.groom.swipo.domain.point.dto.Response.SwipstoneSwapResponse;
import com.groom.swipo.domain.point.service.PointService;
Expand All @@ -27,6 +30,46 @@
public class PointController {
private final PointService pointService;

@GetMapping("/home")
@Operation(
summary = "스윕페이/포인트 홈 조회",
description = "상단 스웹페이 탭 클릭시 조회되는 정보 제공",
security = {},
responses = {
@ApiResponse(responseCode = "200", description = "조회 성공"),
@ApiResponse(responseCode = "400", description = "잘못된 요청"),
@ApiResponse(responseCode = "401", description = "인증되지 않은 요청"),
@ApiResponse(responseCode = "500", description = "서버 오류")
}
)
public ResTemplate<PointHomeResponse> getHome(Principal principal) {
PointHomeResponse data = pointService.getHome(principal);
return new ResTemplate<>(HttpStatus.OK, "조회 성공", data);
}

@PostMapping("/card-register")
@Operation(
summary = "포인트 카드 등록",
description = "지역 정보와 이미지 파일을 사용하여 포인트 카드를 등록합니다.",
security = {},
responses = {
@ApiResponse(responseCode = "201", description = "카드 등록 성공"),
@ApiResponse(responseCode = "400", description = "유효하지 않은 동네"),
@ApiResponse(responseCode = "401", description = "유효하지 않은 인증 토큰"),
@ApiResponse(responseCode = "409", description = "중복 카드 등록"),
@ApiResponse(responseCode = "500", description = "서버 오류")
}
)
public ResTemplate<Void> registerCard(
@RequestPart("region") String region,
@RequestPart(value = "custom_image", required = false) MultipartFile customImage,
Principal principal) {

pointService.registerCard(region, customImage, principal);
return new ResTemplate<>(HttpStatus.CREATED, "카드 등록 성공");
}


@GetMapping("/swipstone")
@Operation(
summary = "스윕스톤 조회",
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/groom/swipo/domain/point/dto/CardInfo.java
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();
}
}
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();
}
}
15 changes: 6 additions & 9 deletions src/main/java/com/groom/swipo/domain/point/entity/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@ public class Card extends BaseEntity {
@Column(name = "card_id")
private Long id;

@Column(nullable = false)
private String number;

private String contents;

@Column(nullable = false)
@ColumnDefault("0")
private Integer totalPoint;

@Column(nullable = false)
private String customeImage;
private String customImage;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
Expand All @@ -61,11 +58,11 @@ public class Card extends BaseEntity {
private List<Cardlist> cardlists = new ArrayList<>();

@Builder
private Card(String number, String contents, Integer totalPoint, String customeImage, Area area) {
this.number = number;
this.contents = contents;
this.totalPoint = totalPoint;
this.customeImage = customeImage;
private Card(User user, String customImage, Area area) {
this.user = user;
this.contents = "";
this.totalPoint = 0; //default 0
this.customImage = customImage;
this.area = area;
}

Expand Down
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("이미 해당 지역카드가 존재합니다.");
}
}
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("지역명을 잘못 작성하였거나 유효하지 않는 지역입니다.");
}
}
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);
}
Loading

0 comments on commit ad11637

Please sign in to comment.