1
0

implemented readone with parambinder

This commit is contained in:
konrad
2018-07-21 15:08:46 +02:00
committed by kolaente
parent d06ed68125
commit 9e75e9b73b
9 changed files with 44 additions and 42 deletions

View File

@ -3,7 +3,7 @@ package models
// CRUDable defines the crud methods
type CRUDable interface {
Create(*User) error
ReadOne(int64) error
ReadOne() error
ReadAll(*User) (interface{}, error)
Update(int64) error
Delete() error

View File

@ -2,11 +2,11 @@ package models
// List represents a list of items
type List struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"listid"`
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"list"`
Title string `xorm:"varchar(250)" json:"title"`
Description string `xorm:"varchar(1000)" json:"description"`
OwnerID int64 `xorm:"int(11)" json:"-"`
NamespaceID int64 `xorm:"int(11)" json:"-" param:"nid"`
NamespaceID int64 `xorm:"int(11)" json:"-" param:"namespace"`
Owner User `xorm:"-" json:"owner"`
Items []*ListItem `xorm:"-" json:"items"`
@ -75,7 +75,7 @@ func (l *List) ReadAll(user *User) (interface{}, error) {
}
// ReadOne gets one list by its ID
func (l *List) ReadOne(id int64) (err error) {
*l, err = GetListByID(id)
func (l *List) ReadOne() (err error) {
*l, err = GetListByID(l.ID)
return
}

View File

@ -9,7 +9,7 @@ type ListItem struct {
DueDateUnix int64 `xorm:"int(11)" json:"dueDate"`
ReminderUnix int64 `xorm:"int(11)" json:"reminderDate"`
CreatedByID int64 `xorm:"int(11)" json:"-"` // ID of the user who put that item on the list
ListID int64 `xorm:"int(11)" json:"listID" param:"listid"`
ListID int64 `xorm:"int(11)" json:"listID" param:"list"`
Created int64 `xorm:"created" json:"created"`
Updated int64 `xorm:"updated" json:"updated"`

View File

@ -2,7 +2,7 @@ package models
// Namespace holds informations about a namespace
type Namespace struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"nid"`
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"namespace"`
Name string `xorm:"varchar(250)" json:"name"`
Description string `xorm:"varchar(1000)" json:"description"`
OwnerID int64 `xorm:"int(11) not null" json:"-"`
@ -48,15 +48,15 @@ func GetNamespaceByID(id int64) (namespace Namespace, err error) {
}
// ReadOne gets one namespace
func (n *Namespace) ReadOne(id int64) (err error) {
func (n *Namespace) ReadOne() (err error) {
getN := Namespace{}
exists, err := x.ID(id).Get(&getN)
exists, err := x.ID(n.ID).Get(&getN)
if err != nil {
return
}
if !exists {
return ErrNamespaceDoesNotExist{ID: id}
return ErrNamespaceDoesNotExist{ID: n.ID}
}
*n = getN

View File

@ -2,7 +2,7 @@ package models
// Team holds a team object
type Team struct {
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"teamid"`
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"team"`
Name string `xorm:"varchar(250) not null" json:"name"`
Description string `xorm:"varchar(250)" json:"description"`
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
@ -100,8 +100,8 @@ func GetTeamByID(id int64) (team Team, err error) {
}
// ReadOne implements the CRUD method to get one team
func (t *Team) ReadOne(id int64) (err error) {
*t, err = GetTeamByID(id)
func (t *Team) ReadOne() (err error) {
*t, err = GetTeamByID(t.ID)
return
}