Skip to content

Commit

Permalink
New: Support for easily handling custom attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
theriverman committed Oct 4, 2020
1 parent b2f8570 commit e84933e
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 6 deletions.
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,75 @@ if err != nil {

**Note:** Such raw requests return `(*http.Response, error)`.

### \<Taiga Object\> Custom Attributes
The custom attribute of various Taiga objects are made of two major corner stones:
- Field Definitions
- Field Values

**Field Definitions** internally connect a field's name to an ID (int). <br>
Requesting `http://localhost:8000/api/v1/epic-custom-attributes/14` results in something like this:
```json
{
"created_date": "2020-07-02T11:57:22.124Z",
"description": "nesciunt consectetur culpa ullam harum fugit veritatis eius dolorem assumenda",
"extra": null,
"id": 14,
"modified_date": "2020-07-03T08:40:34.667Z",
"name": "Duration 1",
"order": 1,
"project": 3,
"type": "url"
}
```

**Field Values** internally connect the user-provided unique values to the internal IDs. <br>
Requesting `http://localhost:8000/api/v1/epics/custom-attributes-values/15` results in something like this:
```json
{
"attributes_values": {
"14": "240 min"
},
"epic": 15,
"version": 2
}
```
Observe that `Duration 1` has ID `14` in the declaration and that's used as the field's name.

If you request the custom field values of a Taiga object, the values will be returned in a `map[string]interface{}` style by default.

You have the option to manually declare the expected custom attribute fields and types in advance, and use
your custom struct for serializing the returned values.

For example here's the custom epic custom attribute struct for Taigo's Sandbox Project:
```go
import (
taiga "github.com/theriverman/taigo"
)

type TaigoSandboxEpicCustomAttributeFields struct {
SupportTeamName string `json:"9216"`
EstimatedDeliveryDate string `json:"9217"`
CostUSD int `json:"9218"`
}
type TaigoSandboxEpicCustomAttribValues struct {
taiga.EpicCustomAttributeValues
AttributesValues TaigoSandboxEpicCustomAttributeFields `json:"attributes_values,omitempty"`
}
```

Observe how the custom `TaigoSandboxEpicCustomAttributeFields` is promoted in the custom `TaigoSandboxEpicCustomAttribValues` struct.

All that's left is to create an instance of `TaigoSandboxEpicCustomAttribValues` and use it to serialze the returned JSON:
```go
cavs := TaigoSandboxEpicCustomAttribValues{} // Custom Attribute Value(s)
resp, err := client.Request.Get(client.MakeURL("epics", "custom-attributes-values", strconv.Itoa("your-epics-id")), &cavs)
if err != nil {
log.Println(err)
log.Println(resp)
return
}
```

# Contribution
You're contribution would be much appreciated! <br>
Feel free to open Issue tickets or create Pull requests. <br>
Expand Down
9 changes: 9 additions & 0 deletions common.models.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ type ProjectExtraInfo struct {
Slug string `json:"slug"`
}

// TgObjectCAVD is the default type for object custom attribute values
type TgObjectCAVD map[string]interface{}

// TgObjCAVDBase is the bare minimum for all tgCustomAttirbuteValue structs
type TgObjCAVDBase struct {
AttributesValues TgObjectCAVD `json:"attributes_values,omitempty"`
Version int `json:"version,omitempty"`
}

// UserStoryExtraInfo is a read-only field
type UserStoryExtraInfo struct {
Epics []EpicMinimal `json:"epics"`
Expand Down
35 changes: 35 additions & 0 deletions contribute/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,39 @@ func main() {
fmt.Printf(" * meta.FinishedDate = %s\n\n", meta.FinishedDate)
}

/**
* Get Epic Custom Attributes Values Detail
* See README.md for further details
*/

// TaigoSandboxEpicCustomAttributeFields represents the unique fields of your project's (epic) custom attribute values
type TaigoSandboxEpicCustomAttributeFields struct {
SupportTeamName string `json:"9216"`
EstimatedDeliveryDate string `json:"9217"`
CostUSD int `json:"9218"`
}
// TaigoSandboxEpicCustomAttribValues is a unique struct based on the generic taiga.EpicCustomAttribValues
// setting the type of AttributesValues to TaigoSandboxEpicCustomAttributeFields
type TaigoSandboxEpicCustomAttribValues struct {
taiga.EpicCustomAttributeValues
// taiga.UserStoryCustomAttribValues
// taiga.TaskCustomAttribValues
// taiga.IssueCustomAttribValues
AttributesValues TaigoSandboxEpicCustomAttributeFields `json:"attributes_values,omitempty"`
}

cavs := TaigoSandboxEpicCustomAttribValues{} // Custom Attribute Value(s)

resp2, err := client.Request.Get(client.MakeURL("epics", "custom-attributes-values", strconv.Itoa(sandboxEpicID2)), &cavs)
if err != nil {
log.Println(err)
log.Println(resp2)
return
}
fmt.Println("cavs.Epic", cavs.Epic)
fmt.Println("cavs.Version", cavs.Version)
fmt.Println("cavs.AttributesValues", cavs.AttributesValues)
fmt.Println("cavs.AttributesValues.SupportTeamName", cavs.AttributesValues.SupportTeamName)
fmt.Println("cavs.AttributesValues.EstimatedDeliveryDate", cavs.AttributesValues.EstimatedDeliveryDate)
fmt.Println("cavs.AttributesValues.CostUSD", cavs.AttributesValues.CostUSD)
}
3 changes: 0 additions & 3 deletions epic_custom_attribute_values.go

This file was deleted.

8 changes: 8 additions & 0 deletions epic_custom_attributes_values.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package taigo

// EpicCustomAttributeValues -> http://taigaio.github.io/taiga-doc/dist/api.html#object-epic-custom-attributes-values-detail
// You must populate TgObjCAVDBase.AttributesValues with your custom struct representing the actual CAVD
type EpicCustomAttributeValues struct {
TgObjCAVDBase
Epic int `json:"epic,omitempty"`
}
7 changes: 6 additions & 1 deletion issue_custom_attributes_values.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package taigo

// TODO: To be implemented
// IssueCustomAttribValues -> http://taigaio.github.io/taiga-doc/dist/api.html#object-epic-custom-attributes-values-detail
// You must populate TgObjCAVDBase.AttributesValues with your custom struct representing the actual CAVD
type IssueCustomAttribValues struct {
TgObjCAVDBase
Epic int `json:"epic,omitempty"`
}
7 changes: 6 additions & 1 deletion task_custom_attributes_values.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package taigo

// TODO: To be implemented
// TaskCustomAttribValues -> http://taigaio.github.io/taiga-doc/dist/api.html#object-epic-custom-attributes-values-detail
// You must populate TgObjCAVDBase.AttributesValues with your custom struct representing the actual CAVD
type TaskCustomAttribValues struct {
TgObjCAVDBase
Epic int `json:"epic,omitempty"`
}
7 changes: 6 additions & 1 deletion user_story_custom_attributes_values.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
package taigo

// TODO: To be implemented
// UserStoryCustomAttribValues -> http://taigaio.github.io/taiga-doc/dist/api.html#object-epic-custom-attributes-values-detail
// You must populate TgObjCAVDBase.AttributesValues with your custom struct representing the actual CAVD
type UserStoryCustomAttribValues struct {
TgObjCAVDBase
Epic int `json:"epic,omitempty"`
}

0 comments on commit e84933e

Please sign in to comment.