This Flask application is a RESTful API that manages items, stores, tags, and user-related operations. The API utilizes Flask-Restful, SQLAlchemy for database interactions, and JSON Web Tokens (JWT) for user authentication.
-
items.py
- Flask RESTful resource for handling operations on items.
- Endpoints: GET, DELETE, UPDATE specific items, GET all items.
-
stores.py
- Flask RESTful resource for handling operations on stores.
- Endpoints: GET, DELETE, UPDATE specific stores, GET all stores.
-
tags.py
- Flask RESTful resource for handling operations on tags.
- Endpoints: GET tags in a store, POST a tag to a store, POST linking tags to items, DELETE a tag.
-
users.py
- Flask RESTful resource for handling user-related operations.
- Endpoints: User registration, login, token refresh, logout, user retrieval.
The ItemModel
represents an item in the store. It is designed to store information such as the item's name, description, price, and the store it belongs to. The model also handles the relationships with tags through a many-to-many relationship using the ItemTags
model.
id
: Integer, Primary Key, unique identifier for the item.name
: String, unique name of the item.description
: String, description of the item.price
: Float, price of the item.store_id
: Integer, Foreign Key (referencesstores.id
), the ID of the store to which the item belongs.store
: Relationship withStoreModel
, representing the store to which the item belongs.tags
: Relationship withTagModel
, representing the tags associated with the item.
The ItemTags
model establishes a many-to-many relationship between items and tags. It serves as a link between ItemModel
and TagModel
.
id
: Integer, Primary Key, unique identifier for the item-tag relationship.item_id
: Integer, Foreign Key (referencesitems.id
), the ID of the item in the relationship.tag_id
: Integer, Foreign Key (referencestags.id
), the ID of the tag in the relationship.
The StoreModel
represents a store in the system. It includes information about the store's name and maintains relationships with items and tags associated with the store.
id
: Integer, Primary Key, unique identifier for the store.name
: String, unique name of the store.items
: Relationship withItemModel
, representing the items associated with the store.tags
: Relationship withTagModel
, representing the tags associated with the store.
The TagModel
represents a tag that can be associated with items. It includes information about the tag's name and maintains relationships with items and the store to which it belongs.
id
: Integer, Primary Key, unique identifier for the tag.name
: String, unique name of the tag.store_id
: Integer, Foreign Key (referencesstores.id
), the ID of the store to which the tag belongs.store
: Relationship withStoreModel
, representing the store to which the tag belongs.items
: Relationship withItemModel
, representing the items associated with the tag.
The UserModel
represents a user in the system. It includes information about the user's username and password.
id
: Integer, Primary Key, unique identifier for the user.username
: String, unique username of the user.password
: String, hashed password of the user.
-
Install dependencies:
pip install -r requirements.txt
-
Run the application:
python app.py
-
Access the API at
http://localhost:5000
.
-
GET /item/int:item_id: Get a specific item by item_id.
-
DELETE /item/int:item_id: Delete a specific item by item_id (requires admin privilege).
-
PUT /item/int:item_id: Update a specific item by item_id.
-
GET /item: Get all items.
-
POST /item: Create a new item.
-
GET /store/int:store_id: Get a specific store by store_id.
-
DELETE /store/int:store_id: Delete a specific store by store_id (requires admin privilege).
-
PUT /store/int:store_id: Update a specific store by store_id.
-
GET /store: Get all stores.
-
POST /store: Create a new store.
-
GET /store/int:store_id/tag: Get all tags in a specific store by store_id.
-
POST /store/int:store_id/tag: Create a new tag in a specific store by store_id.
-
POST /item/int:item_id/tag/string:tag_id: Add a specific tag to a specific item.
-
DELETE /item/int:item_id/tag/string:tag_id: Remove a specific tag from a specific item.
-
GET /tag/int:tag_id: Get a specific tag by tag_id.
-
DELETE /tag/int:tag_id: Delete a specific tag by tag_id.
-
POST /register: Register a new user.
-
POST /login: Log in a user.
-
POST /refresh: Refresh the access token.
-
POST /logout: Log out a user.
-
GET /user/int:user_id: Get a specific user by user_id.
-
DELETE /user/int:user_id: Delete a specific user by user_id (requires admin privilege).
- Flask
- Flask-Restful
- Flask-SQLAlchemy
- Flask-JWT-Extended
- Passlib
- Flask-Smorest
- python-Dotenv
- SQLAlchemy
- Flask-Migrate
- Gunicorn
- Blocklist
- Psycopg2-Binary
This project is not open to Contribution at this moment. The project is solely built in response to ALX Webstack (Portfolio) Project for Cohort 11
This project is licensed under the GNU General Public License.
- The API uses JWT for user authentication, and certain endpoints require admin privileges.
- Error handling is implemented to provide informative responses.
- The API is designed to manage stores, items, tags, and user authentication in a secure and efficient manner.
Feel free to explore the different endpoints and functionalities provided by the API!