diff --git a/backend/app/routes/desafios.py b/backend/app/routes/desafios.py index ebe412e..499e4eb 100644 --- a/backend/app/routes/desafios.py +++ b/backend/app/routes/desafios.py @@ -1,3 +1,4 @@ +from sqlalchemy import inspect from typing import List, Annotated from fastapi import APIRouter, Depends, HTTPException @@ -11,34 +12,29 @@ from sqlalchemy.orm import Session router = APIRouter( - prefix="/desafios", - tags=["desafios"], - responses={404: {"description": "Not found"}} + prefix="/desafios", tags=["desafios"], responses={404: {"description": "Not found"}} ) -from sqlalchemy import inspect + @router.post("/", response_model=Desafio) def create_desafio( desafio: DesafioCreate, current_user: Annotated[Users, Depends(get_current_active_user)], - db: Session = Depends(get_db) + db: Session = Depends(get_db), ): # TODO: check if user is allowed to create desafio (staff) try: with db.begin(): # create 'Atividade' object - db_atividade = Atividade( - nome=desafio.nome, - pontos=desafio.pontos - ) + db_atividade = Atividade(nome=desafio.nome, pontos=desafio.pontos) db.add(db_atividade) - db.flush() # flush to get the id + db.flush() # flush to get the id # create 'Desafios' object db_desafio = Desafios( descricao=desafio.descricao, - empresa_id=desafio.empresa_id, - atividade_id=db_atividade.id + # empresa_id=desafio.empresa_id, + atividade_id=db_atividade.id, ) db.add(db_desafio) @@ -51,12 +47,12 @@ def create_desafio( nome=db_atividade.nome, pontos=db_atividade.pontos, descricao=db_desafio.descricao, - empresa_id=db_desafio.empresa_id ) except Exception as e: db.rollback() return HTTPException(status_code=400, detail=str(e)) + @router.get("/", response_model=List[Desafio]) def read_desafios(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)): # Join 'Atividade' and 'Desafios' tables @@ -66,16 +62,16 @@ def read_desafios(skip: int = 0, limit: int = 10, db: Session = Depends(get_db)) Atividade.nome, Atividade.pontos, Desafios.descricao, - Desafios.empresa_id ) .join(Atividade, Desafios.atividade_id == Atividade.id) .offset(skip) .limit(limit) .all() ) - + return db_desafios + @router.get("/{desafio_id}", response_model=Desafio) def read_desafio(desafio_id: int, db: Session = Depends(get_db)): # Join 'Atividade' and 'Desafios' tables @@ -85,7 +81,6 @@ def read_desafio(desafio_id: int, db: Session = Depends(get_db)): Atividade.nome, Atividade.pontos, Desafios.descricao, - Desafios.empresa_id ) .join(Atividade, Desafios.atividade_id == Atividade.id) .filter(Desafios.id == desafio_id) @@ -95,12 +90,13 @@ def read_desafio(desafio_id: int, db: Session = Depends(get_db)): raise HTTPException(status_code=404, detail="Desafio not found") return db_desafio + @router.put("/{desafio_id}", response_model=Desafio) def update_desafio( desafio_id: int, desafio: DesafioUpdate, current_user: Annotated[Users, Depends(get_current_active_user)], - db: Session = Depends(get_db) + db: Session = Depends(get_db), ): # TODO: check if user is allowed to update desafio (staff) @@ -111,7 +107,6 @@ def update_desafio( Atividade.nome, Atividade.pontos, Desafios.descricao, - Desafios.empresa_id ) .join(Atividade, Desafios.atividade_id == Atividade.id) .filter(Desafios.id == desafio_id) @@ -119,33 +114,32 @@ def update_desafio( ) if db_desafio is None: raise HTTPException(status_code=404, detail="Desafio not found") - + # update 'Atividade' object - db.query(Atividade).filter(Atividade.id == db_desafio.id).update({ - "nome": desafio.nome, - "pontos": desafio.pontos - }) + db.query(Atividade).filter(Atividade.id == db_desafio.id).update( + {"nome": desafio.nome, "pontos": desafio.pontos} + ) # update 'Desafios' object db.query(Desafios).filter(Desafios.id == db_desafio.id).update({ "descricao": desafio.descricao, - "empresa_id": desafio.empresa_id }) db.commit() - + # return updated object return Desafio( id=db_desafio.id, nome=desafio.nome, pontos=desafio.pontos, descricao=desafio.descricao, - empresa_id=desafio.empresa_id ) + @router.delete("/{desafio_id}", response_model=Desafio) def delete_desafio( desafio_id: int, current_user: Annotated[Users, Depends(get_current_active_user)], - db: Session = Depends(get_db)): + db: Session = Depends(get_db), +): # TODO: check if user is allowed to delete desafio (staff) # Join 'Atividade' and 'Desafios' tables @@ -155,7 +149,6 @@ def delete_desafio( Atividade.nome, Atividade.pontos, Desafios.descricao, - Desafios.empresa_id ) .join(Atividade, Desafios.atividade_id == Atividade.id) .filter(Desafios.id == desafio_id) @@ -163,8 +156,8 @@ def delete_desafio( ) if db_desafio is None: raise HTTPException(status_code=404, detail="Desafio not found") - + # delete atividade (this will delete desafio too) db.query(Atividade).filter(Atividade.id == db_desafio.id).delete() db.commit() - return db_desafio \ No newline at end of file + return db_desafio diff --git a/frontend/public/icons/circle_right.svg b/frontend/public/icons/circle_right.svg new file mode 100644 index 0000000..04ed392 --- /dev/null +++ b/frontend/public/icons/circle_right.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/icons/circle_right_30.svg b/frontend/public/icons/circle_right_30.svg new file mode 100644 index 0000000..04ed392 --- /dev/null +++ b/frontend/public/icons/circle_right_30.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/frontend/public/logo_white.png b/frontend/public/logo_white.png new file mode 100644 index 0000000..87d3032 Binary files /dev/null and b/frontend/public/logo_white.png differ diff --git a/frontend/public/loop.png b/frontend/public/loop.png new file mode 100644 index 0000000..29121e4 Binary files /dev/null and b/frontend/public/loop.png differ diff --git a/frontend/src/components/BaseLayout.jsx b/frontend/src/components/BaseLayout.jsx new file mode 100644 index 0000000..3472627 --- /dev/null +++ b/frontend/src/components/BaseLayout.jsx @@ -0,0 +1,10 @@ +import React from "react"; +import Navbar from "./Navbar"; +export default function BaseLayout({ children }) { + return ( + <> + + {children} + + ); +} diff --git a/frontend/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx new file mode 100644 index 0000000..e03348d --- /dev/null +++ b/frontend/src/components/Navbar.jsx @@ -0,0 +1,85 @@ +export default function Navbar() { + return ( +
+
+
+ logo +
+
+
+ +
+
+ Button +
+
+ + + +
+ +
+
+
+ ); +} diff --git a/frontend/src/pages/desafios.jsx b/frontend/src/pages/desafios.jsx new file mode 100644 index 0000000..9eb8506 --- /dev/null +++ b/frontend/src/pages/desafios.jsx @@ -0,0 +1,86 @@ +import React, { useState, useEffect } from "react"; +export const Desafios = () => { + const [desafios, setDesafios] = useState([]); + const [loading, setLoading] = useState(true); + useEffect(() => { + fetch("http://127.0.0.1:8000/desafios") + .then((response) => response.json()) + .then((data) => { + setDesafios(data); + setLoading(false); + }); + }, []); + const handleAddDesafio = (event) => { + event.preventDefault(); + const nome = event.target.nome.value; + const pontos = event.target.pontos.value; + const descricao = event.target.descricao.value; + fetch("http://127.0.0.1:8000/desafios", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ nome, pontos, descricao }), + }) + .then((response) => response.json()) + .then((data) => { + setDesafios([...desafios, data]); + event.target.reset(); + }); + }; + return ( + <> +

Desafios

+ {loading ? ( +

Loading...

+ ) : ( +
+ + + + + + + + + + {desafios.map((desafio) => ( + + + + + + + ))} +
NomePontosDescrição
{desafio.id}{desafio.nome}{desafio.pontos}{desafio.descricao}
+
+ )} +
+ + + + + + + +
+ + ); +}; diff --git a/frontend/src/pages/home.jsx b/frontend/src/pages/home.jsx index 2ac79bc..17e6bb3 100644 --- a/frontend/src/pages/home.jsx +++ b/frontend/src/pages/home.jsx @@ -1,22 +1,54 @@ -import useAuthUser from "react-auth-kit/hooks/useAuthUser"; -import useSignOut from "react-auth-kit/hooks/useSignOut"; -import { useNavigate } from "react-router-dom"; +import BaseLayout from "../components/BaseLayout"; export const Home = () => { - const auth = useAuthUser(); - const signOut = useSignOut(); - const navigate = useNavigate(); - - const logout = () => { - signOut(); - navigate("/login"); - } - return ( - <> -

Hello {auth.username}

- - + +
+
+
+ +
+
+ DETI4Devs +
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod +
+
Saber mais
+
+
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod +
+
+
Eventos
+ +
+
+
+
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod +
+
+
Empresas
+ +
+
+
+
+
Horário
+ +
+
+
); }; diff --git a/frontend/src/pages/login.jsx b/frontend/src/pages/login.jsx index e481828..571173d 100644 --- a/frontend/src/pages/login.jsx +++ b/frontend/src/pages/login.jsx @@ -2,6 +2,7 @@ import { useForm } from "react-hook-form"; import { login } from "../api/auth"; import useSignIn from "react-auth-kit/hooks/useSignIn"; import { useNavigate } from "react-router-dom"; +import Navbar from "../components/Navbar"; export const Login = () => { const { @@ -21,33 +22,36 @@ export const Login = () => { signIn({ auth: { token: response.data.access_token, - type: response.data.token_type + type: response.data.token_type, }, userState: response.data.user, }) ) { return navigate("/"); - } - else { + } else { console.log("Failed to login"); } } }; return ( -
- - - -
+ <> +
+ + + +
+ ); }; diff --git a/frontend/src/utils/router.jsx b/frontend/src/utils/router.jsx index a09cf01..604ff0a 100644 --- a/frontend/src/utils/router.jsx +++ b/frontend/src/utils/router.jsx @@ -1,19 +1,20 @@ import { createBrowserRouter } from "react-router-dom"; -import { Home } from "../pages/home" -import { Login } from "../pages/login" -import { Register } from "../pages/register" +import { Home } from "../pages/home"; +import { Login } from "../pages/login"; +import { Register } from "../pages/register"; import AuthOutlet from "@auth-kit/react-router/AuthOutlet"; +import { Desafios } from "../pages/desafios"; export const router = createBrowserRouter([ { path: "/", - element: , + element: , children: [ { path: "/", element: , - } - ] + }, + ], }, { path: "/login", @@ -23,4 +24,8 @@ export const router = createBrowserRouter([ path: "/register", element: , }, -]) + { + path: "/desafios", + element: , + }, +]); diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.js index 1de8634..68ca561 100644 --- a/frontend/tailwind.config.js +++ b/frontend/tailwind.config.js @@ -1,13 +1,19 @@ /** @type {import('tailwindcss').Config} */ export default { - content: [ - "./index.html", - "./src/**/*.{js,ts,jsx,tsx}", - ], + content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], theme: { extend: {}, }, - plugins: [ - require('daisyui') - ], -} + plugins: [require("daisyui")], + daisyui: { + themes: [ + { + dark: { + primary: "#f27a23", + secondary: "#272654", + "base-100": "#1b1b1b", + }, + }, + ], + }, +};