Ejemplo n.º 1
0
def rec_detail(recommendation_id):
    """ Manage Recommendation Detail"""
    rec = Recommendation.find_by_id(recommendation_id)
    recJSON = rec.serialize()
    return render_template(
        'manage/detail.html',
        detail_id=recJSON["id"],
        product_id=recJSON["product_id"],
        rec_type=recJSON["rec_type"]["id"],
        rec_product_id=recJSON["rec_product_id"],
        weight=recJSON["weight"],
        status=recJSON["rec_type"]["is_active"]), status.HTTP_200_OK
Ejemplo n.º 2
0
    def delete(self, recommendation_id):
        """ Delete a Recommendation

        This endpoint will delete a Recommendation based the id specified in the path
        """
        recommendation = Recommendation.find_by_id(recommendation_id)

        if not recommendation:
            raise NotFound("Recommendation with id '{}' was not found.".format(
                recommendation_id))

        recommendation.delete()

        return '', status.HTTP_204_NO_CONTENT
Ejemplo n.º 3
0
    def put(self, recommendation_id):
        """ Update a Recommendation

        This endpoint will update a Recommendations based the body that is posted
        """
        recommendation = Recommendation.find_by_id(recommendation_id)

        if not recommendation:
            raise NotFound("Recommendation with id '{}' was not found.".format(
                recommendation_id))

        recommendation.deserialize(request.get_json())
        recommendation.id = recommendation_id
        recommendation.save()

        return recommendation.serialize(), status.HTTP_200_OK
Ejemplo n.º 4
0
    def get(self, recommendation_id):
        """ Retrieve a single Recommendation

        This endpoint will return a Recommendations based on it's id
        """
        recommendation = Recommendation.find_by_id(recommendation_id)

        recJSON = ""
        if not recommendation:
            raise NotFound(
                "Recommendations with id '{}' was not found.".format(
                    recommendation_id))
        else:
            recJSON = recommendation.serialize()

        return recJSON, status.HTTP_200_OK