def create_category(title: str):
     """
     Create new section if the params fields are valid and section is not created before.
     :param title: "section title",
     :return:
     """
     category = CategoryModel(title=title)
     category.save_to_db()
     return category
Beispiel #2
0
    def post(self):
        args = request.args
        title = args["title"]
        existing_category = CategoryModel.find_by_title(title)
        if existing_category:
            return {"message": "Category already exists"}, 409
        """ Saving title in capitalized letter. Which can prevent inconsistency in finding existing category title. """
        category = CategoryModel(title.capitalize())
        category.save_to_db()

        return {"message": "Category added"}, 201