Skip to content

Commit 674ddf7

Browse files
author
JEstebanC
committed
Finish the api with the validations and his verification
1 parent fcb201b commit 674ddf7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1106
-513
lines changed

src/main/java/JEstebanC/FastFoodApp/controller/IngredientController.java renamed to src/main/java/JEstebanC/FastFoodApp/controller/AdditionalController.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,76 +20,76 @@
2020
import org.springframework.web.bind.annotation.RequestMapping;
2121
import org.springframework.web.bind.annotation.RestController;
2222

23-
import JEstebanC.FastFoodApp.model.Ingredient;
23+
import JEstebanC.FastFoodApp.model.Additional;
2424
import JEstebanC.FastFoodApp.model.Response;
25-
import JEstebanC.FastFoodApp.service.IngredientServiceImp;
25+
import JEstebanC.FastFoodApp.service.AdditionalServiceImp;
2626
import lombok.RequiredArgsConstructor;
2727

2828
/**
2929
* @author Juan Esteban Castaño Holguin castanoesteban9@gmail.com 2022-01-24
3030
*/
3131
@RestController
3232
@RequiredArgsConstructor
33-
@RequestMapping("/ingredient")
34-
public class IngredientController {
33+
@RequestMapping("/additional")
34+
public class AdditionalController {
3535

3636
@Autowired
37-
private final IngredientServiceImp serviceImp;
37+
private final AdditionalServiceImp serviceImp;
3838

3939
// CREATE
4040
@PostMapping()
41-
public ResponseEntity<Response> saveIngredient(@RequestBody @Valid Ingredient ingredient) {
41+
public ResponseEntity<Response> saveAdditional(@RequestBody @Valid Additional addiotional) {
4242
return ResponseEntity
43-
.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("ingredient", serviceImp.create(ingredient)))
44-
.message("Create ingredient").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
43+
.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("additional", serviceImp.create(addiotional)))
44+
.message("Create additional").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
4545
}
4646

4747
// READ
4848
@GetMapping(value = "/list")
49-
public ResponseEntity<Response> getIngredient() {
50-
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("ingredient", serviceImp.list()))
51-
.message("List ingredients").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
49+
public ResponseEntity<Response> getadditional() {
50+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("additional", serviceImp.list()))
51+
.message("List additionals").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
5252
}
5353

5454
// UPDATE
5555
@PutMapping(value = "/{id}")
56-
public ResponseEntity<Response> updateIngredient(@PathVariable("id") Long id, @RequestBody @Valid Ingredient ingredient) {
56+
public ResponseEntity<Response> updateAdditional(@PathVariable("id") Long id, @RequestBody @Valid Additional addiotional) {
5757
if (serviceImp.exist(id)) {
5858
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
59-
.data(Map.of("ingredient", serviceImp.update(ingredient))).message("Update ingredient with id:" + id)
59+
.data(Map.of("additional", serviceImp.update(addiotional))).message("Update additional with id:" + id)
6060
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
6161
} else {
6262
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
63-
.message("The ingredient with id:" + id + " does not exist").status(HttpStatus.BAD_REQUEST)
63+
.message("The additional with id:" + id + " does not exist").status(HttpStatus.BAD_REQUEST)
6464
.statusCode(HttpStatus.BAD_REQUEST.value()).build());
6565
}
6666
}
6767

