feat(notification): Feign 클라이언트 설정 추가 및 주문 정보 가져오기 로직 구현

This commit is contained in:
bum12ark
2022-03-17 11:43:59 +09:00
parent 4fbf90d415
commit 867bdbeb5b
7 changed files with 68 additions and 8 deletions

View File

@@ -3,9 +3,11 @@ package com.justpickup.notificationservice;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
@SpringBootApplication
@EnableEurekaClient
@EnableFeignClients
@SpringBootApplication
public class NotificationServiceApplication {
public static void main(String[] args) {

View File

@@ -1,5 +1,22 @@
package com.justpickup.notificationservice.domain.notification.messagequeue;
public enum OrderStatus {
import lombok.Getter;
// 주문 대기 -> 주문 신청 --> 주문수락 -> 픽업대기 -> 픽업완료
// \
// ㄴ> 주문거절
@Getter
public enum OrderStatus {
PENDING("주문대기(장바구니)"),
PLACED("주문신청"),
ACCEPTED("주문수락"),
REJECTED("주문거절"),
WAITING("픽업대기"),
FINISHED("픽업완료");
private String message;
OrderStatus(String message) {
this.message = message;
}
}

View File

@@ -10,5 +10,5 @@ public interface NotificationService {
List<FindNotificationDto> findNotificationByUserId(Long id);
void updateNotification(UpdateNotificationDto dto);
Long findNotificationCounts(Long userId, Yn readYn);
void insertOrderPlaced(Long userId);
void insertOrderPlaced(Long userId, Long storeId);
}

View File

@@ -5,6 +5,8 @@ import com.justpickup.notificationservice.domain.notification.dto.UpdateNotifica
import com.justpickup.notificationservice.domain.notification.entity.Notification;
import com.justpickup.notificationservice.domain.notification.exception.NotExistNotification;
import com.justpickup.notificationservice.domain.notification.repository.NotificationRepository;
import com.justpickup.notificationservice.global.client.store.GetStoreResponse;
import com.justpickup.notificationservice.global.client.store.StoreClient;
import com.justpickup.notificationservice.global.dto.Yn;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Sort;
@@ -21,6 +23,7 @@ import java.util.stream.Collectors;
public class NotificationServiceImpl implements NotificationService {
private final NotificationRepository notificationRepository;
private final StoreClient storeClient;
@Override
public List<FindNotificationDto> findNotificationByUserId(Long userId) {
@@ -52,12 +55,13 @@ public class NotificationServiceImpl implements NotificationService {
@Transactional
@Override
public void insertOrderPlaced(Long userId) {
String title = "주문이 수락되었어요.";
String storeName = "[]";
String message = storeName + "매장의 주문이 수락되었습니다.";
Notification notification = Notification.of(userId, message, title);
public void insertOrderPlaced(Long userId, Long storeId) {
GetStoreResponse storeResponse = storeClient.getStore(String.valueOf(storeId)).getData();
String title = "주문이 신청되었어요.";
String storeName = "[" + storeResponse.getName() + "]";
String message = storeName + "매장의 주문이 신청되었습니다.";
Notification notification = Notification.of(userId, message, title);
notificationRepository.save(notification);
}
}

View File

@@ -0,0 +1,10 @@
package com.justpickup.notificationservice.global.client.store;
import lombok.Getter;
@Getter
public class GetStoreResponse {
private Long id;
private String name;
private String phoneNumber;
}

View File

@@ -0,0 +1,13 @@
package com.justpickup.notificationservice.global.client.store;
import com.justpickup.notificationservice.global.dto.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient("STORE-SERVICE")
public interface StoreClient {
@GetMapping("/store/{storeId}")
Result<GetStoreResponse> getStore(@PathVariable(value = "storeId") String storeId);
}

View File

@@ -0,0 +1,14 @@
package com.justpickup.notificationservice.global.config;
import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class FeignClientConfig {
@Bean
public Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}