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
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
Expand All @@ -16,6 +16,7 @@
<properties>
<java.version>17</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -48,6 +49,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>

</dependencies>

Expand Down
66 changes: 45 additions & 21 deletions src/main/java/Proyecto/GestorAlmuerzo/FoodExpress.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package Proyecto.GestorAlmuerzo;

import Proyecto.GestorAlmuerzo.Repository.RoleRepository;
import Proyecto.GestorAlmuerzo.model.Category;
import Proyecto.GestorAlmuerzo.service.AppServices;
import Proyecto.GestorAlmuerzo.service.CategoryServices;
import Proyecto.GestorAlmuerzo.service.UserServices;
import Proyecto.GestorAlmuerzo.service.PlateServices;
import Proyecto.GestorAlmuerzo.model.User;
Expand All @@ -12,42 +15,63 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

@SpringBootApplication
public class FoodExpress {
@Autowired
RoleRepository roleRepository;
@Autowired(required = true)
UserServices usuarioService;

@Autowired
@Autowired(required = true)
AppServices appService;

@Autowired
@Autowired(required = true)
CategoryServices categoryServices;

@Autowired(required = true)
PlateServices plateServices;
public static void main(String[] args) {
SpringApplication.run(FoodExpress.class, args);
}



@Bean
public CommandLineRunner run() throws Exception {
return (args) -> {
appService.addRol(new Role("1", "cliente"));
appService.addRol(new Role("2", "administrador"));
appService.addRol(new Role("3", "empleado"));
usuarioService.addUser(new User("sebastian@foodexpres.com", "Sebastian", "Zamora", "1234", "1"));
plateServices.addPlate(new Plate("1", "Brillo Andino", "Ensalada de quinoa con aguacate y tomate cherry"));
plateServices.addPlate(new Plate("2", "Delicia Marina", "Carpaccio de salmón con alcaparras y limón"));
plateServices.addPlate(new Plate("3", "Susurros Tropicales", "Crema de calabaza con jengibre y coco"));
plateServices.addPlate(new Plate("4", "Aromas de la Tierra", "Sopa de lentejas con chorizo y espinacas"));
plateServices.addPlate(new Plate("5", "Melodía de Sabores", "Solomillo de ternera con salsa de vino tinto"));
plateServices.addPlate(new Plate("6", "Fusión Exótica", "Pollo al curry con leche de coco y verduras"));
plateServices.addPlate(new Plate("7", "Ritmo del Mar", "Filete de salmón a la parrilla con salsa de eneldo"));
plateServices.addPlate(new Plate("8", "Viaje a la Costa", "Paella de mariscos"));
plateServices.addPlate(new Plate("9", "Armonía en el Plato", "Risotto de champiñones y espinacas"));
plateServices.addPlate(new Plate("10", "Capricho Vegetal", "Lasaña de berenjena con ricotta y espinacas"));
plateServices.addPlate(new Plate("11", "Dulce Contraste", "Puré de batata con nueces y miel"));
plateServices.addPlate(new Plate("12", "Elegancia Verde", "Brócoli al vapor con almendras tostadas"));
plateServices.addPlate(new Plate("13", "Tradición Italiana", "Lasaña boloñesa"));
plateServices.addPlate(new Plate("14", "Fiesta Mexicana", "Tacos de carnitas con salsa de aguacate"));
plateServices.getAllPlates().forEach(plate -> System.out.println(plate));
appService.addRol(new Role("1", "client"));
appService.addRol(new Role("2", "admin"));
appService.addRol(new Role("3", "cooker"));
appService.addRol(new Role("4", "waiter"));
usuarioService.addUser(new User("sebassele2008@gmail.com", "Sebastian", "Zamora", "1234", "client",roleRepository));
usuarioService.addUser(new User("christian@foodexpres.com", "Chirstian", "Duarte", "1234", "admin",roleRepository));
usuarioService.addUser(new User("cesar@foodexpres.com", "Cesar", "Amaya", "1234", "cooker",roleRepository));
usuarioService.addUser(new User("johann@foodexpres.com", "Johann", "Amaya", "1234", "waiter",roleRepository));
categoryServices.addCategory(new Category("Ensalada"));
categoryServices.addCategory(new Category("Postre"));
categoryServices.addCategory(new Category("Entradas"));
categoryServices.addCategory(new Category("Plato Principal"));
categoryServices.addCategory(new Category("Especiales"));
categoryServices.addCategory(new Category("Nuevo Plato"));
Set<Category> defaulCategoria = new HashSet<>();
defaulCategoria.add(categoryServices.getCategoryByName("salads"));
plateServices.addPlate(new Plate(1, "Brillo Andino", "Ensalada de quinoa con aguacate y tomate cherry",12000,defaulCategoria));
plateServices.addPlate(new Plate(2, "Delicia Marina", "Carpaccio de salmón con alcaparras y limón",13000,defaulCategoria));
plateServices.addPlate(new Plate(3, "Susurros Tropicales", "Crema de calabaza con jengibre y coco",11000,defaulCategoria));
plateServices.addPlate(new Plate(4, "Aromas de la Tierra", "Sopa de lentejas con chorizo y espinacas",12300,defaulCategoria));
plateServices.addPlate(new Plate(5, "Melodía de Sabores", "Solomillo de ternera con salsa de vino tinto",11800,defaulCategoria));
plateServices.addPlate(new Plate(6, "Fusión Exótica", "Pollo al curry con leche de coco y verduras",14000,defaulCategoria));
plateServices.addPlate(new Plate(7, "Ritmo del Mar", "Filete de salmón a la parrilla con salsa de eneldo",15000,defaulCategoria));
plateServices.addPlate(new Plate(8, "Viaje a la Costa", "Paella de mariscos",13200,defaulCategoria));
plateServices.addPlate(new Plate(9, "Armonía en el Plato", "Risotto de champiñones y espinacas",11500,defaulCategoria));
plateServices.addPlate(new Plate(10, "Capricho Vegetal", "Lasaña de berenjena con ricotta y espinacas",14500,defaulCategoria));
plateServices.addPlate(new Plate(11, "Dulce Contraste", "Puré de batata con nueces y miel",10000,defaulCategoria));
plateServices.addPlate(new Plate(12, "Elegancia Verde", "Brócoli al vapor con almendras tostadas",10800,defaulCategoria));
plateServices.addPlate(new Plate(13, "Tradición Italiana", "Lasaña boloñesa",12100,defaulCategoria));
plateServices.addPlate(new Plate(14, "Fiesta Mexicana", "Tacos de carnitas con salsa de aguacate",11500,defaulCategoria));
};
}}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package Proyecto.GestorAlmuerzo.Repository;

