Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/distribute crawl #15

Open
wants to merge 33 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a37d525
Merge pull request #3 from f-lab-edu/dev
oortclwd Apr 11, 2022
5405373
pinning version
SB-Jo May 21, 2022
cbf7c67
add expiration passed exception
SB-Jo May 22, 2022
564aa3f
fix wrong - return exception -> raise exception
SB-Jo May 22, 2022
901840c
fix error : add arbitrary_types_allowed attribute
SB-Jo May 22, 2022
dae313b
add logger - use middleware
SB-Jo May 22, 2022
6104d84
move pre-commit to requirements-dev.txt
SB-Jo May 22, 2022
a51d79f
add filehandler / add formatter / remove datetime
SB-Jo Jun 12, 2022
01c0f6d
fix typing mistake
SB-Jo Jun 12, 2022
e122c76
crawling with aiohttp / asyncio.queue
SB-Jo Jun 12, 2022
15daf36
make scrap server to get cafe information
SB-Jo Jun 12, 2022
1d977f9
change url to /main/v1/ & remove selenium
SB-Jo Aug 15, 2022
17b504d
add main.py - send request to remote host and get response about cafe…
oortclwd Oct 19, 2022
112b4d0
change add.py - fix dict value didn't change problem
oortclwd Oct 19, 2022
c90c8fa
remove unnecessary files
oortclwd Oct 19, 2022
c277e57
add Dockerfile for dockering scraping_app
oortclwd Oct 19, 2022
fc4cb1e
remove unnecessary file
oortclwd Oct 19, 2022
72bded8
add config.py for get db information and remote host ip
oortclwd Oct 19, 2022
dcb0340
add utils.py - Utility Function for scraping
oortclwd Oct 19, 2022
20329db
add scrap_app.py - application which will be deployed in remote host
oortclwd Oct 19, 2022
2c57328
add sqlalchemy setup
oortclwd Oct 19, 2022
903a783
add db cafe model
oortclwd Oct 19, 2022
bf21630
change cafe db schema - add N:M realtionship with facilities and loca…
oortclwd Oct 19, 2022
5393031
Merge branch 'main' of https://github.com/f-lab-edu/cafe-search-csb i…
oortclwd Oct 19, 2022
4926197
split prod-test env file
oortclwd Oct 19, 2022
1f7088b
change db schema - add M:N relationship
oortclwd Oct 23, 2022
2c06be6
add test data and change test utility
oortclwd Oct 23, 2022
22fc84b
add pydantic schemas for cafe
oortclwd Oct 23, 2022
c66d35b
change url - more restful
oortclwd Oct 23, 2022
9ce8536
add more logic to search and update cafe info
oortclwd Oct 23, 2022
10d84d1
fix logger
oortclwd Oct 30, 2022
f7b5a04
add more test
oortclwd Oct 30, 2022
309ef7b
apply b lack formatting
oortclwd Oct 30, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ celerybeat.pid
*.sage.py

# Environments
.env
*.env
.venv
env/
venv/
Expand Down
78 changes: 39 additions & 39 deletions backend/apis/version1/route_cafes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
update_cafe_by_id,
)
from fastapi import APIRouter, Depends, HTTPException, status
from schemas.cafes import CafeCreate, ShowCafe, CommentCreate, ShowComment
from schemas.cafes import CafeCreate, CafeUpdate, ShowCafe, CommentCreate, ShowComment
from sqlalchemy.orm import Session


router = APIRouter()


Expand All @@ -27,7 +28,15 @@ def __init__(self, offset: int = 0, limit: int = 5):
self.limit = limit


@router.post("/create", response_model=ShowCafe)
@router.get("", response_model=List[ShowCafe])
def read_cafes(
db: Session = Depends(get_db), params: LimitParams = Depends(LimitParams)
):
cafes = get_all_cafes(db=db, limit=params.limit)
return cafes


@router.post("", response_model=ShowCafe)
def create_cafe(
cafe: CafeCreate,
db: Session = Depends(get_db),
Expand All @@ -42,7 +51,28 @@ def create_cafe(
return cafe


@router.get("/get/{id}", response_model=ShowCafe)
@router.get("/search", response_model=List[ShowCafe])
def searching_cafe(
cafename: str = None,
location: str = None,
db: Session = Depends(get_db),
params: LimitParams = Depends(LimitParams),
):
if not cafename and not location:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Must Input Cafe Name or Location",
)
cafes = search_cafe(db, params.limit, cafename=cafename, location=location)
if not cafes:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Can't find Cafe",
)
return cafes


@router.get("/{id}", response_model=ShowCafe)
def read_cafe(id: int, db: Session = Depends(get_db)):
cafe = get_cafe_by_id(id=id, db=db)
if not cafe:
Expand All @@ -53,22 +83,13 @@ def read_cafe(id: int, db: Session = Depends(get_db)):
return cafe


