support typed url params, add create handlers
This commit is contained in:
+1
-1
@@ -84,7 +84,7 @@ func (*Channel) Read(r *channelReadRequest) (interface{}, error) {
|
||||
return (&Channel{}).load(r.id)
|
||||
}
|
||||
|
||||
func (*Channel) Search(r *channelSearchRequest) (interface{}, error) {
|
||||
func (*Channel) List(r *channelListRequest) (interface{}, error) {
|
||||
db, err := factory.Database.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+15
-6
@@ -13,6 +13,19 @@ const (
|
||||
sqlOrganisationSelect = "SELECT * FROM organisations WHERE " + sqlOrganisationScope
|
||||
)
|
||||
|
||||
func (*Organisation) Create(r *organisationCreateRequest) (interface{}, error) {
|
||||
db, err := factory.Database.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// @todo: permission check if user can add/edit organisation
|
||||
// @todo: make sure archived & deleted entries can not be edited
|
||||
|
||||
o := Organisation{}.New().SetName(r.name).SetID(factory.Sonyflake.NextID())
|
||||
return o, db.Insert("organisation", o)
|
||||
}
|
||||
|
||||
func (*Organisation) Edit(r *organisationEditRequest) (interface{}, error) {
|
||||
db, err := factory.Database.Get()
|
||||
if err != nil {
|
||||
@@ -23,11 +36,7 @@ func (*Organisation) Edit(r *organisationEditRequest) (interface{}, error) {
|
||||
// @todo: make sure archived & deleted entries can not be edited
|
||||
|
||||
o := Organisation{}.New().SetID(r.id).SetName(r.name)
|
||||
if o.GetID() > 0 {
|
||||
return o, db.Replace("organisation", o)
|
||||
}
|
||||
o.SetID(factory.Sonyflake.NextID())
|
||||
return o, db.Insert("organisation", o)
|
||||
return o, db.Replace("organisation", o)
|
||||
}
|
||||
|
||||
func (*Organisation) Remove(r *organisationRemoveRequest) (interface{}, error) {
|
||||
@@ -59,7 +68,7 @@ func (*Organisation) Read(r *organisationReadRequest) (interface{}, error) {
|
||||
return o, db.Get(o, sqlOrganisationSelect+" AND id = ?", r.id)
|
||||
}
|
||||
|
||||
func (*Organisation) Search(r *organisationSearchRequest) (interface{}, error) {
|
||||
func (*Organisation) List(r *organisationListRequest) (interface{}, error) {
|
||||
db, err := factory.Database.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -101,7 +101,7 @@ func (o *organisationEditRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
o.id = chi.URLParam(r, "id")
|
||||
o.id = parseUInt64(chi.URLParam(r, "id"))
|
||||
|
||||
o.name = post["name"]
|
||||
return nil
|
||||
@@ -131,7 +131,7 @@ func (o *organisationRemoveRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
o.id = chi.URLParam(r, "id")
|
||||
o.id = parseUInt64(chi.URLParam(r, "id"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ func (o *organisationArchiveRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
o.id = chi.URLParam(r, "id")
|
||||
o.id = parseUInt64(chi.URLParam(r, "id"))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+16
-6
@@ -13,6 +13,20 @@ const (
|
||||
sqlTeamSelect = "SELECT * FROM teams WHERE " + sqlTeamScope
|
||||
)
|
||||
|
||||
func (*Team) Create(r *teamCreateRequest) (interface{}, error) {
|
||||
db, err := factory.Database.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// @todo: permission check if user can add/edit the team
|
||||
// @todo: make sure archived & deleted entries can not be edited
|
||||
|
||||
t := Team{}.New()
|
||||
t.SetName(r.name).SetMemberIDs(r.members).SetID(factory.Sonyflake.NextID())
|
||||
return t, db.Insert("team", t)
|
||||
}
|
||||
|
||||
func (*Team) Edit(r *teamEditRequest) (interface{}, error) {
|
||||
db, err := factory.Database.Get()
|
||||
if err != nil {
|
||||
@@ -24,11 +38,7 @@ func (*Team) Edit(r *teamEditRequest) (interface{}, error) {
|
||||
|
||||
t := Team{}.New()
|
||||
t.SetID(r.id).SetName(r.name).SetMemberIDs(r.members)
|
||||
if t.GetID() > 0 {
|
||||
return t, db.Replace("team", t)
|
||||
}
|
||||
t.SetID(factory.Sonyflake.NextID())
|
||||
return t, db.Insert("team", t)
|
||||
return t, db.Replace("team", t)
|
||||
}
|
||||
|
||||
func (*Team) Remove(r *teamRemoveRequest) (interface{}, error) {
|
||||
@@ -55,7 +65,7 @@ func (*Team) Read(r *teamReadRequest) (interface{}, error) {
|
||||
return t, db.Get(t, sqlTeamSelect+" AND id = ?", r.id)
|
||||
}
|
||||
|
||||
func (*Team) Search(r *teamSearchRequest) (interface{}, error) {
|
||||
func (*Team) List(r *teamListRequest) (interface{}, error) {
|
||||
db, err := factory.Database.Get()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+6
-6
@@ -103,7 +103,7 @@ func (t *teamEditRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.id = chi.URLParam(r, "id")
|
||||
t.id = parseUInt64(chi.URLParam(r, "id"))
|
||||
|
||||
t.name = post["name"]
|
||||
return nil
|
||||
@@ -133,7 +133,7 @@ func (t *teamReadRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.id = chi.URLParam(r, "id")
|
||||
t.id = parseUInt64(chi.URLParam(r, "id"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func (t *teamRemoveRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.id = chi.URLParam(r, "id")
|
||||
t.id = parseUInt64(chi.URLParam(r, "id"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ func (t *teamArchiveRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.id = chi.URLParam(r, "id")
|
||||
t.id = parseUInt64(chi.URLParam(r, "id"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ func (t *teamMoveRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.id = chi.URLParam(r, "id")
|
||||
t.id = parseUInt64(chi.URLParam(r, "id"))
|
||||
|
||||
t.organisation_id = parseUInt64(post["organisation_id"])
|
||||
return nil
|
||||
@@ -249,7 +249,7 @@ func (t *teamMergeRequest) Fill(r *http.Request) error {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
t.id = chi.URLParam(r, "id")
|
||||
t.id = parseUInt64(chi.URLParam(r, "id"))
|
||||
|
||||
t.destination = parseUInt64(post["destination"])
|
||||
return nil
|
||||
|
||||
@@ -38,7 +38,7 @@ func ({self} *{name|lcfirst}{call.name|capitalize}Request) Fill(r *http.Request)
|
||||
{foreach $call.parameters as $method => $params}
|
||||
{foreach $params as $param}
|
||||
{if strtolower($method) === "path"}
|
||||
{self}.{param.name} = chi.URLParam(r, "{param.name}")
|
||||
{self}.{param.name} = {if ($param.type !== "string")}{$parsers[$param.type]}({/if}chi.URLParam(r, "{param.name}"){if ($param.type !== "string")}){/if}{newline}
|
||||
{elseif substr($param.type, 0, 2) !== '[]'}
|
||||
{self}.{param.name} = {if ($param.type !== "string")}{$parsers[$param.type]}({method|strtolower}["{param.name}"]){else}{method|strtolower}["{param.name}"]{/if}{newline}
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user