import Proyecto.GestorAlmuerzo.model.Category;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CategoryRepository extends JpaRepository<Category, Integer> {
Category findByName(String categoryName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package Proyecto.GestorAlmuerzo.Repository;

import Proyecto.GestorAlmuerzo.model.Pay;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PayRepository extends JpaRepository<Pay,String> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import Proyecto.GestorAlmuerzo.model.Plate;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

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

/**
* Interface que nos permite conectar con la base de datos.
Expand All @@ -15,6 +17,7 @@
* @version 14/11/2023
*/
@Repository
public interface PlateRepository extends JpaRepository<Plate, String> {
List<Plate> findById(Long id);
public interface PlateRepository extends JpaRepository<Plate, Integer> {

List<Plate> findByCategoriesId(Long categoryId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package Proyecto.GestorAlmuerzo.Repository;

import Proyecto.GestorAlmuerzo.model.Role;
import Proyecto.GestorAlmuerzo.model.Suscription;
import org.springframework.data.jpa.repository.JpaRepository;

public interface SuscriptionRepository extends JpaRepository<Suscription, String> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package Proyecto.GestorAlmuerzo.controller;

import Proyecto.GestorAlmuerzo.model.Category;
import Proyecto.GestorAlmuerzo.model.Plate;
import Proyecto.GestorAlmuerzo.service.CategoryServices;
import Proyecto.GestorAlmuerzo.service.PlateServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

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

@Controller
public class MenuController {

@Autowired
private PlateServices plateServices;

@Autowired
private CategoryServices categoryServices;

@GetMapping("/configure-menu")
public String showMenu(@RequestParam(name = "sortBy",defaultValue = "name") String sortBy,
@RequestParam(name = "categoryFilter",required = false) Long categoryId,
Model model) {

List<Plate> menu;

if(categoryId != null){
menu = plateServices.findByCategoriesId(categoryId);
}else {

if ("name".equals(sortBy)) {
menu = plateServices.getAllPlatesOrderedByName();
} else if ("price".equals(sortBy)) {
menu = plateServices.getAllPlatesOrderedByPrice();
} else {
menu = plateServices.getAllPlates();
}
}
List<Category> allCategories = categoryServices.getAllCategories();
model.addAttribute("allCategories", allCategories);
model.addAttribute("menu", menu);
return "admin/menu";
}


@PostMapping("/addPlate")
public String addPlate(@ModelAttribute("plate") Plate plate) {
plateServices.addPlate(plate);
return "redirect:/admin/menu";
}

@GetMapping("/editPlate/{id}")
public String showEditPlateForm(@PathVariable String id, Model model) {
int plateId = Integer.parseInt(id);
Optional<Plate> plate = plateServices.getPlateById(plateId);
List<Category> allCategories = categoryServices.getAllCategories();
model.addAttribute("allCategories", allCategories);
model.addAttribute("plate", plate);
return "admin/editPlate";
}

@PostMapping("/editPlate/{id}")
public String editPlate(@PathVariable String id, @ModelAttribute("plate") Plate plate) {
int plateId = Integer.parseInt(id);
Optional<Plate> existingPlate = plateServices.getPlateById(plateId);
if(existingPlate.isEmpty()) {
}
else {
plate.setId(plateId);
plateServices.updatePlate(plate);
}
return "redirect:/admin/menu";
}

@RequestMapping("/deletePlate/{id}")
public String deletePlate(@PathVariable String id) {
int plateId = Integer.parseInt(id);
plateServices.deletePlate(plateId);
return "redirect:/admin/menu";
}
}

Loading