Added readall attachments
This commit is contained in:
parent
6455120b49
commit
05c71b6c75
|
@ -30,7 +30,7 @@ type TaskAttachment struct {
|
|||
CreatedByID int64 `xorm:"int(11) not null" json:"-"`
|
||||
CreatedBy *User `xorm:"-" json:"created_by"`
|
||||
|
||||
File *files.File `xorm:"-" json:"-"`
|
||||
File *files.File `xorm:"extends" json:"file"`
|
||||
|
||||
Created int64 `xorm:"created"`
|
||||
|
||||
|
@ -38,6 +38,10 @@ type TaskAttachment struct {
|
|||
web.Rights `xorm:"-" json:"-"`
|
||||
}
|
||||
|
||||
func (TaskAttachment) TableName() string {
|
||||
return "task_attachments"
|
||||
}
|
||||
|
||||
// Create creates a new task attachment
|
||||
func (ta *TaskAttachment) Create(a web.Auth) error {
|
||||
|
||||
|
@ -77,16 +81,18 @@ func (ta *TaskAttachment) ReadOne() (err error) {
|
|||
// Get the file
|
||||
ta.File.ID = ta.FileID
|
||||
err = ta.File.GetFileByID()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// ReadAll returns a list with all attachments
|
||||
func (ta *TaskAttachment) ReadAll(string, web.Auth, int) (interface{}, error) {
|
||||
panic("implement me")
|
||||
func (ta *TaskAttachment) ReadAll(s string, a web.Auth, page int) (interface{}, error) {
|
||||
result := []*TaskAttachment{}
|
||||
|
||||
err := x.
|
||||
Limit(getLimitFromPageIndex(page)).
|
||||
Join("LEFT", "files", "task_attachments.file_id = files.id").
|
||||
Find(result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Delete removes an attachment
|
||||
|
|
|
@ -266,6 +266,13 @@ func registerAPIRoutes(a *echo.Group) {
|
|||
a.PUT("/tasks/:task/relations", taskRelationHandler.CreateWeb)
|
||||
a.DELETE("/tasks/:task/relations", taskRelationHandler.DeleteWeb)
|
||||
|
||||
taskAttachmentHandler := &handler.WebHandler{
|
||||
EmptyStruct: func() handler.CObject {
|
||||
return &models.TaskAttachment{}
|
||||
},
|
||||
}
|
||||
a.GET("/tasks/:task/attachments", taskAttachmentHandler.ReadAllWeb)
|
||||
a.DELETE("/tasks/:task/attachments/:attachment", taskAttachmentHandler.DeleteWeb)
|
||||
a.PUT("/tasks/:task/attachments", apiv1.UploadTaskAttachment)
|
||||
a.GET("/tasks/:task/attachments/:attachment", apiv1.GetTaskAttachment)
|
||||
|
||||
|
|
Loading…
Reference in New Issue