This repository has been archived by the owner on Dec 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
541 additions
and
110 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
54 changes: 54 additions & 0 deletions
54
src/main/java/com/example/comerce/core/controller/OrderController.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.example.comerce.core.controller; | ||
|
||
import com.example.comerce.core.dto.OrderDTO; | ||
import com.example.comerce.core.entities.Order; | ||
import com.example.comerce.core.services.OrderService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequestMapping("/api/orders") | ||
public final class OrderController { | ||
|
||
private final OrderService orderService; | ||
|
||
@Autowired | ||
public OrderController(final OrderService orderService) { | ||
this.orderService = orderService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<Order>> getAllOrders() { | ||
final List<Order> orders = orderService.findAll(); | ||
return ResponseEntity.ok(orders); | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<Order> getOrderById(@PathVariable final UUID id) { | ||
final Optional<Order> order = orderService.findById(id); | ||
return order.map(ResponseEntity::ok).orElseGet(() -> ResponseEntity.notFound().build()); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<Order> createOrder(@RequestBody final OrderDTO orderDTO) { | ||
final Order savedOrder = orderService.save(orderDTO); | ||
return ResponseEntity.ok(savedOrder); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity<Void> deleteOrder(@PathVariable final UUID id) { | ||
orderService.delete(id); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public ResponseEntity<Order> updateOrder(@PathVariable final UUID id, @RequestBody final OrderDTO orderDTO) { | ||
final Order updatedOrder = orderService.update(id, orderDTO); | ||
return ResponseEntity.ok(updatedOrder); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.