Skip to content

Commit

Permalink
Merge pull request #30 from vanderleik/PPI-29---Documentar-A-API
Browse files Browse the repository at this point in the history
Ppi 29   documentar a api
  • Loading branch information
vanderleik authored Jul 13, 2024
2 parents 8665a45 + e352c99 commit e790cb2
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 27 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,7 @@
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import com.produtopedidoitens.api.adapters.web.requests.OrderRequest;
import com.produtopedidoitens.api.adapters.web.responses.OrderResponse;
import com.produtopedidoitens.api.application.port.OrderInputPort;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -14,6 +20,7 @@

import java.util.UUID;

@Tag(name = "Order", description = "API de pedidos")
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/v1/orders")
Expand All @@ -22,24 +29,58 @@ public class OrderController {

private final OrderInputPort orderInputPort;

@Operation(summary = "Endpoint responsável por cadastrar um pedido no sistema")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Pedido cadastrado com sucesso",
content = @Content(schema = @Schema(implementation = OrderResponse.class))),
@ApiResponse(responseCode = "400", description = "Requisição inválida",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@PostMapping
public ResponseEntity<OrderResponse> create(@Valid @RequestBody OrderRequest orderRequest) {
log.info("create:: Recebendo requisição para criar um pedido com os dados: {}", orderRequest);
return ResponseEntity.ok(orderInputPort.create(orderRequest));
}

@Operation(summary = "Endpoint responsável por listar todos os pedidos cadastrados no sistema")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Lista de pedidos retornada com sucesso",
content = @Content(schema = @Schema(implementation = Page.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@GetMapping
public ResponseEntity<Page<OrderProjection>> findAll(Pageable pageable) {
log.info("findAll:: Recebendo requisição para buscar todos os pedidos");
return ResponseEntity.ok(orderInputPort.list(pageable));
}

@Operation(summary = "Endpoint responsável por buscar um pedido pelo id")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Pedido encontrado com sucesso",
content = @Content(schema = @Schema(implementation = OrderProjection.class))),
@ApiResponse(responseCode = "404", description = "Pedido não encontrado",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@GetMapping("/{id}")
public ResponseEntity<OrderProjection> read(@PathVariable String id) {
log.info("findById:: Recebendo requisição para buscar um pedido pelo id: {}", id);
return ResponseEntity.ok(orderInputPort.read(UUID.fromString(id)));
}

@Operation(summary = "Endpoint responsável por buscar pedidos com filtros")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Lista de pedidos filtrados retornada com sucesso",
content = @Content(schema = @Schema(implementation = Page.class))),
@ApiResponse(responseCode = "400", description = "Requisição inválida",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@GetMapping("/filter")
public ResponseEntity<Page<OrderProjection>> getItemsWithFilters(@RequestParam(required = false) String orderNumber,
@RequestParam(required = false) String status,
Expand All @@ -49,12 +90,31 @@ public ResponseEntity<Page<OrderProjection>> getItemsWithFilters(@RequestParam(r
return ResponseEntity.ok(orders);
}

@Operation(summary = "Endpoint responsável por atualizar um pedido")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Pedido atualizado com sucesso",
content = @Content(schema = @Schema(implementation = OrderResponse.class))),
@ApiResponse(responseCode = "400", description = "Requisição inválida",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "404", description = "Pedido não encontrado",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@PutMapping("/{id}")
public ResponseEntity<OrderResponse> update(@PathVariable String id, @Valid @RequestBody OrderRequest orderRequest) {
log.info("update:: Recebendo requisição para atualizar um pedido com os dados: {}", orderRequest);
return ResponseEntity.ok(orderInputPort.update(UUID.fromString(id), orderRequest));
}

@Operation(summary = "Endpoint responsável por deletar um pedido")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Pedido deletado com sucesso"),
@ApiResponse(responseCode = "404", description = "Pedido não encontrado",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable String id) {
log.info("delete:: Recebendo requisição para deletar um pedido pelo id: {}", id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import com.produtopedidoitens.api.adapters.web.requests.OrderItemRequest;
import com.produtopedidoitens.api.adapters.web.responses.OrderItemResponse;
import com.produtopedidoitens.api.application.port.OrderItemInputPort;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -14,7 +20,7 @@
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@Tag(name = "OrderItem", description = "API de itens de pedido")
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/v1/orderitems")
Expand All @@ -23,36 +29,89 @@ public class OrderItemController {

private final OrderItemInputPort orderItemInputPort;

@Operation(summary = "Endpoint responsável por cadastrar um item de pedido no sistema")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Item de pedido cadastrado com sucesso",
content = @Content(schema = @Schema(implementation = OrderItemResponse.class))),
@ApiResponse(responseCode = "400", description = "Requisição inválida",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@PostMapping
public ResponseEntity<OrderItemResponse> create(@Valid @RequestBody OrderItemRequest orderItemRequest) {
log.info("create:: Recebendo requisição para criar um item de pedido com os dados: {}", orderItemRequest);
return ResponseEntity.ok(orderItemInputPort.create(orderItemRequest));
}

@Operation(summary = "Endpoint responsável por listar todos os itens de pedido cadastrados no sistema")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Lista de itens de pedido retornada com sucesso",
content = @Content(schema = @Schema(implementation = Page.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@GetMapping
public ResponseEntity<Page<OrderItemProjection>> listAll(Pageable pageable) {
log.info("listAll:: Recebendo requisição para listar todos os itens de pedido");
return ResponseEntity.ok(orderItemInputPort.list(pageable));
}

@Operation(summary = "Endpoint responsável por buscar um item de pedido pelo id")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Item de pedido encontrado com sucesso",
content = @Content(schema = @Schema(implementation = OrderItemProjection.class))),
@ApiResponse(responseCode = "404", description = "Item de pedido não encontrado",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@GetMapping("/{id}")
public ResponseEntity<OrderItemProjection> read(@PathVariable String id) {
log.info("read:: Recebendo requisição para buscar um item de pedido pelo id: {}", id);
return ResponseEntity.ok(orderItemInputPort.read(UUID.fromString(id)));
}

@Operation(summary = "Endpoint responsável por buscar itens de pedido com filtros")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Lista de itens de pedido filtrados retornada com sucesso",
content = @Content(schema = @Schema(implementation = Page.class))),
@ApiResponse(responseCode = "400", description = "Requisição inválida",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@GetMapping("/order/{orderNumber}")
public ResponseEntity<Page<OrderByOrderNumber>> getOrdersByOrderNumber(@PathVariable String orderNumber) {
log.info("getOrdersByOrderNumber:: Recebendo requisição para buscar itens de pedido pelo número do pedido: {}", orderNumber);
return ResponseEntity.ok(orderItemInputPort.getOrdersByOrderNumber(orderNumber));
}

@Operation(summary = "Endpoint responsável por atualizar um item de pedido")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Item de pedido atualizado com sucesso",
content = @Content(schema = @Schema(implementation = OrderItemResponse.class))),
@ApiResponse(responseCode = "400", description = "Requisição inválida",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "404", description = "Item de pedido não encontrado",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@PutMapping("/{id}")
public ResponseEntity<OrderItemResponse> update(@PathVariable String id, @Valid @RequestBody OrderItemRequest orderItemRequest) {
log.info("update:: Recebendo requisição para atualizar um item de pedido com os dados: {}", orderItemRequest);
return ResponseEntity.ok(orderItemInputPort.update(UUID.fromString(id), orderItemRequest));
}

@Operation(summary = "Endpoint responsável por deletar um item de pedido")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Item de pedido deletado com sucesso"),
@ApiResponse(responseCode = "404", description = "Item de pedido não encontrado",
content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "500", description = "Erro interno do servidor",
content = @Content(schema = @Schema(implementation = String.class)))
})
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable String id) {
log.info("delete:: Recebendo requisição para deletar um item de pedido pelo id: {}", id);
Expand Down
Loading

0 comments on commit e790cb2

Please sign in to comment.