diff --git a/src/main/java/com/jangburich/domain/store/domain/StoreTeam.java b/src/main/java/com/jangburich/domain/store/domain/StoreTeam.java index b546b88..e5d8f48 100644 --- a/src/main/java/com/jangburich/domain/store/domain/StoreTeam.java +++ b/src/main/java/com/jangburich/domain/store/domain/StoreTeam.java @@ -10,6 +10,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import java.time.LocalDate; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -44,6 +45,9 @@ public class StoreTeam extends BaseEntity { @Column(name = "remain_point") private Integer remainPoint; + @Column(name = "prepaid_expiration_date") + private LocalDate prepaidExpirationDate; + public void updatePersonalAllocatedPoint(Integer point) { this.personalAllocatedPoint = point; } @@ -71,13 +75,16 @@ public void subRemainPoint(Integer point) { this.remainPoint -= point; } + @Builder - public StoreTeam(Store store, Team team, Integer point, Integer personalAllocatedPoint, Integer remainPoint) { + public StoreTeam(Store store, Team team, Integer point, Integer personalAllocatedPoint, Integer remainPoint, + LocalDate prepaidExpirationDate) { this.store = store; this.team = team; this.point = point; this.personalAllocatedPoint = personalAllocatedPoint; this.remainPoint = remainPoint; + this.prepaidExpirationDate = prepaidExpirationDate; } public static StoreTeam create(Team team, Store store, Integer point) { diff --git a/src/main/java/com/jangburich/domain/store/service/PrepayService.java b/src/main/java/com/jangburich/domain/store/service/PrepayService.java index d66958e..87e7cbe 100644 --- a/src/main/java/com/jangburich/domain/store/service/PrepayService.java +++ b/src/main/java/com/jangburich/domain/store/service/PrepayService.java @@ -15,6 +15,7 @@ import com.jangburich.global.error.DefaultNullPointerException; import com.jangburich.global.payload.ErrorCode; import com.jangburich.global.payload.Message; +import java.time.LocalDate; import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -57,6 +58,8 @@ public Message prepay(String userId, PrepayRequest prepayRequest) { pointTransactionRepository.save(pointTransaction); + LocalDate expirationDate = LocalDate.now().plusDays(store.getPrepaymentDuration()); + StoreTeam buildedStoreTeam = StoreTeam .builder() .team(team) @@ -64,6 +67,7 @@ public Message prepay(String userId, PrepayRequest prepayRequest) { .point(prepayRequest.prepayAmount()) .personalAllocatedPoint(prepayRequest.personalAllocatedAmount()) .remainPoint(prepayRequest.prepayAmount()) + .prepaidExpirationDate(expirationDate) .build(); Optional storeAndTeam = storeTeamRepository.findByStoreAndTeam(store, team); diff --git a/src/main/java/com/jangburich/domain/user/dto/response/TeamsResponse.java b/src/main/java/com/jangburich/domain/user/dto/response/TeamsResponse.java index 856f28c..5949054 100644 --- a/src/main/java/com/jangburich/domain/user/dto/response/TeamsResponse.java +++ b/src/main/java/com/jangburich/domain/user/dto/response/TeamsResponse.java @@ -5,6 +5,7 @@ public record TeamsResponse( Long teamId, Long storeId, + int dDay, String storeImgUrl, Boolean isLikedAtStore, String teamName, @@ -14,10 +15,12 @@ public record TeamsResponse( ) { @QueryProjection - public TeamsResponse(Long teamId, Long storeId, String storeImgUrl, Boolean isLikedAtStore, String teamName, + public TeamsResponse(Long teamId, Long storeId, int dDay, String storeImgUrl, Boolean isLikedAtStore, + String teamName, String storeName, int totalAmount, int currentAmount) { this.teamId = teamId; this.storeId = storeId; + this.dDay = dDay; this.storeImgUrl = storeImgUrl; this.isLikedAtStore = isLikedAtStore; this.teamName = teamName; diff --git a/src/main/java/com/jangburich/domain/user/repository/UserQueryDslRepositoryImpl.java b/src/main/java/com/jangburich/domain/user/repository/UserQueryDslRepositoryImpl.java index cdfe8cc..b76d8f9 100644 --- a/src/main/java/com/jangburich/domain/user/repository/UserQueryDslRepositoryImpl.java +++ b/src/main/java/com/jangburich/domain/user/repository/UserQueryDslRepositoryImpl.java @@ -33,8 +33,11 @@ public UserHomeResponse findUserHomeData(Long userId) { List teamsResponses = queryFactory .selectDistinct(new QTeamsResponse( - storeTeam.team.id, + userTeam.team.id, storeTeam.store.id, + Expressions.numberTemplate(Integer.class, + "DATEDIFF({0}, CURRENT_DATE)", + storeTeam.prepaidExpirationDate), storeTeam.store.representativeImage, Expressions.constant(false), storeTeam.team.name, @@ -42,15 +45,14 @@ public UserHomeResponse findUserHomeData(Long userId) { storeTeam.point, storeTeam.remainPoint )) - .from(storeTeam) - .leftJoin(team).on(team.id.eq(storeTeam.team.id)) - .leftJoin(userTeam).on(storeTeam.team.eq(team)) + .from(userTeam) + .leftJoin(team).on(team.id.eq(userTeam.team.id)) + .leftJoin(storeTeam).on(storeTeam.team.eq(team)) .where(storeTeam.status.eq(Status.ACTIVE), userTeam.user.userId.eq(userId)) .orderBy(storeTeam.createdAt.desc()) .fetch(); - UserHomeResponse userHomeResponse = queryFactory.select(new QUserHomeResponse( user.userId, Expressions.constant(formattedDate),