Skip to content

Commit

Permalink
update readme use
Browse files Browse the repository at this point in the history
  • Loading branch information
gusgonza committed May 29, 2024
1 parent 5c0532b commit e4d361e
Show file tree
Hide file tree
Showing 27 changed files with 797 additions and 72 deletions.
11 changes: 11 additions & 0 deletions M01-SISTEMAS/docker-mongo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Usa la imagen base desde Docker Hub
FROM jgusgonza/my-mongo

# Exponemos el puerto 3306 para que se pueda acceder a MySQL desde fuera del contenedor
EXPOSE 27017

# Establecemos las variables de entorno para MySQL
ENV MYSQL_ROOT_PASSWORD=Sabores1234

# Copia el archivo SQL al directorio de inicialización de MySQL
#COPY ../../M02-BBDD/script/script_inicial.sql /docker-entrypoint-initdb.d/
19 changes: 19 additions & 0 deletions M01-SISTEMAS/docker-mongo/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.8'

services:
mongo:
image: gusgonza/mymongo
container_name: mymongo
ports:
- "27017:27017"
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: root
ME_CONFIG_MONGODB_URL: mongodb://root:root@mongo:27017/
ME_CONFIG_BASICAUTH: "false"
volumes:
- mongo_data:/data/db
restart: always

