started with README.md
This commit is contained in:
parent
5590a793c9
commit
22c080572e
2 changed files with 69 additions and 19 deletions
78
README.md
78
README.md
|
@ -1,14 +1,68 @@
|
||||||
|
### Flask-API managing Users And Events
|
||||||
|
|
||||||
|
A RESTful API that manages events, offering users the ability to schedule, retrieve,
|
||||||
|
update, delete, and be reminded of events with additional advanced features.
|
||||||
|
|
||||||
|
# Flask-API - Interface
|
||||||
|
- The User Will be able to retrieve upcomming event/s
|
||||||
|
- sort by
|
||||||
|
- popularity
|
||||||
|
- date
|
||||||
|
- filter by:
|
||||||
|
- location
|
||||||
|
- The User will be abale to create/update a new event
|
||||||
|
- The User will be able to login/out
|
||||||
|
- The User can `Attend`/`UnAttend` to an event
|
||||||
|
- The Anonymous User will be able to create a new user
|
||||||
|
|
||||||
|
- Event:
|
||||||
|
- (Auth Users) An event is an upcomming Party/Concert/Sport event/etc. It is tied to a user that created this event.
|
||||||
|
|
||||||
|
- Authentication:
|
||||||
|
- The User will be able to login:
|
||||||
|
- The API will generate a JWT token and set the userId inside the Flask session.
|
||||||
|
- The API will return the JWT token in the response cookie header.
|
||||||
|
|
||||||
|
# Backend-reminder
|
||||||
|
- The Users will be able to be reminded of upcoming events.
|
||||||
|
- The backend will Send reminders 30 minutes before the event's scheduled time.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Database
|
||||||
|
- Sqlite(for simplicity use)
|
||||||
|
# Schema
|
||||||
|
- User -
|
||||||
|
- Id (UUID, primary key)
|
||||||
|
- Name (string, required)
|
||||||
|
- Email (string, required, unique)
|
||||||
|
- Password_hash (string, required)
|
||||||
|
- location (string, required)
|
||||||
|
- Event
|
||||||
|
- Id (int, primary key)
|
||||||
|
- Title (string, required)
|
||||||
|
- Description (string, required)
|
||||||
|
- Location (string, required)
|
||||||
|
- Deleted (bool, required)
|
||||||
|
- DueDate (string, required)
|
||||||
|
- User_id (string, required, foreign key)
|
||||||
|
|
||||||
|
- User Event Association (Many to Many)
|
||||||
|
- User_id (string, required, foreign key)
|
||||||
|
- Event_id (Integer, required, foreign key)
|
||||||
|
- Notification Made (bool, required)
|
||||||
|
|
||||||
|
|
||||||
|
# API EndPoints
|
||||||
|
- GET /events (Optional: ?['location' = String, 'sort_by' = Enum('date'/'popularity'/'creation' ) ])
|
||||||
|
- GET /events/{id} - returns a single event
|
||||||
|
- POST /events - create a new event (Auth)
|
||||||
|
- PUT /events/{id} - update an event (Auth + authorized)
|
||||||
|
- DELETE /events/{id} - (Soft)delete an event (Auth + authorized)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
To create the DB in sqlite, make those commends:
|
|
||||||
```
|
|
||||||
flask db init
|
|
||||||
flask db migrate -m "initial migration"
|
|
||||||
flask db upgrade
|
|
||||||
```
|
|
||||||
or
|
|
||||||
```
|
|
||||||
python3 -m flask db init
|
|
||||||
python3 -m flask db migrate -m "initial migration"
|
|
||||||
python3 -m flask db upgrade
|
|
||||||
```
|
|
|
@ -28,15 +28,12 @@ class EventService:
|
||||||
if location:
|
if location:
|
||||||
query = query.filter(Event.location.ilike(f"%{location}%"))
|
query = query.filter(Event.location.ilike(f"%{location}%"))
|
||||||
|
|
||||||
# Sort based on the provided sort_by parameter
|
|
||||||
if sort_by == 'date':
|
if sort_by == 'date':
|
||||||
query = query.order_by(Event.duedate)
|
query = query.order_by(Event.duedate)
|
||||||
elif sort_by == 'popularity':
|
elif sort_by == 'popularity':
|
||||||
query = query.outerjoin(user_event_association).group_by(Event.id).order_by(func.count(user_event_association.c.user_id).desc())
|
query = query.outerjoin(user_event_association).group_by(Event.id).order_by(func.count(user_event_association.c.user_id).desc())
|
||||||
elif sort_by == 'creation':
|
elif sort_by == 'creation':
|
||||||
query = query.order_by(Event.created_at)
|
query = query.order_by(Event.created_at)
|
||||||
else:
|
|
||||||
query = query.order_by(Event.duedate)
|
|
||||||
|
|
||||||
events = query.all()
|
events = query.all()
|
||||||
return [event.to_dict() for event in events]
|
return [event.to_dict() for event in events]
|
||||||
|
@ -51,7 +48,7 @@ class EventService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_event(event_id, data):
|
def update_event(event_id, data):
|
||||||
event = Event.query.get(event_id)
|
event = Event.query.filter_by(user_id=g.user_id, id=event_id).first()
|
||||||
if not event:
|
if not event:
|
||||||
return None
|
return None
|
||||||
event.title = data['title']
|
event.title = data['title']
|
||||||
|
@ -63,7 +60,7 @@ class EventService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delete_event(event_id):
|
def delete_event(event_id):
|
||||||
event = Event.query.filter_by(id=event_id, deleted=False).first()
|
event = Event.query.filter_by(id=event_id, user_id=g.user_id, deleted=False).first()
|
||||||
if event:
|
if event:
|
||||||
event.deleted = True
|
event.deleted = True
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -74,8 +71,7 @@ class EventService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def attend_event(event_id):
|
def attend_event(event_id):
|
||||||
user_id = g.user_id # Assuming user_id is stored in Flask's global g object
|
user_id = g.user_id
|
||||||
# Check if the event is valid and in the future
|
|
||||||
event = Event.query.filter(
|
event = Event.query.filter(
|
||||||
Event.id == event_id,
|
Event.id == event_id,
|
||||||
Event.duedate > datetime.now(),
|
Event.duedate > datetime.now(),
|
||||||
|
|
Loading…
Reference in a new issue