go-mcm/model/ticketnote.go

47 lines
1.0 KiB
Go
Raw Normal View History

2019-10-02 19:03:23 +00:00
package model
import (
"encoding/json"
2019-10-03 20:22:22 +00:00
"go.etztech.xyz/go-mcm/internal"
2019-10-02 19:03:23 +00:00
"go.etztech.xyz/go-mcm/model/django"
)
type TicketNote struct {
ID int64 `json:"id"`
AuthorID int64 `json:"author_id"`
TicketID int64 `json:"ticket_id"`
Message string `json:"message"`
LastUpdate string `json:"last_update"`
Date string `json:"date"`
Link string `json:"link"`
2019-11-24 21:20:07 +00:00
model *Model `json:"-"`
2019-10-02 19:03:23 +00:00
}
2019-10-03 20:22:22 +00:00
func (q *Model) TicketNote(builder *django.Builder) ([]*TicketNote, error) {
2019-11-24 21:20:07 +00:00
endpoint := q.queryEndpoint("ticketnote", builder.QueryString())
2019-10-02 19:03:23 +00:00
ticketNotes := make([]*TicketNote, 0)
2019-10-03 20:22:22 +00:00
resp, err := internal.ResponseGet(endpoint)
2019-10-02 19:03:23 +00:00
if err != nil {
return nil, err
}
err = json.Unmarshal(resp, &ticketNotes)
if err != nil {
return nil, err
}
2019-11-24 21:20:07 +00:00
for _, ticketNote := range ticketNotes {
ticketNote.model = q
}
2019-10-02 19:03:23 +00:00
return ticketNotes, nil
}
2019-11-24 21:20:07 +00:00
func (t *TicketNote) Save() (*internal.Status, error) {
endpoint := t.model.endpoint("ticketnote")
return internal.ResponseStatus(endpoint, t.model.Values(t))
}