Skip to content

Commit

Permalink
Merge pull request #96 from CoolPeace-yanolza/develop
Browse files Browse the repository at this point in the history
쿠폰 조회(검색) 관련 및 swagger ui URL 관련 수정사항 반영 release
  • Loading branch information
tkddn204 authored Jan 10, 2024
2 parents bc140d1 + 5fa4b3d commit 0d9bbc6
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
shell: bash

- name: Gradle 빌드 및 테스트 실행
run: ./gradlew build
run: ./gradlew build -Pprod
shell: bash

- name: Gradle bootJar 패키징
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ sourceSets {
main.java.srcDir querydslDir
}

def isProd = project.hasProperty('prod')

// Swagger UI 설정
openapi3 {
servers = [ { url = "http://localhost:8080" }, { url = "https://coolpeace.store" } ]
server = isProd ? "https://coolpeace.store" : "http://localhost:8080"
title = "CoolPeace API"
description = "CoolPeace API Document"
version = "0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.springframework.web.bind.annotation.*;

import java.net.URI;
import java.util.Optional;
import java.util.List;

@RestController
@RequestMapping("/v1/coupons")
Expand All @@ -28,7 +28,7 @@ public class CouponController {
@GetMapping
public ResponseEntity<Page<CouponResponse>> searchCoupons(
SearchCouponParams searchCouponParams,
@PageableDefault(size = 6) Pageable pageable,
@PageableDefault Pageable pageable,
@AuthJwtPrincipal JwtPrincipal jwtPrincipal
) {
return ResponseEntity.ok(couponService.searchCoupons(
Expand All @@ -39,11 +39,11 @@ public ResponseEntity<Page<CouponResponse>> searchCoupons(
public ResponseEntity<?> getCouponRecentHistory(
@AuthJwtPrincipal JwtPrincipal jwtPrincipal
) {
Optional<CouponResponse> couponResponse = couponService.getRecentHistory(Long.valueOf(jwtPrincipal.getMemberId()));
if (couponResponse.isEmpty()) {
List<CouponResponse> couponResponses = couponService.getRecentHistory(Long.valueOf(jwtPrincipal.getMemberId()));
if (couponResponses.isEmpty()) {
return ResponseEntity.noContent().build();
}
return ResponseEntity.ok().body(couponResponse.get());
return ResponseEntity.ok().body(couponResponses);
}

@PostMapping("/register")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.coolpeace.domain.coupon.entity.type.CouponRoomType;
import org.springframework.core.convert.converter.Converter;

public class CouponRoomTypeConverter implements Converter<String, CouponRoomType> {
public class CouponRoomTypeRequestConverter implements Converter<String, CouponRoomType> {
@Override
public CouponRoomType convert(String couponRoomTypeString) {
return CouponRoomType.valueOf(couponRoomTypeString.toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.coolpeace.domain.coupon.entity.type.CustomerType;
import org.springframework.core.convert.converter.Converter;

public class CustomerTypeConverter implements Converter<String, CustomerType> {
public class CustomerTypeRequestConverter implements Converter<String, CustomerType> {
@Override
public CustomerType convert(String customerTypeString) {
return CustomerType.valueOf(customerTypeString.toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import java.time.DayOfWeek;

public class DayOfWeekConverter implements Converter<String, DayOfWeek> {
public class DayOfWeekRequestConverter implements Converter<String, DayOfWeek> {
@Override
public DayOfWeek convert(String discountTypeString) {
return DayOfWeek.valueOf(discountTypeString.toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.coolpeace.domain.coupon.entity.type.DiscountType;
import org.springframework.core.convert.converter.Converter;

public class DiscountTypeConverter implements Converter<String, DiscountType> {
public class DiscountTypeRequestConverter implements Converter<String, DiscountType> {
@Override
public DiscountType convert(String discountTypeString) {
return DiscountType.valueOf(discountTypeString.toUpperCase());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,58 @@
package com.coolpeace.domain.coupon.dto.response;

import com.coolpeace.domain.coupon.entity.Coupon;
import com.coolpeace.domain.coupon.entity.type.CouponRoomType;
import com.coolpeace.domain.coupon.entity.type.CouponStatusType;
import com.coolpeace.domain.coupon.entity.type.CustomerType;
import com.coolpeace.domain.coupon.entity.type.DiscountType;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.TextStyle;
import java.util.List;
import java.util.Locale;

public record CouponResponse(
String title,
String couponNumber,
CouponStatusType couponStatus,
DiscountType discountType,
String couponStatus,
Boolean couponPromotion,
String couponConcatTitle,
String discountType,
Integer discountValue,
CustomerType customerType,
CouponRoomType couponRoomType,
String customerType,
String couponRoomType,
Integer minimumReservationPrice,
List<DayOfWeek> couponUseConditionDays,
List<String> couponUseConditionDays,
LocalDate exposureStartDate,
LocalDate exposureEndDate,
Integer couponExpiration,
Integer downloadCount,
Integer useCount,
Long accommodationId,
List<Integer> registerRoomNumbers,
LocalDateTime createdDate
List<String> registerRoomNumbers,
LocalDate createdDate
) {

public static CouponResponse from(Coupon coupon, List<Integer> registerRoomNumbers) {
public static CouponResponse from(Coupon coupon) {
return new CouponResponse(
coupon.getTitle(),
coupon.getCouponNumber(),
coupon.getCouponStatus(),
coupon.getDiscountType(),
coupon.getCouponStatus().getValue(),
false, // 프로모션이 개발되면 추후 수정 예정
coupon.getConcatTitle(),
coupon.getDiscountType().getValue(),
coupon.getDiscountValue(),
coupon.getCustomerType(),
coupon.getCouponRoomType(),
coupon.getCustomerType().getValue(),
coupon.getCouponRoomType().getValue(),
coupon.getMinimumReservationPrice(),
coupon.getCouponUseConditionDays(),
coupon.getCouponUseConditionDays()
.stream().map(dayOfWeek -> dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.KOREAN))
.toList(),
coupon.getExposureStartDate(),
coupon.getExposureEndDate(),
coupon.getCouponExpiration(),
coupon.getDownloadCount(),
coupon.getUseCount(),
coupon.getAccommodation() != null ? coupon.getAccommodation().getId() : null,
registerRoomNumbers,
coupon.getCreatedAt()
coupon.getCouponRooms().stream()
.map(couponRooms -> couponRooms.getRoom().getRoomNumber() + "호").toList(),
coupon.getCreatedAt().toLocalDate()
);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/coolpeace/domain/coupon/entity/Coupon.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,11 @@ public void updateCoupon(
this.exposureEndDate = Optional.ofNullable(exposureEndDate).orElse(this.exposureEndDate);
updateCouponStatusByExposureDate();
}

public String getConcatTitle() {
return switch (this.discountType) {
case FIXED_PRICE -> String.format("%s %d원 할인", customerType.getValue(), discountValue);
case FIXED_RATE -> String.format("%s %d%% 할인", customerType.getValue(), discountValue);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface CouponRepositoryCustom {

Page<Coupon> findAllCoupons(Long memberId, SearchCouponParams params, PageRequest pageable);

Optional<Coupon> findRecentCouponByMemberId(Long memberId);
List<Coupon> findRecentCouponByMemberId(Long memberId);

Optional<Coupon> findByCouponNumber(String couponNumber);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public Page<Coupon> findAllCoupons(Long memberId, SearchCouponParams params, Pag
if (params.status() != null) {
searchCouponPredicate.and(switch (params.status()) {
case EXPOSURE_ON -> coupon.couponStatus.eq(CouponStatusType.EXPOSURE_ON);
case EXPOSURE_OFF -> coupon.couponStatus.eq(CouponStatusType.EXPOSURE_OFF);
case EXPOSURE_OFF -> coupon.couponStatus.eq(CouponStatusType.EXPOSURE_OFF)
.or(coupon.couponStatus.eq(CouponStatusType.EXPOSURE_WAIT));
case EXPIRED -> coupon.couponStatus.eq(CouponStatusType.EXPOSURE_END)
.or(coupon.couponStatus.eq(CouponStatusType.DELETED));
case All -> coupon.couponStatus.isNotNull();
Expand Down Expand Up @@ -73,18 +74,14 @@ public Page<Coupon> findAllCoupons(Long memberId, SearchCouponParams params, Pag
}

@Override
public Optional<Coupon> findRecentCouponByMemberId(Long memberId) {
List<Coupon> coupons = jpaQueryFactory.selectFrom(coupon)
public List<Coupon> findRecentCouponByMemberId(Long memberId) {
return jpaQueryFactory.selectFrom(coupon)
.leftJoin(coupon.couponRooms, couponRooms).fetchJoin()
.leftJoin(couponRooms.room, room).fetchJoin()
.where(coupon.member.id.eq(memberId))
.orderBy(coupon.createdAt.desc())
.limit(4)
.fetch();
if (coupons.isEmpty()) {
return Optional.empty();
} else {
return Optional.ofNullable(coupons.get(0));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

@RequiredArgsConstructor
@Service
Expand All @@ -46,20 +46,15 @@ public class CouponService {
@Transactional(readOnly = true)
public Page<CouponResponse> searchCoupons(Long memberId, SearchCouponParams searchCouponParams, Pageable pageable) {
return couponRepository.findAllCoupons(memberId, searchCouponParams,
PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), pageable.getSort()))
.map(coupon -> CouponResponse.from(coupon,
coupon.getCouponRooms().stream()
.map(couponRooms -> couponRooms.getRoom().getRoomNumber()).toList())
);
PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(),
pageable.getSortOr(Sort.by(Sort.Direction.DESC, "createdAt"))))
.map(CouponResponse::from);
}

@Transactional(readOnly = true)
public Optional<CouponResponse> getRecentHistory(Long memberId) {
public List<CouponResponse> getRecentHistory(Long memberId) {
return couponRepository.findRecentCouponByMemberId(memberId)
.map(coupon -> CouponResponse.from(coupon,
coupon.getCouponRooms().stream()
.map(couponRooms -> couponRooms.getRoom().getRoomNumber()).toList())
);
.stream().map(CouponResponse::from).toList();
}

@Transactional
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/coolpeace/global/config/ConverterConfig.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.coolpeace.global.config;

import com.coolpeace.domain.coupon.dto.request.converter.CouponRoomTypeConverter;
import com.coolpeace.domain.coupon.dto.request.converter.CustomerTypeConverter;
import com.coolpeace.domain.coupon.dto.request.converter.DayOfWeekConverter;
import com.coolpeace.domain.coupon.dto.request.converter.DiscountTypeConverter;
import com.coolpeace.domain.coupon.dto.request.converter.CouponRoomTypeRequestConverter;
import com.coolpeace.domain.coupon.dto.request.converter.CustomerTypeRequestConverter;
import com.coolpeace.domain.coupon.dto.request.converter.DayOfWeekRequestConverter;
import com.coolpeace.domain.coupon.dto.request.converter.DiscountTypeRequestConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand All @@ -12,10 +12,10 @@
public class ConverterConfig implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
// coupons
registry.addConverter(new CustomerTypeConverter());
registry.addConverter(new DiscountTypeConverter());
registry.addConverter(new CouponRoomTypeConverter());
registry.addConverter(new DayOfWeekConverter());
// coupon requests
registry.addConverter(new CustomerTypeRequestConverter());
registry.addConverter(new DiscountTypeRequestConverter());
registry.addConverter(new CouponRoomTypeRequestConverter());
registry.addConverter(new DayOfWeekRequestConverter());
}
}
Loading

0 comments on commit 0d9bbc6

Please sign in to comment.