33 lines
1.0 KiB
Python
33 lines
1.0 KiB
Python
import pdb
|
|
|
|
from flask import Blueprint, jsonify, request
|
|
|
|
from app import db
|
|
from app.models import Station
|
|
from presenter import StationPresenter
|
|
from utils import create_response, StateCode
|
|
|
|
trains_bp = Blueprint('stations', __name__)
|
|
|
|
|
|
@trains_bp.route('/trains/query_train', methods=['GET'])
|
|
def query_train():
|
|
return jsonify({'message': 'Ticket booked successfully'}), 201
|
|
|
|
|
|
@trains_bp.route('/stations', methods=['GET'])
|
|
def query_station():
|
|
stations = Station.query.all()
|
|
stations_presenters = [StationPresenter(station).as_dict() for station in stations]
|
|
return jsonify(create_response(StateCode.SUCCESS, multiple_data={"stations": stations_presenters})), 200
|
|
|
|
|
|
@trains_bp.route('/stations', methods=['POST'])
|
|
def create_station():
|
|
data = request.form
|
|
new_station = Station(data=data)
|
|
db.session.add(new_station)
|
|
db.session.commit()
|
|
station_presenter = StationPresenter(new_station).as_dict()
|
|
return jsonify(create_response(StateCode.SUCCESS, single_data=station_presenter)), 200
|