Skip to content

Commit 34655f3

Browse files
committed
fix requests warnings and add nfts api schemas
Signed-off-by: wiseaidev <[email protected]>
1 parent 42a878e commit 34655f3

File tree

3 files changed

+81
-48
lines changed

3 files changed

+81
-48
lines changed

app/nfts/router.py

Lines changed: 52 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@
2020
from typing import (
2121
Any,
2222
Dict,
23+
Union,
2324
)
2425

26+
from app.auth import (
27+
schemas as auth_schemas,
28+
)
2529
from app.config import (
2630
settings,
2731
)
@@ -44,41 +48,46 @@
4448
@router.post(
4549
"/nft/mint-offer",
4650
name="nft:mint-nft-with-offer",
47-
# response_model=Any,
48-
# responses={
49-
# 201: {
50-
# "model": Any,
51-
# "description": "A response object that contains info about"
52-
# " a wallet.",
53-
# },
54-
# },
51+
response_model=auth_schemas.ResponseSchema,
52+
responses={
53+
200: {
54+
"model": auth_schemas.ResponseSchema,
55+
"description": "A response object that indicates an nft"
56+
" has been minted successfully!",
57+
},
58+
},
5559
)
5660
async def mint_nft_token_with_offer(
5761
nft_info: nfts_schemas.NFTObjectSchema,
5862
current_wallet: Any = Depends(jwt.get_current_active_wallet),
5963
session: AIOSession = Depends(dependencies.get_db_transactional_session),
6064
) -> Dict[str, Any]:
6165
"""
62-
Generate a faucet wallet.
66+
mint an nft token and create a sell offer.
6367
"""
6468
meta_data = f"{nft_info.picture},{nft_info.title},{nft_info.price}"
65-
results = await nfts_crud.mint_nft_token(
69+
await nfts_crud.mint_nft_token(
6670
current_wallet.classic_address, meta_data, session, True
6771
)
68-
return results
72+
return {"status_code": 200, "message": "NFT minted successfully!"}
6973

7074

7175
@router.post(
7276
"/nft/upload-image",
7377
name="nft:upload-image",
74-
# response_model=Any,
75-
# responses={
76-
# 201: {
77-
# "model": Any,
78-
# "description": "A response object that contains info about"
79-
# " a wallet.",
80-
# },
81-
# },
78+
response_model=Union[
79+
auth_schemas.ResponseSchema, nfts_schemas.UploadImageResponseSchema
80+
],
81+
responses={
82+
400: {
83+
"model": auth_schemas.ResponseSchema,
84+
"description": "A response object that indicates something went wrong!",
85+
},
86+
200: {
87+
"model": nfts_schemas.UploadImageResponseSchema,
88+
"description": "A response object that contains an ipfs url of the image.",
89+
},
90+
},
8291
)
8392
async def upload_nft_image(
8493
file: UploadFile = File(...),
@@ -108,14 +117,14 @@ async def upload_nft_image(
108117
@router.post(
109118
"/nft/upload-mint-nft",
110119
name="nft:upload-mint-nft",
111-
# response_model=Any,
112-
# responses={
113-
# 201: {
114-
# "model": Any,
115-
# "description": "A response object that contains info about"
116-
# " a wallet.",
117-
# },
118-
# },
120+
response_model=auth_schemas.ResponseSchema,
121+
responses={
122+
200: {
123+
"model": auth_schemas.ResponseSchema,
124+
"description": "A response object that indicates an nft"
125+
" has been minted successfully!",
126+
},
127+
},
119128
)
120129
async def upload_nft_image_and_mint_nft(
121130
nft_info: nfts_schemas.NFTBase64ObjectSchema,
@@ -144,14 +153,14 @@ async def upload_nft_image_and_mint_nft(
144153
@router.get(
145154
"/nft/get-wallet-nfts",
146155
name="nft:get-wallet-nfts",
147-
# response_model=Any,
148-
# responses={
149-
# 201: {
150-
# "model": Any,
151-
# "description": "A response object that contains info about"
152-
# " a wallet.",
153-
# },
154-
# },
156+
response_model=nfts_schemas.ResponseSchema,
157+
responses={
158+
200: {
159+
"model": Any,
160+
"description": "A response object that contains info about"
161+
" a given wallet nfts.",
162+
},
163+
},
155164
)
156165
async def fetch_all_nfts(
157166
current_wallet: Any = Depends(jwt.get_current_active_wallet),
@@ -166,14 +175,14 @@ async def fetch_all_nfts(
166175
@router.get(
167176
"/nft/get-all",
168177
name="nft:get-wallets-nfts",
169-
# response_model=Any,
170-
# responses={
171-
# 201: {
172-
# "model": Any,
173-
# "description": "A response object that contains info about"
174-
# " a wallet.",
175-
# },
176-
# },
178+
response_model=nfts_schemas.ResponseSchema,
179+
responses={
180+
200: {
181+
"model": nfts_schemas.ResponseSchema,
182+
"description": "A response object that contains info about"
183+
" a all nfts available on the marketplace.",
184+
},
185+
},
177186
)
178187
async def fetch_all_wallets_nfts(
179188
session: AIOSession = Depends(dependencies.get_db_transactional_session),

app/nfts/schemas.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
BaseModel,
55
Field,
66
)
7+
from typing import (
8+
Any,
9+
Dict,
10+
List,
11+
Optional,
12+
)
713

814

915
class NFTObjectSchema(BaseModel):
@@ -25,3 +31,23 @@ class NFTBase64ObjectSchema(BaseModel):
2531
author_avatar: str = Field(..., example="Owner profile picture.")
2632
title: str = Field(..., example="Your NFT title.")
2733
price: str = Field(..., example="Your NFT price in XRP.")
34+
35+
36+
class ResponseSchema(BaseModel):
37+
"""
38+
A Pydantic class that defines the wallet schema for fetching wallet info.
39+
"""
40+
41+
status_code: int = Field(..., example=200)
42+
results: List[Optional[Dict[str, Any]]] = Field(
43+
..., example="Owner profile picture."
44+
)
45+
46+
47+
class UploadImageResponseSchema(BaseModel):
48+
"""
49+
A Pydantic class that defines the wallet schema for fetching wallet info.
50+
"""
51+
52+
status_code: int = Field(..., example=200)
53+
url: str = Field(..., example="IPFS URL of the image.")

app/wallets/crud.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ async def get_wallet_info(classic_address: str, session: AIOSession) -> Dict[str
120120
for nft_token in account_nfts:
121121
meta_data_url = hex_to_str(nft_token["URI"])
122122
if "png" not in meta_data_url:
123-
meta_data = requests.get(url=meta_data_url, verify=False, timeout=30).text
123+
meta_data = requests.get(url=meta_data_url, timeout=30).text
124124
meta_data_array = meta_data.split(",")
125125
if len(meta_data_array) == 2:
126126
first_name, bio = meta_data_array
@@ -166,7 +166,7 @@ async def update_wallet_info(
166166
meta_data_url = hex_to_str(nft_token["URI"])
167167
# burn it, then mint a new one.
168168
if "png" not in meta_data_url:
169-
meta_data = requests.get(url=meta_data_url, verify=False, timeout=30).text
169+
meta_data = requests.get(url=meta_data_url, timeout=30).text
170170
meta_data_array = meta_data.split(",")
171171
if len(meta_data_array) == 2:
172172
await nfts_crud.burn_nft_token(
@@ -246,9 +246,7 @@ async def get_all_wallet_info(session: AIOSession) -> List[Any]:
246246
for nft_token in account_nfts:
247247
meta_data_url = hex_to_str(nft_token["URI"])
248248
if "png" not in meta_data_url:
249-
meta_data = requests.get(
250-
url=meta_data_url, verify=False, timeout=30
251-
).text
249+
meta_data = requests.get(url=meta_data_url, timeout=30).text
252250
meta_data_array = meta_data.split(",")
253251
if len(meta_data_array) == 2:
254252
first_name, bio = meta_data_array

0 commit comments

Comments
 (0)