Compare commits
No commits in common. "0c7f0f4ca467883a2ed746bac14a23d43d8ac151" and "573fbcc7ea4d0da590dd3e996fcf9c954764771b" have entirely different histories.
0c7f0f4ca4
...
573fbcc7ea
4 changed files with 12 additions and 58 deletions
22
README.md
22
README.md
|
@ -12,6 +12,7 @@ update, delete, and be reminded of events with additional advanced features.
|
||||||
- location
|
- location
|
||||||
- The User will be abale to create/update a new event
|
- The User will be abale to create/update a new event
|
||||||
- The User will be able to login/out
|
- 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
|
- The Anonymous User will be able to create a new user
|
||||||
|
|
||||||
- Event:
|
- Event:
|
||||||
|
@ -24,7 +25,9 @@ update, delete, and be reminded of events with additional advanced features.
|
||||||
|
|
||||||
# Backend-reminder
|
# Backend-reminder
|
||||||
- The Users will be able to be reminded of upcoming events.
|
- The Users will be able to be reminded of upcoming events.
|
||||||
- The backend will Send reminders 30 minutes before the event's scheduled time based on there location and the event location.
|
- The backend will Send reminders 30 minutes before the event's scheduled time.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,9 +49,10 @@ update, delete, and be reminded of events with additional advanced features.
|
||||||
- DueDate (string, required)
|
- DueDate (string, required)
|
||||||
- User_id (string, required, foreign key)
|
- User_id (string, required, foreign key)
|
||||||
|
|
||||||
- User Event Association (Many to Many) - this table will hold the notifyed users to the event
|
- User Event Association (Many to Many)
|
||||||
- User_id (string, required, foreign key, primary key)
|
- User_id (string, required, foreign key)
|
||||||
- Event_id (Integer, required, foreign key, primary key)
|
- Event_id (Integer, required, foreign key)
|
||||||
|
- Notifiyed Made (bool, default: false)
|
||||||
|
|
||||||
|
|
||||||
# API EndPoints
|
# API EndPoints
|
||||||
|
@ -58,19 +62,9 @@ update, delete, and be reminded of events with additional advanced features.
|
||||||
- PUT /events/{id} - update an event (Auth + authorized)
|
- PUT /events/{id} - update an event (Auth + authorized)
|
||||||
- DELETE /events/{id} - (Soft)delete an event (Auth + authorized)
|
- DELETE /events/{id} - (Soft)delete an event (Auth + authorized)
|
||||||
|
|
||||||
- GET /user - returns all users
|
|
||||||
- GET /user/{id} - returns a single user
|
|
||||||
- POST /user - create a new user
|
|
||||||
- PUT /user/{id} - update an user (Auth + authorized)
|
|
||||||
- DELETE /user/{id} - (Soft)delete an user (Auth + authorized)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Application init flow
|
|
||||||
- init schaduler
|
|
||||||
- run the flask app
|
|
||||||
|
|
||||||
|
|
||||||
# how to run?
|
# how to run?
|
||||||
- pip install -r requirements.txt
|
- pip install -r requirements.txt
|
||||||
- flask db upgrade
|
- flask db upgrade
|
||||||
|
|
3
app.py
3
app.py
|
@ -27,8 +27,7 @@ class App:
|
||||||
self.scheduler.init_app(self.app)
|
self.scheduler.init_app(self.app)
|
||||||
self.scheduler.start()
|
self.scheduler.start()
|
||||||
# Schedule the job
|
# Schedule the job
|
||||||
self.scheduler.add_job(id='notifyUpcommingEvents', func=self.notifyUpcommingEvents, trigger='interval', minutes=30)
|
self.scheduler.add_job(id='notifyUpcommingEvents', func=self.notifyUpcommingEvents, trigger='interval', seconds=1)
|
||||||
print("Scheduler started")
|
|
||||||
|
|
||||||
|
|
||||||
def set_config(self):
|
def set_config(self):
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from flask import Blueprint, jsonify, request, g
|
from flask import Blueprint, jsonify, request
|
||||||
from services.UserService import UserService
|
from services.UserService import UserService
|
||||||
from flask_jwt_extended import JWTManager, jwt_required, create_access_token
|
from flask_jwt_extended import JWTManager, jwt_required, create_access_token
|
||||||
from middlewares.userMiddlewares import validate_user_post_request, validate_user_login_request, authenticate_user
|
from middlewares.userMiddlewares import validate_user_post_request, validate_user_login_request
|
||||||
|
|
||||||
userRoutes = Blueprint('userRoutes', __name__)
|
userRoutes = Blueprint('userRoutes', __name__)
|
||||||
|
|
||||||
|
@ -11,30 +11,6 @@ def allUsers():
|
||||||
users = UserService.get_all_users()
|
users = UserService.get_all_users()
|
||||||
return jsonify(users), 200
|
return jsonify(users), 200
|
||||||
|
|
||||||
@userRoutes.route('/<string:user_id>', methods=['GET'])
|
|
||||||
def getUser(user_id):
|
|
||||||
user = UserService.get_user_by_id(user_id)
|
|
||||||
if user:
|
|
||||||
return jsonify(user), 200
|
|
||||||
else:
|
|
||||||
return jsonify({'error': 'User not found'}), 404
|
|
||||||
|
|
||||||
@userRoutes.route('/<string:user_id>', methods=['PUT'])
|
|
||||||
@validate_user_post_request
|
|
||||||
@authenticate_user
|
|
||||||
def updateUser(user_id):
|
|
||||||
try:
|
|
||||||
if user_id != g.user_id:
|
|
||||||
return jsonify({'error': 'Unauthorized'}), 401
|
|
||||||
data = request.json
|
|
||||||
updated_user = UserService.update_user(user_id, data)
|
|
||||||
if updated_user:
|
|
||||||
return jsonify(updated_user), 200
|
|
||||||
else:
|
|
||||||
return jsonify({'error': 'User not found'}), 404
|
|
||||||
except Exception as e:
|
|
||||||
return jsonify({'error': str(e)}), 500
|
|
||||||
|
|
||||||
@userRoutes.route('/', methods=['POST'])
|
@userRoutes.route('/', methods=['POST'])
|
||||||
@userRoutes.route('', methods=['POST'])
|
@userRoutes.route('', methods=['POST'])
|
||||||
@validate_user_post_request
|
@validate_user_post_request
|
||||||
|
|
|
@ -28,10 +28,7 @@ class UserService:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_user_by_id(user_id):
|
def get_user_by_id(user_id):
|
||||||
user = User.query.filter_by(id=user_id).first()
|
return User.query.get(user_id)
|
||||||
if user:
|
|
||||||
return user.to_dict()
|
|
||||||
return
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def verify_user(data):
|
def verify_user(data):
|
||||||
|
@ -47,15 +44,3 @@ class UserService:
|
||||||
return [user.to_dict() for user in users]
|
return [user.to_dict() for user in users]
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def update_user(user_id, data):
|
|
||||||
# update user
|
|
||||||
user = User.query.filter_by(id=user_id).first()
|
|
||||||
if user:
|
|
||||||
user.name = data['username']
|
|
||||||
user.email = data['email']
|
|
||||||
user.location = data['location']
|
|
||||||
db.session.commit()
|
|
||||||
return user.to_dict()
|
|
||||||
return None
|
|
||||||
|
|
Loading…
Reference in a new issue