-
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.
Merge pull request #13 from joselevelh/jlevel/pre_deployment
Jlevel/pre deployment
- Loading branch information
Showing
9 changed files
with
75 additions
and
79 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,24 @@ | ||
# | ||
FROM python:3.9 | ||
|
||
# | ||
LABEL authors="JoseLevel" | ||
|
||
# Setting env variable via arg to be passed at container run time or build time | ||
ARG MONGO_URI_ARG | ||
ENV MONGO_URI=$MONGO_URI_ARG | ||
|
||
# | ||
WORKDIR /drakes_api | ||
|
||
# | ||
COPY ./requirements.txt /drakes_api/requirements.txt | ||
|
||
# | ||
RUN pip install --no-cache-dir --upgrade -r /drakes_api/requirements.txt | ||
|
||
# | ||
COPY ./app /drakes_api/app | ||
|
||
# | ||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] |
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,8 +1,9 @@ | ||
from pymongo import MongoClient | ||
from models import Lookbook | ||
from app.models import Lookbook | ||
import os | ||
|
||
# MongoDB Setup | ||
MONGO_URI = "mongodb+srv://user2:[email protected]/?retryWrites=true&w=majority" | ||
MONGO_URI = os.getenv("MONGO_URI") | ||
client = MongoClient(MONGO_URI) | ||
db = client.drakes_lookbooks | ||
lookbooks_collection = db.lookbooks | ||
|
@@ -19,7 +20,10 @@ def check_db_connection(): | |
if db.lookbooks is not None: | ||
print(f"Lookbook collection: {db.lookbooks}") | ||
check += 1 | ||
return check == 3 | ||
if db.lookbooks.find_one({"lookbook_name": "spring-summer-2017-lookbook"}) is not None: | ||
print(f'Lookbook = {db.lookbooks.find_one({"lookbook_name": "spring-summer-2017-lookbook"})}') | ||
check += 1 | ||
return check == 4 | ||
|
||
|
||
def retrieve_lookbook_by_tag(tags: list[str]) -> list[Lookbook]: | ||
|
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,9 +1,10 @@ | ||
import os | ||
from pymongo import MongoClient | ||
|
||
from app.crud import client | ||
|
||
import typer | ||
|
||
MONGO_URI = "mongodb+srv://user2:[email protected]/?retryWrites=true&w=majority" | ||
|
||
app = typer.Typer() | ||
google_storage_bucket_base = "https://storage.googleapis.com/drakes_lookbooks_bucket/drakes_images/" | ||
|
||
|
@@ -26,12 +27,8 @@ def iterate_subdirectories(directory_path: str): | |
for root, directories, _ in os.walk(directory_path): | ||
for lookbook in directories: | ||
lookbook_path = os.path.join(root, lookbook) | ||
# typer.echo(f"Lookbook: {lookbook_path}") | ||
for _, _, files in os.walk(lookbook_path): | ||
# typer.echo(f"lookbook_name: {lookbook}") | ||
# typer.echo(f" tags: []") | ||
image_paths = [google_storage_bucket_base + lookbook + "/" + image_name for image_name in files] | ||
# typer.echo(f" images: {image_paths}") | ||
new_lookbook = create_lookbook_dict(lookbook_name=lookbook, lookbook_tags=[], image_paths=image_paths) | ||
upload_lookbook(new_lookbook) | ||
|
||
|
@@ -52,7 +49,7 @@ def upload_lookbook(lookbooks_to_upload: list[dict]): | |
"""Uploads given lookbook to Google Cloud""" | ||
|
||
try: | ||
client = MongoClient(MONGO_URI) | ||
|
||
# Check the connection by listing database names | ||
print(f"Client: {client}") | ||
database_names = client.list_databases() | ||
|
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,39 +1,31 @@ | ||
from fastapi import FastAPI, Query | ||
|
||
from models import FilterParams, Lookbook | ||
import crud | ||
from app.models import Lookbook | ||
from app import crud | ||
|
||
|
||
app = FastAPI(title="Unofficial Drakes Lookbook API", | ||
summary="An API to browse Drakes lookbooks", ) | ||
|
||
|
||
@app.get("/syscheck") | ||
async def system_check(): | ||
def system_check(): | ||
print(f"Starting system check for API and DB connection") | ||
return crud.check_db_connection() | ||
|
||
|
||
@app.get("/lookbooks/{title}") | ||
async def get_lookbook(title: str) -> list[Lookbook]: | ||
def get_lookbook(title: str) -> list[Lookbook]: | ||
print(f"Searching for {title} in lookbooks db...") | ||
lookbooks = crud.retrieve_lookbook_by_name(name=title) | ||
print(f"{lookbooks =}") | ||
return lookbooks | ||
|
||
|
||
@app.get("/lookbooks/any/") | ||
async def get_lookbooks_any(tags: list[str] = Query(default=None)) -> list[Lookbook]: | ||
def get_lookbooks_any(tags: list[str] = Query(default=None)) -> list[Lookbook]: | ||
"""Returns all lookbooks that have the given tag(s)""" | ||
print(f"Searching for {tags} in lookbooks db...") | ||
lookbooks = crud.retrieve_lookbook_by_tag(tags=tags) | ||
print(f"{lookbooks =}") | ||
return lookbooks | ||
|
||
|
||
@app.get("/lookbooks/all") | ||
async def get_lookbooks_all(filter_params: FilterParams): | ||
"""Returns lookbooks that match ALL the tags given""" | ||
# Use 'filter_params.tags' to filter lookbooks | ||
# ... | ||
return None |
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,28 @@ | ||
from fastapi.testclient import TestClient | ||
from app.main import app | ||
|
||
client = TestClient(app) | ||
|
||
|
||
def test_system_check(): | ||
response = client.get("/syscheck") | ||
assert response.status_code == 200 | ||
assert response.json() == True | ||
|
||
|
||
def test_get_lookbook(): | ||
response = client.get("/lookbooks/paris") | ||
assert response.status_code == 200 | ||
assert len(response.json()) == 1 | ||
assert response.json()[0]["lookbook_name"] == "autumn-in-paris-lookbook" | ||
|
||
|
||
def test_get_lookbooks_any(): | ||
response = client.get("/lookbooks/any/?tags=2017") | ||
assert response.status_code == 200 | ||
assert len(response.json()) >= 1 | ||
assert response.json()[0]["tags"] == [ | ||
"spring-summer", | ||
"2017", | ||
"casual", | ||
"menswear"] |
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,7 @@ | ||
from pymongo import MongoClient | ||
import os | ||
|
||
MONGO_URI = "mongodb+srv://user2:[email protected]/?retryWrites=true&w=majority" | ||
MONGO_URI = os.getenv("MONGO_URI") | ||
client = MongoClient(MONGO_URI) | ||
db = client.drakes_lookbooks | ||
|
||
|
This file was deleted.
Oops, something went wrong.
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