volumes:
mongo_data:
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ public class DataBaseConnection {
public ArrayList<Plato_Producto> platos_productos;


public void init() throws SQLException {
//Conectamos
conectar();
//Cargamos datos
cargaDeDatosCSV();
System.out.println("CARGA DE DATOS COMPLETADA :)!");
//Desconectamos
desconectar();
public void init() throws CheckError {
try {
//Conectamos
conectar();
//Cargamos datos
cargaDeDatosCSV();
System.out.println("CARGA DE DATOS COMPLETADA :)!");
//Desconectamos
desconectar();
}catch (SQLException e) {
throw new CheckError(CheckError.ERROR_CONNECT_BBDD);
}
}

public static Connection getConnection()throws CheckError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
package abp.project.mesapp.database;

import abp.project.mesapp.util.CheckError;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;

import java.util.logging.Level;
import java.util.logging.Logger;

public class DataBaseConnectionMongo {
public MongoClient connectDB(String uri) throws CheckError{
// Reduce logging level from MongoDB driver
Logger.getLogger("org.mongodb.driver").setLevel(Level.SEVERE);
MongoClient mongoClient = null;
try {
mongoClient = MongoClients.create(uri);
System.out.println("Connected");
} catch (Exception e) {
System.out.println("Error connecting");
throw new CheckError(CheckError.ERROR_CONNECT_BBDD);
}
return mongoClient;
}

public void disconnectDB(MongoClient mongoClient) {
System.out.println("Disconnected");
mongoClient.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ public class Producto {
private int stock;
private String proveedor;


public Producto(int id_producto, String nombre, int stock, String proveedor) {
setIdproducto(id_producto);
setNombre(nombre);
setStock(stock);
setProveedor(proveedor);
}


public int getIdproducto() {
return id_producto;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package abp.project.mesapp.model;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;

import java.util.List;

public class Proveedores {
private int id;
private String nombre;
private String direccion;
private String telefono;
private String email;
private List<Producto> productos;


public Proveedores(int id, String nombre, String direccion, String telefono, String email) {
this.id = id;
this.nombre = nombre;
this.direccion = direccion;
this.telefono = telefono;
this.email = email;
this.productos = productos;
}

public int getId() {
return id;
}

public String getNombre() {
return nombre;
}

public String getDireccion() {
return direccion;
}

public String getTelefono() {
return telefono;
}

public String getEmail() {
return email;
}

public void setId(int id) {
this.id = id;
}

public void setNombre(String nombre) {
this.nombre = nombre;
}

public void setDireccion(String direccion) {
this.direccion = direccion;
}

public void setTelefono(String telefono) {
this.telefono = telefono;
}

public void setEmail(String email) {
this.email = email;
}

public List<Producto> getProductos() {
return productos;
}

public void setProductos(List<Producto> productos) {
this.productos = productos;
}

@Override
public String toString() {
return "Proveedores{" +
"id=" + id +
", nombre='" + nombre + '\'' +
", direccion='" + direccion + '\'' +
", telefono='" + telefono + '\'' +
", email='" + email + '\'' +
'}';
}
public static void saveProveedorToMongoDB(MongoClient mongoClient, String databaseName, String collectionName, Proveedores proveedor) {
MongoDatabase database = mongoClient.getDatabase(databaseName);
MongoCollection<Document> collection = database.getCollection(collectionName);

Document proveedorDocument = new Document();
proveedorDocument.append("id", proveedor.getId())
.append("nombre", proveedor.getNombre())
.append("direccion", proveedor.getDireccion())
.append("telefono", proveedor.getTelefono())
.append("email", proveedor.getEmail());

// Convertir lista de productos a documentos BSON
List<Producto> productos = proveedor.getProductos();
for (Producto producto : productos) {
Document productoDocument = new Document();
productoDocument.append("id_producto", producto.getIdproducto())
.append("nombre", producto.getNombre())
.append("stock", producto.getStock())
.append("proveedor", proveedor.getNombre()); // El nombre del proveedor se asocia con cada producto

proveedorDocument.append("productos", productoDocument);
}

// Insertar documento del proveedor en la colección
collection.insertOne(proveedorDocument);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package abp.project.mesapp.model;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoCollection;
import lombok.Getter;
import org.bson.Document;

import java.util.Date;


public class Tickets {
int order;
int table;
int waiter;
Date date;
int num_diners;

public Tickets(int order, int table, int waiter, Date date, int num_diners) {
setOrder(order);
setTable(table);
setWaiter(waiter);
setDate(date);
setNumDinners(num_diners);
}

public void setOrder(int order) {
this.order = order;
}

public void setTable(int table) {
this.table = table;
}

public void setWaiter(int waiter) {
this.waiter = waiter;
}

public void setDate(Date date) {
this.date = date;
}

public void setNumDinners(int num_diners) {
this.num_diners = num_diners;
}

public String toString() {
return "Order: " + order + ", Table: " + table + ", Waiter: " + waiter + ", Date: " + date + ", Number of diners: " + num_diners;
}

public void saveTicket(MongoClient mongoClient, String databaseName, String collectionName) {
MongoCollection<Document> collection = mongoClient.getDatabase(databaseName).getCollection(collectionName);

Document ticketDocument = new Document();
ticketDocument.append("order", this.order)
.append("table", this.table)
.append("waiter", this.waiter)
.append("date", this.date)
.append("num_diners", this.num_diners);

collection.insertOne(ticketDocument);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Constantes {
public static final String PASS = "Sabores1234";
public static final String SCHEMA = "vialacteadesabores";
public static final String BBDD = "jdbc:mysql://localhost:3307/";
public static final String uri = "mongodb://root:root@localhost:27017";
//RUTAS DE ARCHIVO
public static final String PATH = "src/main/java/abp/project/mesapp/data/";
//RUTAS DE ARCHIVO ESPECÍFICO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
package abp.project.mesapp.util;

import abp.project.mesapp.database.DataBaseConnection;
import abp.project.mesapp.database.DataBaseConnectionMongo;
import abp.project.mesapp.model.MenuFunciones;
import abp.project.mesapp.model.Producto;
import abp.project.mesapp.model.Proveedores;
import abp.project.mesapp.model.Tickets;
import com.mongodb.client.MongoClient;

import java.sql.SQLException;
import java.util.Date;

public class Main {
public static void main(String[] args) throws SQLException {
DataBaseConnection db = new DataBaseConnection();
db.init();
MenuFunciones menu = new MenuFunciones();
menu.menuFunciones(db);
// DESCONECTAR
db.desconectar();
public static void main(String[] args) throws CheckError {
try{
DataBaseConnection db = new DataBaseConnection();
db.init();
DataBaseConnectionMongo dbMongo = new DataBaseConnectionMongo();
System.out.println("Conexión establecida");
MongoClient mongoClient = dbMongo.connectDB(Constantes.uri);
System.out.println("Disconnected");
dbMongo.disconnectDB(mongoClient);
Tickets ticket = new Tickets(1, 1, 1, new Date(), 1);
ticket.saveTicket(mongoClient, "vialacteadesabores", "tickets");
Proveedores proveedor = new Proveedores(1, "Proveedor A", "Calle 123", "123456789", "proveedor@example.com");
Producto producto1 = new Producto(1, "Producto 1", 10, "Proveedor A");
Producto producto2 = new Producto(2, "Producto 2", 20, "Proveedor A");
proveedor.getProductos().add(producto1);
proveedor.getProductos().add(producto2);
Proveedores.saveProveedorToMongoDB(mongoClient, "vialacteadesabores", "proveedores", proveedor);
db.desconectar();
}catch (SQLException e){
throw new CheckError(CheckError.ERROR_CONNECT_BBDD);
}
}
}

3 changes: 3 additions & 0 deletions M04-LENGUAJES/via-lactea-fronted/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<div id="app">
<router-view/>
<footer>
<p>© 2024 La Vía Lactea de Sabores Todos los derechos reservados</p>
</footer>
</div>

</template>
Expand Down
4 changes: 2 additions & 2 deletions M04-LENGUAJES/via-lactea-fronted/src/assets/css/registro.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ body, html {
}

.registro-container {
position: relative;
position: fixed;
text-align: center;
padding: 20px;
padding: 7.5%;
width: 100%;
height: 100vh;
overflow-y: auto;
Expand Down
Loading

0 comments on commit e4d361e

Please sign in to comment.