2024-05-07 21:49:09 +03:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2024-05-10 11:46:43 +03:00
|
|
|
"encoding/json"
|
|
|
|
"strconv"
|
2024-05-07 21:49:09 +03:00
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ErrorResponse struct {
|
2024-05-10 11:46:43 +03:00
|
|
|
Errors []string `json:"errors,omitempty"`
|
2024-05-07 21:49:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e ErrorResponse) Error() string {
|
|
|
|
return strings.Join(e.Errors, "; ")
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e ErrorResponse) IsError() bool {
|
|
|
|
return len(e.Errors) > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
type IssueResponse struct {
|
|
|
|
ErrorResponse
|
|
|
|
Issue *Issue `json:"issue"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type NameWithID struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type CustomField struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Value string `json:"value"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Issue struct {
|
2024-05-10 11:46:43 +03:00
|
|
|
ID int `json:"id,omitempty"`
|
|
|
|
Project *NameWithID `json:"project,omitempty"`
|
|
|
|
Tracker *NameWithID `json:"tracker,omitempty"`
|
|
|
|
Status *NameWithID `json:"status,omitempty"`
|
|
|
|
Priority *NameWithID `json:"priority,omitempty"`
|
|
|
|
Author *NameWithID `json:"author,omitempty"`
|
|
|
|
AssignedTo *NameWithID `json:"assigned_to,omitempty"`
|
|
|
|
Parent *NameWithID `json:"parent,omitempty"`
|
|
|
|
Subject string `json:"subject,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
StartDate interface{} `json:"start_date,omitempty"`
|
|
|
|
DueDate interface{} `json:"due_date,omitempty"`
|
|
|
|
DoneRatio int `json:"done_ratio,omitempty"`
|
|
|
|
IsPrivate bool `json:"is_private,omitempty"`
|
|
|
|
EstimatedHours Hours `json:"estimated_hours,omitempty"`
|
|
|
|
TotalEstimatedHours Hours `json:"total_estimated_hours,omitempty"`
|
|
|
|
SpentHours Hours `json:"spent_hours,omitempty"`
|
|
|
|
TotalSpentHours Hours `json:"total_spent_hours,omitempty"`
|
|
|
|
CustomFields []CustomField `json:"custom_fields,omitempty"`
|
|
|
|
CreatedOn *time.Time `json:"created_on,omitempty"`
|
|
|
|
UpdatedOn *time.Time `json:"updated_on,omitempty"`
|
|
|
|
ClosedOn interface{} `json:"closed_on,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Hours string
|
|
|
|
|
|
|
|
func (h Hours) MarshalJSON() ([]byte, error) {
|
|
|
|
f, err := strconv.ParseFloat(string(h), 64)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return []byte(strconv.FormatFloat(f, 'f', 2, 64)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Hours) UnmarshalJSON(b []byte) error {
|
|
|
|
f, err := strconv.ParseFloat(string(b), 64)
|
|
|
|
if err != nil {
|
|
|
|
var output string
|
|
|
|
defer func() {
|
|
|
|
*h = Hours(output)
|
|
|
|
}()
|
|
|
|
return json.Unmarshal(b, &output)
|
|
|
|
}
|
|
|
|
*h = Hours(strconv.FormatFloat(f, 'f', 2, 64))
|
|
|
|
return nil
|
2024-05-07 21:49:09 +03:00
|
|
|
}
|
2024-05-12 23:34:28 +03:00
|
|
|
|
|
|
|
type SearchIssue struct {
|
|
|
|
ID int `json:"id"`
|
|
|
|
Title string `json:"title,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
URL string `json:"url,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
DateTime *time.Time `json:"datetime,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SearchIssuesResponse struct {
|
|
|
|
ErrorResponse
|
|
|
|
Results []SearchIssue `json:"results"`
|
|
|
|
TotalCount int `json:"total_count"`
|
|
|
|
Offset int `json:"offset"`
|
|
|
|
Limit int `json:"limit"`
|
|
|
|
}
|