-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/#64' of https://github.com/SVTeamJ/DeepBlue into c…
…hore/#67
- Loading branch information
Showing
5 changed files
with
116 additions
and
1 deletion.
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,37 @@ | ||
from fastapi import APIRouter,Depends | ||
from database import SessionLocal | ||
|
||
from database import SessionLocal,engine,Base | ||
from schemas import fish_schema | ||
from crud import fish_crud | ||
import model | ||
from sqlalchemy.orm import Session | ||
from model import fish | ||
fish.Base.metadata.create_all(bind=engine) | ||
|
||
def get_db(): | ||
db = SessionLocal() | ||
try: | ||
yield db | ||
finally: | ||
db.close() | ||
|
||
router=APIRouter( | ||
prefix="/api/fish", | ||
) | ||
|
||
|
||
|
||
@router.post("/",response_model=fish_schema.FishCreate) | ||
def post_fish(fish:fish_schema.FishCreate,db:Session=Depends(get_db)): | ||
fish_crud.create_fish(db,fish) | ||
# return fish_crud.create_fish(db, fish=fish) | ||
|
||
|
||
|
||
@router.get("/{fish_id}",response_model=fish_schema.Fish) | ||
def get_fish(fish_id:int,db:Session=Depends(get_db)): | ||
fish_information=db.query(fish.Fish).filter(fish.Fish.fish_id==fish_id).first() | ||
return fish_information | ||
|
||
|
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 @@ | ||
from sqlalchemy.orm import Session | ||
from schemas import fish_schema | ||
from model.fish import Fish | ||
|
||
def create_fish(db:Session,fish:fish_schema.FishCreate): | ||
db_fish=Fish( | ||
fish_id=fish.fish_id, | ||
fish_type=fish.fish_type, | ||
open_season=fish.open_season, | ||
closed_season=fish.closed_season, | ||
fish_url=fish.fish_url, | ||
description=fish.description, | ||
toxicity=fish.toxicity | ||
) | ||
db.add(db_fish) | ||
db.commit() | ||
db.refresh(db_fish) | ||
return db_fish |
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,23 @@ | ||
from sqlalchemy import Boolean, Column,Integer, String | ||
from sqlalchemy.types import TIMESTAMP,DateTime | ||
from sqlalchemy.sql import text, func | ||
|
||
|
||
from database import Base | ||
from sqlalchemy import func | ||
|
||
class Fish(Base): | ||
__tablename__="fish" | ||
|
||
fish_id=Column(Integer,primary_key=True,index=True) | ||
fish_type=Column(String(64),nullable=False,index=True) | ||
toxicity=Column(String(16),nullable=False,index=True) | ||
open_season=Column(String(64),nullable=False,index=True) | ||
closed_season=Column(String(64),nullable=False,index=True) | ||
description=Column(String(255),nullable=False,index=True) | ||
fish_url=Column(String(100),nullable=False,index=True) | ||
created_at=Column(TIMESTAMP,server_default=func.now()) | ||
updated_at=Column(TIMESTAMP,server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")) | ||
is_active=Column(Boolean,nullable=False,default=True) | ||
|
||
|
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,36 @@ | ||
from pydantic import BaseModel | ||
|
||
class FishBase(BaseModel): | ||
|
||
|
||
class Config: | ||
orm_mode=True | ||
|
||
|
||
|
||
|
||
class Fish(FishBase): | ||
fish_id:int | ||
description:str | ||
toxicity:str | ||
fish_type:str | ||
open_season:str | ||
closed_season:str | ||
fish_url:str | ||
is_active:bool | ||
|
||
|
||
|
||
class FishCreate(FishBase): | ||
fish_id:int | ||
description:str | ||
toxicity:str | ||
fish_type:str | ||
open_season:str | ||
closed_season:str | ||
fish_url:str | ||
|
||
class FishRead(FishCreate): | ||
fish_id:int | ||
|
||
|