Skip to content
Snippets Groups Projects
Commit 88c30e01 authored by Carl Schönfelder's avatar Carl Schönfelder
Browse files

add: crud-api for City

parent 09a728c0
No related branches found
No related tags found
No related merge requests found
Pipeline #38647 passed
import app.core.controller as dbc
from app.core.dto import MiscDTO from app.core.dto import MiscDTO
from app.core.models import City, MediaType, QuestionType, Role from app.core.models import City, MediaType, QuestionType, Role
from flask_jwt_extended import jwt_required from flask_jwt_extended import jwt_required
from flask_restx import Resource from flask_restx import Resource, reqparse
api = MiscDTO.api api = MiscDTO.api
...@@ -11,6 +12,10 @@ role_model = MiscDTO.role_model ...@@ -11,6 +12,10 @@ role_model = MiscDTO.role_model
city_model = MiscDTO.city_model city_model = MiscDTO.city_model
name_parser = reqparse.RequestParser()
name_parser.add_argument("name", type=str, required=True, location="json")
@api.route("/media_types") @api.route("/media_types")
class MediaTypeList(Resource): class MediaTypeList(Resource):
@jwt_required @jwt_required
...@@ -36,8 +41,35 @@ class RoleList(Resource): ...@@ -36,8 +41,35 @@ class RoleList(Resource):
@api.route("/cities") @api.route("/cities")
class CityList(Resource): class CitiesList(Resource):
@jwt_required @jwt_required
@api.marshal_with(city_model) @api.marshal_with(city_model)
def get(self): def get(self):
return City.query.all() return City.query.all()
@jwt_required
@api.marshal_with(role_model)
def post(self):
args = name_parser.parse_args(strict=True)
dbc.add.default(City(args["name"]))
return City.query.all()
@api.route("/cities/<ID>")
@api.param("ID")
class Cities(Resource):
@jwt_required
@api.marshal_with(city_model)
def put(self, ID):
item = City.query.filter(City.id == ID).first()
args = name_parser.parse_args(strict=True)
item.name = args["name"]
dbc.edit.default(item)
return City.query.all()
@jwt_required
@api.marshal_with(city_model)
def delete(self, ID):
item = City.query.filter(City.id == ID).first()
dbc.delete.default(item)
return City.query.all()
import math
from app.core import db from app.core import db
from app.core.models import Blacklist, City, Competition, Role, Slide, User
def default(item):
db.session.commit()
db.session.refresh(item)
return item
def switch_order(item1, item2): def switch_order(item1, item2):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment