-
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 'develop' of https://github.com/SVTeamJ/DeepBlue into ch…
…ore/#63
- Loading branch information
Showing
44 changed files
with
1,590 additions
and
507 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 |
---|---|---|
|
@@ -2,4 +2,8 @@ | |
*__pycache__* | ||
.DS_Store | ||
.env | ||
aws_key.py | ||
./.idea | ||
.idea/ | ||
backend/api/endpoints/aws/aws_key.py | ||
|
||
|
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,105 @@ | ||
# A generic, single database configuration. | ||
|
||
[alembic] | ||
# path to migration scripts | ||
script_location = alembic | ||
|
||
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s | ||
# Uncomment the line below if you want the files to be prepended with date and time | ||
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file | ||
# for all available tokens | ||
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s | ||
|
||
# sys.path path, will be prepended to sys.path if present. | ||
# defaults to the current working directory. | ||
prepend_sys_path = . | ||
|
||
# timezone to use when rendering the date within the migration file | ||
# as well as the filename. | ||
# If specified, requires the python-dateutil library that can be | ||
# installed by adding `alembic[tz]` to the pip requirements | ||
# string value is passed to dateutil.tz.gettz() | ||
# leave blank for localtime | ||
# timezone = | ||
|
||
# max length of characters to apply to the | ||
# "slug" field | ||
# truncate_slug_length = 40 | ||
|
||
# set to 'true' to run the environment during | ||
# the 'revision' command, regardless of autogenerate | ||
# revision_environment = false | ||
|
||
# set to 'true' to allow .pyc and .pyo files without | ||
# a source .py file to be detected as revisions in the | ||
# versions/ directory | ||
# sourceless = false | ||
|
||
# version location specification; This defaults | ||
# to alembic/versions. When using multiple version | ||
# directories, initial revisions must be specified with --version-path. | ||
# The path separator used here should be the separator specified by "version_path_separator" below. | ||
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions | ||
|
||
# version path separator; As mentioned above, this is the character used to split | ||
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep. | ||
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas. | ||
# Valid values for version_path_separator are: | ||
# | ||
# version_path_separator = : | ||
# version_path_separator = ; | ||
# version_path_separator = space | ||
version_path_separator = os # Use os.pathsep. Default configuration used for new projects. | ||
|
||
# the output encoding used when revision files | ||
# are written from script.py.mako | ||
# output_encoding = utf-8 | ||
# 172.17.0.1 | ||
sqlalchemy.url = mysql+pymysql://taegong:[email protected]:3306/taegong | ||
|
||
|
||
[post_write_hooks] | ||
# post_write_hooks defines scripts or Python functions that are run | ||
# on newly generated revision scripts. See the documentation for further | ||
# detail and examples | ||
|
||
# format using "black" - use the console_scripts runner, against the "black" entrypoint | ||
# hooks = black | ||
# black.type = console_scripts | ||
# black.entrypoint = black | ||
# black.options = -l 79 REVISION_SCRIPT_FILENAME | ||
|
||
# Logging configuration | ||
[loggers] | ||
keys = root,sqlalchemy,alembic | ||
|
||
[handlers] | ||
keys = console | ||
|
||
[formatters] | ||
keys = generic | ||
|
||
[logger_root] | ||
level = WARN | ||
handlers = console | ||
qualname = | ||
|
||
[logger_sqlalchemy] | ||
level = WARN | ||
handlers = | ||
qualname = sqlalchemy.engine | ||
|
||
[logger_alembic] | ||
level = INFO | ||
handlers = | ||
qualname = alembic | ||
|
||
[handler_console] | ||
class = StreamHandler | ||
args = (sys.stderr,) | ||
level = NOTSET | ||
formatter = generic | ||
|
||
[formatter_generic] | ||
format = %(levelname)-5.5s [%(name)s] %(message)s | ||
datefmt = %H:%M:%S |
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 @@ | ||
Generic single-database configuration. |
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,78 @@ | ||
from logging.config import fileConfig | ||
|
||
from sqlalchemy import engine_from_config | ||
from sqlalchemy import pool | ||
|
||
from alembic import context | ||
|
||
# this is the Alembic Config object, which provides | ||
# access to the values within the .ini file in use. | ||
config = context.config | ||
|
||
# Interpret the config file for Python logging. | ||
# This line sets up loggers basically. | ||
if config.config_file_name is not None: | ||
fileConfig(config.config_file_name) | ||
|
||
# add your model's MetaData object here | ||
# for 'autogenerate' support | ||
from database import Base | ||
target_metadata = Base.metadata | ||
#target_metadata = None | ||
|
||
# other values from the config, defined by the needs of env.py, | ||
# can be acquired: | ||
# my_important_option = config.get_main_option("my_important_option") | ||
# ... etc. | ||
|
||
|
||
def run_migrations_offline() -> None: | ||
"""Run migrations in 'offline' mode. | ||
This configures the context with just a URL | ||
and not an Engine, though an Engine is acceptable | ||
here as well. By skipping the Engine creation | ||
we don't even need a DBAPI to be available. | ||
Calls to context.execute() here emit the given string to the | ||
script output. | ||
""" | ||
url = config.get_main_option("sqlalchemy.url") | ||
context.configure( | ||
url=url, | ||
target_metadata=target_metadata, | ||
literal_binds=True, | ||
dialect_opts={"paramstyle": "named"}, | ||
) | ||
|
||
with context.begin_transaction(): | ||
context.run_migrations() | ||
|
||
|
||
def run_migrations_online() -> None: | ||
"""Run migrations in 'online' mode. | ||
In this scenario we need to create an Engine | ||
and associate a connection with the context. | ||
""" | ||
connectable = engine_from_config( | ||
config.get_section(config.config_ini_section), | ||
prefix="sqlalchemy.", | ||
poolclass=pool.NullPool, | ||
) | ||
|
||
with connectable.connect() as connection: | ||
context.configure( | ||
connection=connection, target_metadata=target_metadata | ||
) | ||
|
||
with context.begin_transaction(): | ||
context.run_migrations() | ||
|
||
|
||
if context.is_offline_mode(): | ||
run_migrations_offline() | ||
else: | ||
run_migrations_online() |
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,24 @@ | ||
"""${message} | ||
|
||
Revision ID: ${up_revision} | ||
Revises: ${down_revision | comma,n} | ||
Create Date: ${create_date} | ||
|
||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
${imports if imports else ""} | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = ${repr(up_revision)} | ||
down_revision = ${repr(down_revision)} | ||
branch_labels = ${repr(branch_labels)} | ||
depends_on = ${repr(depends_on)} | ||
|
||
|
||
def upgrade() -> None: | ||
${upgrades if upgrades else "pass"} | ||
|
||
|
||
def downgrade() -> None: | ||
${downgrades if downgrades else "pass"} |
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,105 @@ | ||
"""populate data | ||
Revision ID: 3928deaba815 | ||
Revises: | ||
Create Date: 2023-01-20 11:36:44.234410 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import mysql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '3928deaba815' | ||
down_revision = None | ||
branch_labels = None | ||
depends_on = None | ||
|
||
def upgrade() -> None: | ||
# create a fish table | ||
fish_table =op.create_table('fish', | ||
sa.Column('fish_id', mysql.INTEGER(), autoincrement=True, nullable=False), | ||
sa.Column('fish_type', mysql.VARCHAR(length=64), nullable=False), | ||
sa.Column('toxicity', mysql.VARCHAR(length=16), nullable=False), | ||
sa.Column('open_season', mysql.VARCHAR(length=64), nullable=False), | ||
sa.Column('closed_season', mysql.VARCHAR(length=64), nullable=False), | ||
sa.Column('description', mysql.VARCHAR(length=512), nullable=False), | ||
sa.Column('classification', mysql.VARCHAR(length=64), nullable=False), | ||
sa.Column('scientific_name', mysql.VARCHAR(length=128), nullable=False), | ||
sa.Column('habitat', mysql.VARCHAR(length=64), nullable=False), | ||
sa.Column('fish_url', mysql.VARCHAR(length=100), nullable=True), | ||
sa.Column('created_at', mysql.TIMESTAMP(), server_default=sa.text('CURRENT_TIMESTAMP'),nullable=True), | ||
sa.Column('updated_at', mysql.TIMESTAMP(), | ||
server_default=sa.text('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), nullable=True), | ||
sa.Column('is_active', mysql.TINYINT(display_width=1), autoincrement=False, nullable=False), | ||
sa.PrimaryKeyConstraint('fish_id'), | ||
mysql_collate='utf8mb4_0900_ai_ci', | ||
mysql_default_charset='utf8mb4', | ||
mysql_engine='InnoDB' | ||
) | ||
|
||
# populate some fish data | ||
op.bulk_insert(fish_table,[ | ||
{'fish_type': 'mackerel', | ||
'toxicity': 'No', | ||
'classification': 'Pisces', | ||
'scientific_name': 'Scomber japonicus', | ||
'open_season': 'january~december', 'closed_season': 'jan~dec', | ||
'description': """It is one of the representative blue-backed fish in the family such as mackerel and tuna and tuna. | ||
It is a migratory fish species that likes the warm sea with a body length of more than 40cm and a temperature of 10-22℃. | ||
It is widely distributed worldwide, eating plankton when fried, and adult fish mainly feed on anchovies or small fish.""", | ||
'fish_url': 'https://www.google.com', | ||
'habitat': 'Pacific Ocean', | ||
'is_active': 1}, | ||
{'fish_type': 'red stingray', | ||
'classification': 'Chondrichthyes', | ||
'scientific_name': 'Dasyatis akajei', | ||
'toxicity': 'Yes', | ||
'open_season': 'May', 'closed_season': 'August', | ||
'description': """ The yellow stingray is a species of fish in the family Colomidae. | ||
There is a long poisonous thorn on the tail, which is about 15cm long, so not only is it very long, but it also has teeth on both sides. if it pokes a human body, | ||
not only does it hurt terribly, but it also has poison at the end of the venomous thorn, which can lead to fainting and even death. """, | ||
'fish_url': 'https://www.google.com', | ||
'habitat': 'Pacific Ocean', | ||
'is_active': 1}, | ||
{'fish_type': 'red snapper', | ||
'classification': 'Actinopterygii', | ||
'scientific_name': 'Lutjanus campechanus', | ||
'toxicity': 'Yes', | ||
'open_season': 'June', 'closed_season': 'October', | ||
'description': """Red tung sea bream is a coastal fish species that lives well in brackish waters where fresh water and seawater are mixed, especially in the mangrove area of the estuary of the river. | ||
It is found mainly in the sea, but some species live in the mouth of the river or feed in fresh water. | ||
Red tung sea bream caught in the tropics is said to require attention because cases of cigar terra poisoning have been found in the past.""", | ||
'fish_url': 'https://www.google.com', | ||
'habitat': 'Indian Ocean', | ||
'is_active': 1}, | ||
{'fish_type': 'flat fish', | ||
'classification': 'Actinopterygii', | ||
'scientific_name': 'Paralichthys olivaceus', | ||
'toxicity': 'Yes', | ||
'open_season': 'January', 'closed_season': 'December', | ||
'description': """It is a species of sea fish belonging to the flounder family of flounder order It is a flat fish that is also well known as flatfish in Korea. | ||
Sand floors located between 10 and 200 meters deep are mainly preferred. It is not good at swimming long distances. | ||
Some flatfish live in parts of the Korean Peninsula's freshwater depending on the season.You should be careful not to get bitten when you catch a halibut caught by fishing because it has sharp teeth in your mouth.""", | ||
'fish_url': 'https://www.google.com', | ||
'habitat': 'The western part of Pacific Ocean', | ||
'is_active': 1}, | ||
{'fish_type': 'dark-banded rockfish', | ||
'classification': 'Actinopterygii', | ||
'scientific_name': 'Sebastes inermis', | ||
'toxicity': 'No', | ||
'open_season': 'December', 'closed_season': 'February', | ||
'description': """It is distributed in all coasts of Korea, southern North Sea of Japan, and northern coast of China, especially in the Yellow Sea and Balhae Bay. | ||
At the age of 4-6 months, 2-6 centimeters of fry appear in a seaweed-rich place and live under the sea from summer to autumn. | ||
Small fish can be caught recklessly and your hands can be cut by pointed dorsal fins and gill caps. """ | ||
, 'fish_url': 'https://www.google.com', | ||
'habitat': 'a reef of Korean Peninsula', | ||
'is_active': 1}, | ||
|
||
] | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
# drop table | ||
op.drop_table('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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
from fastapi import APIRouter | ||
from api.endpoints import users, ai | ||
from api.endpoints import users, ai,fish,history | ||
|
||
api_router = APIRouter() | ||
api_router.include_router(users.router, prefix="/users", tags=["users"]) | ||
api_router.include_router(ai.router, prefix="/ai", tags=["ai"]) | ||
api_router.include_router(ai.router, prefix="/ai", tags=["ai"]) | ||
api_router.include_router(history.router, prefix="/history",tags=["history"]) | ||
api_router.include_router(fish.router, prefix="/fish",tags=["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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from fastapi import APIRouter,Depends | ||
from database import SessionLocal | ||
|
||
from schemas import fish_schema | ||
from crud import fish_crud | ||
from sqlalchemy.orm import Session | ||
from model import fish | ||
from api.dep import get_db | ||
|
||
router=APIRouter() | ||
|
||
# @router.post("/",response_model=fish_schema.FishRead) | ||
# 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) | ||
|
||
|
||
|
||
@router.get("/{fish_id}",response_model=fish_schema.FishRead) | ||
def get_fish(fish_id:int,db:Session=Depends(get_db)): | ||
''' | ||
물고기 정보 불러오는 API | ||
''' | ||
return fish_crud.get_fish(db,fish_id) | ||
|
||
|
Oops, something went wrong.