Add backend for creating a category
This commit is contained in:
parent
a05667ef78
commit
3b681e32f6
1 changed files with 21 additions and 0 deletions
|
|
@ -665,6 +665,12 @@ proc executeLike(c: TForumData, postId: int) =
|
|||
# Save the like.
|
||||
exec(db, crud(crCreate, "like", "author", "post"), c.userid, postId)
|
||||
|
||||
proc executeNewCategory(c: TForumData, name, color, description: string): int64 =
|
||||
if name.len == 0:
|
||||
raise newForumError("Category name must not be empty!", @["name"])
|
||||
|
||||
result = insertID(db, crud(crCreate, "category", "name", "color", "description"), name, color, description)
|
||||
|
||||
proc executeUnlike(c: TForumData, postId: int) =
|
||||
# Verify the post and like exists for the current user.
|
||||
const likeQuery = sql"""
|
||||
|
|
@ -1051,6 +1057,21 @@ routes:
|
|||
except ForumError as exc:
|
||||
resp Http400, $(%exc.data), "application/json"
|
||||
|
||||
post "/createCategory":
|
||||
createTFD()
|
||||
let formData = request.formData
|
||||
|
||||
let name = formData["name"].body
|
||||
let color = formData["color"].body.replace("#", "")
|
||||
let description = formData["description"].body
|
||||
|
||||
try:
|
||||
let id = executeNewCategory(c, name, color, description)
|
||||
let category = Category(id: id.int, name: name, color: color, description: description)
|
||||
resp Http200, $(%category), "application/json"
|
||||
except ForumError as exc:
|
||||
resp Http400, $(%exc.data), "application/json"
|
||||
|
||||
get "/status.json":
|
||||
createTFD()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue