From 8291cff180af12cf6e3673aee6aadc6d560d059b Mon Sep 17 00:00:00 2001 From: Spotlight Date: Mon, 24 May 2021 14:12:00 -0500 Subject: [PATCH] Add test ListItems response Not currently functional, but parses succesfully. --- cas.go | 41 +++++++++++++++++++++++++++++++++++++++++ main.go | 5 +++++ structure.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 cas.go diff --git a/cas.go b/cas.go new file mode 100644 index 0000000..cd3999f --- /dev/null +++ b/cas.go @@ -0,0 +1,41 @@ +package main + +func listItems(e *Envelope) { + titleId, err := getKey(e.doc, "TitleId") + if err != nil { + e.Error(9, "Unable to obtain title.", err) + } + + e.AddKVNode("ListResultTotalSize", "1") + e.AddCustomType(Items{ + TitleId: titleId, + Contents: ContentsMetadata{ + TitleIncluded: false, + ContentIndex: 1, + }, + Attributes: []Attributes{ + { + Name: "MaxUserInodes", + Value: "10", + }, + { + Name: "itemComment", + Value: "Does not catch on fire.", + }, + }, + Ratings: Ratings{ + Name: "Testing", + Rating: 1, + Age: 13, + }, + Prices: Prices{ + ItemId: 0, + Price: Price{ + Amount: 1, + Currency: "POINTS", + }, + Limits: LimitStruct(PR), + LicenseKind: "PERMANENT", + }, + }) +} diff --git a/main.go b/main.go index 95c1e53..fdebb51 100644 --- a/main.go +++ b/main.go @@ -96,6 +96,11 @@ func main() { ias.Unauthenticated("Register", register) ias.Authenticated("Unregister", unregister) } + + cas := r.HandleGroup("cas") + { + cas.Authenticated("ListItems", listItems) + } log.Fatal(http.ListenAndServe(readConfig.Address, r.Handle())) // From here on out, all special cool things should go into their respective handler function. diff --git a/structure.go b/structure.go index 1a154b7..0f8c413 100644 --- a/structure.go +++ b/structure.go @@ -163,3 +163,50 @@ type Tickets struct { MigrateCount int `xml:"MigrateCount"` MigrateLimit int `xml:"MigrateLimit"` } + +// Attributes represents a common structure of the same name. +type Attributes struct { + XMLName xml.Name `xml:"Attributes"` + Name string `xml:"Name"` + Value string `xml:"Value"` +} + +// ContentsMetadata describes data about contents within a title. +type ContentsMetadata struct { + XMLName xml.Name `xml:"Contents"` + TitleIncluded bool `xml:"TitleIncluded"` + ContentIndex int `xml:"ContentIndex"` +} + +// Price holds the price for a title. +type Price struct { + XMLName xml.Name `xml:"Price"` + Amount int `xml:"Amount"` + Currency string `xml:"Currency"` +} + +// Prices describes a common structure for listing prices within a title. +type Prices struct { + ItemId int `xml:"ItemId"` + Price Price + Limits Limits `xml:"Limits"` + LicenseKind string `xml:"LicenseKind"` +} + +// Items allows specifying an overview of a title's contents. +type Items struct { + XMLName xml.Name `xml:"Items"` + TitleId string `xml:"TitleId"` + Contents ContentsMetadata `xml:"Contents"` + Attributes []Attributes `xml:"Attribute,omitempty"` + Ratings Ratings `xml:"Ratings,omitempty"` + Prices Prices `xml:"Prices,omitempty"` +} + +// Ratings allows specifying the rating of an item across multiple properties. +type Ratings struct { + XMLName xml.Name `xml:"Ratings"` + Name string `xml:"Name"` + Rating int `xml:"Rating"` + Age int `xml:"Age"` +}