Esempio n. 1
0
def create_review(place_id):
    '''This is the 'create_review' method.

    Creates a Review object of a given place.
    '''
    try:
        r = request.get_json()
    except:
        r = None

    if r is None:
        return "Not a JSON", 400
    if "user_id" not in r.keys():
        return "Missing user_id", 400
    if "text" not in r.keys():
        return "Missing text", 400

    place = storage.get("Place", place_id)
    if place is None:
        abort(404)

    user = storage.get("User", r["user_id"])
    if user is None:
        abort(404)

    review = Review(**r)
    review.place_id = place_id
    review.save()
    return jsonify(review.to_json()), 201
Esempio n. 2
0
def create_review(place_id):
    """
    creates one review
    """
    try:
        r = request.get_json()
    except:
        r = None
    if r is None:
        return "Not a JSON", 400
    if "user_id" not in r.keys():
        return "Missing user_id", 400
    if "text" not in r.keys():
        return "Missing text", 400
    place = storage.get("Place", place_id)
    if place is None:
        abort(404)
    user = storage.get("User", r["user_id"])
    if user is None:
        abort(404)
    review = Review(**r)
    review.place_id = place_id
    review.save()
    return jsonify(review.to_json()), 201
def create_review(place_id):
    """Example endpoint creates one review
    Creates one review associated with a place_id based on the JSON body
    ---
    parameters:
      - name: place_id
        in: path
        type: string
        enum: ["3f54d114-582d-4dab-8559-f0682dbf1fa6"]
        required: true
        default: "3f54d114-582d-4dab-8559-f0682dbf1fa6"
    definitions:
      State:
        type: object
        properties:
          __class__:
            type: string
            description: The string of class object
          created_at:
            type: string
            description: The date the object created
          id:
            type: string
            description: the id of the review
          place_id:
            type: string
            description: the id of the place
          text:
            type: string
            description: written review
          updated_at:
            type: string
            description: The date the object was updated
          user_id:
            type: string
            description: The user id
            items:
              $ref: '#/definitions/Color'
      Color:
        type: string
    responses:
      201:
        description: A list of a dictionary of a Review objects
        schema:
          $ref: '#/definitions/State'
        examples:
            [{"__class__": "Review",
              "created_at": "2017-03-25T02:17:07",
              "id": "3f54d114-582d-4dab-8559-f0682dbf1fa6",
              "place_id": "279b355e-ff9a-4b85-8114-6db7ad2a4cd2",
              "text": "Really nice place and really nice people. Secluded.",
              "updated_at": "2017-03-25T02:17:07",
              "user_id": "887dcd8d-d5ee-48de-9626-73ff4ea732fa"}]
    """
    try:
        r = request.get_json()
    except:
        r = None
    if r is None:
        return "Not a JSON", 400
    if "user_id" not in r.keys():
        return "Missing user_id", 400
    if "text" not in r.keys():
        return "Missing text", 400
    place = storage.get("Place", place_id)
    if place is None:
        abort(404)
    user = storage.get("User", r["user_id"])
    if user is None:
        abort(404)
    review = Review(**r)
    review.place_id = place_id
    review.save()
    return jsonify(review.to_json()), 201
Esempio n. 4
0
def create_review(place_id):
    """Example endpoint creates one review
    Creates one review associated with a place_id based on the JSON body
    ---
    parameters:
      - name: place_id
        in: path
        type: string
        enum: ["3f54d114-582d-4dab-8559-f0682dbf1fa6"]
        required: true
        default: "3f54d114-582d-4dab-8559-f0682dbf1fa6"
    definitions:
      State:
        type: object
        properties:
          __class__:
            type: string
            description: The string of class object
          created_at:
            type: string
            description: The date the object created
          id:
            type: string
            description: the id of the review
          place_id:
            type: string
            description: the id of the place
          text:
            type: string
            description: written review
          updated_at:
            type: string
            description: The date the object was updated
          user_id:
            type: string
            description: The user id
            items:
              $ref: '#/definitions/Color'
      Color:
        type: string
    responses:
      201:
        description: A list of a dictionary of a Review objects
        schema:
          $ref: '#/definitions/State'
        examples:
            [{"__class__": "Review",
              "created_at": "2017-03-25T02:17:07",
              "id": "3f54d114-582d-4dab-8559-f0682dbf1fa6",
              "place_id": "279b355e-ff9a-4b85-8114-6db7ad2a4cd2",
              "text": "Really nice place and really nice people. Secluded.",
              "updated_at": "2017-03-25T02:17:07",
              "user_id": "887dcd8d-d5ee-48de-9626-73ff4ea732fa"}]
    """
    try:
        r = request.get_json()
    except:
        r = None
    if r is None:
        return "Not a JSON", 400
    if "user_id" not in r.keys():
        return "Missing user_id", 400
    if "text" not in r.keys():
        return "Missing text", 400
    place = storage.get("Place", place_id)
    if place is None:
        abort(404)
    user = storage.get("User", r["user_id"])
    if user is None:
        abort(404)
    review = Review(**r)
    review.place_id = place_id
    review.save()
    return jsonify(review.to_json()), 201