6868
// DELETE
6969
@DeleteMapping(value = "/{id}")
70-
public ResponseEntity<Response> deleteIngredient(@PathVariable("id") Long id) {
70+
public ResponseEntity<Response> deleteAdditional(@PathVariable("id") Long id) {
7171
if (serviceImp.exist(id)) {
7272
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
73-
.data(Map.of("ingredient", serviceImp.delete(id))).message("Delete ingredient with id: " + id)
73+
.data(Map.of("additional", serviceImp.delete(id))).message("Delete additional with id: " + id)
7474
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
7575
} else {
7676
return ResponseEntity
77-
.ok(Response.builder().timeStamp(Instant.now()).message("The ingredient " + id + " does not exist")
77+
.ok(Response.builder().timeStamp(Instant.now()).message("The additional " + id + " does not exist")
7878
.status(HttpStatus.BAD_REQUEST).statusCode(HttpStatus.BAD_REQUEST.value()).build());
7979
}
8080
}
8181
// SEARCH BY NAME
8282
@GetMapping(value = "/{name}")
83-
public ResponseEntity<Response> getIngredientByName(@PathVariable("name") String name) {
83+
public ResponseEntity<Response> getAdditionalByName(@PathVariable("name") String name) {
8484

8585
if (serviceImp.findByName(name) != null) {
8686
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
87-
.data(Map.of("ingredient", serviceImp.findByName(name))).message("Get ingredient by name: " + name)
87+
.data(Map.of("additional", serviceImp.findByName(name))).message("Get additional by name: " + name)
8888
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
8989

9090
} else {
9191
return ResponseEntity.ok(
92-
Response.builder().timeStamp(Instant.now()).message("The ingredient called" + name + " does not exist")
92+
Response.builder().timeStamp(Instant.now()).message("The additional called" + name + " does not exist")
9393
.status(HttpStatus.BAD_REQUEST).statusCode(HttpStatus.BAD_REQUEST.value()).build());
9494
}
9595

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package JEstebanC.FastFoodApp.controller;
2+
3+
import java.time.Instant;
4+
import java.util.Map;
5+
6+
import javax.validation.Valid;
7+
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.DeleteMapping;
12+
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.PathVariable;
14+
import org.springframework.web.bind.annotation.PostMapping;
15+
import org.springframework.web.bind.annotation.PutMapping;
16+
import org.springframework.web.bind.annotation.RequestBody;
17+
import org.springframework.web.bind.annotation.RequestMapping;
18+
import org.springframework.web.bind.annotation.RestController;
19+
20+
import JEstebanC.FastFoodApp.model.Bill;
21+
import JEstebanC.FastFoodApp.model.Response;
22+
import JEstebanC.FastFoodApp.service.BillServiceImp;
23+
import lombok.RequiredArgsConstructor;
24+
25+
/**
26+
* @author Juan Esteban Castaño Holguin castanoesteban9@gmail.com 2022-01-26
27+
*/
28+
@RestController
29+
@RequiredArgsConstructor
30+
@RequestMapping("/bill")
31+
public class BillController {
32+
33+
@Autowired
34+
private final BillServiceImp serviceImp;
35+
36+
// CREATE
37+
@PostMapping()
38+
public ResponseEntity<Response> saveBill(@RequestBody @Valid Bill bill) {
39+
return ResponseEntity
40+
.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("bill", serviceImp.create(bill)))
41+
.message("Create bill").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
42+
}
43+
44+
// READ
45+
@GetMapping(value = "/list")
46+
public ResponseEntity<Response> getBill() {
47+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("bill", serviceImp.list()))
48+
.message("List bills").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
49+
}
50+
51+
// UPDATE
52+
@PutMapping(value = "/{id}")
53+
public ResponseEntity<Response> updateBill(@PathVariable("id") Long id, @RequestBody @Valid Bill bill) {
54+
if (serviceImp.exist(id)) {
55+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
56+
.data(Map.of("bill", serviceImp.update(bill))).message("Update bill with id:" + id)
57+
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
58+
} else {
59+
return ResponseEntity.ok(
60+
Response.builder().timeStamp(Instant.now()).message("The bill with id:" + id + " does not exist")
61+
.status(HttpStatus.BAD_REQUEST).statusCode(HttpStatus.BAD_REQUEST.value()).build());
62+
}
63+
}
64+
65+
// DELETE
66+
@DeleteMapping(value = "/{id}")
67+
public ResponseEntity<Response> deleteBill(@PathVariable("id") Long id) {
68+
if (serviceImp.exist(id)) {
69+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
70+
.data(Map.of("bill", serviceImp.delete(id))).message("Delete bill with id: " + id)
71+
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
72+
} else {
73+
return ResponseEntity
74+
.ok(Response.builder().timeStamp(Instant.now()).message("The bill " + id + " does not exist")
75+
.status(HttpStatus.BAD_REQUEST).statusCode(HttpStatus.BAD_REQUEST.value()).build());
76+
}
77+
}
78+
// SEARCH BY CLIENT
79+
@GetMapping(value = "/client/{id}")
80+
public ResponseEntity<Response> getBill(@PathVariable("id") Long id) {
81+
82+
if(serviceImp.findByIdClient(id)!=null) {
83+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("bill", serviceImp.findByIdClient(id)))
84+
.message("List bills").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
85+
}else{
86+
return ResponseEntity
87+
.ok(Response.builder().timeStamp(Instant.now()).message("The bill with id client: " + id + " does not exist")
88+
.status(HttpStatus.BAD_REQUEST).statusCode(HttpStatus.BAD_REQUEST.value()).build());
89+
}
90+
91+
92+
}
93+
}

src/main/java/JEstebanC/FastFoodApp/controller/CategoryIngredientController.java renamed to src/main/java/JEstebanC/FastFoodApp/controller/CategoryAdditionalController.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,80 +20,80 @@
2020
import org.springframework.web.bind.annotation.RequestMapping;
2121
import org.springframework.web.bind.annotation.RestController;
2222

23-
import JEstebanC.FastFoodApp.model.CategoryIngredient;
23+
import JEstebanC.FastFoodApp.model.CategoryAdditional;
2424
import JEstebanC.FastFoodApp.model.Response;
25-
import JEstebanC.FastFoodApp.service.CategoryIngredientServiceImp;
25+
import JEstebanC.FastFoodApp.service.CategoryAdditionalServiceImp;
2626
import lombok.RequiredArgsConstructor;
2727

2828
/**
2929
* @author Juan Esteban Castaño Holguin castanoesteban9@gmail.com 2022-01-24
3030
*/
3131
@RestController
3232
@RequiredArgsConstructor
33-
@RequestMapping("/category-ingredient")
34-
public class CategoryIngredientController {
33+
@RequestMapping("/category-additional")
34+
public class CategoryAdditionalController {
3535

3636
@Autowired
37-
private final CategoryIngredientServiceImp serviceImp;
37+
private final CategoryAdditionalServiceImp serviceImp;
3838

3939
// CREATE
4040
@PostMapping()
41-
public ResponseEntity<Response> saveCategoryIngredient(@RequestBody @Valid CategoryIngredient categoryIngredient) {
41+
public ResponseEntity<Response> saveCategoryAdditional(@RequestBody @Valid CategoryAdditional categoryAdditional) {
4242
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
43-
.data(Map.of("categoryIngredient", serviceImp.create(categoryIngredient)))
44-
.message("Create category ingredient").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
43+
.data(Map.of("categoryAdditional", serviceImp.create(categoryAdditional)))
44+
.message("Create category additional").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
4545
}
4646

4747
// READ
4848
@GetMapping(value = "/list")
49-
public ResponseEntity<Response> getCategoryIngredient() {
49+
public ResponseEntity<Response> getCategoryAdditional() {
5050
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
51-
.data(Map.of("categoryIngredient", serviceImp.list())).message("List categories ingredients")
51+
.data(Map.of("categoryAdditional", serviceImp.list())).message("List categories additionals")
5252
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
5353
}
5454

5555
// UPDATE
5656
@PutMapping(value = "/{id}")
57-
public ResponseEntity<Response> updateCategoryIngredient(@PathVariable("id") Long id,
58-
@RequestBody @Valid CategoryIngredient categoryIngredient) {
57+
public ResponseEntity<Response> updateCategoryAdditional(@PathVariable("id") Long id,
58+
@RequestBody @Valid CategoryAdditional categoryAdditional) {
5959
if (serviceImp.exist(id)) {
6060
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
61-
.data(Map.of("categoryIngredient", serviceImp.update(categoryIngredient)))
62-
.message("Update category ingredient with id:" + id).status(HttpStatus.OK)
61+
.data(Map.of("categoryAdditional", serviceImp.update(categoryAdditional)))
62+
.message("Update category additional with id:" + id).status(HttpStatus.OK)
6363
.statusCode(HttpStatus.OK.value()).build());
6464
} else {
6565
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
66-
.message("The category ingredient with id:" + id + " does not exist").status(HttpStatus.BAD_REQUEST)
66+
.message("The category additional with id:" + id + " does not exist").status(HttpStatus.BAD_REQUEST)
6767
.statusCode(HttpStatus.BAD_REQUEST.value()).build());
6868
}
6969
}
7070

7171
// DELETE
7272
@DeleteMapping(value = "/{id}")
73-
public ResponseEntity<Response> deleteCategoryIngredient(@PathVariable("id") Long id) {
73+
public ResponseEntity<Response> deleteCategoryAdditional(@PathVariable("id") Long id) {
7474
if (serviceImp.exist(id)) {
7575
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
76-
.data(Map.of("categoryIngredient", serviceImp.delete(id)))
77-
.message("Delete category ingredient with id: " + id).status(HttpStatus.OK)
76+
.data(Map.of("categoryAdditional", serviceImp.delete(id)))
77+
.message("Delete category additional with id: " + id).status(HttpStatus.OK)
7878
.statusCode(HttpStatus.OK.value()).build());
7979
} else {
8080
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
81-
.message("The category ingredient " + id + " does not exist").status(HttpStatus.BAD_REQUEST)
81+
.message("The category additional " + id + " does not exist").status(HttpStatus.BAD_REQUEST)
8282
.statusCode(HttpStatus.BAD_REQUEST.value()).build());
8383
}
8484
}
8585

8686
// SEARCH BY NAME
8787
@GetMapping(value = "/{name}")
88-
public ResponseEntity<Response> getCategoryIngredientByName(@PathVariable("name") String name) {
88+
public ResponseEntity<Response> getCategoryAdditionalByName(@PathVariable("name") String name) {
8989
if (serviceImp.findByName(name) != null) {
9090
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
91-
.data(Map.of("categoryIngredient", serviceImp.findByName(name)))
92-
.message("Get category ingredient by name: " + name).status(HttpStatus.OK)
91+
.data(Map.of("categoryAdditional", serviceImp.findByName(name)))
92+
.message("Get category additional by name: " + name).status(HttpStatus.OK)
9393
.statusCode(HttpStatus.OK.value()).build());
9494
} else {
9595
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
96-
.message("The category ingredient called" + name + " does not exist").status(HttpStatus.BAD_REQUEST)
96+
.message("The category additional called" + name + " does not exist").status(HttpStatus.BAD_REQUEST)
9797
.statusCode(HttpStatus.BAD_REQUEST.value()).build());
9898
}
9999

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package JEstebanC.FastFoodApp.controller;
2+
3+
import java.time.Instant;
4+
import java.util.Map;
5+
6+
import javax.validation.Valid;
7+
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.http.ResponseEntity;
11+
import org.springframework.web.bind.annotation.DeleteMapping;
12+
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.PathVariable;
14+
import org.springframework.web.bind.annotation.PostMapping;
15+
import org.springframework.web.bind.annotation.PutMapping;
16+
import org.springframework.web.bind.annotation.RequestBody;
17+
import org.springframework.web.bind.annotation.RequestMapping;
18+
import org.springframework.web.bind.annotation.RestController;
19+
20+
import JEstebanC.FastFoodApp.model.Orders;
21+
import JEstebanC.FastFoodApp.model.Response;
22+
import JEstebanC.FastFoodApp.service.OrdersServiceImp;
23+
import lombok.RequiredArgsConstructor;
24+
25+
/**
26+
* @author Juan Esteban Castaño Holguin castanoesteban9@gmail.com 2022-01-28
27+
*/
28+
29+
@RestController
30+
@RequiredArgsConstructor
31+
@RequestMapping("/orders")
32+
public class OrdersController {
33+
34+
@Autowired
35+
private final OrdersServiceImp serviceImp;
36+
37+
// CREATE
38+
@PostMapping()
39+
public ResponseEntity<Response> saveOrder(@RequestBody @Valid Orders order) {
40+
return ResponseEntity
41+
.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("order", serviceImp.create(order)))
42+
.message("Create order").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
43+
}
44+
45+
// READ
46+
@GetMapping(value = "/list")
47+
public ResponseEntity<Response> getOrder() {
48+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("order", serviceImp.list()))
49+
.message("List orders").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
50+
}
51+
52+
// UPDATE
53+
@PutMapping(value = "/{id}")
54+
public ResponseEntity<Response> updateOrder(@PathVariable("id") Long id, @RequestBody @Valid Orders order) {
55+
if (serviceImp.exist(id)) {
56+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
57+
.data(Map.of("order", serviceImp.update(order))).message("Update order with id:" + id)
58+
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
59+
} else {
60+
return ResponseEntity.ok(
61+
Response.builder().timeStamp(Instant.now()).message("The order with id:" + id + " does not exist")
62+
.status(HttpStatus.BAD_REQUEST).statusCode(HttpStatus.BAD_REQUEST.value()).build());
63+
}
64+
}
65+
66+
// DELETE
67+
@DeleteMapping(value = "/{id}")
68+
public ResponseEntity<Response> deleteOrder(@PathVariable("id") Long id) {
69+
if (serviceImp.exist(id)) {
70+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now())
71+
.data(Map.of("order", serviceImp.delete(id))).message("order bill with id: " + id)
72+
.status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
73+
} else {
74+
return ResponseEntity
75+
.ok(Response.builder().timeStamp(Instant.now()).message("The bill " + id + " does not exist")
76+
.status(HttpStatus.BAD_REQUEST).statusCode(HttpStatus.BAD_REQUEST.value()).build());
77+
}
78+
}
79+
80+
// SEARCH ORDER BY ID CLIENT
81+
@GetMapping(value = "/bill/{idBill}")
82+
public ResponseEntity<Response> getOrderByIdClient(@PathVariable("idBill") Long idBill) {
83+
return ResponseEntity.ok(Response.builder().timeStamp(Instant.now()).data(Map.of("order", serviceImp.findByIdBill(idBill)))
84+
.message("List orders").status(HttpStatus.OK).statusCode(HttpStatus.OK.value()).build());
85+
}
86+
}

0 commit comments

Comments
 (0)