71 lines
1.2 KiB
Crystal
71 lines
1.2 KiB
Crystal
|
require "uuid"
|
||
|
require "uuid/json"
|
||
|
|
||
|
class TodoD
|
||
|
end
|
||
|
|
||
|
class TodoD::List
|
||
|
enum PermissionLevel
|
||
|
None = -1
|
||
|
Read
|
||
|
Post
|
||
|
Edit
|
||
|
Admin
|
||
|
|
||
|
def to_json(o)
|
||
|
to_s.downcase.to_json(o)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
JSON.mapping({
|
||
|
id: String,
|
||
|
title: String,
|
||
|
permissions: Hash(String, Array(Int32)),
|
||
|
extra_properties: Hash(String, JSON::Any),
|
||
|
tasks: {
|
||
|
type: Array(String),
|
||
|
default: [] of String
|
||
|
}
|
||
|
})
|
||
|
|
||
|
def initialize(@title, user, @extra_properties = Hash(String, JSON::Any).new)
|
||
|
@id = UUID.random.to_s
|
||
|
@permissions = {
|
||
|
"admin" => [user.uid],
|
||
|
"edit" => [] of Int32,
|
||
|
"post" => [] of Int32,
|
||
|
"read" => [] of Int32
|
||
|
}
|
||
|
@tasks = [] of String
|
||
|
end
|
||
|
end
|
||
|
|
||
|
class TodoD::Task
|
||
|
# Should we hardcode more properties here?
|
||
|
JSON.mapping({
|
||
|
id: String,
|
||
|
list: String,
|
||
|
title: String,
|
||
|
description: {
|
||
|
type: String,
|
||
|
default: ""
|
||
|
},
|
||
|
creator: Int32,
|
||
|
assigned_to: Int32?,
|
||
|
priority: String?,
|
||
|
tags: {
|
||
|
type: Array(String),
|
||
|
default: [] of String
|
||
|
},
|
||
|
extra_properties: {
|
||
|
type: Hash(String, JSON::Any),
|
||
|
default: {} of String => JSON::Any
|
||
|
}
|
||
|
})
|
||
|
|
||
|
def initialize(@list, @title, @creator, @description = "", @assigned_to = nil, @priority = nil, @tags = [] of String, @extra_properties = {} of String => JSON::Any)
|
||
|
@id = UUID.random.to_s
|
||
|
end
|
||
|
end
|
||
|
|