Skip to content

Commit

Permalink
refactor code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
kudah99 committed Dec 25, 2023
1 parent a549112 commit c2f3afd
Show file tree
Hide file tree
Showing 46 changed files with 717 additions and 146 deletions.
12 changes: 3 additions & 9 deletions app/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,25 @@ class Configs(BaseSettings):

BACKEND_CORS_ORIGINS: List[str] = ["*"]

DB_ENGINE: str = "postgresql"

PROJECT_ROOT: str = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)

# database
DB: str = os.getenv("DB", "postgresql")
DB_ENGINE: str = os.getenv("DB_ENGINE", "postgresql")
DB_USER: str = os.getenv("DB_USER")
DB_PASSWORD: str = os.getenv("DB_PASSWORD")
DB_HOST: str = os.getenv("DB_HOST")
DB_PORT: str = os.getenv("DB_PORT")
DB_ENGINE: str = "postgresql"

DATABASE_URI_FORMAT: str = (
"{db_engine}://{user}:{password}@{host}:{port}/{database}"
)
DB: str = os.getenv("DB")

DATABASE_URI = "{db_engine}://{user}:{password}@{host}:{port}/{database}".format(
db_engine=DB_ENGINE,
user=DB_USER,
password=DB_PASSWORD,
host=DB_HOST,
port=DB_PORT,
database="ecommerce",
database=DB
)

# find query
Expand Down
3 changes: 3 additions & 0 deletions app/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ def __init__(self, db_url: str) -> None:
bind=self._engine,
),
)
print("**********")
print(db_url)

def create_database(self) -> None:
BaseModel.metadata.create_all(self._engine)


