Created
November 13, 2024 04:17
-
-
Save guaracyalima/5cd88b884232f093fc86423bae8c625c to your computer and use it in GitHub Desktop.
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
package br.com.zeroth.zth_product_srv.controller; | |
import br.com.zeroth.zth_product_srv.domain.Order; | |
import br.com.zeroth.zth_product_srv.services.OrderService; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.http.ResponseEntity; | |
import org.springframework.util.DigestUtils; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.PathVariable; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
@RestController | |
@RequestMapping("/orders") | |
public class OrderController { | |
@Autowired | |
private OrderService service; | |
@GetMapping("/{id}") | |
public ResponseEntity<Order> getOrder(@PathVariable Long id) { | |
Order order = service.getOrderWithDetails(id); | |
String eTag = generateDeepETag(order); | |
return ResponseEntity.ok() | |
.eTag(eTag) | |
.body(order); | |
} | |
private String generateDeepETag(Order order) { | |
String productName = order.getProduct().getName(); | |
String paymentStatus = order.getPayment().getStatus(); | |
String shippingHistory = order.getShippingHistory().getLastStatus(); | |
return DigestUtils.md5DigestAsHex((productName + paymentStatus + shippingHistory).getBytes()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment