20 lines
561 B
Python
20 lines
561 B
Python
from flask import Blueprint, jsonify
|
|
from model.Posting import Posting
|
|
from util.flask import not_found_json_response
|
|
|
|
blueprint = Blueprint("api_posting", __name__, url_prefix="/api/posting")
|
|
|
|
|
|
@blueprint.get("/")
|
|
def get_all_posting():
|
|
_posting = Posting.query.all()
|
|
return jsonify([_i.to_json() for _i in _posting])
|
|
|
|
|
|
@blueprint.get("/<int:posting_id>")
|
|
def get_posting_detail(posting_id):
|
|
posting = Posting.query.get(posting_id)
|
|
if posting is None:
|
|
return not_found_json_response(id=posting_id)
|
|
return jsonify(posting.to_dict())
|