@contextmanager
def session(self) -> Callable[..., AbstractContextManager[Session]]:
session: Session = self._session_factory()
Expand Down
2 changes: 1 addition & 1 deletion app/model/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
class Product(BaseModel, table=True):
name: str = Field(sa_column=Column("name", nullable=False))
description: str = Field(sa_column=Column("description", nullable=False))
price: float = Field(sa_column=Column("price", nullable=False))
price: str = Field(sa_column=Column("price", nullable=False))
image: str = Field(sa_column=Column("image", nullable=True))
category_id: int = Field(default=None, foreign_key="category.id")
38 changes: 0 additions & 38 deletions db_migrations/versions/46062dea79c7_added_cart_table.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""init
Revision ID: 318488fef3bb
Revision ID: 89f6d1735a8c
Revises:
Create Date: 2023-12-16 02:35:19.800449
Create Date: 2023-12-23 21:18:39.089295
"""
from alembic import op
Expand All @@ -11,7 +11,7 @@


# revision identifiers, used by Alembic.
revision = '318488fef3bb'
revision = '89f6d1735a8c'
down_revision = None
branch_labels = None
depends_on = None
Expand All @@ -23,31 +23,39 @@ def upgrade() -> None:
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('name', sa.CHAR(length=50), nullable=False),
sa.Column('description', sa.CHAR(length=100), nullable=True),
sa.Column('slug', sa.CHAR(length=100), nullable=True),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('slug',sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('name')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('email', sa.CHAR(length=50), nullable=False),
sa.Column('password', sa.CHAR(length=250), nullable=False),
sa.Column('name', sa.CHAR(length=50), nullable=False),
sa.Column('email',sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('password',sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('name',sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('email')
)

op.create_table('cart',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('products', sqlmodel.JSON(), nullable=False),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('product',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.Column('name', sa.CHAR(length=50), nullable=False),
sa.Column('description', sa.CHAR(length=100), nullable=False),
sa.Column('price', sa.CHAR(length=5), nullable=False),
sa.Column('image', sa.CHAR(length=100), nullable=True),
sa.Column('name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('description', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('price', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column('image', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
sa.Column('category_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['category_id'], ['category.id'], ),
sa.PrimaryKeyConstraint('id')
Expand Down
27 changes: 25 additions & 2 deletions docs/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,38 @@ import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './pages/home/home.component';
import { DocsComponent } from './pages/docs/docs.component';
import { GetAllProductsComponent } from './components/get-all-products/get-all-products.component';
import { GetProductsByIdComponent } from './components/get-products-by-id/get-products-by-id.component';
import { GetProductByCategoryIdComponent } from './components/get-product-by-category-id/get-product-by-category-id.component';
import { GetAllCategoriesComponent } from './components/get-all-categories/get-all-categories.component';
import { GetCategoryByIdComponent } from './components/get-category-by-id/get-category-by-id.component';
import { GetAllCartsComponent } from './components/get-all-carts/get-all-carts.component';
import { GetCartByIdComponent } from './components/get-cart-by-id/get-cart-by-id.component';

const routes: Routes = [
{ path: '', pathMatch: 'full', redirectTo: '/home' },
{ path: 'home', component: HomeComponent},
{path: 'docs', component: DocsComponent, children:[
{path: 'products', children: [
{ path: '', pathMatch: 'full', redirectTo: '/docs/products/get-all-products' },
{path: 'get-all-products', component: GetAllProductsComponent}
]}
{path: 'get-all-products', component: GetAllProductsComponent},
{path: 'get-product-by-id', component: GetProductsByIdComponent},
{path: 'get-products-by-category-id', component: GetProductByCategoryIdComponent},
]},
{
path: 'categories', children: [
{ path: '', pathMatch: 'full', redirectTo: '/docs/categories/get-all-categories' },
{path: 'get-all-categories', component: GetAllCategoriesComponent},
{path: 'get-category-by-id', component: GetCategoryByIdComponent}
]
},
{
path: 'cart', children: [
{ path: '', pathMatch: 'full', redirectTo: '/docs/cart/get-all-carts' },
{path: 'get-all-carts', component: GetAllCartsComponent},
{path: 'get-cart-by-id', component: GetCartByIdComponent}
]
},

]
},

Expand Down
33 changes: 30 additions & 3 deletions docs/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { NgModule ,CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgScrollbarModule } from 'ngx-scrollbar';
import {HIGHLIGHTJS_CONFIG, HighlightJsConfig, HighlightJsModule} from 'ngx-highlight-js';
import {HIGHLIGHTJS_CONFIG, HighlightJsConfig, HighlightJsDirective, HighlightJsModule} from 'ngx-highlight-js';
import { NzCardModule } from "ng-zorro-antd/card";
import { NzBadgeModule } from "ng-zorro-antd/badge";
import { NzTabsModule } from "ng-zorro-antd/tabs";
import { NzButtonModule } from "ng-zorro-antd/button";
import { NzToolTipModule } from "ng-zorro-antd/tooltip";
import { NzModalModule } from "ng-zorro-antd/modal";
import { NzAlertModule } from "ng-zorro-antd/alert";
import { NzSpinModule } from 'ng-zorro-antd/spin';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
Expand All @@ -23,6 +29,13 @@ import { FlexLayoutModule } from '@angular/flex-layout';
import { DocsComponent } from './pages/docs/docs.component';
import { NavBarComponent } from './components/nav-bar/nav-bar.component';
import { GetAllProductsComponent } from './components/get-all-products/get-all-products.component';
import { ExampleCardComponent } from './components/example-card/example-card.component';
import { GetProductByCategoryIdComponent } from './components/get-product-by-category-id/get-product-by-category-id.component';
import { GetProductsByIdComponent } from './components/get-products-by-id/get-products-by-id.component';
import { GetCategoryByIdComponent } from './components/get-category-by-id/get-category-by-id.component';
import { GetAllCategoriesComponent } from './components/get-all-categories/get-all-categories.component';
import { GetAllCartsComponent } from './components/get-all-carts/get-all-carts.component';
import { GetCartByIdComponent } from './components/get-cart-by-id/get-cart-by-id.component';

registerLocaleData(en);

Expand All @@ -40,7 +53,14 @@ const ngZorroConfig: NzConfig = {
HomeComponent,
DocsComponent,
NavBarComponent,
GetAllProductsComponent
GetAllProductsComponent,
GetProductByCategoryIdComponent,
GetProductsByIdComponent,
GetCategoryByIdComponent,
GetAllCategoriesComponent,
GetAllCartsComponent,
GetCartByIdComponent,
ExampleCardComponent
],
imports: [
BrowserModule,
Expand All @@ -55,7 +75,14 @@ const ngZorroConfig: NzConfig = {
NzBadgeModule,
FlexLayoutModule,
NgScrollbarModule,
HighlightJsModule
HighlightJsModule,
HighlightJsDirective,
NzTabsModule,
NzButtonModule,
NzAlertModule,
NzModalModule,
NzToolTipModule,
NzSpinModule
],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
providers: [
Expand Down
44 changes: 44 additions & 0 deletions docs/src/app/components/example-card/example-card.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<nz-ribbon nzText="GET">
<nz-card style="width: 600px" [nzTitle]="extraTitle">
<nz-card-tab>
<nz-tabset nzSize="large" [nzTabBarExtraContent]="extraTemplate">
<nz-tab nzTitle="code">
<textarea rows="5" highlight-js [lang]="'javascript'">
fetch('{{ baseUrl }}{{ route }}')
.then(json=>console.log(json))
</textarea>
</nz-tab>
<nz-tab nzTitle="output">
<textarea rows="10" class="output">
{{output}}
</textarea>
</nz-tab>
</nz-tabset>
</nz-card-tab>
</nz-card>
</nz-ribbon>

<ng-template #extraTitle>
<span style="font-size: large; font-weight: bold; font-family: 'Montserrat', sans-serif;">{{ title}}</span>
</ng-template>

<nz-modal [(nzVisible)]="isVisible" [nzTitle]="modalTitle" (nzOnCancel)="handleCancel()" (nzOnOk)="handleOk()">
<ng-container *nzModalContent>
<nz-spin [nzSpinning]="showSpinner"></nz-spin>
<nz-alert
*ngIf="!showSpinner"
[nzType]="'error'"
[nzMessage]="'Failed to load sample code'"
[nzDescription]="'Error 500: Server failed to handle your request'"
></nz-alert>
</ng-container>
</nz-modal>

<ng-template #extraTemplate>
<button nz-button (click)="showModal()"> sample code</button>
</ng-template>

<ng-template #modalTitle>
<span>Sample code ({{title }})</span>
</ng-template>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.output {
background: #000;
color: #ccc;
display: block;
padding: 5px;
width: 100%;
height: auto;
overflow-y: hidden;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ExampleCardComponent } from './example-card.component';

describe('ExampleCardComponent', () => {
let component: ExampleCardComponent;
let fixture: ComponentFixture<ExampleCardComponent>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [ExampleCardComponent]
});
fixture = TestBed.createComponent(ExampleCardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
38 changes: 38 additions & 0 deletions docs/src/app/components/example-card/example-card.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Component ,Input} from '@angular/core';
import { setOptions } from 'marked';

@Component({
selector: 'app-example-card',
templateUrl: './example-card.component.html',
styleUrls: ['./example-card.component.scss']
})
export class ExampleCardComponent {

@Input() route: String;
@Input() is_get: boolean;
@Input() output: any;
@Input() title: string;

baseUrl = "http://127.0.0.1:8000/api";

isVisible = false;
showSpinner =false;

constructor() {}

showModal(): void {
this.isVisible = true;
clearTimeout( setTimeout(() =>{
this.showSpinner =true;
},5000));
this.showSpinner = false;
}

handleOk(): void {
this.isVisible = false;
}

handleCancel(): void {
this.isVisible = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<app-example-card [is_get]="true" [title]="title" [route]="route" [output]="output"></app-example-card>
Empty file.
Loading

0 comments on commit c2f3afd

Please sign in to comment.