@router.get("/all", response_model=List[ShowCafe])
def read_cafes(
db: Session = Depends(get_db), params: LimitParams = Depends(LimitParams)
):
cafes = get_all_cafes(db=db, limit=params.limit)
return cafes


@router.post("/update/{id}")
@router.post("/{id}")
def update_cafe(
id: int,
cafe: CafeCreate,
cafe: CafeUpdate,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user_from_token),
):
print("Current User : ", current_user.is_superuser)
if not current_user.is_superuser:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
Expand All @@ -82,28 +103,7 @@ def update_cafe(
return {"msg": "Updated Successfully"}


@router.get("/search", response_model=List[ShowCafe])
def searching_cafe(
cafename: str = None,
location: str = None,
db: Session = Depends(get_db),
params: LimitParams = Depends(LimitParams),
):
if not cafename and not location:
return HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Must Input Cafe Name or Location",
)
cafes = search_cafe(cafename, location, db)
if not cafes:
return HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Can't find Cafe",
)
return cafes[params.offest : params.offset + params.limit]


@router.delete("/delete/{id}")
@router.delete("/{id}")
def delete_cafe(
id: int,
db: Session = Depends(get_db),
Expand Down Expand Up @@ -138,21 +138,21 @@ def add_comment(
return comment


@router.get("/{cafeid}/comments", response_model=List[ShowComment])
@router.get("/{cafeid}/comment", response_model=List[ShowComment])
def read_comments(
cafeid: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user_from_token),
):
comments = get_comments_by_cafeid(cafeid=cafeid, db=db)
if not comments:
return HTTPException(
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Can't Find Comment"
)
return comments


@router.delete("/comments/{commentid}/delete")
@router.delete("/{cafeid}/comment/{commentid}")
def delete_comment(
commentid: int,
db: Session = Depends(get_db),
Expand Down
23 changes: 15 additions & 8 deletions backend/apis/version1/route_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from db.logics.login import create_access_token
from fastapi import APIRouter, Depends, HTTPException, status
from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer
from jose import JWTError, jwt
from jose import ExpiredSignatureError, JWTError, jwt
from schemas.tokens import Token
from sqlalchemy.orm import Session

Expand Down Expand Up @@ -37,21 +37,28 @@ def login_for_access_token(
def get_current_user_from_token(
token: str = Depends(oauth2_scheme), db: Session = Depends(get_db)
):
authorize_exception = HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="Can't Validate Token"
)

try:
payload = jwt.decode(
token, settings.SECRET_KEY, algorithms=[settings.SECRET_ALGORITHM]
)
username: str = payload.get("sub")
if username is None:
raise authorize_exception
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Expiration Time Passed.",
)
except ExpiredSignatureError:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="Expiration Time Passed."
)
except JWTError:
raise authorize_exception
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="Can't Validate Token"
)

user = get_user(username=username, db=db)
if user is None:
raise authorize_exception
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="Can't Validate Token"
)
return user
14 changes: 13 additions & 1 deletion backend/apis/version1/route_users.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
from apis.version1.route_login import get_current_user_from_token
from db.session import get_db
from db.logics.users import create_new_user
from db.models.users import User
from db.logics.users import create_new_user, delete_user
from fastapi import APIRouter, Depends, status
from schemas.users import UserCreate, ShowUser
from sqlalchemy.orm import Session


router = APIRouter()


@router.post("/", response_model=ShowUser, status_code=status.HTTP_201_CREATED)
def create_user(user: UserCreate, db: Session = Depends(get_db)):
user = create_new_user(user=user, db=db)
return user


@router.delete("/")
def delete_user(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user_from_token),
):
delete_user(user=current_user, db=db)
return {"msg": "Deleted"}
9 changes: 6 additions & 3 deletions backend/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,26 @@ class Config:


class TestSettings(BaseSettings):
PROJECT_NAME: str = "Cafe Search"
PROJECT_VERSION: str = "1.0.0"

DB_USERNAME: str
DB_PASSWORD: SecretStr
DB_HOST: str
DB_PORT: int
DB_NAME = "test"
DB_NAME: str

TEST_USER_EMAIL = "sbjo@naver.com"
TEST_USER_PASSWORD = "sbjo"
TEST_ADMIN_EMAIL = "admin@naver.com"
TEST_SECOND_USER_EMAIL = "sb@naver.com"

SECRET_KEY: str = "secret"
SECRET_KEY: str
SECRET_ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = 30

class Config:
env_file = str(BASE_DIR / ".env")
env_file = str(BASE_DIR / "dev.env")
env_file_encoding = "utf-8"


Expand Down
1 change: 1 addition & 0 deletions backend/core/hashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")


class Hasher:
@staticmethod
def verify_password(plain_password, hashed_password):
Expand Down
Loading