diff --git a/.vscode/settings.json b/.vscode/settings.json index ba435c7..4d6f196 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,8 +1,7 @@ { "editor.codeActionsOnSave": { "source.organizeImports": "always", - "source.fixAll": "always", - "source.fixAll.eslint": "explicit" + "source.fixAll": "always" }, "editor.suggest.preview": true, "editor.inlayHints.enabled": "offUnlessPressed", diff --git a/Taskfile.yml b/Taskfile.yml index c9116f5..f6eb772 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -15,9 +15,9 @@ tasks: py:dev: desc: runs the backend server cmds: - - poetry run python fuware/app.py + - poetry run python backend/app.py ui:dev: desc: runs the frontend server - dir: fuware-fe + dir: frontend cmds: - pnpm dev diff --git a/alembic/env.py b/alembic/env.py index c210583..6176ca7 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -5,8 +5,8 @@ from sqlalchemy import pool from alembic import context -from fuware.core.config import get_app_settings -from fuware.db.models._model_base import SqlAlchemyBase +from backend.core.config import get_app_settings +from backend.db.models._model_base import SqlAlchemyBase # this is the Alembic Config object, which provides # access to the values within the .ini file in use. diff --git a/fuware/__init__.py b/backend/__init__.py similarity index 100% rename from fuware/__init__.py rename to backend/__init__.py diff --git a/fuware/app.py b/backend/app.py similarity index 89% rename from fuware/app.py rename to backend/app.py index d7b7ed9..50393d5 100644 --- a/fuware/app.py +++ b/backend/app.py @@ -1,15 +1,14 @@ from collections.abc import AsyncGenerator from contextlib import asynccontextmanager -from mimetypes import init from fastapi import FastAPI, Request, HTTPException from fastapi.responses import JSONResponse from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.gzip import GZipMiddleware -from fuware.core.config import get_app_settings -from fuware.core.root_logger import get_logger -from fuware.routes import router -from fuware import __version__ +from backend.core.config import get_app_settings +from backend.core.root_logger import get_logger +from backend.routes import router +from backend import __version__ import uvicorn settings = get_app_settings() @@ -22,7 +21,7 @@ fuware is a web application for managing your hours items and tracking them. @asynccontextmanager async def lifespan_fn(_: FastAPI) -> AsyncGenerator[None, None]: logger.info("start: database initialization") - import fuware.db.init_db as init_db + import backend.db.init_db as init_db init_db.main() logger.info("end: database initialization") diff --git a/fuware/core/__init__.py b/backend/core/__init__.py similarity index 100% rename from fuware/core/__init__.py rename to backend/core/__init__.py diff --git a/fuware/core/config.py b/backend/core/config.py similarity index 91% rename from fuware/core/config.py rename to backend/core/config.py index 0d5ebe9..44fb3e6 100644 --- a/fuware/core/config.py +++ b/backend/core/config.py @@ -4,7 +4,7 @@ from pathlib import Path from dotenv import load_dotenv -from fuware.core.settings.settings import AppSettings, app_settings_constructor +from backend.core.settings import AppSettings, app_settings_constructor CWD = Path(__file__).parent BASE_DIR = CWD.parent.parent diff --git a/fuware/core/dependencies/__init__.py b/backend/core/dependencies/__init__.py similarity index 100% rename from fuware/core/dependencies/__init__.py rename to backend/core/dependencies/__init__.py diff --git a/fuware/core/dependencies/dependencies.py b/backend/core/dependencies/dependencies.py similarity index 94% rename from fuware/core/dependencies/dependencies.py rename to backend/core/dependencies/dependencies.py index 8202e1f..ab21bf5 100644 --- a/fuware/core/dependencies/dependencies.py +++ b/backend/core/dependencies/dependencies.py @@ -1,11 +1,11 @@ from fastapi import Depends, HTTPException, Request, status from fastapi.security import OAuth2PasswordBearer -from fuware.core.config import get_app_settings -from fuware.core import MessageCode +from backend.core.config import get_app_settings +from backend.core import MessageCode import jwt -from fuware.services.user.user_service import UserService +from backend.services.user.user_service import UserService oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/token") oauth2_scheme_soft_fail = OAuth2PasswordBearer(tokenUrl="/api/auth/token", auto_error=False) diff --git a/fuware/core/logger/config.py b/backend/core/logger/config.py similarity index 100% rename from fuware/core/logger/config.py rename to backend/core/logger/config.py diff --git a/fuware/core/logger/logconf.dev.json b/backend/core/logger/logconf.dev.json similarity index 100% rename from fuware/core/logger/logconf.dev.json rename to backend/core/logger/logconf.dev.json diff --git a/fuware/core/logger/logconf.prod.json b/backend/core/logger/logconf.prod.json similarity index 100% rename from fuware/core/logger/logconf.prod.json rename to backend/core/logger/logconf.prod.json diff --git a/fuware/core/logger/logconf.test.json b/backend/core/logger/logconf.test.json similarity index 100% rename from fuware/core/logger/logconf.test.json rename to backend/core/logger/logconf.test.json diff --git a/fuware/core/message_code.py b/backend/core/message_code.py similarity index 100% rename from fuware/core/message_code.py rename to backend/core/message_code.py diff --git a/fuware/core/root_logger.py b/backend/core/root_logger.py similarity index 100% rename from fuware/core/root_logger.py rename to backend/core/root_logger.py diff --git a/fuware/core/security/__init__.py b/backend/core/security/__init__.py similarity index 100% rename from fuware/core/security/__init__.py rename to backend/core/security/__init__.py diff --git a/fuware/core/security/hasher.py b/backend/core/security/hasher.py similarity index 94% rename from fuware/core/security/hasher.py rename to backend/core/security/hasher.py index f8044fa..7cec06a 100644 --- a/fuware/core/security/hasher.py +++ b/backend/core/security/hasher.py @@ -2,7 +2,7 @@ from functools import lru_cache from typing import Protocol import bcrypt -from fuware.core.config import get_app_settings +from backend.core.config import get_app_settings class Hasher(Protocol): diff --git a/fuware/core/security/security.py b/backend/core/security/security.py similarity index 90% rename from fuware/core/security/security.py rename to backend/core/security/security.py index 558bb54..06186dd 100644 --- a/fuware/core/security/security.py +++ b/backend/core/security/security.py @@ -4,9 +4,9 @@ from pathlib import Path import jwt -from fuware.core.config import get_app_settings -from fuware.core import root_logger -from fuware.core.security.hasher import get_hasher +from backend.core.config import get_app_settings +from backend.core import root_logger +from backend.core.security.hasher import get_hasher ALGORITHM = "HS256" diff --git a/fuware/core/settings/__init__.py b/backend/core/settings/__init__.py similarity index 100% rename from fuware/core/settings/__init__.py rename to backend/core/settings/__init__.py diff --git a/fuware/core/settings/db_providers.py b/backend/core/settings/db_providers.py similarity index 100% rename from fuware/core/settings/db_providers.py rename to backend/core/settings/db_providers.py diff --git a/fuware/core/settings/settings.py b/backend/core/settings/settings.py similarity index 96% rename from fuware/core/settings/settings.py rename to backend/core/settings/settings.py index 63fbb13..08dbd1b 100644 --- a/fuware/core/settings/settings.py +++ b/backend/core/settings/settings.py @@ -1,5 +1,5 @@ from pathlib import Path -from fuware.core.settings.db_providers import AbstractDBProvider, SQLiteProvider +from backend.core.settings.db_providers import AbstractDBProvider, SQLiteProvider from pydantic_settings import BaseSettings # type: ignore diff --git a/fuware/db/__init__.py b/backend/db/__init__.py similarity index 100% rename from fuware/db/__init__.py rename to backend/db/__init__.py diff --git a/fuware/db/db_setup.py b/backend/db/db_setup.py similarity index 96% rename from fuware/db/db_setup.py rename to backend/db/db_setup.py index bc64ee7..73c5a01 100644 --- a/fuware/db/db_setup.py +++ b/backend/db/db_setup.py @@ -3,7 +3,7 @@ from contextlib import contextmanager from sqlalchemy.orm.session import Session from sqlalchemy import create_engine, event, Engine from sqlalchemy.orm import scoped_session, sessionmaker -from fuware.core.config import get_app_settings +from backend.core.config import get_app_settings settings = get_app_settings() diff --git a/fuware/db/init_db.py b/backend/db/init_db.py similarity index 89% rename from fuware/db/init_db.py rename to backend/db/init_db.py index b0de2b8..f2d768e 100644 --- a/fuware/db/init_db.py +++ b/backend/db/init_db.py @@ -7,12 +7,11 @@ from sqlalchemy import engine, orm, text from alembic import command, config, script from alembic.config import Config from alembic.runtime import migration -from fuware.core import root_logger -from fuware.core.config import get_app_settings -from fuware.db.db_setup import session_context -from fuware.repos.repository_users import RepositoryUsers -from fuware.repos.seeder import default_users_init -from fuware.db.models._model_base import Model +from backend.core import root_logger +from backend.core.config import get_app_settings +from backend.db.db_setup import session_context +from backend.repos.repository_users import RepositoryUsers +from backend.repos.seeder import default_users_init # from fuware.db.models import User PROJECT_DIR = Path(__file__).parent.parent.parent diff --git a/fuware/db/models/__init__.py b/backend/db/models/__init__.py similarity index 100% rename from fuware/db/models/__init__.py rename to backend/db/models/__init__.py diff --git a/fuware/db/models/_model_base.py b/backend/db/models/_model_base.py similarity index 87% rename from fuware/db/models/_model_base.py rename to backend/db/models/_model_base.py index 39b0424..8fc0eae 100644 --- a/fuware/db/models/_model_base.py +++ b/backend/db/models/_model_base.py @@ -1,10 +1,10 @@ from datetime import datetime -from sqlalchemy import DateTime, Integer +from sqlalchemy import DateTime from sqlalchemy.orm import declarative_base, Mapped, mapped_column from text_unidecode import unidecode -from fuware.db.db_setup import SessionLocal +from backend.db.db_setup import SessionLocal Model = declarative_base() Model.query = SessionLocal.query_property() diff --git a/fuware/db/models/users/__init__.py b/backend/db/models/users/__init__.py similarity index 100% rename from fuware/db/models/users/__init__.py rename to backend/db/models/users/__init__.py diff --git a/fuware/db/models/users/users.py b/backend/db/models/users/users.py similarity index 100% rename from fuware/db/models/users/users.py rename to backend/db/models/users/users.py diff --git a/fuware/main.py b/backend/main.py similarity index 85% rename from fuware/main.py rename to backend/main.py index bf762c7..b9e48df 100644 --- a/fuware/main.py +++ b/backend/main.py @@ -1,6 +1,6 @@ import uvicorn -from fuware.app import settings +from backend.app import settings def main(): diff --git a/fuware/repos/__init__.py b/backend/repos/__init__.py similarity index 100% rename from fuware/repos/__init__.py rename to backend/repos/__init__.py diff --git a/fuware/repos/repository_users.py b/backend/repos/repository_users.py similarity index 78% rename from fuware/repos/repository_users.py rename to backend/repos/repository_users.py index 443f2d0..acaee17 100644 --- a/fuware/repos/repository_users.py +++ b/backend/repos/repository_users.py @@ -1,11 +1,11 @@ -from fuware.core.config import get_app_settings -from fuware.core.security.security import hash_password -from fuware.db.models import User -from fuware.schemas import UserCreate +from backend.core.config import get_app_settings +from backend.core.security.security import hash_password +from backend.db.models import User +from backend.schemas import UserCreate from sqlalchemy.orm import Session from uuid import UUID -from fuware.schemas.user.user import UserSeeds +from backend.schemas.user.user import UserSeeds settings = get_app_settings() diff --git a/fuware/repos/seeder/__init__.py b/backend/repos/seeder/__init__.py similarity index 100% rename from fuware/repos/seeder/__init__.py rename to backend/repos/seeder/__init__.py diff --git a/fuware/repos/seeder/init_users.py b/backend/repos/seeder/init_users.py similarity index 73% rename from fuware/repos/seeder/init_users.py rename to backend/repos/seeder/init_users.py index 2be0506..f220730 100644 --- a/fuware/repos/seeder/init_users.py +++ b/backend/repos/seeder/init_users.py @@ -1,9 +1,9 @@ -from fuware.core.config import get_app_settings -from fuware.core.root_logger import get_logger -from fuware.repos.repository_users import RepositoryUsers +from backend.core.config import get_app_settings +from backend.core.root_logger import get_logger +from backend.repos.repository_users import RepositoryUsers from sqlalchemy.orm import Session -from fuware.schemas.user import UserSeeds +from backend.schemas.user import UserSeeds logger = get_logger("init_users") diff --git a/fuware/routes/__init__.py b/backend/routes/__init__.py similarity index 100% rename from fuware/routes/__init__.py rename to backend/routes/__init__.py diff --git a/fuware/routes/_base/routers.py b/backend/routes/_base/routers.py similarity index 84% rename from fuware/routes/_base/routers.py rename to backend/routes/_base/routers.py index 9324abb..f4a8a71 100644 --- a/fuware/routes/_base/routers.py +++ b/backend/routes/_base/routers.py @@ -1,7 +1,7 @@ from enum import Enum from fastapi import APIRouter, Depends -from fuware.core.dependencies import get_auth_user +from backend.core.dependencies import get_auth_user class PrivateAPIRouter(APIRouter): diff --git a/fuware/routes/auth/__init__.py b/backend/routes/auth/__init__.py similarity index 100% rename from fuware/routes/auth/__init__.py rename to backend/routes/auth/__init__.py diff --git a/fuware/routes/auth/auth.py b/backend/routes/auth/auth.py similarity index 89% rename from fuware/routes/auth/auth.py rename to backend/routes/auth/auth.py index 314fc65..6602d41 100644 --- a/fuware/routes/auth/auth.py +++ b/backend/routes/auth/auth.py @@ -5,12 +5,12 @@ from fastapi import APIRouter, Depends, HTTPException, Response, status # from fastapi.encoders import jsonable_encoder from fastapi.security import OAuth2PasswordRequestForm from sqlalchemy.orm import Session -from fuware.core.config import get_app_settings -from fuware.core.dependencies.dependencies import get_current_user -from fuware.core import MessageCode -from fuware.db.db_setup import generate_session -from fuware.schemas import ReturnValue, UserRequest, LoginResponse, UserCreate, PrivateUser -from fuware.services.user import UserService +from backend.core.config import get_app_settings +from backend.core.dependencies.dependencies import get_current_user +from backend.core import MessageCode +from backend.db.db_setup import generate_session +from backend.schemas import ReturnValue, UserRequest, LoginResponse, UserCreate, PrivateUser +from backend.services.user import UserService auth_router = APIRouter(tags=["Users: Authentication"]) diff --git a/fuware/routes/user/__init__.py b/backend/routes/user/__init__.py similarity index 100% rename from fuware/routes/user/__init__.py rename to backend/routes/user/__init__.py diff --git a/fuware/routes/user/user.py b/backend/routes/user/user.py similarity index 65% rename from fuware/routes/user/user.py rename to backend/routes/user/user.py index e864627..f171120 100644 --- a/fuware/routes/user/user.py +++ b/backend/routes/user/user.py @@ -1,12 +1,12 @@ from typing import Annotated, Any from fastapi import APIRouter, Depends from sqlalchemy.orm import Session -from fuware.core.config import get_app_settings -from fuware.core.dependencies import is_logged_in -from fuware.db.db_setup import generate_session -from fuware.schemas.common import ReturnValue -from fuware.schemas.user import ProfileResponse -from fuware.services.user import UserService +from backend.core.config import get_app_settings +from backend.core.dependencies import is_logged_in +from backend.db.db_setup import generate_session +from backend.schemas.common import ReturnValue +from backend.schemas.user import ProfileResponse +from backend.services.user import UserService public_router = APIRouter(tags=["Users: Info"]) diff --git a/fuware/schemas/__init__.py b/backend/schemas/__init__.py similarity index 100% rename from fuware/schemas/__init__.py rename to backend/schemas/__init__.py diff --git a/fuware/schemas/common.py b/backend/schemas/common.py similarity index 100% rename from fuware/schemas/common.py rename to backend/schemas/common.py diff --git a/fuware/schemas/fuware_model.py b/backend/schemas/fuware_model.py similarity index 100% rename from fuware/schemas/fuware_model.py rename to backend/schemas/fuware_model.py diff --git a/fuware/schemas/user/__init__.py b/backend/schemas/user/__init__.py similarity index 100% rename from fuware/schemas/user/__init__.py rename to backend/schemas/user/__init__.py diff --git a/fuware/schemas/user/user.py b/backend/schemas/user/user.py similarity index 91% rename from fuware/schemas/user/user.py rename to backend/schemas/user/user.py index bf43af0..709baf8 100644 --- a/fuware/schemas/user/user.py +++ b/backend/schemas/user/user.py @@ -3,7 +3,7 @@ from uuid import UUID from pydantic import ConfigDict from fastapi import Form -from fuware.schemas.fuware_model import FuwareModel +from backend.schemas.fuware_model import FuwareModel class UserBase(FuwareModel): username: str = Form(...) @@ -30,7 +30,6 @@ class PrivateUser(UserBase): class ProfileResponse(UserBase): name: str is_admin: bool - is_lock: bool created_at: datetime updated_at: datetime model_config = ConfigDict(from_attributes=True) diff --git a/fuware/services/__init__.py b/backend/services/__init__.py similarity index 100% rename from fuware/services/__init__.py rename to backend/services/__init__.py diff --git a/fuware/services/_base_service/__init__.py b/backend/services/_base_service/__init__.py similarity index 64% rename from fuware/services/_base_service/__init__.py rename to backend/services/_base_service/__init__.py index 9334f71..731d3a7 100644 --- a/fuware/services/_base_service/__init__.py +++ b/backend/services/_base_service/__init__.py @@ -1,4 +1,4 @@ -from fuware.core.config import get_app_settings +from backend.core.config import get_app_settings class BaseService: diff --git a/fuware/services/user/__init__.py b/backend/services/user/__init__.py similarity index 100% rename from fuware/services/user/__init__.py rename to backend/services/user/__init__.py diff --git a/fuware/services/user/user_service.py b/backend/services/user/user_service.py similarity index 77% rename from fuware/services/user/user_service.py rename to backend/services/user/user_service.py index 9377cea..c60f947 100644 --- a/fuware/services/user/user_service.py +++ b/backend/services/user/user_service.py @@ -1,10 +1,10 @@ from sqlalchemy.orm import Session -from fuware.core.security.hasher import get_hasher -from fuware.core.security import create_access_token -from fuware.core.security.security import create_refresh_token -from fuware.repos import RepositoryUsers -from fuware.schemas import UserRequest, UserCreate -from fuware.services._base_service import BaseService +from backend.core.security.hasher import get_hasher +from backend.core.security import create_access_token +from backend.core.security.security import create_refresh_token +from backend.repos import RepositoryUsers +from backend.schemas import UserRequest, UserCreate +from backend.services._base_service import BaseService class UserService(BaseService): def __init__(self): diff --git a/fuware-fe/.dockerignore b/frontend/.dockerignore similarity index 100% rename from fuware-fe/.dockerignore rename to frontend/.dockerignore diff --git a/fuware-fe/.eslintrc.cjs b/frontend/.eslintrc.cjs similarity index 100% rename from fuware-fe/.eslintrc.cjs rename to frontend/.eslintrc.cjs diff --git a/fuware-fe/.gitignore b/frontend/.gitignore similarity index 100% rename from fuware-fe/.gitignore rename to frontend/.gitignore diff --git a/fuware-fe/.lintstagedrc b/frontend/.lintstagedrc similarity index 100% rename from fuware-fe/.lintstagedrc rename to frontend/.lintstagedrc diff --git a/fuware-fe/.prettierignore b/frontend/.prettierignore similarity index 100% rename from fuware-fe/.prettierignore rename to frontend/.prettierignore diff --git a/fuware-fe/.prettierrc b/frontend/.prettierrc similarity index 100% rename from fuware-fe/.prettierrc rename to frontend/.prettierrc diff --git a/fuware-fe/Dockerfile b/frontend/Dockerfile similarity index 100% rename from fuware-fe/Dockerfile rename to frontend/Dockerfile diff --git a/fuware-fe/index.html b/frontend/index.html similarity index 93% rename from fuware-fe/index.html rename to frontend/index.html index d155b08..9beb395 100644 --- a/fuware-fe/index.html +++ b/frontend/index.html @@ -8,7 +8,7 @@ href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet" /> - <title>Vite + Solid</title> + <title>Fuware</title> </head> <body> <div id="root"></div> diff --git a/fuware-fe/jsconfig.json b/frontend/jsconfig.json similarity index 100% rename from fuware-fe/jsconfig.json rename to frontend/jsconfig.json diff --git a/fuware-fe/jsconfig.paths.json b/frontend/jsconfig.paths.json similarity index 100% rename from fuware-fe/jsconfig.paths.json rename to frontend/jsconfig.paths.json diff --git a/fuware-fe/package.json b/frontend/package.json similarity index 97% rename from fuware-fe/package.json rename to frontend/package.json index 57314ed..7ea1395 100644 --- a/fuware-fe/package.json +++ b/frontend/package.json @@ -1,5 +1,5 @@ { - "name": "fuware-fe", + "name": "fuware", "private": true, "version": "0.0.0", "type": "module", diff --git a/fuware-fe/pnpm-lock.yaml b/frontend/pnpm-lock.yaml similarity index 100% rename from fuware-fe/pnpm-lock.yaml rename to frontend/pnpm-lock.yaml diff --git a/fuware-fe/postcss.config.js b/frontend/postcss.config.js similarity index 100% rename from fuware-fe/postcss.config.js rename to frontend/postcss.config.js diff --git a/fuware-fe/public/images/bg-login.jpg b/frontend/public/images/bg-login.jpg similarity index 100% rename from fuware-fe/public/images/bg-login.jpg rename to frontend/public/images/bg-login.jpg diff --git a/fuware-fe/public/vite.svg b/frontend/public/vite.svg similarity index 100% rename from fuware-fe/public/vite.svg rename to frontend/public/vite.svg diff --git a/fuware-fe/src/App.css b/frontend/src/App.css similarity index 61% rename from fuware-fe/src/App.css rename to frontend/src/App.css index fda00ab..bae046d 100644 --- a/fuware-fe/src/App.css +++ b/frontend/src/App.css @@ -9,20 +9,16 @@ } #main-page { - height: calc(100svh - 56px); + height: calc(100svh - 64px); display: flex; + overflow: hidden; } #main-page.login-page { height: 100svh; } -#main-page .navbar { - width: 350px; - border-right: 1px solid #dedede; -} - #main-page .main-content { - width: calc(100vw - 350px); + max-height: calc(100svh - 64px); overflow-y: auto; } diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx new file mode 100644 index 0000000..404885e --- /dev/null +++ b/frontend/src/App.jsx @@ -0,0 +1,23 @@ +import { MetaProvider } from '@solidjs/meta' +import { Toaster } from 'solid-toast' +import './App.css' +import { SiteContextProvider } from './context/SiteContext' + +function App(props) { + return ( + <MetaProvider> + <SiteContextProvider> + <Toaster + containerStyle={ + props.location?.pathname.indexOf('/login') >= 0 + ? null + : { 'margin-top': '60px' } + } + /> + {props.children} + </SiteContextProvider> + </MetaProvider> + ) +} + +export default App diff --git a/fuware-fe/src/api/auth.js b/frontend/src/api/auth.js similarity index 100% rename from fuware-fe/src/api/auth.js rename to frontend/src/api/auth.js diff --git a/fuware-fe/src/api/index.js b/frontend/src/api/index.js similarity index 100% rename from fuware-fe/src/api/index.js rename to frontend/src/api/index.js diff --git a/fuware-fe/src/api/url.js b/frontend/src/api/url.js similarity index 100% rename from fuware-fe/src/api/url.js rename to frontend/src/api/url.js diff --git a/fuware-fe/src/api/user.js b/frontend/src/api/user.js similarity index 100% rename from fuware-fe/src/api/user.js rename to frontend/src/api/user.js diff --git a/fuware-fe/src/assets/logo-fuware.svg b/frontend/src/assets/logo-fuware.svg similarity index 100% rename from fuware-fe/src/assets/logo-fuware.svg rename to frontend/src/assets/logo-fuware.svg diff --git a/fuware-fe/src/assets/solid.svg b/frontend/src/assets/solid.svg similarity index 100% rename from fuware-fe/src/assets/solid.svg rename to frontend/src/assets/solid.svg diff --git a/frontend/src/components/Header.jsx b/frontend/src/components/Header.jsx new file mode 100644 index 0000000..6111d69 --- /dev/null +++ b/frontend/src/components/Header.jsx @@ -0,0 +1,79 @@ +import { getProfile } from '@api/user' +import fuwareLogo from '@assets/logo-fuware.svg' +import { useSiteContext } from '@context/SiteContext' +import useAuth from '@hooks/useAuth' +import useToast from '@hooks/useToast' +import { A } from '@solidjs/router' +import { IconLogout, IconMenuDeep } from '@tabler/icons-solidjs' +import { Show, onMount } from 'solid-js' + +export default function Header() { + const { store, setAuth, setUser } = useSiteContext() + const { clickLogOut } = useAuth(setAuth) + const notify = useToast() + + onMount(async () => { + try { + const resp = await getProfile() + if (resp.status === 200) { + setUser(resp.data) + } + } catch (error) { + notify.error({ + title: 'Get profile fail!', + closable: false, + description: error?.data || 'Can not get user profile!', + }) + } + }) + + const logOut = async () => { + try { + await clickLogOut() + } catch (error) { + console.log({ + status: 'danger', + title: 'Logout fail!', + closable: false, + }) + } + } + + return ( + <header class="w-full navbar py-3 px-4 items-center justify-between bg-emerald-500"> + <div class="flex items-center justify-end"> + <A href="/" class="text-white flex items-center hover:text-white"> + <img src={fuwareLogo} class="w-8" alt="Fuware logo" /> + <span class="ml-2 text-2xl">Fuware</span> + </A> + </div> + <Show when={store.auth}> + <div class="flex items-center justify-end"> + <div class="avatar hidden lg:block"> + <div class="w-9 mask mask-hexagon"> + <img + src={`https://ui-avatars.com/api/?name=${store.userInfo?.name}`} + alt="avatar" + /> + </div> + </div> + <A + href="/me" + class="mx-3 text-white hover:text-white hidden lg:block" + > + {store.userInfo?.name} + </A> + <button class="btn btn-ghost btn-sm hidden lg:block" onClick={logOut}> + <IconLogout size={16} /> + </button> + <label + for="nav-menu" + class="btn btn-ghost btn-sm drawer-button pr-0 lg:hidden" + > + <IconMenuDeep size={25} color="white" /> + </label> + </div> + </Show> + </header> + ) +} diff --git a/fuware-fe/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx similarity index 70% rename from fuware-fe/src/components/Navbar.jsx rename to frontend/src/components/Navbar.jsx index d783112..6d4bdc0 100644 --- a/fuware-fe/src/components/Navbar.jsx +++ b/frontend/src/components/Navbar.jsx @@ -2,22 +2,12 @@ import { useSiteContext } from '@context/SiteContext' import useAuth from '@hooks/useAuth' -import useLanguage from '@hooks/useLanguage' +import { NAV_ROUTES } from '@routes/routes' import { A } from '@solidjs/router' -import { IconDashboard, IconLogout, IconTriangle } from '@tabler/icons-solidjs' +import { IconLogout, IconTriangle } from '@tabler/icons-solidjs' import { For, Show } from 'solid-js' import { Dynamic } from 'solid-js/web' -const language = useLanguage('vi') - -const NAVBAR_ITEM = [ - { - path: '/dashboard', - icon: IconDashboard, - text: language?.ui.dashboard, - }, -] - export default function Navbar() { const { store, setAuth } = useSiteContext() const { clickLogOut } = useAuth(setAuth) @@ -35,7 +25,7 @@ export default function Navbar() { } return ( - <div class="drawer-side"> + <div class="drawer-side lg:h-[calc(100svh-64px)]"> <label for="nav-menu" aria-label="close sidebar" class="drawer-overlay" /> <div class="bg-base-200 w-80 min-h-full"> <Show when={store.auth}> @@ -48,7 +38,9 @@ export default function Navbar() { /> </div> </div> - <span class="mx-3 line-clamp-1">{store.userInfo?.name}</span> + <span class="mx-3 line-clamp-1"> + <A href="/me">{store.userInfo?.name}</A> + </span> <button class="btn btn-ghost btn-sm" onClick={logOut}> <IconLogout size={16} /> </button> @@ -58,15 +50,17 @@ export default function Navbar() { </div> </Show> <ul class="menu p-4 w-80 text-base-content"> - <For each={NAVBAR_ITEM}> - {(item) => ( - <li> - <A href={item.path}> - <Dynamic component={item.icon} /> - {item.text} - </A> - </li> - )} + <For each={NAV_ROUTES}> + {(item) => + item.show && ( + <li class="mb-2"> + <A href={item.path}> + <Dynamic component={item.icon} /> + {item.text} + </A> + </li> + ) + } </For> </ul> </div> diff --git a/fuware-fe/src/components/Notify.jsx b/frontend/src/components/Notify.jsx similarity index 100% rename from fuware-fe/src/components/Notify.jsx rename to frontend/src/components/Notify.jsx diff --git a/fuware-fe/src/context/SiteContext.jsx b/frontend/src/context/SiteContext.jsx similarity index 98% rename from fuware-fe/src/context/SiteContext.jsx rename to frontend/src/context/SiteContext.jsx index d06841d..dbfe70f 100644 --- a/fuware-fe/src/context/SiteContext.jsx +++ b/frontend/src/context/SiteContext.jsx @@ -41,6 +41,7 @@ export function SiteContextProvider(props) { s.userInfo = user }), ) + setLocalStore() } return ( diff --git a/fuware-fe/src/hooks/useAuth.js b/frontend/src/hooks/useAuth.js similarity index 100% rename from fuware-fe/src/hooks/useAuth.js rename to frontend/src/hooks/useAuth.js diff --git a/fuware-fe/src/hooks/useLanguage.js b/frontend/src/hooks/useLanguage.js similarity index 100% rename from fuware-fe/src/hooks/useLanguage.js rename to frontend/src/hooks/useLanguage.js diff --git a/fuware-fe/src/hooks/useToast.jsx b/frontend/src/hooks/useToast.jsx similarity index 100% rename from fuware-fe/src/hooks/useToast.jsx rename to frontend/src/hooks/useToast.jsx diff --git a/fuware-fe/src/index.css b/frontend/src/index.css similarity index 100% rename from fuware-fe/src/index.css rename to frontend/src/index.css diff --git a/fuware-fe/src/index.jsx b/frontend/src/index.jsx similarity index 100% rename from fuware-fe/src/index.jsx rename to frontend/src/index.jsx diff --git a/fuware-fe/src/lang/en.json b/frontend/src/lang/en.json similarity index 100% rename from fuware-fe/src/lang/en.json rename to frontend/src/lang/en.json diff --git a/fuware-fe/src/lang/vi.json b/frontend/src/lang/vi.json similarity index 82% rename from fuware-fe/src/lang/vi.json rename to frontend/src/lang/vi.json index d9ea066..4cf8f07 100644 --- a/fuware-fe/src/lang/vi.json +++ b/frontend/src/lang/vi.json @@ -4,7 +4,8 @@ "password": "Mật khẩu", "login": "Đăng Nhập", "logout": "Đăng xuất", - "dashboard": "Bảng điều khiển" + "dashboard": "Bảng điều khiển", + "profile": "Hồ sơ" }, "message": { "CREATED_USER": "Username already registered!", diff --git a/fuware-fe/src/pages/Dashboard.jsx b/frontend/src/pages/Dashboard.jsx similarity index 100% rename from fuware-fe/src/pages/Dashboard.jsx rename to frontend/src/pages/Dashboard.jsx diff --git a/fuware-fe/src/pages/Home.jsx b/frontend/src/pages/Home.jsx similarity index 54% rename from fuware-fe/src/pages/Home.jsx rename to frontend/src/pages/Home.jsx index 4ffe70b..4b90298 100644 --- a/fuware-fe/src/pages/Home.jsx +++ b/frontend/src/pages/Home.jsx @@ -1,3 +1,4 @@ +import { NAV_ROUTES } from '@routes/routes' import { useNavigate } from '@solidjs/router' import { onMount } from 'solid-js' @@ -5,7 +6,8 @@ export default function Home() { const navigate = useNavigate() onMount(() => { - navigate('/dashboard', { replace: true }) + const first = NAV_ROUTES.filter((item) => item.show)[0]?.path || '/me' + navigate(first, { replace: true }) }) return <></> diff --git a/fuware-fe/src/pages/Layout.jsx b/frontend/src/pages/Layout.jsx similarity index 93% rename from fuware-fe/src/pages/Layout.jsx rename to frontend/src/pages/Layout.jsx index cb67749..5103ff0 100644 --- a/fuware-fe/src/pages/Layout.jsx +++ b/frontend/src/pages/Layout.jsx @@ -20,7 +20,7 @@ export default function Layout(props) { <div id="main-page"> <div class="drawer lg:drawer-open"> <input id="nav-menu" type="checkbox" class="drawer-toggle" /> - <div class="drawer-content"> + <div class="drawer-content flex flex-col"> <main class="main-content p-3">{props.children}</main> </div> <Navbar /> diff --git a/fuware-fe/src/pages/Login.jsx b/frontend/src/pages/Login.jsx similarity index 100% rename from fuware-fe/src/pages/Login.jsx rename to frontend/src/pages/Login.jsx diff --git a/fuware-fe/src/pages/NotFound.jsx b/frontend/src/pages/NotFound.jsx similarity index 100% rename from fuware-fe/src/pages/NotFound.jsx rename to frontend/src/pages/NotFound.jsx diff --git a/frontend/src/pages/Profile.jsx b/frontend/src/pages/Profile.jsx new file mode 100644 index 0000000..d05afd0 --- /dev/null +++ b/frontend/src/pages/Profile.jsx @@ -0,0 +1,3 @@ +export default function Profile() { + return <>Profile</> +} diff --git a/fuware-fe/src/routes/index.js b/frontend/src/routes/index.js similarity index 100% rename from fuware-fe/src/routes/index.js rename to frontend/src/routes/index.js diff --git a/frontend/src/routes/routes.js b/frontend/src/routes/routes.js new file mode 100644 index 0000000..8f07daf --- /dev/null +++ b/frontend/src/routes/routes.js @@ -0,0 +1,42 @@ +import useLanguage from '@hooks/useLanguage' +import { IconDashboard } from '@tabler/icons-solidjs' +import UserHelper from '@utils/auth' +import { lazy } from 'solid-js' + +const language = useLanguage() +const userHelper = new UserHelper() + +console.log(userHelper.isAdmin) + +export const NAV_ROUTES = [ + { + path: '/dashboard', + components: lazy(() => import('@pages/Dashboard')), + filter: {}, + show: false, + icon: IconDashboard, + text: language?.ui.dashboard, + }, + { + path: '/profile', + components: lazy(() => import('@pages/Profile')), + filter: {}, + show: true, + icon: IconDashboard, + text: language?.ui.profile, + }, +] + +export const ROUTES = [ + { + path: '/', + components: lazy(() => import('@pages/Home')), + filter: {}, + }, + ...NAV_ROUTES, + { + path: '/me', + components: lazy(() => import('@pages/Profile')), + filter: {}, + }, +] diff --git a/frontend/src/utils/auth.js b/frontend/src/utils/auth.js new file mode 100644 index 0000000..825a2fa --- /dev/null +++ b/frontend/src/utils/auth.js @@ -0,0 +1,14 @@ +import { STORE_KEY } from './enum' +import { Helpers } from './helper' + +export default class UserHelper { + #user + + constructor() { + this.#user = Helpers.decrypt(localStorage.getItem(STORE_KEY)) + } + + get isAdmin() { + return this.#user?.userInfo?.isAdmin + } +} diff --git a/fuware-fe/src/utils/enum.js b/frontend/src/utils/enum.js similarity index 100% rename from fuware-fe/src/utils/enum.js rename to frontend/src/utils/enum.js diff --git a/fuware-fe/src/utils/helper.js b/frontend/src/utils/helper.js similarity index 92% rename from fuware-fe/src/utils/helper.js rename to frontend/src/utils/helper.js index 570b48d..5f395d3 100644 --- a/fuware-fe/src/utils/helper.js +++ b/frontend/src/utils/helper.js @@ -38,10 +38,6 @@ export class Helpers { return exp < currentTime } - static checkAuth = () => { - return !!this.getCookie(LOGIN_KEY) && !!localStorage.getItem(STORE_KEY) - } - static encrypt = (obj) => { return AES.encrypt(JSON.stringify(obj), SECRET_KEY).toString() } diff --git a/fuware-fe/tailwind.config.js b/frontend/tailwind.config.js similarity index 100% rename from fuware-fe/tailwind.config.js rename to frontend/tailwind.config.js diff --git a/fuware-fe/vite.config.js b/frontend/vite.config.js similarity index 97% rename from fuware-fe/vite.config.js rename to frontend/vite.config.js index c561a06..4161c01 100644 --- a/fuware-fe/vite.config.js +++ b/frontend/vite.config.js @@ -8,7 +8,7 @@ const _dirname = dirname(fileURLToPath(import.meta.url)) // https://vitejs.dev/config/ // production -export default defineConfig(({ command, mode }) => { +export default defineConfig(({ mode }) => { // eslint-disable-next-line no-undef const env = loadEnv(mode, process.cwd(), '') diff --git a/fuware-fe/.gitignore copy b/fuware-fe/.gitignore copy deleted file mode 100644 index a547bf3..0000000 --- a/fuware-fe/.gitignore copy +++ /dev/null @@ -1,24 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -dist -dist-ssr -*.local - -# Editor directories and files -.vscode/* -!.vscode/extensions.json -.idea -.DS_Store -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/fuware-fe/public/images/logo-fuware.png b/fuware-fe/public/images/logo-fuware.png deleted file mode 100644 index d9611b2..0000000 Binary files a/fuware-fe/public/images/logo-fuware.png and /dev/null differ diff --git a/fuware-fe/src/App.jsx b/fuware-fe/src/App.jsx deleted file mode 100644 index 7dc2628..0000000 --- a/fuware-fe/src/App.jsx +++ /dev/null @@ -1,20 +0,0 @@ -import { Toaster } from 'solid-toast' -import './App.css' -import { SiteContextProvider } from './context/SiteContext' - -function App(props) { - return ( - <SiteContextProvider> - <Toaster - containerStyle={ - props.location?.pathname.indexOf('/login') >= 0 - ? null - : { 'margin-top': '60px' } - } - /> - {props.children} - </SiteContextProvider> - ) -} - -export default App diff --git a/fuware-fe/src/components/Header.jsx b/fuware-fe/src/components/Header.jsx deleted file mode 100644 index 8f07525..0000000 --- a/fuware-fe/src/components/Header.jsx +++ /dev/null @@ -1,88 +0,0 @@ -import { getProfile } from '@api/user' -import fuwareLogo from '@assets/logo-fuware.svg' -import { useSiteContext } from '@context/SiteContext' -import useAuth from '@hooks/useAuth' -import useToast from '@hooks/useToast' -import { A } from '@solidjs/router' -import { IconLogout, IconMenuDeep } from '@tabler/icons-solidjs' -import { Show, onMount } from 'solid-js' -import { css } from 'solid-styled-components' - -export default function Header() { - const { store, setAuth, setUser } = useSiteContext() - const { clickLogOut } = useAuth(setAuth) - const notify = useToast() - - onMount(async () => { - try { - const resp = await getProfile() - if (resp.status === 200) { - setUser(resp.data) - } - } catch (error) { - notify.error({ - title: 'Get profile fail!', - closable: false, - description: error?.data || 'Can not get user profile!', - }) - } - }) - - const logOut = async () => { - try { - await clickLogOut() - } catch (error) { - console.log({ - status: 'danger', - title: 'Logout fail!', - closable: false, - }) - } - } - - return ( - <header> - <div class="flex py-3 px-4 items-center justify-between bg-emerald-500"> - <div class="flex items-center justify-end"> - <A href="/" class="text-white flex items-center hover:text-white"> - <img - src={fuwareLogo} - class={css` - width: 30px; - `} - alt="Fuware logo" - /> - <span class="ml-2 text-2xl">Fuware</span> - </A> - </div> - <Show when={store.auth}> - <div class="flex items-center justify-end"> - <div class="avatar hidden lg:block"> - <div class="w-9 mask mask-hexagon"> - <img - src={`https://ui-avatars.com/api/?name=${store.userInfo?.name}`} - alt="avatar" - /> - </div> - </div> - <span class="mx-3 text-white hidden lg:block"> - {store.userInfo?.name} - </span> - <button - class="btn btn-ghost btn-sm hidden lg:block" - onClick={logOut} - > - <IconLogout size={16} /> - </button> - <label - for="nav-menu" - class="btn btn-ghost btn-sm drawer-button pr-0 lg:hidden" - > - <IconMenuDeep size={25} color="white" /> - </label> - </div> - </Show> - </div> - </header> - ) -} diff --git a/fuware-fe/src/routes/routes.js b/fuware-fe/src/routes/routes.js deleted file mode 100644 index c7f28ae..0000000 --- a/fuware-fe/src/routes/routes.js +++ /dev/null @@ -1,21 +0,0 @@ -import { lazy } from 'solid-js' - -export const ROUTES = [ - { - path: '/', - components: lazy(() => import('@pages/Home')), - filter: {}, - }, - { - path: '/dashboard', - components: lazy(() => import('@pages/Dashboard')), - filter: {}, - }, - // { - // path: '/champions/:tab', - // components: lazy(() => import('@pages/Champion')), - // filter: { - // tab: ['list', 'favourite'], - // }, - // }, -] diff --git a/package.json b/package.json new file mode 100644 index 0000000..c2f4ac7 --- /dev/null +++ b/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "@solidjs/meta": "^0.29.4" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..a6f69c1 --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,56 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: + dependencies: + '@solidjs/meta': + specifier: ^0.29.4 + version: 0.29.4(solid-js@1.8.17) + +packages: + + '@solidjs/meta@0.29.4': + resolution: {integrity: sha512-zdIWBGpR9zGx1p1bzIPqF5Gs+Ks/BH8R6fWhmUa/dcK1L2rUC8BAcZJzNRYBQv74kScf1TSOs0EY//Vd/I0V8g==} + peerDependencies: + solid-js: '>=1.8.4' + + csstype@3.1.3: + resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} + + seroval-plugins@1.0.7: + resolution: {integrity: sha512-GO7TkWvodGp6buMEX9p7tNyIkbwlyuAWbI6G9Ec5bhcm7mQdu3JOK1IXbEUwb3FVzSc363GraG/wLW23NSavIw==} + engines: {node: '>=10'} + peerDependencies: + seroval: ^1.0 + + seroval@1.0.7: + resolution: {integrity: sha512-n6ZMQX5q0Vn19Zq7CIKNIo7E75gPkGCFUEqDpa8jgwpYr/vScjqnQ6H09t1uIiZ0ZSK0ypEGvrYK2bhBGWsGdw==} + engines: {node: '>=10'} + + solid-js@1.8.17: + resolution: {integrity: sha512-E0FkUgv9sG/gEBWkHr/2XkBluHb1fkrHywUgA6o6XolPDCJ4g1HaLmQufcBBhiF36ee40q+HpG/vCZu7fLpI3Q==} + +snapshots: + + '@solidjs/meta@0.29.4(solid-js@1.8.17)': + dependencies: + solid-js: 1.8.17 + + csstype@3.1.3: {} + + seroval-plugins@1.0.7(seroval@1.0.7): + dependencies: + seroval: 1.0.7 + + seroval@1.0.7: {} + + solid-js@1.8.17: + dependencies: + csstype: 3.1.3 + seroval: 1.0.7 + seroval-plugins: 1.0.7(seroval@1.0.7) diff --git a/poetry.toml b/poetry.toml new file mode 100644 index 0000000..ab1033b --- /dev/null +++ b/poetry.toml @@ -0,0 +1,2 @@ +[virtualenvs] +in-project = true diff --git a/pyproject.toml b/pyproject.toml index 5ce63f1..9f555ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -name = "fuware" +name = "backend" version = "0.1.0" description = "project for manage item with exp date" authors = ["Sam Liu <luu.dat.tham@gmail.com>"]