-
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
Edith Soares
committed
May 15, 2021
1 parent
b58d6e9
commit 1d930ec
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/main/java/spg/finalchallenge/controller/ClientController.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,56 @@ | ||
package spg.finalchallenge.controller; | ||
|
||
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.service.ClientService; | ||
|
||
import java.util.Optional; | ||
|
||
@RestController | ||
@RequestMapping( "/api") | ||
public class ClientController { | ||
|
||
@Autowired | ||
private ClientService clientService; | ||
|
||
|
||
@PostMapping("/client") | ||
public ResponseEntity<Client> addClient(@RequestBody Client client){ | ||
try{ | ||
return new ResponseEntity<>(clientService.add(client), HttpStatus.CREATED); | ||
}catch (Exception e){ | ||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
} | ||
} | ||
|
||
@GetMapping("/client/{id}") | ||
public ResponseEntity<Client> getId(@PathVariable(value = "id") long id) { | ||
try{ | ||
return new ResponseEntity<>(clientService.getId(id), HttpStatus.OK); | ||
}catch (Exception e){ | ||
return new ResponseEntity<>(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()){ | ||
client.setId(clientResult.get().getId()); | ||
return new ResponseEntity<>(clientService.update(client), HttpStatus.OK); | ||
} | ||
return new ResponseEntity<>(HttpStatus.NOT_FOUND); | ||
}catch (Exception e){ | ||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST); | ||
} | ||
} | ||
|
||
@GetMapping("/client/cout") | ||
public long qtdeClient() { | ||
return clientService.count(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/spg/finalchallenge/controller/ProductController.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,37 @@ | ||
package spg.finalchallenge.controller; | ||
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
import spg.finalchallenge.entity.Product; | ||
import spg.finalchallenge.service.ProductService; | ||
|
||
import java.util.Optional; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
public class ProductController { | ||
|
||
@Autowired | ||
private ProductService productService; | ||
|
||
@PostMapping("/product") | ||
public Product addProduto(@RequestBody Product product) { | ||
return productService.add(product); | ||
} | ||
|
||
@GetMapping("/product/{id}") | ||
public Product getId(@PathVariable(value = "id") long id) { | ||
return productService.getId(id); | ||
} | ||
|
||
@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); | ||
} | ||
return null; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/spg/finalchallenge/controller/WishlistController.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,37 @@ | ||
package spg.finalchallenge.controller; | ||
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
import spg.finalchallenge.entity.Wishlist; | ||
import spg.finalchallenge.service.WishlistService; | ||
|
||
import java.util.Optional; | ||
|
||
@RestController | ||
@RequestMapping("/api") | ||
public class WishlistController { | ||
|
||
@Autowired | ||
private WishlistService wishlistService; | ||
|
||
@PostMapping("/wishlist") | ||
public Wishlist addWish(@RequestBody Wishlist wishlist) { | ||
return wishlistService.add(wishlist); | ||
} | ||
|
||
@GetMapping("/wishlist/{id}") | ||
public Wishlist getId(@PathVariable(value = "id") long id) { | ||
return wishlistService.getId(id); | ||
} | ||
|
||
@PutMapping("/wishlist/{id}") | ||
public Wishlist update(@RequestBody Wishlist wishlist, @PathVariable(value = "id") long id) { | ||
Optional<Wishlist> wishlistResult = wishlistService.findById(id); | ||
if(wishlistResult.isPresent()){ | ||
wishlist.setId(wishlistResult.get().getId()); | ||
return wishlistService.update(wishlist); | ||
} | ||
return null; | ||
} | ||
} |