Skip to content

Commit

Permalink
deploy heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
Edith Soares committed May 19, 2021
1 parent 1fb452d commit 1d26b35
Show file tree
Hide file tree
Showing 22 changed files with 895 additions and 116 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ requisitos:**
<table>
<td align="center"><br>
<a href="">
<img src="https://avatars.githubusercontent.com/u/60053229?v=4" width="105px;" alt="Edith Soares" style="max-width:100%;">
<img src="https://avatars.githubusercontent.com/u/60053229?v=4" width="105px;" alt="Edith Soares" style="max-width:100%;border-radius: 50%;">
<br><sub><b>Edith Soares</b></sub><br>
<p align="center">
</a>
Expand All @@ -53,7 +53,7 @@ requisitos:**
</td>
<td align="center"><br>
<a href="">
<img src="https://avatars.githubusercontent.com/u/83894378?v=4" width="105px;" alt="Pollyana Veloso" style="max-width:100%;">
<img src="https://avatars.githubusercontent.com/u/83894378?v=4" width="105px;" alt="Pollyana Veloso" style="max-width:100%;border-radius: 50%;">
<br><sub><b>Pollyana Veloso</b></sub><br>
<p align="center">
</a>
Expand All @@ -72,7 +72,7 @@ requisitos:**
//CONTINUAR AQUI
<td align="center"><br>
<a href="">
<img src="https://avatars.githubusercontent.com/u/83829276?v=4" width="105px;" alt="Marcela Lima" style="max-width:100%;">
<img src="https://avatars.githubusercontent.com/u/83829276?v=4" width="105px;" alt="Marcela Lima" style="max-width:100%;border-radius: 50%;">
<br><sub><b>Marcela Lima</b></sub><br>
<p align="center">
</a>
Expand All @@ -89,7 +89,7 @@ requisitos:**
</td>
<td align="center"><br>
<a href="">
<img src="https://media-exp1.licdn.com/dms/image/C4E03AQEvax-YywQ5_Q/profile-displayphoto-shrink_800_800/0/1520895453031?e=1626307200&v=beta&t=RobigoX5QOGHIOSDcs7Zqiq3eTopU3lc3wBE2zO506U" width="105px;" alt="Maria Tereza" style="max-width:100%;">
<img src="https://media-exp1.licdn.com/dms/image/C4E03AQEvax-YywQ5_Q/profile-displayphoto-shrink_800_800/0/1520895453031?e=1626307200&v=beta&t=RobigoX5QOGHIOSDcs7Zqiq3eTopU3lc3wBE2zO506U" width="105px;" alt="Maria Tereza" style="max-width:100%;border-radius: 50%;">
<br><sub><b>Maria Tereza</b></sub><br>
<p align="center">
</a>
Expand All @@ -106,7 +106,7 @@ requisitos:**
</td>
<td align="center"><br>
<a href="">
<img src="https://media-exp1.licdn.com/dms/image/C4E03AQE6FGRIkmi9QA/profile-displayphoto-shrink_800_800/0/1620351775178?e=1626307200&v=beta&t=ZnnNt9FzKCnidGL6MQtmQQR7oUCyZ8q70viHGOAfFto" width="105px;" alt="Maria Tereza" style="max-width:100%;">
<img src="https://media-exp1.licdn.com/dms/image/C4E03AQE6FGRIkmi9QA/profile-displayphoto-shrink_800_800/0/1620351775178?e=1626307200&v=beta&t=ZnnNt9FzKCnidGL6MQtmQQR7oUCyZ8q70viHGOAfFto" width="105px;" alt="Maria Tereza" style="max-width:100%;border-radius: 50%;">
<br><sub><b>Larissa Palhao</b></sub><br>
<p align="center">
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class FinalchallengeApplication {
public class FinalChallengeApplication {

public static void main(String[] args) {
SpringApplication.run(FinalchallengeApplication.class, args);
SpringApplication.run(FinalChallengeApplication.class, args);
}

}
7 changes: 4 additions & 3 deletions src/main/java/spg/finalchallenge/config/SwaggerConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ public Docket api(){

private ApiInfo metaInfo(){
ApiInfo apiInfo = new ApiInfo(
"Luiza Code",
"API REST desenvolvida para as aulas do curso da Luiza Code",
"Wishlist API",
"API REST desenvolvida para o desafio final Luiza Code",
"1.0",
"Terms of service",
new Contact("Tainá Medeiros", "","[email protected]"),
new Contact("Edith Soares / Pollyana Veloso / Marcela Lima / Maria Tereza / Larissa Palhao",
"","[edith.soaares, pollyvel20, limamarcela6795, therezaaltarugio, larissa.palhao]@gmail.com"),
"Apcahe License Version 2.0",
"https://www.apache.org/license.html", new ArrayList<VendorExtension>()
);
Expand Down
96 changes: 77 additions & 19 deletions src/main/java/spg/finalchallenge/controller/ClientController.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package spg.finalchallenge.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import spg.finalchallenge.entity.Client;
import spg.finalchallenge.payload.Response;
import spg.finalchallenge.service.ClientService;

import java.util.List;
import java.util.Optional;

@RestController
Expand All @@ -16,41 +21,94 @@ public class ClientController {
@Autowired
private ClientService clientService;


@ApiOperation(value = "save a new client")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Returns the registered client", response = Response.class),
@ApiResponse(code = 401, message = "You do not have permission to access this feature.", response = Response.class),
@ApiResponse(code = 400, message = "Bad request", response = Response.class),
@ApiResponse(code = 500, message = "An exception was thrown", response = Response.class),
})
@PostMapping("/client")
public ResponseEntity<Client> addClient(@RequestBody Client client){
public ResponseEntity<?> saveClient(@RequestBody Client client){
try{
return new ResponseEntity<>(clientService.add(client), HttpStatus.CREATED);
return new ResponseEntity<>(clientService.saveClient(client), HttpStatus.CREATED);
}catch (Exception e){
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>( new Response(false, "Request Errors"),
HttpStatus.BAD_REQUEST);
}
}

@GetMapping("/client/{id}")
public ResponseEntity<Client> getId(@PathVariable(value = "id") long id) {
try{
return new ResponseEntity<>(clientService.getId(id), HttpStatus.OK);

@ApiOperation(value = "Search all clients")
@ApiResponses(value ={
@ApiResponse(code = 200, message = "Returns the list of clients", response = Response.class),
@ApiResponse(code = 401, message = "You do not have permission to access this feature.", response = Response.class),
@ApiResponse(code = 404, message = "List products not found", response = Response.class),
@ApiResponse(code = 500, message = "An exception was thrown", response = Response.class),
})
@GetMapping("/clients")
public ResponseEntity<?> listAllClients(){
try {
List<Client> clients = clientService.listAllClient();
if (clients != null){
return new ResponseEntity<>(clients, HttpStatus.OK);
}else{
return new ResponseEntity(new Response(false, "Client not found"),
HttpStatus.NOT_FOUND);
}
}catch (Exception e){
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>( new Response(false, "Request Errors"),
HttpStatus.BAD_REQUEST);
}
}

@PutMapping("/client/{id}")
public ResponseEntity<Client> update(@RequestBody Client client, @PathVariable(value = "id") long id) {
try{
Optional<Client> clientResult = clientService.findById(id);
if(clientResult.isPresent()){
@ApiOperation(value = "Update client")
@ApiResponses(value ={
@ApiResponse(code = 200, message = "Returns the client", response = Response.class),
@ApiResponse(code = 401, message = "You do not have permission to access this feature.", response = Response.class),
@ApiResponse(code = 404, message = "List products not found", response = Response.class),
@ApiResponse(code = 500, message = "An exception was thrown", response = Response.class),
})
@PutMapping("/client/update/{id}")
public ResponseEntity<?> updateClient(@PathVariable long id, @RequestBody Client client){
try {
Optional<Client> clientResult = clientService.findByIdClient(id);
if (clientResult.isPresent()){
client.setId(clientResult.get().getId());
return new ResponseEntity<>(clientService.update(client), HttpStatus.OK);
}else{
return new ResponseEntity(new Response(false, "Client not found"),
HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}catch (Exception e){
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>( new Response(false, "Request Errors"),
HttpStatus.BAD_REQUEST);
}

}

@GetMapping("/client/cout")
public long qtdeClient() {
return clientService.count();
@ApiOperation(value = "Delete client by Cpf")
@ApiResponses(value ={
@ApiResponse(code = 200, message = "Returns the cpf deleted", response = Response.class),
@ApiResponse(code = 401, message = "You do not have permission to access this feature.", response = Response.class),
@ApiResponse(code = 404, message = "List products not found", response = Response.class),
@ApiResponse(code = 500, message = "An exception was thrown", response = Response.class),
})
@DeleteMapping("client/delete/{cpf}")
public ResponseEntity<?> deleteClientByCpf(@PathVariable String cpf){
try {
Client client = clientService.findByCpfClient(cpf);
if (client != null){
clientService.deleteClient(client);
return new ResponseEntity<>(new Response(true, "Cliente deleted cpd: " + cpf ),
HttpStatus.OK);
}else {
return new ResponseEntity(new Response(false, "Client not found"),
HttpStatus.NOT_FOUND);
}
}catch (Exception e){
return new ResponseEntity<>( new Response(false, "Request Errors"),
HttpStatus.BAD_REQUEST);
}
}
}
100 changes: 88 additions & 12 deletions src/main/java/spg/finalchallenge/controller/ProductController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package spg.finalchallenge.controller;


import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import spg.finalchallenge.entity.Client;
import spg.finalchallenge.entity.Product;
import spg.finalchallenge.payload.Response;
import spg.finalchallenge.service.ProductService;

import java.util.List;
import java.util.Optional;

@RestController
Expand All @@ -15,23 +23,91 @@ public class ProductController {
@Autowired
private ProductService productService;

@ApiOperation(value = "Save a new Product")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "Returns the registered product", response = Response.class),
@ApiResponse(code = 401, message = "You do not have permission to access this feature.", response = Response.class),
@ApiResponse(code = 400, message = "Bad request", response = Response.class),
@ApiResponse(code = 500, message = "An exception was thrown", response = Response.class),
})
@PostMapping("/product")
public Product addProduto(@RequestBody Product product) {
return productService.add(product);
public ResponseEntity<?> saveProduct(@RequestBody Product product) {
try {
return new ResponseEntity<>(productService.saveProduct(product), HttpStatus.CREATED);
}catch (Exception e){
return new ResponseEntity<>( new Response(false, "Request Errors"),
HttpStatus.BAD_REQUEST);
}
}

@ApiOperation(value = "Search all products")
@ApiResponses(value ={
@ApiResponse(code = 200, message = "Returns the list of products", response = Response.class),
@ApiResponse(code = 401, message = "You do not have permission to access this feature.", response = Response.class),
@ApiResponse(code = 404, message = "List products not found", response = Response.class),
@ApiResponse(code = 500, message = "An exception was thrown", response = Response.class),
})
@GetMapping("/products")
public ResponseEntity<?> listAllProducts(){
try {
List<Product> products = productService.listAllProduct();
if (products != null){
return new ResponseEntity<>(products, HttpStatus.OK);
}else {
return new ResponseEntity(new Response(false, "Product not found"),
HttpStatus.NOT_FOUND);
}
}catch (Exception e){
return new ResponseEntity<>( new Response(false, "Request Errors"),
HttpStatus.BAD_REQUEST);
}
}

@GetMapping("/product/{id}")
public Product getId(@PathVariable(value = "id") long id) {
return productService.getId(id);
@ApiOperation(value = "Update product")
@ApiResponses(value ={
@ApiResponse(code = 200, message = "Returns the list of products", response = Response.class),
@ApiResponse(code = 401, message = "You do not have permission to access this feature.", response = Response.class),
@ApiResponse(code = 404, message = "List products not found", response = Response.class),
@ApiResponse(code = 500, message = "An exception was thrown", response = Response.class),
})
@PutMapping("/product/update/{id}")
public ResponseEntity<?> updateProduto(@RequestBody Product produto, @PathVariable(value = "id") long id) {
try {
Optional<Product> prod = productService.findById(id);
if(prod.isPresent()){
produto.setId(prod.get().getId());
return new ResponseEntity<>(productService.update(produto), HttpStatus.OK);
}
return new ResponseEntity(new spg.finalchallenge.payload.Response(false, "Product not found"),
HttpStatus.NOT_FOUND);
}catch (Exception e){
return new ResponseEntity<>( new Response(false, "Request Errors"),
HttpStatus.BAD_REQUEST);
}
}

@PutMapping("/produto/{id}")
public Product updateProduto(@RequestBody Product product, @PathVariable(value = "id") long id) {
Optional<Product> productResult = productService.findById(id);
if(productResult.isPresent()){
product.setId(productResult.get().getId());
return productService.update(product);
@ApiOperation(value = "Delete products")
@ApiResponses(value ={
@ApiResponse(code = 200, message = "Returns the id deleted", response = Response.class),
@ApiResponse(code = 401, message = "You do not have permission to access this feature.", response = Response.class),
@ApiResponse(code = 404, message = "List products not found", response = Response.class),
@ApiResponse(code = 500, message = "An exception was thrown", response = Response.class),
})
@DeleteMapping("product/delete/{id}")
public ResponseEntity<?> deleteProductByCpf(@PathVariable long id){
try {
Product productResult = productService.getId(id);
if (productResult != null){
productService.deleteProduct(productResult);
return new ResponseEntity<>(new Response(true, "Product deleted id: " + id ),
HttpStatus.OK);
}else {
return new ResponseEntity(new Response(false, "Product not found"),
HttpStatus.NOT_FOUND);
}
}catch (Exception e){
return new ResponseEntity<>( new Response(false, "Request Errors"),
HttpStatus.BAD_REQUEST);
}
return null;
}
}
Loading

0 comments on commit 1d26b35

Please sign in to comment.