Skip to content

Commit

Permalink
Merge pull request #4 from prolicht-dev/issues_dev
Browse files Browse the repository at this point in the history
API functions for Issue
  • Loading branch information
theriverman authored Feb 28, 2021
2 parents f72ded6 + 24082bb commit 738f49e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 22 deletions.
60 changes: 60 additions & 0 deletions issues.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package taigo

import (
"errors"
"fmt"
"strconv"

"github.com/google/go-querystring/query"
)
Expand Down Expand Up @@ -43,3 +45,61 @@ func (s *IssueService) CreateAttachment(attachment *Attachment, task *Task) (*At
url := s.client.MakeURL(s.Endpoint, "attachments")
return newfileUploadRequest(s.client, url, attachment, task)
}

// Get -> https://taigaio.github.io/taiga-doc/dist/api.html#issues-get
//
// Available Meta: *IssueDetailGET
func (s *IssueService) Get(issueID int) (*Issue, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(issueID))
var issue IssueDetailGET
_, err := s.client.Request.Get(url, &issue)
if err != nil {
return nil, err
}
return issue.AsIssue()
}

// Edit sends a PATCH request to edit a Issue -> https://taigaio.github.io/taiga-doc/dist/api.html#issues-edit
// Available Meta: IssueDetail
func (s *IssueService) Edit(issue *Issue) (*Issue, error) {
url := s.client.MakeURL(s.Endpoint, strconv.Itoa(issue.ID))
var responseIssue IssueDetail

if issue.ID == 0 {
return nil, errors.New("Passed Issue does not have an ID yet. Does it exist?")
}

// Taiga OCC
remoteIssue, err := s.Get(issue.ID)
if err != nil {
return nil, err
}

issue.Version = remoteIssue.Version
_, err = s.client.Request.Patch(url, &issue, &responseIssue)
if err != nil {
return nil, err
}
return responseIssue.AsIssue()
}

// Create creates a new Issue | https://taigaio.github.io/taiga-doc/dist/api.html#issues-create
//
// Available Meta: *IssueDetail
func (s *IssueService) Create(issue *Issue) (*Issue, error) {
url := s.client.MakeURL(s.Endpoint)
var issueDetail IssueDetail

// Check for required fields
// project, subject
if isEmpty(issue.Project) || isEmpty(issue.Subject) {
return nil, errors.New("A mandatory field is missing. See API documentataion")
}

_, err := s.client.Request.Post(url, &issue, &issueDetail)
if err != nil {
return nil, err
}

return issueDetail.AsIssue()
}
44 changes: 22 additions & 22 deletions issues.models.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@ func genericToIssues(anyIssueObjectSlice interface{}) []Issue {
// Issue represents the mandatory fields of an Issue only
type Issue struct {
TaigaBaseObject
ID int `json:"id"`
Ref int `json:"ref"`
Version int `json:"version"`
AssignedTo int `json:"assigned_to"`
BlockedNote string `json:"blocked_note"`
Description string `json:"description"`
IsBlocked bool `json:"is_blocked"`
IsClosed bool `json:"is_closed"`
Milestone int `json:"milestone"`
Owner int `json:"owner"`
Priority int `json:"priority"`
ID int `json:"id,omitempty"`
Ref int `json:"ref,omitempty"`
Version int `json:"version,omitempty"`
AssignedTo int `json:"assigned_to,omitempty"`
BlockedNote string `json:"blocked_note,omitempty"`
Description string `json:"description,omitempty"`
IsBlocked bool `json:"is_blocked,omitempty"`
IsClosed bool `json:"is_closed,omitempty"`
Milestone int `json:"milestone,omitempty"`
Owner int `json:"owner,omitempty"`
Priority int `json:"priority,omitempty"`
Project int `json:"project"`
Severity int `json:"severity"`
Status int `json:"status"`
Severity int `json:"severity,omitempty"`
Status int `json:"status,omitempty"`
Subject string `json:"subject"`
Tags Tags `json:"tags"`
Type int `json:"type"`
Watchers []int `json:"watchers"`
CreatedDate time.Time `json:"created_date"`
ModifiedDate time.Time `json:"modified_date"`
FinishedDate time.Time `json:"finished_date"`
DueDate string `json:"due_date"`
DueDateReason string `json:"due_date_reason"`
DueDateStatus string `json:"due_date_status"`
Tags Tags `json:"tags,omitempty"`
Type int `json:"type,omitempty"`
Watchers []int `json:"watchers,omitempty"`
CreatedDate time.Time `json:"created_date,omitempty"`
ModifiedDate time.Time `json:"modified_date,omitempty"`
FinishedDate time.Time `json:"finished_date,omitempty"`
DueDate string `json:"due_date,omitempty"`
DueDateReason string `json:"due_date_reason,omitempty"`
DueDateStatus string `json:"due_date_status,omitempty"`
IssueDetail *IssueDetail
IssueDetailGET *IssueDetailGET
IssueDetailLIST *IssueDetailLIST
Expand Down

0 comments on commit 738f49e

Please sign in to comment.