This repository was archived by the owner on Apr 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCartController.java
More file actions
39 lines (30 loc) · 1.46 KB
/
CartController.java
File metadata and controls
39 lines (30 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package group.rohlik.controller;
import com.fasterxml.jackson.databind.JsonNode;
import group.rohlik.application.CartDiscountAdder;
import group.rohlik.application.CartLineAdder;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@AllArgsConstructor
public class CartController {
private final CartLineAdder cartLineAdder;
private final CartDiscountAdder cartDiscountAdder;
@PostMapping(path = "/carts/{id}/lines", consumes = "application/json", produces = "application/json")
public ResponseEntity addLine(@PathVariable long id, @RequestBody JsonNode payload) {
String sku = payload.get("sku").textValue();
int quantity = payload.get("quantity").intValue();
cartLineAdder.add(id, sku, quantity);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping(path = "/carts/{id}/discounts", consumes = "application/json", produces = "application/json")
public ResponseEntity addDiscount(@PathVariable long id, @RequestBody JsonNode payload) {
String code = payload.get("code").textValue();
cartDiscountAdder.add(id, code);
return new ResponseEntity<>(HttpStatus.OK);
}
}