-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
128 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Build and Push Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build_and_push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Build the Docker image | ||
run: docker build . --file Dockerfile --tag wangsl0809/yuezi_server:${{ github.sha }} | ||
- name: Login to DockerHub | ||
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | ||
- name: Push the Docker image to DockerHub | ||
run: docker push wangsl0809/yuezi_server:${{ github.sha }} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from datetime import datetime | ||
from typing import Union | ||
|
||
from fastapi import APIRouter, Depends | ||
from pydantic import BaseModel | ||
from sqlalchemy.orm import Session | ||
|
||
import model | ||
from database import get_db | ||
|
||
router = APIRouter() | ||
|
||
|
||
class ProductCreate(BaseModel): | ||
name: str | ||
quantity: int | ||
price: float | ||
note: Union[str, None] = None | ||
|
||
|
||
class ProductResponse(BaseModel): | ||
id: int | ||
name: str | ||
quantity: int | ||
price: float | ||
note: Union[str, None] = None | ||
created_at: datetime | ||
updated_at: datetime | ||
|
||
class Config: | ||
orm_mode = True | ||
|
||
|
||
class LogResponse(BaseModel): | ||
id: int | ||
product_id: int | ||
user_id: int | ||
operation: str | ||
quantity_changed: int | ||
timestamp: datetime | ||
|
||
class Config: | ||
orm_mode = True | ||
|
||
|
||
def update_product_quantity(db, product_id, quantity): | ||
db_product = db.query(model.Product).filter(model.Product.id == product_id).first() | ||
db_product.quantity = quantity | ||
db.commit() | ||
db.refresh(db_product) | ||
return db_product | ||
|
||
|
||
def get_all_products(db): | ||
return db.query(model.Product).all() | ||
|
||
|
||
@router.post("/IMS/create_product", response_model=ProductResponse) | ||
async def create_product(product: ProductCreate, db: Session = Depends(get_db)): | ||
db_product = model.Product(name=product.name, quantity=product.quantity, price=product.price, note=product.note) | ||
db.add(db_product) | ||
db.commit() | ||
db.refresh(db_product) | ||
return db_product | ||
|
||
|
||
@router.get("/IMS/get_all_products") | ||
async def get_all_products(db: Session = Depends(get_db)): | ||
return get_all_products(db) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from sqlalchemy import DECIMAL, Column, ForeignKey, Integer, String, DateTime, func | ||
from sqlalchemy.orm import relationship | ||
|
||
from database import Base | ||
|
||
|
||
class Product(Base): | ||
__tablename__ = "product" | ||
|
||
id = Column(Integer, primary_key=True) | ||
name = Column(String(255), unique=True, index=True) | ||
quantity = Column(Integer) | ||
price = Column(DECIMAL(precision=10, scale=2)) | ||
note = Column(String(255)) | ||
created_at = Column(DateTime, default=func.now()) | ||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now()) | ||
|
||
|
||
class Log(Base): | ||
__tablename__ = "log" | ||
|
||
id = Column(Integer, primary_key=True) | ||
product_id = Column(Integer, ForeignKey("product.id")) | ||
user_id = Column(Integer, ForeignKey("users.id")) | ||
operation = Column(String(255)) | ||
quantity_changed = Column(Integer) | ||
timestamp = Column(DateTime, default=func.now()) | ||
|
||
product = relationship("Product", backref="logs") | ||
user = relationship("User", backref="logs") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .client import * | ||
from .base import * | ||
from .room import * | ||
from .IMS import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters