diff --git a/README.md b/README.md index 9a3834d..a9ed121 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,75 @@ if err != nil { **Note:** Such raw requests return `(*http.Response, error)`. +### \ 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).
+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.
+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!
Feel free to open Issue tickets or create Pull requests.
diff --git a/common.models.go b/common.models.go index b97b2b5..ad702ad 100644 --- a/common.models.go +++ b/common.models.go @@ -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"` diff --git a/contribute/main.go b/contribute/main.go index 42fc07a..4623fb5 100644 --- a/contribute/main.go +++ b/contribute/main.go @@ -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) } diff --git a/epic_custom_attribute_values.go b/epic_custom_attribute_values.go deleted file mode 100644 index a25d1a3..0000000 --- a/epic_custom_attribute_values.go +++ /dev/null @@ -1,3 +0,0 @@ -package taigo - -// TODO: To be implemented diff --git a/epic_custom_attributes_values.go b/epic_custom_attributes_values.go new file mode 100644 index 0000000..34a460f --- /dev/null +++ b/epic_custom_attributes_values.go @@ -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"` +} diff --git a/issue_custom_attributes_values.go b/issue_custom_attributes_values.go index a25d1a3..05eb904 100644 --- a/issue_custom_attributes_values.go +++ b/issue_custom_attributes_values.go @@ -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"` +} diff --git a/task_custom_attributes_values.go b/task_custom_attributes_values.go index a25d1a3..5dd427a 100644 --- a/task_custom_attributes_values.go +++ b/task_custom_attributes_values.go @@ -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"` +} diff --git a/user_story_custom_attributes_values.go b/user_story_custom_attributes_values.go index a25d1a3..ee4ed8c 100644 --- a/user_story_custom_attributes_values.go +++ b/user_story_custom_attributes_values.go @@ -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"` +}