From ed25c95d40c900cee94af53c11adb590b136ac70 Mon Sep 17 00:00:00 2001 From: HyuckJuneHong Date: Mon, 20 Nov 2023 18:25:20 +0900 Subject: [PATCH] =?UTF-8?q?style:=20=EC=BF=A0=ED=8F=B0=20=EB=B0=8F=20?= =?UTF-8?q?=EB=85=B8=EC=85=98=20=EB=A9=94=EC=84=9C=EB=93=9C,=20=EB=B3=80?= =?UTF-8?q?=EC=88=98,=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/application/coupon/CouponMapper.java | 22 +++++----- .../coupon/CouponQueueService.java | 6 +-- .../api/application/coupon/CouponService.java | 22 +++++----- .../notification/NotificationService.java | 25 ++++++----- .../application/room/RoomSearchService.java | 2 +- .../moabam/api/domain/coupon/CouponType.java | 8 ++-- .../repository/CouponQueueRepository.java | 4 +- .../repository/CouponSearchRepository.java | 22 +++++----- .../repository/NotificationRepository.java | 6 +-- .../moabam/api/dto/coupon/CouponResponse.java | 6 +-- .../api/dto/coupon/CouponSearchRequest.java | 12 ------ .../api/dto/coupon/CouponStatusRequest.java | 12 ++++++ .../api/dto/coupon/CreateCouponRequest.java | 2 +- .../fcm/FcmMapper.java} | 6 +-- .../api/infrastructure/fcm/FcmService.java | 7 ++-- .../api/presentation/CouponController.java | 18 ++++---- .../presentation/NotificationController.java | 2 +- src/main/resources/static/docs/coupon.html | 14 +++---- .../coupon/CouponQueueServiceTest.java | 12 +++--- .../application/coupon/CouponServiceTest.java | 42 +++++++++---------- .../notification/NotificationServiceTest.java | 34 +++++++-------- .../api/domain/coupon/CouponTypeTest.java | 2 +- .../repository/CouponQueueRepositoryTest.java | 8 ++-- .../CouponSearchRepositoryTest.java | 18 ++++---- .../NotificationRepositoryTest.java | 8 ++-- .../infrastructure/fcm/FcmServiceTest.java | 4 +- .../presentation/CouponControllerTest.java | 20 ++++----- .../NotificationControllerTest.java | 2 +- .../moabam/support/fixture/CouponFixture.java | 14 +++---- .../support/fixture/CouponSnippetFixture.java | 24 +++++------ 30 files changed, 191 insertions(+), 193 deletions(-) delete mode 100644 src/main/java/com/moabam/api/dto/coupon/CouponSearchRequest.java create mode 100644 src/main/java/com/moabam/api/dto/coupon/CouponStatusRequest.java rename src/main/java/com/moabam/api/{application/notification/NotificationMapper.java => infrastructure/fcm/FcmMapper.java} (75%) diff --git a/src/main/java/com/moabam/api/application/coupon/CouponMapper.java b/src/main/java/com/moabam/api/application/coupon/CouponMapper.java index a04f298e..f61a6c3c 100644 --- a/src/main/java/com/moabam/api/application/coupon/CouponMapper.java +++ b/src/main/java/com/moabam/api/application/coupon/CouponMapper.java @@ -11,15 +11,15 @@ @NoArgsConstructor(access = AccessLevel.PRIVATE) public final class CouponMapper { - public static Coupon toEntity(Long adminId, CreateCouponRequest request) { + public static Coupon toEntity(Long adminId, CreateCouponRequest coupon) { return Coupon.builder() - .name(request.name()) - .description(request.description()) - .type(CouponType.from(request.couponType())) - .point(request.point()) - .stock(request.stock()) - .startAt(request.startAt()) - .endAt(request.endAt()) + .name(coupon.name()) + .description(coupon.description()) + .type(CouponType.from(coupon.type())) + .point(coupon.point()) + .stock(coupon.stock()) + .startAt(coupon.startAt()) + .endAt(coupon.endAt()) .adminId(adminId) .build(); } @@ -27,13 +27,13 @@ public static Coupon toEntity(Long adminId, CreateCouponRequest request) { // TODO : Admin Table 생성 시, 관리자 명 추가할 예정 public static CouponResponse toDto(Coupon coupon) { return CouponResponse.builder() - .couponId(coupon.getId()) - .couponAdminName(coupon.getAdminId() + "admin") + .id(coupon.getId()) + .adminName(coupon.getAdminId() + "admin") .name(coupon.getName()) .description(coupon.getDescription()) .point(coupon.getPoint()) .stock(coupon.getStock()) - .couponType(coupon.getType()) + .type(coupon.getType()) .startAt(coupon.getStartAt()) .endAt(coupon.getEndAt()) .build(); diff --git a/src/main/java/com/moabam/api/application/coupon/CouponQueueService.java b/src/main/java/com/moabam/api/application/coupon/CouponQueueService.java index 5da33e6a..4bc3a165 100644 --- a/src/main/java/com/moabam/api/application/coupon/CouponQueueService.java +++ b/src/main/java/com/moabam/api/application/coupon/CouponQueueService.java @@ -25,12 +25,12 @@ public void register(AuthorizationMember member, String couponName) { return; } - couponQueueRepository.addQueue(couponName, member.nickname(), registerTime); + couponQueueRepository.addIfAbsent(couponName, member.nickname(), registerTime); } private boolean canRegister(String couponName) { - Coupon coupon = couponService.validateCouponPeriod(couponName); + Coupon coupon = couponService.validatePeriod(couponName); - return coupon.getStock() <= couponQueueRepository.queueSize(coupon.getName()); + return coupon.getStock() <= couponQueueRepository.size(coupon.getName()); } } diff --git a/src/main/java/com/moabam/api/application/coupon/CouponService.java b/src/main/java/com/moabam/api/application/coupon/CouponService.java index f967c096..5bf73a70 100644 --- a/src/main/java/com/moabam/api/application/coupon/CouponService.java +++ b/src/main/java/com/moabam/api/application/coupon/CouponService.java @@ -11,7 +11,7 @@ import com.moabam.api.domain.coupon.repository.CouponSearchRepository; import com.moabam.api.domain.member.Role; import com.moabam.api.dto.coupon.CouponResponse; -import com.moabam.api.dto.coupon.CouponSearchRequest; +import com.moabam.api.dto.coupon.CouponStatusRequest; import com.moabam.api.dto.coupon.CreateCouponRequest; import com.moabam.global.auth.model.AuthorizationMember; import com.moabam.global.common.util.ClockHolder; @@ -32,31 +32,31 @@ public class CouponService { private final ClockHolder clockHolder; @Transactional - public void createCoupon(AuthorizationMember admin, CreateCouponRequest request) { + public void create(AuthorizationMember admin, CreateCouponRequest request) { validateAdminRole(admin); - validateConflictCouponName(request.name()); - validateCouponPeriod(request.startAt(), request.endAt()); + validateConflictName(request.name()); + validatePeriod(request.startAt(), request.endAt()); Coupon coupon = CouponMapper.toEntity(admin.id(), request); couponRepository.save(coupon); } @Transactional - public void deleteCoupon(AuthorizationMember admin, Long couponId) { + public void delete(AuthorizationMember admin, Long couponId) { validateAdminRole(admin); Coupon coupon = couponRepository.findById(couponId) .orElseThrow(() -> new NotFoundException(ErrorMessage.NOT_FOUND_COUPON)); couponRepository.delete(coupon); } - public CouponResponse getCouponById(Long couponId) { + public CouponResponse getById(Long couponId) { Coupon coupon = couponRepository.findById(couponId) .orElseThrow(() -> new NotFoundException(ErrorMessage.NOT_FOUND_COUPON)); return CouponMapper.toDto(coupon); } - public List getCoupons(CouponSearchRequest request) { + public List getAllByStatus(CouponStatusRequest request) { LocalDateTime now = clockHolder.times(); List coupons = couponSearchRepository.findAllByStatus(now, request); @@ -65,7 +65,7 @@ public List getCoupons(CouponSearchRequest request) { .toList(); } - public Coupon validateCouponPeriod(String couponName) { + public Coupon validatePeriod(String couponName) { LocalDateTime now = clockHolder.times(); Coupon coupon = couponRepository.findByName(couponName) .orElseThrow(() -> new NotFoundException(ErrorMessage.NOT_FOUND_COUPON)); @@ -77,7 +77,7 @@ public Coupon validateCouponPeriod(String couponName) { throw new BadRequestException(ErrorMessage.INVALID_COUPON_PERIOD_END); } - private void validateCouponPeriod(LocalDateTime startAt, LocalDateTime endAt) { + private void validatePeriod(LocalDateTime startAt, LocalDateTime endAt) { if (startAt.isAfter(endAt)) { throw new BadRequestException(ErrorMessage.INVALID_COUPON_PERIOD); } @@ -89,8 +89,8 @@ private void validateAdminRole(AuthorizationMember admin) { } } - private void validateConflictCouponName(String name) { - if (couponRepository.existsByName(name)) { + private void validateConflictName(String couponName) { + if (couponRepository.existsByName(couponName)) { throw new ConflictException(ErrorMessage.CONFLICT_COUPON_NAME); } } diff --git a/src/main/java/com/moabam/api/application/notification/NotificationService.java b/src/main/java/com/moabam/api/application/notification/NotificationService.java index 0f7f30d8..a8f891ab 100644 --- a/src/main/java/com/moabam/api/application/notification/NotificationService.java +++ b/src/main/java/com/moabam/api/application/notification/NotificationService.java @@ -40,21 +40,21 @@ public class NotificationService { private final ClockHolder clockHolder; @Transactional - public void sendKnockNotification(AuthorizationMember member, Long targetId, Long roomId) { + public void sendKnock(AuthorizationMember member, Long targetId, Long roomId) { roomService.validateRoomById(roomId); String knockKey = generateKnockKey(member.id(), targetId, roomId); - validateConflictKnockNotification(knockKey); + validateConflictKnock(knockKey); validateFcmToken(targetId); String fcmToken = notificationRepository.findFcmTokenByMemberId(targetId); String notificationBody = String.format(KNOCK_BODY, member.nickname()); - fcmService.sendAsyncFcm(fcmToken, notificationBody); - notificationRepository.saveKnockNotification(knockKey); + fcmService.sendAsync(fcmToken, notificationBody); + notificationRepository.saveKnock(knockKey); } @Scheduled(cron = "0 50 * * * *") - public void sendCertificationTimeNotification() { + public void sendCertificationTime() { int certificationTime = (clockHolder.times().getHour() + ONE_HOUR) % HOURS_IN_A_DAY; List participants = participantSearchRepository.findAllByRoomCertifyTime(certificationTime); @@ -62,28 +62,27 @@ public void sendCertificationTimeNotification() { String roomTitle = participant.getRoom().getTitle(); String fcmToken = notificationRepository.findFcmTokenByMemberId(participant.getMemberId()); String notificationBody = String.format(CERTIFY_TIME_BODY, roomTitle); - fcmService.sendAsyncFcm(fcmToken, notificationBody); + fcmService.sendAsync(fcmToken, notificationBody); }); } - public List getMyKnockedNotificationStatusInRoom(Long memberId, Long roomId, - List participants) { + public List getMyKnockStatusInRoom(Long memberId, Long roomId, List participants) { List filteredParticipants = participants.stream() .filter(participant -> !participant.getMemberId().equals(memberId)) .toList(); Predicate knockPredicate = targetId -> - notificationRepository.existsByKey(generateKnockKey(memberId, targetId, roomId)); + notificationRepository.existsKnockByKnockKey(generateKnockKey(memberId, targetId, roomId)); - Map> knockNotificationStatus = filteredParticipants.stream() + Map> knockStatus = filteredParticipants.stream() .map(Participant::getMemberId) .collect(Collectors.partitioningBy(knockPredicate)); - return knockNotificationStatus.get(true); + return knockStatus.get(true); } - private void validateConflictKnockNotification(String knockKey) { - if (notificationRepository.existsByKey(knockKey)) { + private void validateConflictKnock(String knockKey) { + if (notificationRepository.existsKnockByKnockKey(knockKey)) { throw new ConflictException(ErrorMessage.CONFLICT_KNOCK); } } diff --git a/src/main/java/com/moabam/api/application/room/RoomSearchService.java b/src/main/java/com/moabam/api/application/room/RoomSearchService.java index 1d7e3c57..ee181003 100644 --- a/src/main/java/com/moabam/api/application/room/RoomSearchService.java +++ b/src/main/java/com/moabam/api/application/room/RoomSearchService.java @@ -158,7 +158,7 @@ private List getTodayCertificateRankResponses(Long .map(Participant::getMemberId) .toList()); - List myKnockedNotificationStatusInRoom = notificationService.getMyKnockedNotificationStatusInRoom( + List myKnockedNotificationStatusInRoom = notificationService.getMyKnockStatusInRoom( memberId, roomId, participants); addCompletedMembers(responses, dailyMemberCertifications, members, certifications, participants, date, diff --git a/src/main/java/com/moabam/api/domain/coupon/CouponType.java b/src/main/java/com/moabam/api/domain/coupon/CouponType.java index f8bfa263..722d4e8a 100644 --- a/src/main/java/com/moabam/api/domain/coupon/CouponType.java +++ b/src/main/java/com/moabam/api/domain/coupon/CouponType.java @@ -23,16 +23,16 @@ public enum CouponType { GOLDEN_COUPON("황금"), DISCOUNT_COUPON("할인"); - private final String typeName; + private final String name; private static final Map COUPON_TYPE_MAP; static { COUPON_TYPE_MAP = Collections.unmodifiableMap(Arrays.stream(values()) - .collect(Collectors.toMap(CouponType::getTypeName, Function.identity()))); + .collect(Collectors.toMap(CouponType::getName, Function.identity()))); } - public static CouponType from(String typeName) { - return Optional.ofNullable(COUPON_TYPE_MAP.get(typeName)) + public static CouponType from(String name) { + return Optional.ofNullable(COUPON_TYPE_MAP.get(name)) .orElseThrow(() -> new NotFoundException(ErrorMessage.NOT_FOUND_COUPON_TYPE)); } } diff --git a/src/main/java/com/moabam/api/domain/coupon/repository/CouponQueueRepository.java b/src/main/java/com/moabam/api/domain/coupon/repository/CouponQueueRepository.java index 6c82e022..a7ab35ef 100644 --- a/src/main/java/com/moabam/api/domain/coupon/repository/CouponQueueRepository.java +++ b/src/main/java/com/moabam/api/domain/coupon/repository/CouponQueueRepository.java @@ -14,11 +14,11 @@ public class CouponQueueRepository { private final ZSetRedisRepository zSetRedisRepository; - public void addQueue(String couponName, String memberNickname, double score) { + public void addIfAbsent(String couponName, String memberNickname, double score) { zSetRedisRepository.addIfAbsent(requireNonNull(couponName), requireNonNull(memberNickname), score); } - public Long queueSize(String couponName) { + public Long size(String couponName) { return zSetRedisRepository.size(requireNonNull(couponName)); } } diff --git a/src/main/java/com/moabam/api/domain/coupon/repository/CouponSearchRepository.java b/src/main/java/com/moabam/api/domain/coupon/repository/CouponSearchRepository.java index 7bbc3889..7a922d2a 100644 --- a/src/main/java/com/moabam/api/domain/coupon/repository/CouponSearchRepository.java +++ b/src/main/java/com/moabam/api/domain/coupon/repository/CouponSearchRepository.java @@ -8,7 +8,7 @@ import org.springframework.stereotype.Repository; import com.moabam.api.domain.coupon.Coupon; -import com.moabam.api.dto.coupon.CouponSearchRequest; +import com.moabam.api.dto.coupon.CouponStatusRequest; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.core.types.dsl.Expressions; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -21,48 +21,48 @@ public class CouponSearchRepository { private final JPAQueryFactory jpaQueryFactory; - public List findAllByStatus(LocalDateTime now, CouponSearchRequest request) { + public List findAllByStatus(LocalDateTime now, CouponStatusRequest couponStatus) { return jpaQueryFactory.selectFrom(coupon) - .where(filterCouponStatus(now, request)) + .where(filterStatus(now, couponStatus)) .fetch(); } - private BooleanExpression filterCouponStatus(LocalDateTime now, CouponSearchRequest request) { - if (request.couponOngoing() && request.couponNotStarted() && request.couponEnded()) { + private BooleanExpression filterStatus(LocalDateTime now, CouponStatusRequest couponStatus) { + if (couponStatus.ongoing() && couponStatus.notStarted() && couponStatus.ended()) { return null; } // 시작 전이거나 진행 중인 쿠폰들을 조회하고 싶은 경우 - if (request.couponOngoing() && request.couponNotStarted()) { + if (couponStatus.ongoing() && couponStatus.notStarted()) { return (coupon.startAt.gt(now)) .or(coupon.startAt.loe(now).and(coupon.endAt.goe(now))); } // 종료 됐거나 진행 중인 쿠폰들을 조회하고 싶은 경우 - if (request.couponOngoing() && request.couponEnded()) { + if (couponStatus.ongoing() && couponStatus.ended()) { return (coupon.endAt.lt(now)) .or(coupon.startAt.loe(now).and(coupon.endAt.goe(now))); } // 진행 중이 아니고, 시작 전이거나, 종료된 쿠폰들을 조회하고 싶은 경우 - if (request.couponNotStarted() && request.couponEnded()) { + if (couponStatus.notStarted() && couponStatus.ended()) { return coupon.startAt.gt(now) .or(coupon.endAt.lt(now)); } // 진행 중인 쿠폰들을 조회하고 싶은 경우 - if (request.couponOngoing()) { + if (couponStatus.ongoing()) { return coupon.startAt.loe(now) .and(coupon.endAt.goe(now)); } // 시작 적인 쿠폰들을 조회하고 싶은 경우 - if (request.couponNotStarted()) { + if (couponStatus.notStarted()) { return coupon.startAt.gt(now); } // 종료된 쿠폰들을 조회하고 싶은 경우 - if (request.couponEnded()) { + if (couponStatus.ended()) { return coupon.endAt.lt(now); } diff --git a/src/main/java/com/moabam/api/domain/notification/repository/NotificationRepository.java b/src/main/java/com/moabam/api/domain/notification/repository/NotificationRepository.java index df41d185..2701d9d8 100644 --- a/src/main/java/com/moabam/api/domain/notification/repository/NotificationRepository.java +++ b/src/main/java/com/moabam/api/domain/notification/repository/NotificationRepository.java @@ -29,7 +29,7 @@ public void saveFcmToken(Long memberId, String fcmToken) { ); } - public void saveKnockNotification(String knockKey) { + public void saveKnock(String knockKey) { stringRedisRepository.save( requireNonNull(knockKey), BLANK, @@ -46,8 +46,8 @@ public String findFcmTokenByMemberId(Long memberId) { return stringRedisRepository.get(String.valueOf(requireNonNull(memberId))); } - public boolean existsByKey(String key) { - return stringRedisRepository.hasKey(requireNonNull(key)); + public boolean existsKnockByKnockKey(String knockKey) { + return stringRedisRepository.hasKey(requireNonNull(knockKey)); } public boolean existsFcmTokenByMemberId(Long memberId) { diff --git a/src/main/java/com/moabam/api/dto/coupon/CouponResponse.java b/src/main/java/com/moabam/api/dto/coupon/CouponResponse.java index 3be5e025..0a323acd 100644 --- a/src/main/java/com/moabam/api/dto/coupon/CouponResponse.java +++ b/src/main/java/com/moabam/api/dto/coupon/CouponResponse.java @@ -9,13 +9,13 @@ @Builder public record CouponResponse( - Long couponId, - String couponAdminName, + Long id, + String adminName, String name, String description, int point, int stock, - CouponType couponType, + CouponType type, @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm") LocalDateTime startAt, @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm") diff --git a/src/main/java/com/moabam/api/dto/coupon/CouponSearchRequest.java b/src/main/java/com/moabam/api/dto/coupon/CouponSearchRequest.java deleted file mode 100644 index 8e8e1c2d..00000000 --- a/src/main/java/com/moabam/api/dto/coupon/CouponSearchRequest.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.moabam.api.dto.coupon; - -import lombok.Builder; - -@Builder -public record CouponSearchRequest( - boolean couponOngoing, - boolean couponNotStarted, - boolean couponEnded -) { - -} diff --git a/src/main/java/com/moabam/api/dto/coupon/CouponStatusRequest.java b/src/main/java/com/moabam/api/dto/coupon/CouponStatusRequest.java new file mode 100644 index 00000000..0c41fcdb --- /dev/null +++ b/src/main/java/com/moabam/api/dto/coupon/CouponStatusRequest.java @@ -0,0 +1,12 @@ +package com.moabam.api.dto.coupon; + +import lombok.Builder; + +@Builder +public record CouponStatusRequest( + boolean ongoing, + boolean notStarted, + boolean ended +) { + +} diff --git a/src/main/java/com/moabam/api/dto/coupon/CreateCouponRequest.java b/src/main/java/com/moabam/api/dto/coupon/CreateCouponRequest.java index ade47498..245ff76e 100644 --- a/src/main/java/com/moabam/api/dto/coupon/CreateCouponRequest.java +++ b/src/main/java/com/moabam/api/dto/coupon/CreateCouponRequest.java @@ -15,7 +15,7 @@ public record CreateCouponRequest( @NotBlank(message = "쿠폰명이 입력되지 않았거나 20자를 넘었습니다.") @Length(max = 20) String name, @Length(max = 50, message = "쿠폰 간단 소개는 최대 50자까지 가능합니다.") String description, - @NotBlank(message = "쿠폰 종류를 입력해주세요.") String couponType, + @NotBlank(message = "쿠폰 종류를 입력해주세요.") String type, @Min(value = 1, message = "벌레 수 혹은 할인 금액은 1 이상이어야 합니다.") int point, @Min(value = 1, message = "쿠폰 재고는 1 이상이어야 합니다.") int stock, @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm") diff --git a/src/main/java/com/moabam/api/application/notification/NotificationMapper.java b/src/main/java/com/moabam/api/infrastructure/fcm/FcmMapper.java similarity index 75% rename from src/main/java/com/moabam/api/application/notification/NotificationMapper.java rename to src/main/java/com/moabam/api/infrastructure/fcm/FcmMapper.java index 57e027c1..f977fc84 100644 --- a/src/main/java/com/moabam/api/application/notification/NotificationMapper.java +++ b/src/main/java/com/moabam/api/infrastructure/fcm/FcmMapper.java @@ -1,4 +1,4 @@ -package com.moabam.api.application.notification; +package com.moabam.api.infrastructure.fcm; import com.google.firebase.messaging.Message; import com.google.firebase.messaging.Notification; @@ -7,7 +7,7 @@ import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class NotificationMapper { +public final class FcmMapper { private static final String NOTIFICATION_TITLE = "모아밤"; @@ -18,7 +18,7 @@ public static Notification toNotification(String body) { .build(); } - public static Message toMessageEntity(Notification notification, String fcmToken) { + public static Message toMessage(Notification notification, String fcmToken) { return Message.builder() .setNotification(notification) .setToken(fcmToken) diff --git a/src/main/java/com/moabam/api/infrastructure/fcm/FcmService.java b/src/main/java/com/moabam/api/infrastructure/fcm/FcmService.java index e995688c..357be42d 100644 --- a/src/main/java/com/moabam/api/infrastructure/fcm/FcmService.java +++ b/src/main/java/com/moabam/api/infrastructure/fcm/FcmService.java @@ -5,7 +5,6 @@ import com.google.firebase.messaging.FirebaseMessaging; import com.google.firebase.messaging.Message; import com.google.firebase.messaging.Notification; -import com.moabam.api.application.notification.NotificationMapper; import lombok.RequiredArgsConstructor; @@ -15,11 +14,11 @@ public class FcmService { private final FirebaseMessaging firebaseMessaging; - public void sendAsyncFcm(String fcmToken, String notificationBody) { - Notification notification = NotificationMapper.toNotification(notificationBody); + public void sendAsync(String fcmToken, String notificationBody) { + Notification notification = FcmMapper.toNotification(notificationBody); if (fcmToken != null) { - Message message = NotificationMapper.toMessageEntity(notification, fcmToken); + Message message = FcmMapper.toMessage(notification, fcmToken); firebaseMessaging.sendAsync(message); } } diff --git a/src/main/java/com/moabam/api/presentation/CouponController.java b/src/main/java/com/moabam/api/presentation/CouponController.java index a1aa4664..f37259e4 100644 --- a/src/main/java/com/moabam/api/presentation/CouponController.java +++ b/src/main/java/com/moabam/api/presentation/CouponController.java @@ -15,7 +15,7 @@ import com.moabam.api.application.coupon.CouponQueueService; import com.moabam.api.application.coupon.CouponService; import com.moabam.api.dto.coupon.CouponResponse; -import com.moabam.api.dto.coupon.CouponSearchRequest; +import com.moabam.api.dto.coupon.CouponStatusRequest; import com.moabam.api.dto.coupon.CreateCouponRequest; import com.moabam.global.auth.annotation.CurrentMember; import com.moabam.global.auth.model.AuthorizationMember; @@ -32,27 +32,27 @@ public class CouponController { @PostMapping("/admins/coupons") @ResponseStatus(HttpStatus.CREATED) - public void createCoupon(@CurrentMember AuthorizationMember admin, + public void create(@CurrentMember AuthorizationMember admin, @Valid @RequestBody CreateCouponRequest request) { - couponService.createCoupon(admin, request); + couponService.create(admin, request); } @DeleteMapping("/admins/coupons/{couponId}") @ResponseStatus(HttpStatus.OK) - public void deleteCoupon(@CurrentMember AuthorizationMember admin, @PathVariable("couponId") Long couponId) { - couponService.deleteCoupon(admin, couponId); + public void delete(@CurrentMember AuthorizationMember admin, @PathVariable("couponId") Long couponId) { + couponService.delete(admin, couponId); } @GetMapping("/coupons/{couponId}") @ResponseStatus(HttpStatus.OK) - public CouponResponse getCouponById(@PathVariable("couponId") Long couponId) { - return couponService.getCouponById(couponId); + public CouponResponse getById(@PathVariable("couponId") Long couponId) { + return couponService.getById(couponId); } @PostMapping("/coupons/search") @ResponseStatus(HttpStatus.OK) - public List getCoupons(@Valid @RequestBody CouponSearchRequest request) { - return couponService.getCoupons(request); + public List getAllByStatus(@Valid @RequestBody CouponStatusRequest request) { + return couponService.getAllByStatus(request); } @PostMapping("/coupons") diff --git a/src/main/java/com/moabam/api/presentation/NotificationController.java b/src/main/java/com/moabam/api/presentation/NotificationController.java index 7ddb34f1..f83d74aa 100644 --- a/src/main/java/com/moabam/api/presentation/NotificationController.java +++ b/src/main/java/com/moabam/api/presentation/NotificationController.java @@ -21,6 +21,6 @@ public class NotificationController { @GetMapping("/rooms/{roomId}/members/{memberId}") public void sendKnockNotification(@CurrentMember AuthorizationMember member, @PathVariable("roomId") Long roomId, @PathVariable("memberId") Long memberId) { - notificationService.sendKnockNotification(member, memberId, roomId); + notificationService.sendKnock(member, memberId, roomId); } } diff --git a/src/main/resources/static/docs/coupon.html b/src/main/resources/static/docs/coupon.html index e4adf5d6..b554d168 100644 --- a/src/main/resources/static/docs/coupon.html +++ b/src/main/resources/static/docs/coupon.html @@ -461,13 +461,13 @@

요청

POST /admins/coupons HTTP/1.1
 Content-Type: application/json;charset=UTF-8
-Content-Length: 192
+Content-Length: 186
 Host: localhost:8080
 
 {
   "name" : "couponName",
   "description" : "coupon description",
-  "couponType" : "황금",
+  "type" : "황금",
   "point" : 10,
   "stock" : 10,
   "startAt" : "2023-01-01T00:00",
@@ -569,13 +569,13 @@ 

요청

POST /coupons/search HTTP/1.1
 Content-Type: application/json;charset=UTF-8
-Content-Length: 84
+Content-Length: 66
 Host: localhost:8080
 
 {
-  "couponOngoing" : false,
-  "couponNotStarted" : false,
-  "couponEnded" : false
+  "ongoing" : false,
+  "notStarted" : false,
+  "ended" : false
 }
@@ -655,7 +655,7 @@

쿠폰 사용 (진행 중)

diff --git a/src/test/java/com/moabam/api/application/coupon/CouponQueueServiceTest.java b/src/test/java/com/moabam/api/application/coupon/CouponQueueServiceTest.java index 31d90635..f2c375e6 100644 --- a/src/test/java/com/moabam/api/application/coupon/CouponQueueServiceTest.java +++ b/src/test/java/com/moabam/api/application/coupon/CouponQueueServiceTest.java @@ -40,14 +40,14 @@ void couponQueueService_register() { AuthorizationMember member = AuthorizationThreadLocal.getAuthorizationMember(); Coupon coupon = CouponFixture.coupon("couponName", 1, 2); - given(couponService.validateCouponPeriod(any(String.class))).willReturn(coupon); - given(couponQueueRepository.queueSize(any(String.class))).willReturn(coupon.getStock() - 1L); + given(couponService.validatePeriod(any(String.class))).willReturn(coupon); + given(couponQueueRepository.size(any(String.class))).willReturn(coupon.getStock() - 1L); // When couponQueueService.register(member, coupon.getName()); // Then - verify(couponQueueRepository).addQueue(any(String.class), any(String.class), any(double.class)); + verify(couponQueueRepository).addIfAbsent(any(String.class), any(String.class), any(double.class)); } @WithMember @@ -56,7 +56,7 @@ void couponQueueService_register() { void couponQueueService_register_BadRequestException() { // Given AuthorizationMember member = AuthorizationThreadLocal.getAuthorizationMember(); - given(couponService.validateCouponPeriod(any(String.class))) + given(couponService.validatePeriod(any(String.class))) .willThrow(new BadRequestException(ErrorMessage.INVALID_COUPON_PERIOD_END)); // When & Then @@ -73,8 +73,8 @@ void couponQueueService_register_End() { AuthorizationMember member = AuthorizationThreadLocal.getAuthorizationMember(); Coupon coupon = CouponFixture.coupon("couponName", 1, 2); - given(couponService.validateCouponPeriod(any(String.class))).willReturn(coupon); - given(couponQueueRepository.queueSize(any(String.class))).willReturn((long)coupon.getStock()); + given(couponService.validatePeriod(any(String.class))).willReturn(coupon); + given(couponQueueRepository.size(any(String.class))).willReturn((long)coupon.getStock()); // When & Then assertThatNoException().isThrownBy(() -> couponQueueService.register(member, coupon.getName())); diff --git a/src/test/java/com/moabam/api/application/coupon/CouponServiceTest.java b/src/test/java/com/moabam/api/application/coupon/CouponServiceTest.java index 06b6e480..4dd3ebe4 100644 --- a/src/test/java/com/moabam/api/application/coupon/CouponServiceTest.java +++ b/src/test/java/com/moabam/api/application/coupon/CouponServiceTest.java @@ -22,7 +22,7 @@ import com.moabam.api.domain.coupon.repository.CouponSearchRepository; import com.moabam.api.domain.member.Role; import com.moabam.api.dto.coupon.CouponResponse; -import com.moabam.api.dto.coupon.CouponSearchRequest; +import com.moabam.api.dto.coupon.CouponStatusRequest; import com.moabam.api.dto.coupon.CreateCouponRequest; import com.moabam.global.auth.model.AuthorizationMember; import com.moabam.global.auth.model.AuthorizationThreadLocal; @@ -56,13 +56,13 @@ class CouponServiceTest { void couponService_createCoupon() { // Given AuthorizationMember admin = AuthorizationThreadLocal.getAuthorizationMember(); - String couponType = CouponType.GOLDEN_COUPON.getTypeName(); + String couponType = CouponType.GOLDEN_COUPON.getName(); CreateCouponRequest request = CouponFixture.createCouponRequest(couponType, 1, 2); given(couponRepository.existsByName(any(String.class))).willReturn(false); // When - couponService.createCoupon(admin, request); + couponService.create(admin, request); // Then verify(couponRepository).save(any(Coupon.class)); @@ -74,11 +74,11 @@ void couponService_createCoupon() { void couponService_createCoupon_Admin_NotFoundException() { // Given AuthorizationMember admin = AuthorizationThreadLocal.getAuthorizationMember(); - String couponType = CouponType.GOLDEN_COUPON.getTypeName(); + String couponType = CouponType.GOLDEN_COUPON.getName(); CreateCouponRequest request = CouponFixture.createCouponRequest(couponType, 1, 2); // When & Then - assertThatThrownBy(() -> couponService.createCoupon(admin, request)) + assertThatThrownBy(() -> couponService.create(admin, request)) .isInstanceOf(NotFoundException.class) .hasMessage(ErrorMessage.MEMBER_NOT_FOUND.getMessage()); } @@ -89,13 +89,13 @@ void couponService_createCoupon_Admin_NotFoundException() { void couponService_createCoupon_ConflictException() { // Given AuthorizationMember admin = AuthorizationThreadLocal.getAuthorizationMember(); - String couponType = CouponType.GOLDEN_COUPON.getTypeName(); + String couponType = CouponType.GOLDEN_COUPON.getName(); CreateCouponRequest request = CouponFixture.createCouponRequest(couponType, 1, 2); given(couponRepository.existsByName(any(String.class))).willReturn(true); // When & Then - assertThatThrownBy(() -> couponService.createCoupon(admin, request)) + assertThatThrownBy(() -> couponService.create(admin, request)) .isInstanceOf(ConflictException.class) .hasMessage(ErrorMessage.CONFLICT_COUPON_NAME.getMessage()); } @@ -110,7 +110,7 @@ void couponService_createCoupon_NotFoundException() { given(couponRepository.existsByName(any(String.class))).willReturn(false); // When & Then - assertThatThrownBy(() -> couponService.createCoupon(admin, request)) + assertThatThrownBy(() -> couponService.create(admin, request)) .isInstanceOf(NotFoundException.class) .hasMessage(ErrorMessage.NOT_FOUND_COUPON_TYPE.getMessage()); } @@ -121,12 +121,12 @@ void couponService_createCoupon_NotFoundException() { void couponService_createCoupon_BadRequestException() { // Given AuthorizationMember admin = AuthorizationThreadLocal.getAuthorizationMember(); - String couponType = CouponType.GOLDEN_COUPON.getTypeName(); + String couponType = CouponType.GOLDEN_COUPON.getName(); CreateCouponRequest request = CouponFixture.createCouponRequest(couponType, 2, 1); given(couponRepository.existsByName(any(String.class))).willReturn(false); // When & Then - assertThatThrownBy(() -> couponService.createCoupon(admin, request)) + assertThatThrownBy(() -> couponService.create(admin, request)) .isInstanceOf(BadRequestException.class) .hasMessage(ErrorMessage.INVALID_COUPON_PERIOD.getMessage()); } @@ -141,7 +141,7 @@ void couponService_deleteCoupon() { given(couponRepository.findById(any(Long.class))).willReturn(Optional.of(coupon)); // When - couponService.deleteCoupon(admin, 1L); + couponService.delete(admin, 1L); // Then verify(couponRepository).delete(coupon); @@ -155,7 +155,7 @@ void couponService_deleteCoupon_Admin_NotFoundException() { AuthorizationMember admin = AuthorizationThreadLocal.getAuthorizationMember(); // When & Then - assertThatThrownBy(() -> couponService.deleteCoupon(admin, 1L)) + assertThatThrownBy(() -> couponService.delete(admin, 1L)) .isInstanceOf(NotFoundException.class) .hasMessage(ErrorMessage.MEMBER_NOT_FOUND.getMessage()); } @@ -169,7 +169,7 @@ void couponService_deleteCoupon_NotFoundException() { given(couponRepository.findById(any(Long.class))).willReturn(Optional.empty()); // When & Then - assertThatThrownBy(() -> couponService.deleteCoupon(admin, 1L)) + assertThatThrownBy(() -> couponService.delete(admin, 1L)) .isInstanceOf(NotFoundException.class) .hasMessage(ErrorMessage.NOT_FOUND_COUPON.getMessage()); } @@ -182,7 +182,7 @@ void couponService_getCouponById() { given(couponRepository.findById(any(Long.class))).willReturn(Optional.of(coupon)); // When - CouponResponse actual = couponService.getCouponById(1L); + CouponResponse actual = couponService.getById(1L); // Then assertThat(actual.point()).isEqualTo(coupon.getPoint()); @@ -196,7 +196,7 @@ void couponService_getCouponById_NotFoundException() { given(couponRepository.findById(any(Long.class))).willReturn(Optional.empty()); // When & Then - assertThatThrownBy(() -> couponService.getCouponById(1L)) + assertThatThrownBy(() -> couponService.getById(1L)) .isInstanceOf(NotFoundException.class) .hasMessage(ErrorMessage.NOT_FOUND_COUPON.getMessage()); } @@ -206,13 +206,13 @@ void couponService_getCouponById_NotFoundException() { @ParameterizedTest void couponService_getCoupons(List coupons) { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(true, true, true); - given(couponSearchRepository.findAllByStatus(any(LocalDateTime.class), any(CouponSearchRequest.class))) + CouponStatusRequest request = CouponFixture.couponStatusRequest(true, true, true); + given(couponSearchRepository.findAllByStatus(any(LocalDateTime.class), any(CouponStatusRequest.class))) .willReturn(coupons); given(clockHolder.times()).willReturn(LocalDateTime.now()); // When - List actual = couponService.getCoupons(request); + List actual = couponService.getAllByStatus(request); // Then assertThat(actual).hasSize(coupons.size()); @@ -228,7 +228,7 @@ void couponService_validateCouponPeriod() { given(clockHolder.times()).willReturn(now); // When - Coupon actual = couponService.validateCouponPeriod(coupon.getName()); + Coupon actual = couponService.validatePeriod(coupon.getName()); // Then assertThat(actual.getName()).isEqualTo(coupon.getName()); @@ -244,7 +244,7 @@ void couponService_validateCouponPeriod_BadRequestException() { given(clockHolder.times()).willReturn(now); // When & Then - assertThatThrownBy(() -> couponService.validateCouponPeriod("couponName")) + assertThatThrownBy(() -> couponService.validatePeriod("couponName")) .isInstanceOf(BadRequestException.class) .hasMessage(ErrorMessage.INVALID_COUPON_PERIOD_END.getMessage()); } @@ -258,7 +258,7 @@ void couponService_validateCouponPeriod_NotFoundException() { given(clockHolder.times()).willReturn(now); // When & Then - assertThatThrownBy(() -> couponService.validateCouponPeriod("Not found coupon name")) + assertThatThrownBy(() -> couponService.validatePeriod("Not found coupon name")) .isInstanceOf(NotFoundException.class) .hasMessage(ErrorMessage.NOT_FOUND_COUPON.getMessage()); } diff --git a/src/test/java/com/moabam/api/application/notification/NotificationServiceTest.java b/src/test/java/com/moabam/api/application/notification/NotificationServiceTest.java index b54b7236..51c266be 100644 --- a/src/test/java/com/moabam/api/application/notification/NotificationServiceTest.java +++ b/src/test/java/com/moabam/api/application/notification/NotificationServiceTest.java @@ -59,15 +59,15 @@ void notificationService_sendKnockNotification() { willDoNothing().given(roomService).validateRoomById(any(Long.class)); given(notificationRepository.existsFcmTokenByMemberId(any(Long.class))).willReturn(true); - given(notificationRepository.existsByKey(any(String.class))).willReturn(false); + given(notificationRepository.existsKnockByKnockKey(any(String.class))).willReturn(false); given(notificationRepository.findFcmTokenByMemberId(any(Long.class))).willReturn("FCM-TOKEN"); // When - notificationService.sendKnockNotification(member, 2L, 1L); + notificationService.sendKnock(member, 2L, 1L); // Then - verify(fcmService).sendAsyncFcm(any(String.class), any(String.class)); - verify(notificationRepository).saveKnockNotification(any(String.class)); + verify(fcmService).sendAsync(any(String.class), any(String.class)); + verify(notificationRepository).saveKnock(any(String.class)); } @WithMember @@ -79,7 +79,7 @@ void notificationService_sendKnockNotification_Room_NotFoundException() { willThrow(NotFoundException.class).given(roomService).validateRoomById(any(Long.class)); // When & Then - assertThatThrownBy(() -> notificationService.sendKnockNotification(member, 1L, 1L)) + assertThatThrownBy(() -> notificationService.sendKnock(member, 1L, 1L)) .isInstanceOf(NotFoundException.class); } @@ -91,11 +91,11 @@ void notificationService_sendKnockNotification_FcmToken_NotFoundException() { AuthorizationMember member = AuthorizationThreadLocal.getAuthorizationMember(); willDoNothing().given(roomService).validateRoomById(any(Long.class)); - given(notificationRepository.existsByKey(any(String.class))).willReturn(false); + given(notificationRepository.existsKnockByKnockKey(any(String.class))).willReturn(false); given(notificationRepository.existsFcmTokenByMemberId(any(Long.class))).willReturn(false); // When & Then - assertThatThrownBy(() -> notificationService.sendKnockNotification(member, 1L, 1L)) + assertThatThrownBy(() -> notificationService.sendKnock(member, 1L, 1L)) .isInstanceOf(NotFoundException.class) .hasMessage(ErrorMessage.NOT_FOUND_FCM_TOKEN.getMessage()); } @@ -108,10 +108,10 @@ void notificationService_sendKnockNotification_ConflictException() { AuthorizationMember member = AuthorizationThreadLocal.getAuthorizationMember(); willDoNothing().given(roomService).validateRoomById(any(Long.class)); - given(notificationRepository.existsByKey(any(String.class))).willReturn(true); + given(notificationRepository.existsKnockByKnockKey(any(String.class))).willReturn(true); // When & Then - assertThatThrownBy(() -> notificationService.sendKnockNotification(member, 1L, 1L)) + assertThatThrownBy(() -> notificationService.sendKnock(member, 1L, 1L)) .isInstanceOf(ConflictException.class) .hasMessage(ErrorMessage.CONFLICT_KNOCK.getMessage()); } @@ -126,10 +126,10 @@ void notificationService_sendCertificationTimeNotification(List par given(clockHolder.times()).willReturn(LocalDateTime.now()); // When - notificationService.sendCertificationTimeNotification(); + notificationService.sendCertificationTime(); // Then - verify(fcmService, times(3)).sendAsyncFcm(any(String.class), any(String.class)); + verify(fcmService, times(3)).sendAsync(any(String.class), any(String.class)); } @WithMember @@ -143,10 +143,10 @@ void notificationService_sendCertificationTimeNotification_NoFirebaseMessaging(L given(clockHolder.times()).willReturn(LocalDateTime.now()); // When - notificationService.sendCertificationTimeNotification(); + notificationService.sendCertificationTime(); // Then - verify(fcmService, times(0)).sendAsyncFcm(any(String.class), any(String.class)); + verify(fcmService, times(0)).sendAsync(any(String.class), any(String.class)); } @WithMember @@ -157,11 +157,11 @@ void notificationService_knocked_checkMyKnockNotificationStatusInRoom(List actual = - notificationService.getMyKnockedNotificationStatusInRoom(member.id(), 1L, participants); + notificationService.getMyKnockStatusInRoom(member.id(), 1L, participants); // Then assertThat(actual).hasSize(2); @@ -176,11 +176,11 @@ void notificationService_notKnocked_checkMyKnockNotificationStatusInRoom(List actual = - notificationService.getMyKnockedNotificationStatusInRoom(member.id(), 1L, participants); + notificationService.getMyKnockStatusInRoom(member.id(), 1L, participants); // Then assertThat(actual).isEmpty(); diff --git a/src/test/java/com/moabam/api/domain/coupon/CouponTypeTest.java b/src/test/java/com/moabam/api/domain/coupon/CouponTypeTest.java index 64759cbb..406bc061 100644 --- a/src/test/java/com/moabam/api/domain/coupon/CouponTypeTest.java +++ b/src/test/java/com/moabam/api/domain/coupon/CouponTypeTest.java @@ -14,7 +14,7 @@ class CouponTypeTest { @Test void couponType_from() { // When - CouponType actual = CouponType.from("황금"); + CouponType actual = CouponType.from(CouponType.GOLDEN_COUPON.getName()); // Then assertThat(actual).isEqualTo(CouponType.GOLDEN_COUPON); diff --git a/src/test/java/com/moabam/api/domain/coupon/repository/CouponQueueRepositoryTest.java b/src/test/java/com/moabam/api/domain/coupon/repository/CouponQueueRepositoryTest.java index d4a4219f..9c48c266 100644 --- a/src/test/java/com/moabam/api/domain/coupon/repository/CouponQueueRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/coupon/repository/CouponQueueRepositoryTest.java @@ -26,7 +26,7 @@ class CouponQueueRepositoryTest { @Test void addQueue() { // When - couponQueueRepository.addQueue("couponName", "memberNickname", 1); + couponQueueRepository.addIfAbsent("couponName", "memberNickname", 1); // Then verify(zSetRedisRepository).addIfAbsent(any(String.class), any(String.class), any(Double.class)); @@ -36,7 +36,7 @@ void addQueue() { @Test void addQueue_NullPointerException() { // When & Then - assertThatThrownBy(() -> couponQueueRepository.addQueue(null, "value", 1)) + assertThatThrownBy(() -> couponQueueRepository.addIfAbsent(null, "value", 1)) .isInstanceOf(NullPointerException.class); } @@ -47,7 +47,7 @@ void queueSize() { given(zSetRedisRepository.size(any(String.class))).willReturn(3L); // When - long actual = couponQueueRepository.queueSize("key"); + long actual = couponQueueRepository.size("key"); // Then assertThat(actual).isEqualTo(3); @@ -57,7 +57,7 @@ void queueSize() { @Test void queueSize_NullPointerException() { // When & Then - assertThatThrownBy(() -> couponQueueRepository.queueSize(null)) + assertThatThrownBy(() -> couponQueueRepository.size(null)) .isInstanceOf(NullPointerException.class); } } diff --git a/src/test/java/com/moabam/api/domain/coupon/repository/CouponSearchRepositoryTest.java b/src/test/java/com/moabam/api/domain/coupon/repository/CouponSearchRepositoryTest.java index 91df34ad..92994bd1 100644 --- a/src/test/java/com/moabam/api/domain/coupon/repository/CouponSearchRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/coupon/repository/CouponSearchRepositoryTest.java @@ -13,7 +13,7 @@ import org.springframework.context.annotation.Import; import com.moabam.api.domain.coupon.Coupon; -import com.moabam.api.dto.coupon.CouponSearchRequest; +import com.moabam.api.dto.coupon.CouponStatusRequest; import com.moabam.global.config.JpaConfig; import com.moabam.support.fixture.CouponFixture; @@ -32,7 +32,7 @@ class CouponSearchRepositoryTest { @ParameterizedTest void couponSearchRepository_findAllByStatus(List coupons) { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(true, true, true); + CouponStatusRequest request = CouponFixture.couponStatusRequest(true, true, true); LocalDateTime now = LocalDateTime.now(); couponRepository.saveAll(coupons); @@ -49,7 +49,7 @@ void couponSearchRepository_findAllByStatus(List coupons) { @ParameterizedTest void couponSearchRepository_findAllByStatus_and_ongoing_notStarted(List coupons) { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(true, true, false); + CouponStatusRequest request = CouponFixture.couponStatusRequest(true, true, false); LocalDateTime now = LocalDateTime.of(2023, 5, 1, 0, 0); couponRepository.saveAll(coupons); @@ -66,7 +66,7 @@ void couponSearchRepository_findAllByStatus_and_ongoing_notStarted(List @ParameterizedTest void couponSearchRepository_findAllByStatus_and_ongoing_ended(List coupons) { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(true, false, true); + CouponStatusRequest request = CouponFixture.couponStatusRequest(true, false, true); LocalDateTime now = LocalDateTime.of(2023, 5, 1, 0, 0); couponRepository.saveAll(coupons); @@ -83,7 +83,7 @@ void couponSearchRepository_findAllByStatus_and_ongoing_ended(List coupo @ParameterizedTest void couponSearchRepository_findAllByStatus_ongoing_and_ended(List coupons) { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(false, true, true); + CouponStatusRequest request = CouponFixture.couponStatusRequest(false, true, true); LocalDateTime now = LocalDateTime.of(2023, 5, 1, 0, 0); couponRepository.saveAll(coupons); @@ -100,7 +100,7 @@ void couponSearchRepository_findAllByStatus_ongoing_and_ended(List coupo @ParameterizedTest void couponSearchRepository_findAllByStatus_ongoing(List coupons) { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(true, false, false); + CouponStatusRequest request = CouponFixture.couponStatusRequest(true, false, false); LocalDateTime now = LocalDateTime.of(2023, 5, 1, 0, 0); couponRepository.saveAll(coupons); @@ -117,7 +117,7 @@ void couponSearchRepository_findAllByStatus_ongoing(List coupons) { @ParameterizedTest void couponSearchRepository_findAllByStatus_notStarted(List coupons) { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(false, true, false); + CouponStatusRequest request = CouponFixture.couponStatusRequest(false, true, false); LocalDateTime now = LocalDateTime.of(2023, 5, 1, 0, 0); couponRepository.saveAll(coupons); @@ -134,7 +134,7 @@ void couponSearchRepository_findAllByStatus_notStarted(List coupons) { @ParameterizedTest void couponSearchRepository_findAllByStatus_ended(List coupons) { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(false, false, true); + CouponStatusRequest request = CouponFixture.couponStatusRequest(false, false, true); LocalDateTime now = LocalDateTime.of(2023, 5, 1, 0, 0); couponRepository.saveAll(coupons); @@ -151,7 +151,7 @@ void couponSearchRepository_findAllByStatus_ended(List coupons) { @ParameterizedTest void couponSearchRepository_findAllByStatus__not_status(List coupons) { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(false, false, false); + CouponStatusRequest request = CouponFixture.couponStatusRequest(false, false, false); LocalDateTime now = LocalDateTime.of(2023, 5, 1, 0, 0); couponRepository.saveAll(coupons); diff --git a/src/test/java/com/moabam/api/domain/notification/repository/NotificationRepositoryTest.java b/src/test/java/com/moabam/api/domain/notification/repository/NotificationRepositoryTest.java index 6822b175..ad33c2d0 100644 --- a/src/test/java/com/moabam/api/domain/notification/repository/NotificationRepositoryTest.java +++ b/src/test/java/com/moabam/api/domain/notification/repository/NotificationRepositoryTest.java @@ -45,7 +45,7 @@ void notificationRepository_save_NullPointerException() { @Test void notificationRepository_saveKnockNotification() { // When - notificationRepository.saveKnockNotification("knockKey"); + notificationRepository.saveKnock("knockKey"); // Then verify(stringRedisRepository).save(any(String.class), any(String.class), any(Duration.class)); @@ -55,7 +55,7 @@ void notificationRepository_saveKnockNotification() { @Test void notificationRepository_saveKnockNotification_NullPointerException() { // When & Then - assertThatThrownBy(() -> notificationRepository.saveKnockNotification(null)) + assertThatThrownBy(() -> notificationRepository.saveKnock(null)) .isInstanceOf(NullPointerException.class); } @@ -117,7 +117,7 @@ void notificationRepository_existsFcmTokenByMemberId_NullPointerException() { @Test void notificationRepository_existsKnockByMemberId() { // When - notificationRepository.existsByKey("knock key"); + notificationRepository.existsKnockByKnockKey("knock key"); // Then verify(stringRedisRepository).hasKey(any(String.class)); @@ -127,7 +127,7 @@ void notificationRepository_existsKnockByMemberId() { @Test void notificationRepository_existsKnockByMemberId_NullPointerException() { // When & Then - assertThatThrownBy(() -> notificationRepository.existsByKey(null)) + assertThatThrownBy(() -> notificationRepository.existsKnockByKnockKey(null)) .isInstanceOf(NullPointerException.class); } } diff --git a/src/test/java/com/moabam/api/infrastructure/fcm/FcmServiceTest.java b/src/test/java/com/moabam/api/infrastructure/fcm/FcmServiceTest.java index c7a331e3..3c067fb8 100644 --- a/src/test/java/com/moabam/api/infrastructure/fcm/FcmServiceTest.java +++ b/src/test/java/com/moabam/api/infrastructure/fcm/FcmServiceTest.java @@ -25,7 +25,7 @@ class FcmServiceTest { @Test void fcmService_sendAsyncFcm() { // When - fcmService.sendAsyncFcm("FCM-TOKEN", "알림"); + fcmService.sendAsync("FCM-TOKEN", "알림"); // Then verify(firebaseMessaging).sendAsync(any(Message.class)); @@ -35,7 +35,7 @@ void fcmService_sendAsyncFcm() { @Test void fcmService_sendAsyncFcm_null() { // When - fcmService.sendAsyncFcm(null, "알림"); + fcmService.sendAsync(null, "알림"); // Then verify(firebaseMessaging, times(0)).sendAsync(any(Message.class)); diff --git a/src/test/java/com/moabam/api/presentation/CouponControllerTest.java b/src/test/java/com/moabam/api/presentation/CouponControllerTest.java index 6b332f61..ec9a4afb 100644 --- a/src/test/java/com/moabam/api/presentation/CouponControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/CouponControllerTest.java @@ -30,7 +30,7 @@ import com.moabam.api.domain.coupon.CouponType; import com.moabam.api.domain.coupon.repository.CouponRepository; import com.moabam.api.domain.member.Role; -import com.moabam.api.dto.coupon.CouponSearchRequest; +import com.moabam.api.dto.coupon.CouponStatusRequest; import com.moabam.api.dto.coupon.CreateCouponRequest; import com.moabam.global.common.util.ClockHolder; import com.moabam.global.error.model.ErrorMessage; @@ -63,7 +63,7 @@ class CouponControllerTest extends WithoutFilterSupporter { @Test void couponController_createCoupon() throws Exception { // Given - String couponType = CouponType.GOLDEN_COUPON.getTypeName(); + String couponType = CouponType.GOLDEN_COUPON.getName(); CreateCouponRequest request = CouponFixture.createCouponRequest(couponType, 1, 2); // When & Then @@ -83,7 +83,7 @@ void couponController_createCoupon() throws Exception { @Test void couponController_createCoupon_BadRequestException() throws Exception { // Given - String couponType = CouponType.GOLDEN_COUPON.getTypeName(); + String couponType = CouponType.GOLDEN_COUPON.getName(); CreateCouponRequest request = CouponFixture.createCouponRequest(couponType, 2, 1); // When & Then @@ -106,7 +106,7 @@ void couponController_createCoupon_BadRequestException() throws Exception { @Test void couponController_createCoupon_ConflictException() throws Exception { // Given - String couponType = CouponType.GOLDEN_COUPON.getTypeName(); + String couponType = CouponType.GOLDEN_COUPON.getName(); CreateCouponRequest request = CouponFixture.createCouponRequest(couponType, 1, 2); couponRepository.save(CouponMapper.toEntity(1L, request)); @@ -172,7 +172,7 @@ void couponController_getCouponById() throws Exception { CouponSnippetFixture.COUPON_RESPONSE)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.couponId").value(coupon.getId())); + .andExpect(jsonPath("$.id").value(coupon.getId())); } @DisplayName("존재하지 않는 쿠폰을 조회한다. - NotFoundException") @@ -195,7 +195,7 @@ void couponController_getCouponById_NotFoundException() throws Exception { @ParameterizedTest void couponController_getCoupons(List coupons) throws Exception { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(true, true, true); + CouponStatusRequest request = CouponFixture.couponStatusRequest(true, true, true); List coupon = couponRepository.saveAll(coupons); // When & Then @@ -206,8 +206,8 @@ void couponController_getCoupons(List coupons) throws Exception { .andDo(document("coupons/search", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), - CouponSnippetFixture.COUPON_SEARCH_REQUEST, - CouponSnippetFixture.COUPON_SEARCH_RESPONSE)) + CouponSnippetFixture.COUPON_STATUS_REQUEST, + CouponSnippetFixture.COUPON_STATUS_RESPONSE)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$", hasSize(coupon.size()))); @@ -218,7 +218,7 @@ void couponController_getCoupons(List coupons) throws Exception { @ParameterizedTest void couponController_getCoupons_not_status(List coupons) throws Exception { // Given - CouponSearchRequest request = CouponFixture.couponSearchRequest(false, false, false); + CouponStatusRequest request = CouponFixture.couponStatusRequest(false, false, false); couponRepository.saveAll(coupons); // When & Then @@ -229,7 +229,7 @@ void couponController_getCoupons_not_status(List coupons) throws Excepti .andDo(document("coupons/search", preprocessRequest(prettyPrint()), preprocessResponse(prettyPrint()), - CouponSnippetFixture.COUPON_SEARCH_REQUEST)) + CouponSnippetFixture.COUPON_STATUS_REQUEST)) .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$", hasSize(0))); diff --git a/src/test/java/com/moabam/api/presentation/NotificationControllerTest.java b/src/test/java/com/moabam/api/presentation/NotificationControllerTest.java index 86cd81f5..b750410b 100644 --- a/src/test/java/com/moabam/api/presentation/NotificationControllerTest.java +++ b/src/test/java/com/moabam/api/presentation/NotificationControllerTest.java @@ -120,7 +120,7 @@ void notificationController_sendKnockNotification_NotFoundException() throws Exc void notificationController_sendKnockNotification_ConflictException() throws Exception { // Given notificationRepository.saveFcmToken(target.getId(), "FCM_TOKEN"); - notificationRepository.saveKnockNotification(knockKey); + notificationRepository.saveKnock(knockKey); // When & Then mockMvc.perform(get("/notifications/rooms/" + room.getId() + "/members/" + target.getId())) diff --git a/src/test/java/com/moabam/support/fixture/CouponFixture.java b/src/test/java/com/moabam/support/fixture/CouponFixture.java index 1f2082f1..4f270ef3 100644 --- a/src/test/java/com/moabam/support/fixture/CouponFixture.java +++ b/src/test/java/com/moabam/support/fixture/CouponFixture.java @@ -8,7 +8,7 @@ import com.moabam.api.domain.coupon.Coupon; import com.moabam.api.domain.coupon.CouponType; -import com.moabam.api.dto.coupon.CouponSearchRequest; +import com.moabam.api.dto.coupon.CouponStatusRequest; import com.moabam.api.dto.coupon.CreateCouponRequest; public final class CouponFixture { @@ -59,18 +59,18 @@ public static CreateCouponRequest createCouponRequest(String couponType, int sta .name("couponName") .description("coupon description") .point(10) - .couponType(couponType) + .type(couponType) .stock(10) .startAt(LocalDateTime.of(2023, startMonth, 1, 0, 0)) .endAt(LocalDateTime.of(2023, endMonth, 1, 0, 0)) .build(); } - public static CouponSearchRequest couponSearchRequest(boolean ongoing, boolean notStarted, boolean ended) { - return CouponSearchRequest.builder() - .couponOngoing(ongoing) - .couponNotStarted(notStarted) - .couponEnded(ended) + public static CouponStatusRequest couponStatusRequest(boolean ongoing, boolean notStarted, boolean ended) { + return CouponStatusRequest.builder() + .ongoing(ongoing) + .notStarted(notStarted) + .ended(ended) .build(); } diff --git a/src/test/java/com/moabam/support/fixture/CouponSnippetFixture.java b/src/test/java/com/moabam/support/fixture/CouponSnippetFixture.java index e263b158..57b7499e 100644 --- a/src/test/java/com/moabam/support/fixture/CouponSnippetFixture.java +++ b/src/test/java/com/moabam/support/fixture/CouponSnippetFixture.java @@ -12,7 +12,7 @@ public final class CouponSnippetFixture { public static final RequestFieldsSnippet CREATE_COUPON_REQUEST = requestFields( fieldWithPath("name").type(STRING).description("쿠폰명"), fieldWithPath("description").type(STRING).description("쿠폰 간단 소개 (NULL 가능)"), - fieldWithPath("couponType").type(STRING).description("쿠폰 종류 (아침, 저녁, 황금, 할인)"), + fieldWithPath("type").type(STRING).description("쿠폰 종류 (아침, 저녁, 황금, 할인)"), fieldWithPath("point").type(NUMBER).description("쿠폰 사용 시, 제공하는 포인트량"), fieldWithPath("stock").type(NUMBER).description("쿠폰을 발급 받을 수 있는 수"), fieldWithPath("startAt").type(STRING).description("쿠폰 발급 시작 날짜 (Ex: yyyy-MM-dd'T'HH:mm)"), @@ -20,32 +20,32 @@ public final class CouponSnippetFixture { ); public static final ResponseFieldsSnippet COUPON_RESPONSE = responseFields( - fieldWithPath("couponId").type(NUMBER).description("쿠폰 ID"), - fieldWithPath("couponAdminName").type(STRING).description("쿠폰 관리자명"), + fieldWithPath("id").type(NUMBER).description("쿠폰 ID"), + fieldWithPath("adminName").type(STRING).description("쿠폰 관리자명"), fieldWithPath("name").type(STRING).description("쿠폰명"), fieldWithPath("description").type(STRING).description("쿠폰에 대한 간단 소개 (NULL 가능)"), fieldWithPath("point").type(NUMBER).description("쿠폰 사용 시, 제공하는 포인트량"), fieldWithPath("stock").type(NUMBER).description("쿠폰을 발급 받을 수 있는 수"), - fieldWithPath("couponType").type(STRING) + fieldWithPath("type").type(STRING) .description("쿠폰 종류 (MORNING_COUPON, NIGHT_COUPON, GOLDEN_COUPON, DISCOUNT_COUPON)"), fieldWithPath("startAt").type(STRING).description("쿠폰 발급 시작 날짜 (Ex: yyyy-MM-dd'T'HH:mm)"), fieldWithPath("endAt").type(STRING).description("쿠폰 발급 종료 날짜 (Ex: yyyy-MM-dd'T'HH:mm)") ); - public static final Snippet COUPON_SEARCH_REQUEST = requestFields( - fieldWithPath("couponOngoing").type(BOOLEAN).description("진행 상태 쿠폰 (true, false)"), - fieldWithPath("couponNotStarted").type(BOOLEAN).description("시작전 상태 쿠폰 (true, false)"), - fieldWithPath("couponEnded").type(BOOLEAN).description("종료 상태 쿠폰 (true, false)") + public static final Snippet COUPON_STATUS_REQUEST = requestFields( + fieldWithPath("ongoing").type(BOOLEAN).description("진행 상태 쿠폰 (true, false)"), + fieldWithPath("notStarted").type(BOOLEAN).description("시작전 상태 쿠폰 (true, false)"), + fieldWithPath("ended").type(BOOLEAN).description("종료 상태 쿠폰 (true, false)") ); - public static final ResponseFieldsSnippet COUPON_SEARCH_RESPONSE = responseFields( - fieldWithPath("[].couponId").type(NUMBER).description("쿠폰 ID"), - fieldWithPath("[].couponAdminName").type(STRING).description("쿠폰 관리자명"), + public static final ResponseFieldsSnippet COUPON_STATUS_RESPONSE = responseFields( + fieldWithPath("[].id").type(NUMBER).description("쿠폰 ID"), + fieldWithPath("[].adminName").type(STRING).description("쿠폰 관리자명"), fieldWithPath("[].name").type(STRING).description("쿠폰명"), fieldWithPath("[].description").type(STRING).description("쿠폰에 대한 간단 소개 (NULL 가능)"), fieldWithPath("[].point").type(NUMBER).description("쿠폰 사용 시, 제공하는 포인트량"), fieldWithPath("[].stock").type(NUMBER).description("쿠폰을 발급 받을 수 있는 수"), - fieldWithPath("[].couponType").type(STRING) + fieldWithPath("[].type").type(STRING) .description("쿠폰 종류 (MORNING_COUPON, NIGHT_COUPON, GOLDEN_COUPON, DISCOUNT_COUPON)"), fieldWithPath("[].startAt").type(STRING).description("쿠폰 발급 시작 날짜 (Ex: yyyy-MM-dd'T'HH:mm)"), fieldWithPath("[].endAt").type(STRING).description("쿠폰 발급 종료 날짜 (Ex: yyyy-MM-dd'T'HH:mm)")