Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data base #26

Merged
merged 4 commits into from
Mar 10, 2025
Merged
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
84 changes: 84 additions & 0 deletions migrations/versions/fef466e6c4fb_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
"""empty message

Revision ID: fef466e6c4fb
Revises:
Create Date: 2025-03-10 10:51:02.175212

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'fef466e6c4fb'
down_revision = None
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=120), nullable=False),
sa.Column('email', sa.String(length=120), nullable=False),
sa.Column('password', sa.String(length=500), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=False),
sa.Column('role', sa.Integer(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)
op.create_table('projects',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('description', sa.String(length=1500), nullable=False),
sa.Column('category', sa.String(length=100), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('goals',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('target', sa.String(length=500), nullable=False),
sa.Column('description', sa.String(length=1000), nullable=False),
sa.Column('ready', sa.Boolean(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('projects_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['projects_id'], ['projects.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('notes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('title', sa.String(length=150), nullable=False),
sa.Column('description', sa.String(length=2000), nullable=False),
sa.Column('category', sa.String(length=100), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('projects_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['projects_id'], ['projects.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('habits',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=100), nullable=False),
sa.Column('description', sa.String(length=1000), nullable=False),
sa.Column('category', sa.String(length=100), nullable=True),
sa.Column('ready', sa.Boolean(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=False),
sa.Column('goals_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['goals_id'], ['goals.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('habits')
op.drop_table('notes')
op.drop_table('goals')
op.drop_table('projects')
op.drop_table('user')
# ### end Alembic commands ###
4 changes: 2 additions & 2 deletions src/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class User(db.Model):
email: Mapped[str] = mapped_column(String(120), unique=True, nullable=False)
password: Mapped[str] = mapped_column(String(500))
is_active: Mapped[bool]
# role: Mapped[int] = mapped_column(Integer, nullable=False)
role: Mapped[int] = mapped_column(Integer, nullable=False)
notes: Mapped["Notes"] = relationship(back_populates="user")
habits: Mapped["Habits"] = relationship(back_populates="user")
goals: Mapped["Goals"] = relationship(back_populates="user")
Expand All @@ -25,7 +25,7 @@ def serialize(self):
"name": self.name,
"email": self.email,
"is_active": self.is_active,
# "role": self.role
"role": self.role
}

class Notes(db.Model):
Expand Down
2 changes: 1 addition & 1 deletion src/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def login():
# 3. Crear token JWT
access_token = create_access_token(identity=email)

return jsonify({"access_token": access_token})
return jsonify({"access_token": access_token}), 200

except Exception as e:
return jsonify({"msg": "Error logging in", "error": str(e)}), 500
Expand Down
12 changes: 8 additions & 4 deletions src/front/js/component/cardnote.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import React from "react";
import React, { useContext } from "react";
import { Link } from "react-router-dom";
import { Thememode } from "./Thememode"
import logo from "../../img/logo-sin-fondo.jpg"
import { FormNote } from "./formNote";


export const Cardnote = (props) => {
// const { store, actions } = useContext(Context);
// const note = store.notes
console.log(props);





export const Cardnote = () => {
return (
<div className="col">
<div className="card">
<div className="card-body d-flex flex-column mb-3">

<div className="container d-flex justify-content-between">
<h5 className="card-title">Card title</h5>
<h5 className="card-title">title</h5>
<div className="d-flex justify-content-end">
<button type="button" className="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#exampleModal">
<i className="fa-solid fa-ellipsis-vertical"></i>
Expand Down Expand Up @@ -57,7 +61,7 @@ export const Cardnote = () => {
</div>

</div>
<p className="card-text text-justufy">text lorem jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.</p>
<p className="card-text text-justufy">text destsdkjvbldafbvldjhfb vfdv</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/front/js/component/formNote.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const FormNote = () => {
const [title, setTitle] = useState("")
const [description, setDescription] = useState("")

console.log((note));
//console.log((note));


async function createNote() {
Expand Down
82 changes: 32 additions & 50 deletions src/front/js/pages/notes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from "react";
import React, { useEffect,useContext } from "react";
import { Context } from "../store/appContext";
import { Link } from "react-router-dom";
import { Cardnote } from "../component/cardnote";
Expand All @@ -7,15 +7,31 @@ import { FormNote } from "../component/formNote";

export const Notes = () => {
const { store, actions } = useContext(Context);
const note = store.notes
console.log(note);






useEffect(() => {
actions.notes();
}, []);


return (
<div className="container" style={{ position: 'relative', minHeight: '100vh' }}>
<div className="container text-center mt-5">
<h1>Notes</h1>
<div className="row row-cols-1 row-cols-md-3 g-4 mt-2">

<Cardnote />
<Cardnote />


{note.length > 0 ? note.map((item) => <Cardnote key={item.id} title={item.tiitle} description={item.description}/>) : null}



<Cardnote />
<Cardnote />

Expand All @@ -40,59 +56,25 @@ export const Notes = () => {

</div>
<div className="modal-footer">
{/* lista de categorias */}
<div class="dropdown-center">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Label
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Health</a></li>
<li><a class="dropdown-item" href="#">Sport</a></li>
<li><a class="dropdown-item" href="#">Education</a></li>
<li><a class="dropdown-item" href="#">Finance</a></li>
</ul>
</div>

{/* lista de categorias */}
<div class="dropdown-center">
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Label
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#">Health</a></li>
<li><a class="dropdown-item" href="#">Sport</a></li>
<li><a class="dropdown-item" href="#">Education</a></li>
<li><a class="dropdown-item" href="#">Finance</a></li>
</ul>
</div>

<button type="button" className="btn btn-primary">Create note</button>
</div>
</div>
</div>
</div>
















{/* <div className="modal fade" id="modal2" tabIndex="-1" aria-labelledby="modal2Label" aria-hidden="true">
<div className="modal-dialog modal-dialog-centered">
<div className="modal-content">
<div className="modal-header">
<h5 className="modal-title" id="modal2Label">new note</h5>
<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div className="modal-body">
<p>Modal body text goes here.</p>
</div>
<div className="modal-footer">
<button type="button" className="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" className="btn btn-primary">Create note</button>
</div>
</div>
</div>
</div> */}

</div >
);
};
Expand Down
Loading