-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
95 lines (81 loc) · 2.77 KB
/
Copy pathapp.py
File metadata and controls
95 lines (81 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Events API deployed through the GitHub Actions CI/CD pipeline.
from flask import Flask, jsonify, send_from_directory
from flask_cors import CORS
from flask_jwt_extended import JWTManager
from flask_swagger_ui import get_swaggerui_blueprint
from config import Config
from models import db
from routes.auth import auth_bp
from routes.events import events_bp
from routes.rsvps import rsvps_bp
import yaml
import os
def create_app(config_override=None):
app = Flask(__name__)
app.config.from_object(Config)
if config_override:
app.config.update(config_override)
# Initialize extensions
db.init_app(app)
CORS(app)
jwt = JWTManager(app)
# Swagger UI configuration
SWAGGER_URL = '/apidocs'
API_URL = '/api/openapi.yaml'
swaggerui_blueprint = get_swaggerui_blueprint(
SWAGGER_URL,
API_URL,
config={
'app_name': "Evently API"
}
)
app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)
# Serve OpenAPI spec file
@app.route('/api/openapi.yaml')
def serve_openapi():
return send_from_directory(os.path.dirname(os.path.abspath(__file__)), 'openapi.yaml')
# Register blueprints
app.register_blueprint(auth_bp)
app.register_blueprint(events_bp)
app.register_blueprint(rsvps_bp)
# Create tables
with app.app_context():
db.create_all()
# Root endpoint
@app.route('/', methods=['GET'])
def root():
return jsonify({
'name': 'Evently API',
'version': '1.0.0',
'description': 'A Flask-based REST API for managing events and RSVPs with different access levels',
'documentation': {
'swagger_ui': '/apidocs',
'openapi_spec': '/api/openapi.yaml'
},
'endpoints': {
'health': '/api/health',
'auth': {
'register': '/api/auth/register',
'login': '/api/auth/login'
},
'events': {
'list': '/api/events',
'get': '/api/events/{id}',
'create': '/api/events'
},
'rsvps': {
'rsvp': '/api/rsvps/event/{event_id}',
'get_rsvps': '/api/rsvps/event/{event_id}'
}
}
}), 200
# Health check endpoint
@app.route('/api/health', methods=['GET'])
def health():
return jsonify({'status': 'healthy'}), 200
return app
if __name__ == '__main__':
app = create_app()
debug = os.environ.get('FLASK_DEBUG', '').lower() in {'1', 'true', 'yes'}
port = int(os.environ.get('PORT', '5000'))
app.run(debug=debug, host='0.0.0.0', port=port)