Skip to content

Commit 865bc89

Browse files
authored
Merge branch 'develop' into ft001-base-de-datos
2 parents e5de680 + 85fa4b2 commit 865bc89

File tree

8 files changed

+189
-62
lines changed

8 files changed

+189
-62
lines changed

migrations/versions/2e3a70a695d4_.py

-35
This file was deleted.

migrations/versions/a08fba8a0180_.py renamed to migrations/versions/a9b7f08f1a62_.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""empty message
22
3-
Revision ID: a08fba8a0180
3+
Revision ID: a9b7f08f1a62
44
Revises:
5-
Create Date: 2025-03-05 14:44:28.016416
5+
Create Date: 2025-03-06 10:20:42.876362
66
77
"""
88
from alembic import op
99
import sqlalchemy as sa
1010

1111

1212
# revision identifiers, used by Alembic.
13-
revision = 'a08fba8a0180'
13+
revision = 'a9b7f08f1a62'
1414
down_revision = None
1515
branch_labels = None
1616
depends_on = None

src/api/commands.py

+5
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def insert_data_catfood():
4242
catfood.weight = 1.
4343
catfood.price = 1.
4444
catfood.animal_type = "gato"
45+
4546
catfood.age = "cachorro"
4647
catfood.pathologies = "renal"
4748
db.session.add(catfood)
@@ -57,6 +58,10 @@ def insert_data_catfood():
5758
catfood.animal_type = "gato"
5859
catfood.age = "adulto"
5960
catfood.pathologies = "diabético"
61+
62+
catfood.age = "sd"
63+
catfood.pathologies = "asd"
64+
6065
db.session.add(catfood)
6166
db.session.commit()
6267

src/api/routes.py

+22
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def get_pet_suggestions(pet_id):
102102
return "no suggestions found", 404
103103
return [food[0].serialize() for food in food_suggestions], 200
104104

105+
105106
#obtener todos los alimentos según tipo de animal
106107
@api.route('/foods/cat', methods=['GET'])
107108
def get_all_cat_food():
@@ -112,28 +113,49 @@ def get_all_cat_food():
112113
if not food_cat:
113114
return jsonify({"error": "No cat food found"}), 404
114115

116+
117+
# #obtener todos los alimentos según tipo de animal
118+
@api.route('/foods/cat', methods=['GET'])
119+
def get_all_cat_food():
120+
food_cat = db.session.query(Food).filter(Food.animal_type.ilike("%gato%")).all()
121+
print("Datos obtenidos:", food_cat)
122+
if not food_cat:
123+
return jsonify({"error": "No cat food found"}), 404
124+
115125
return jsonify([food.serialize() for food in food_cat]), 200
116126

117127
@api.route('/foods/dog', methods=['GET'])
118128
def get_all_dog_food():
119129
food_dog = db.session.query(Food).filter(Food.animal_type.ilike("%perro%")).all()
130+
120131

121132
print("Datos obtenidos:", food_dog)
122133

123134
if not food_dog:
124135
return jsonify({"error": "No dog food found"}), 404
125136

137+
138+
print("Datos obtenidos:", food_dog)
139+
if not food_dog:
140+
return jsonify({"error": "No dog food found"}), 404
141+
126142
return jsonify([food.serialize() for food in food_dog]), 200
127143

128144
@api.route('/foods/exotic', methods=['GET'])
129145
def get_all_exotic_food():
130146
food_exotic = db.session.query(Food).filter(Food.animal_type.ilike("%exótico%")).all()
147+
131148

132149
print("Datos obtenidos:", food_exotic)
133150

134151
if not food_exotic:
135152
return jsonify({"error": "No exotic food found"}), 404
136153

154+
155+
print("Datos obtenidos:", food_exotic)
156+
if not food_exotic:
157+
return jsonify({"error": "No exotic food found"}), 404
158+
137159
return jsonify([food.serialize() for food in food_exotic]), 200
138160

139161
# Obtener todos los accesorios

src/front/js/component/card.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import React, { Component } from "react";
2+
import { useContext } from "react";
3+
import { Context } from "../store/appContext";
24

3-
export const Card = () => {
4-
return (
5+
export const Card = ({name, id, description}) => {
6+
7+
const { store, actions } = useContext(Context);
8+
9+
return (
510
<div className="card m-2" style={{ width: "18rem" }}>
6-
<img
11+
{/* <img
712
src="https://static.zoomalia.com/prod_img/46527/la_53533e8075e9970de0cfea955afd4644bb21537446021.jpg"
813
style={{ width: "150px", height: "200px" }}
914
className="card-img-top mx-auto d-block mt-2"
1015
alt="..."
11-
/>
16+
/> */}
1217
<div className="card-body text-center">
13-
<h5 className="card-title">Título</h5>
14-
<p className="card-text">Some quick example text to build on the card.</p>
18+
<h5 className="card-title">{name}</h5>
19+
<p className="card-text">{description}</p>
1520
</div>
1621
<div className="mt-auto text-center">
1722
<button className="btn btn-primary m-2">Añadir carrito</button>

src/front/js/layout.js

+4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import ScrollToTop from "./component/scrollToTop";
44
import { BackendURL } from "./component/backendURL";
55

66
import { Home } from "./pages/home";
7+
78
import { Demo } from "./pages/demo";
89
import { Single } from "./pages/single";
910
import injectContext from "./store/appContext";
1011

1112
import { Navbar } from "./component/navbar";
1213
import { Footer } from "./component/footer";
1314

15+
1416
//create your first component
1517
const Layout = () => {
1618
//the basename is used when your project is published in a subdirectory and not in the root of the domain
@@ -26,6 +28,8 @@ const Layout = () => {
2628
<Navbar />
2729
<Routes>
2830
<Route element={<Home />} path="/" />
31+
32+
2933
<Route element={<Demo />} path="/demo" />
3034
<Route element={<Single />} path="/single/:theid" />
3135
<Route element={<h1>Not found!</h1>} />

src/front/js/pages/home.js

+54-16
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
import React, { useContext } from "react";
1+
import React, { useContext, useEffect } from "react";
22
import { Context } from "../store/appContext";
33
import { Card } from "../component/card";
44
import "../../styles/home.css";
55

66
export const Home = () => {
7+
78
const { store, actions } = useContext(Context);
89

10+
11+
useEffect(()=>{
12+
actions.getDogFood()
13+
},[])
14+
15+
useEffect(()=>{
16+
actions.getCatFood()
17+
},[])
18+
19+
useEffect(()=>{
20+
actions.getExoticFood()
21+
},[])
22+
923
return (
1024

1125
<div className="container m-0">
@@ -16,35 +30,59 @@ export const Home = () => {
1630
alt="Banner"
1731
/>
1832
</div>
33+
1934
<div className="sección perros m-5">
35+
{/* <div className="cards d-flex overflow-auto m-4"> */}
2036
<h3>Productos top para perros</h3>
2137
<div className="row">
22-
<Card className="col-md-3" />
23-
<Card className="col-md-3" />
24-
<Card className="col-md-3" />
25-
<Card className="col-md-3" />
26-
</div>
38+
39+
{store.dogFood.map((dogFood, index) => {
40+
return(
41+
<Card
42+
name={dogFood.name}
43+
category={"dogFood"}
44+
id={dogFood.id}
45+
description={dogFood.description}
46+
key={index}/>
47+
);
48+
})}</div>
2749
</div>
2850

51+
2952
<div className="sección gatos m-5">
3053
<h3>Productos top para gatos</h3>
3154
<div className="row">
32-
<Card className="col-md-3" />
33-
<Card className="col-md-3" />
34-
<Card className="col-md-3" />
35-
<Card className="col-md-3" />
36-
</div>
55+
56+
{store.catFood.map((catFood, index) => {
57+
return(
58+
<Card
59+
name={catFood.name}
60+
category={"catFood"}
61+
id={catFood.id}
62+
description={catFood.description}
63+
key={index}/>
64+
);
65+
})}</div>
3766
</div>
3867

68+
3969
<div className="sección exóticos m-5">
4070
<h3>Productos top para animales exóticos</h3>
4171
<div className="row">
42-
<Card className="col-md-3" />
43-
<Card className="col-md-3" />
44-
<Card className="col-md-3" />
45-
<Card className="col-md-3" />
46-
</div>
72+
73+
{store.exoticFood.map((exoticFood, index) => {
74+
return(
75+
<Card
76+
name={exoticFood.name}
77+
category={"exóticFood"}
78+
id={exoticFood.id}
79+
description={exoticFood.description}
80+
key={index}/>
81+
);
82+
})}</div>
4783
</div>
84+
85+
4886
</div>
4987
);
5088
};

0 commit comments

Comments
 (0)