File: delegation.go

package info (click to toggle)
golang-github-mimuret-golang-iij-dpf 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,340 kB
  • sloc: makefile: 55
file content (80 lines) | stat: -rw-r--r-- 2,665 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package core

import (
	"net/url"

	"github.com/google/go-querystring/query"
	"github.com/mimuret/golang-iij-dpf/pkg/api"
	"github.com/mimuret/golang-iij-dpf/pkg/apis"
	"github.com/mimuret/golang-iij-dpf/pkg/types"
)

// +k8s:deepcopy-gen:interfaces=github.com/mimuret/golang-iij-dpf/pkg/api.Object
type Delegation struct {
	AttributeMeta
	ID                    string     `read:"id"`
	ServiceCode           string     `read:"service_code"`
	Name                  string     `read:"name"`
	Network               string     `read:"network"`
	Description           string     `read:"description"`
	DelegationRequestedAt types.Time `read:"delegation_requested_at"`
}

var _ apis.CountableListSpec = &DelegationList{}

// +k8s:deepcopy-gen:interfaces=github.com/mimuret/golang-iij-dpf/pkg/api.Object
type DelegationList struct {
	AttributeMeta
	api.Count
	Items []Delegation `read:"items"`
}

func (c *DelegationList) GetName() string         { return "delegations" }
func (c *DelegationList) GetItems() interface{}   { return &c.Items }
func (c *DelegationList) Len() int                { return len(c.Items) }
func (c *DelegationList) Index(i int) interface{} { return c.Items[i] }
func (c *DelegationList) GetMaxLimit() int32      { return 10000 }
func (c *DelegationList) ClearItems()             { c.Items = []Delegation{} }
func (c *DelegationList) AddItem(v interface{}) bool {
	if a, ok := v.(Delegation); ok {
		c.Items = append(c.Items, a)
		return true
	}
	return false
}

func (c *DelegationList) GetPathMethod(action api.Action) (string, string) {
	switch action {
	case api.ActionList:
		return action.ToMethod(), "/delegations"
	case api.ActionCount:
		return action.ToMethod(), "/delegations/count"
	}
	return "", ""
}

func (c *DelegationList) SetPathParams(args ...interface{}) error {
	return nil
}

func (c *DelegationList) Init() {}

var _ api.SearchParams = &DelegationListSearchKeywords{}

// +k8s:deepcopy-gen=false
type DelegationListSearchKeywords struct {
	api.CommonSearchParams
	FullText    api.KeywordsString   `url:"_keywords_full_text[],omitempty"`
	ServiceCode api.KeywordsString   `url:"_keywords_service_code[],omitempty"`
	Name        api.KeywordsString   `url:"_keywords_name[],omitempty"`
	Network     api.KeywordsString   `url:"_keywords_network[],omitempty"`
	Favorite    api.KeywordsFavorite `url:"_keywords_favorite[],omitempty"`
	Description api.KeywordsString   `url:"_keywords_description[],omitempty"`
	Requested   api.KeywordsBoolean  `url:"_keywords_requested[],omitempty"`
}

func (s *DelegationListSearchKeywords) GetValues() (url.Values, error) { return query.Values(s) }

func init() {
	register(&DelegationList{})
}