π―
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import uuid | |
| from datetime import datetime | |
| from app.serializers import CreateOrderReq, GetOrderReq, OrderResp | |
| from .model import Order, OrderStatus | |
| from .repository import get_order as query_order | |
| from .repository import save_order | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from .model import Order | |
| from datetime import datetime | |
| def save_order(order: Order) -> Order: | |
| order.updated_at = datetime.now().isoformat() | |
| Order.orders[order.id] = order | |
| return order | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from ..serialization_types import Btypes | |
| class CreateOrderReq(Btypes): | |
| def __init__(self, user_id: str, items: list): | |
| self.user_id = user_id | |
| self.items = items | |
| class GetOrderReq(Btypes): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from ..serialization_types import Etypes, type_check | |
| from .serializer import CreateOrderReq | |
| class OrderOperations: | |
| CREATE_ORDER = 'create_order' | |
| GET_ORDER = 'get_order' | |
| class CreateOrder(Etypes): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from app.serializers.serialization_types import Btypes | |
| class OrderStatus: | |
| INITIATED = 0 | |
| PACKING = 1 | |
| SHIPPED = 2 | |
| DELIVERED = 3 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import msgpack | |
| class Btypes: | |
| def pack(self): | |
| return msgpack.packb(Btypes.get_all_vars(self)) | |
| @classmethod | |
| def unpack(cls, d): | |
| return cls(**msgpack.unpackb(d, raw=False)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SingletonMeta(type): | |
| _instance = None | |
| def __call__(self): | |
| if self._instance is None: | |
| self._instance = super().__call__() | |
| return self._instance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| @Slf4j | |
| public class TraceIdFilter implements WebFilter { | |
| @Override | |
| public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { | |
| Map<String, String> headers = exchange.getRequest().getHeaders().toSingleValueMap(); | |
| var traceId = ""; | |
| if (headers.containsKey("X-B3-TRACEID")) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| @Slf4j | |
| public class TraceIdFilter implements WebFilter { | |
| @Override | |
| public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { | |
| Map<String, String> headers = exchange.getRequest().getHeaders().toSingleValueMap(); | |
| return chain.filter(exchange) | |
| .subscriberContext(context -> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class AbstractWebClient { | |
| private static final String MIME_TYPE = "application/json"; | |
| private final WebClient webClient; | |
| public AbstractWebClient(String clientUrl) { | |
| this.webClient = WebClient.builder() | |
| .baseUrl(clientUrl) | |
| .defaultHeader(HttpHeaders.CONTENT_TYPE, MIME_TYPE) | |
| .build(); |