Skip to content
Open
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
2 changes: 1 addition & 1 deletion HELP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Restaurant Manager Application

This Spring Boot application is designed to manage various aspects of a restaurant's operations. It provides functionality for customer management, bookings, menu items, orders, and table management.
This Spring Boot application is designed to manage various aspects of a restaurant's operations. It provides functionality for customer management, bookings, menu items, orders, and tableRestaurant management.

## Project Structure

Expand Down
15 changes: 9 additions & 6 deletions _PRA/PRA01.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ Enhance the existing Restaurant Manager project by implementing JPA repositories

Summary tasks

- [ ] Update Entity Classe
- [ ] Create Faker Classe
- [ ] Develop Service Layer
- [ ] Implement JPA Repositories
- [ ] Design REST Controllers
- [ ] Test with Swagger API
- [x] Update Entity Classe
- [x] Create Faker Classe
- [x] Develop Service Layer
- [x] Implement JPA Repositories
- [x] Design REST Controllers
- [x] Test with Swagger API



Expand Down Expand Up @@ -83,3 +83,6 @@ Good luck with your implementation! And remember, **code slow to go far**
Citations:
[1] https://github.com/AlbertProfe/restaurantManager/commits/master/
[2] https://albertprofe.dev/springboot/sblab8-3.ht

##### Preguntas
Puedo crear un metodo que una todos los fakers y ir ejecutando uno por uno para poder sacar datos de ellos, por ejemplo: ejecuto primero Menus y tables para que en order pueda coger aleatoriamente un menu y un table.
88 changes: 88 additions & 0 deletions _PRA/PRA01.md~
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# PRA01: Spring Boot JPA Repository and Entity Class Exercise

## CIFO La Violeta - FullStack IFCD0021-24 MF01-02-03

In this practical exercise, you will enhance the existing Restaurant Manager project by implementing JPA repositories, entity classes, and related components. You'll be working with the **TABLE** and **MENUS** classes, transforming them into entities and creating the necessary supporting structures.

## Objectives

Enhance the existing Restaurant Manager project by implementing JPA repositories, entity classes, and related components.

### Project Base

