Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Implemetação da Controller) ✨ Adicionar classes SplitInvoice Service, Response, Controller e DTO #5

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}