Skip to content

Commit

Permalink
Merge pull request #5 from diegosneves/feat/controller
Browse files Browse the repository at this point in the history
feat(Implemetação da Controller) ✨ Adicionar classes SplitInvoice Service, Response, Controller e DTO
  • Loading branch information
diegosneves authored Dec 20, 2023
2 parents 580d74c + 036d6fe commit 9ded9dc
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private Info getInfo() {
}

private List<Tag> getTags() { // TODO - Ajustar as tags do swagger
return List.of(new Tag().name("Racha-Pedido").description("Operações relacionadas a divisão dos valores do pedido"));
return List.of(new Tag().name("Racha Pedido").description("Operações relacionadas a divisão dos valores do pedido"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package diegosneves.github.rachapedido.controller;

import diegosneves.github.rachapedido.controller.contract.SplitInvoiceControllerContract;
import diegosneves.github.rachapedido.request.SplitInvoiceRequest;
import diegosneves.github.rachapedido.response.SplitInvoiceResponse;
import diegosneves.github.rachapedido.service.SplitInvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/split")
public class SplitInvoiceController implements SplitInvoiceControllerContract {

private final SplitInvoiceService service;

public SplitInvoiceController(@Autowired SplitInvoiceService service) {
this.service = service;
}


@Override
public ResponseEntity<SplitInvoiceResponse> splitInvoice(SplitInvoiceRequest request) {
SplitInvoiceResponse response = this.service.updateEmail(request); // TODO - Criar a regra de negocio
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package diegosneves.github.rachapedido.controller.contract;

import diegosneves.github.rachapedido.request.SplitInvoiceRequest;
import diegosneves.github.rachapedido.response.SplitInvoiceResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

public interface SplitInvoiceControllerContract {

@PostMapping(value = "/invoice", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Receber os dados para realizar a divisão da fatura", tags = "Racha Pedido")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Divisão da Fatura realizada com sucesso", content = @Content)
})
ResponseEntity<SplitInvoiceResponse> splitInvoice(@RequestBody SplitInvoiceRequest request);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package diegosneves.github.rachapedido.response;

import diegosneves.github.rachapedido.dto.PersonDTO;
import lombok.*;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder
public class SplitInvoiceResponse {
private PersonDTO buyer; // TODO - Definir os campos de retorno
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package diegosneves.github.rachapedido.service;

import diegosneves.github.rachapedido.request.SplitInvoiceRequest;
import diegosneves.github.rachapedido.response.SplitInvoiceResponse;
import org.springframework.stereotype.Service;

@Service
public class SplitInvoiceService {

// TODO - Criar as regras de Negocio

public SplitInvoiceResponse updateEmail(SplitInvoiceRequest request) {
final String TEST_EMAIL = "[email protected]";
request.getBuyer().setEmail(TEST_EMAIL);

return new SplitInvoiceResponse(request.getBuyer());
}
}

0 comments on commit 9ded9dc

Please sign in to comment.