- Existing Repository: [Restaurant Manager](https://github.com/AlbertProfe/restaurantManager/commits/master/)[1]
- Reference Lab: [Spring Boot Lab 8.3](https://albertprofe.dev/springboot/sblab8-3.html)[2]

### Tasks

Summary tasks

- [x] Update Entity Classe
- [x] Create Faker Classe
- [x] Develop Service Layer
- [x] Implement JPA Repositories
- [ ] Design REST Controllers
- [ ] Test with Swagger API



1. **Update Entity Classes**

- Transform the **TABLE** and **MENUS** classes into JPA entities.
- Add appropriate annotations such as `@Entity`, `@Id`, and do not use `@GeneratedValue.`Use @id string <mark>UUID</mark>.
- ~~Define relationships between entities if necessary.~~

2. **Create Faker Classes**

- Implement faker classes for **TABLE** and **MENUS** to generate sample data.
- Use libraries like **Faker** or **Java Faker** to create realistic mock data.

3. **Develop Service Layer**

- Create service interfaces for **TABLE** and **MENUS**.
- <mark>Implement the service interfaces </mark>with concrete classes.
- Include methods for CRUD operations and any additional business logic.

4. **Implement JPA Repositories**

- Create JPA repository `interfaces` for **TABLE** and **MENUS**.
- Extend `JpaRepository<T, ID>` for each entity.
- ~~Add any custom query methods if required.~~

5. **Design REST Controllers**

- <mark>Develop REST controllers</mark> for **TABLE** and **MENUS**.
- Implement endpoints for CRUD operations.
- Use appropriate HTTP methods (GET, POST, PUT, DELETE) for each operation.

6. **Test with Swagger API**

- Configure `Swagger` for your Spring Boot application.
- Use `Swagger` UI to test all implemented REST endpoints.
- Verify CRUD operations for both **TABLE** and **MENUS** entities.

### Submission Guidelines

- Fork the existing [Restaurant Manager](https://github.com/AlbertProfe/restaurantManager/commits/master/) repository and clone to your local environment.
- Create a new branch named `PRA01-YourName`from the commit `PRA01: Spring Boot JPA Repository and Entity Class Exercise`
- Commit your changes with clear, descriptive messages.
- **Push** your branch to your forked repository.
- Create a <mark>pull request to the AlbertProfe repository</mark> with a summary of your changes with title:
- `PRA01-YourName-SpringBootJPARepositoryAndEntityClassExercise`

### Evaluation Criteria

- Correct implementation of JPA entities and repositories.
- Proper use of Spring Boot annotations and best practices.
- Functionality of service layer and controllers.
- Quality and coverage of Swagger API tests.
- Code clarity and documentation.

Good luck with your implementation! And remember, **code slow to go far**

Citations:
[1] https://github.com/AlbertProfe/restaurantManager/commits/master/
[2] https://albertprofe.dev/springboot/sblab8-3.ht

##### Preguntas
Puedo crear un metodo que una todos los fakers y ir ejecutando uno por uno para poder sacar datos de ellos, por ejemplo: ejecuto primero Menus y tables para que en order pueda coger aleatoriamente un menu y un table.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package dev.example.restaurantManager;



import dev.example.restaurantManager.utilities.DataLoader;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class RestaurantManagerApplication {
Expand All @@ -10,4 +15,12 @@ public static void main(String[] args) {
SpringApplication.run(RestaurantManagerApplication.class, args);
}



// @Bean
// public ApplicationRunner customerDataLoader(DataLoader DataLoader) {
// return args -> DataLoader.createFakeAllData();
//
// }

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.example.restaurantManager;



import dev.example.restaurantManager.utilities.DataLoader;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class RestaurantManagerApplication {

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



@Bean
public ApplicationRunner customerDataLoader(DataLoader DataLoader) {
return args -> DataLoader.createFakeAllData();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
public class CustomerController {

// inject from application.properties endpoint.url.customers
@Value("${endpoint.url.customers}")
private String endpointUrlCustomers;
// @Value("${endpoint.url.customers}")
// private String endpointUrlCustomers;

@Autowired
private CustomerService customerService;

@GetMapping("/show-endpoint")
public String showEndpointCustomers() {

return "The customers endpoint URL is: " + endpointUrlCustomers;
}
// @GetMapping("/show-endpoint")
// public String showEndpointCustomers() {
//
// return "The customers endpoint URL is: " + endpointUrlCustomers;
// }

// manage request by ResponseEntity with all customers
@GetMapping("/allCustomers")
Expand All @@ -39,7 +39,7 @@ public ResponseEntity<List<Customer>> getAllCustomers( ) {
: new ResponseEntity<>(headers, HttpStatus.NOT_FOUND);
}

@PostMapping
@PostMapping("/add")
public ResponseEntity<Customer> createCustomer(@RequestBody Customer customer) {
Customer createdCustomer = customerService.createCustomer(customer);
HttpHeaders headers = getCommonHeaders("Create a new customer");
Expand All @@ -49,7 +49,7 @@ public ResponseEntity<Customer> createCustomer(@RequestBody Customer customer) {
: new ResponseEntity<>(headers, HttpStatus.BAD_REQUEST);
}

@PutMapping("/{id}")
@PutMapping("/update/{id}")
public ResponseEntity<Customer> updateCustomer(@PathVariable String id, @RequestBody Customer customerDetails) {
Customer updatedCustomer = customerService.updateCustomer(id, customerDetails);
HttpHeaders headers = getCommonHeaders("Update a customer");
Expand All @@ -59,7 +59,7 @@ public ResponseEntity<Customer> updateCustomer(@PathVariable String id, @Request
: new ResponseEntity<>(headers, HttpStatus.NOT_FOUND);
}

@DeleteMapping("/{id}")
@DeleteMapping("/delete/{id}")
public ResponseEntity<Void> deleteCustomer(@PathVariable String id) {
boolean deleted = customerService.deleteCustomer(id);
HttpHeaders headers = getCommonHeaders("Delete a customer");
Expand All @@ -71,7 +71,7 @@ public ResponseEntity<Void> deleteCustomer(@PathVariable String id) {
: new ResponseEntity<>(headers, HttpStatus.NOT_FOUND);
}

@GetMapping("/{id}")
@GetMapping("/get/{id}")
public ResponseEntity<Customer> getCustomerById(@PathVariable String id) {
Customer customer = customerService.getCustomerById(id);
HttpHeaders headers = getCommonHeaders("Get a customer by Id");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package dev.example.restaurantManager.controller;

import dev.example.restaurantManager.model.Customer;
import dev.example.restaurantManager.repository.CustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;

@RequestMapping("/customer")
@Controller
public class CustomerWebController {

@Autowired
CustomerRepository customerRepository;

// CRUD for customer
@GetMapping("/home")
public String home(Model model) {

List<Customer> customers = customerRepository.findAll();
model.addAttribute("customersToView", customers);

return "home";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package dev.example.restaurantManager.controller;


import dev.example.restaurantManager.model.EatInOrderRestaurant;
import dev.example.restaurantManager.service.EatInOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;


@RequestMapping("/api/v1/eatInOrder")
@Controller
public class EatInOrderController {

@Autowired
private EatInOrderService eatInOrderService;

@GetMapping("/allCustomers")
public ResponseEntity<List<EatInOrderRestaurant>> getAllCustomers( ) {
List<EatInOrderRestaurant> eatInOrders = eatInOrderService.getAllEatInOrders();
HttpHeaders headers = getCommonHeaders("Get all eat in orders");
return eatInOrders != null && !eatInOrders.isEmpty()
? new ResponseEntity<>(eatInOrders, headers, HttpStatus.OK)
: new ResponseEntity<>(headers, HttpStatus.NOT_FOUND);
}

@PostMapping("/add")
public ResponseEntity<EatInOrderRestaurant> createEatInOrder(@RequestBody EatInOrderRestaurant eatInOrderDetails) {
EatInOrderRestaurant createdEatInOrder = eatInOrderService.createEatInOrder(eatInOrderDetails);
HttpHeaders headers = getCommonHeaders("Create a new eat in order");
return createdEatInOrder != null
? new ResponseEntity<>(createdEatInOrder, headers, HttpStatus.CREATED)
: new ResponseEntity<>(headers, HttpStatus.BAD_REQUEST);
}

@PutMapping("/update/{id}")
public ResponseEntity<EatInOrderRestaurant> updateEatInOrder(@PathVariable String id, @RequestBody EatInOrderRestaurant eatInOrderDetails) {
EatInOrderRestaurant updatedEatInOrder = eatInOrderService.updateEatInOrder(id, eatInOrderDetails);
HttpHeaders headers = getCommonHeaders("Update a eat in order");
return updatedEatInOrder != null
? new ResponseEntity<>(updatedEatInOrder, headers, HttpStatus.OK)
: new ResponseEntity<>(headers, HttpStatus.NOT_FOUND);
}

@GetMapping("/get/{id}")
public ResponseEntity<EatInOrderRestaurant> getEatInOrderById(@PathVariable String id) {
EatInOrderRestaurant eatInOrder = eatInOrderService.getEatInOrderById(id);
HttpHeaders headers = getCommonHeaders("Get an eat in order");
return eatInOrder != null
? new ResponseEntity<>(eatInOrder, headers, HttpStatus.OK)
: new ResponseEntity<>(headers, HttpStatus.NOT_FOUND);
}

@DeleteMapping("/delete/{id}")
public ResponseEntity<Void> deleteEatInOrder(@PathVariable String id) {
boolean deleted = eatInOrderService.deleteEatInOrder(id);
HttpHeaders headers = getCommonHeaders("Delete a eat in order");
headers.add("deleted", String.valueOf(deleted));
return deleted
? new ResponseEntity<>(headers, HttpStatus.NO_CONTENT)
: new ResponseEntity<>(headers, HttpStatus.NOT_FOUND);
}

private HttpHeaders getCommonHeaders(String description) {
HttpHeaders headers = new HttpHeaders();
headers.add("desc", description);
headers.add("content-type", "application/json");
headers.add("date", new Date().toString());
headers.add("server", "H2 Database");
headers.add("version", "1.0.0");
headers.add("customer-count", String.valueOf(eatInOrderService.countEatInOrders()));
headers.add("object", "customers");
return headers;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package dev.example.restaurantManager.controller;

import dev.example.restaurantManager.model.EatInOrderRestaurant;
import dev.example.restaurantManager.repository.EatInOrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@RequestMapping("/eatInOrder")
@Controller
public class EatInOrderWebController {

@Autowired
EatInOrderRepository eatInOrderRepository;

@GetMapping("home")
public String home(Model model) {
List<EatInOrderRestaurant> eatInOrders = eatInOrderRepository.findAll();
model.addAttribute("eatInOrders", eatInOrders);
return "menuEatInOrder";
}
}
Loading