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
|
package common_configs
import (
"fmt"
"github.com/mimuret/golang-iij-dpf/pkg/api"
"github.com/mimuret/golang-iij-dpf/pkg/apis"
"github.com/mimuret/golang-iij-dpf/pkg/schema"
)
const groupName = "common-configs.api.dns-platform.jp/v1"
func register(items ...apis.Spec) {
schema.NewRegister(groupName).Add(items...)
}
type Spec interface {
apis.Spec
SetCommonConfigID(int64)
GetCommonConfigID() int64
}
type ChildSpec interface {
Spec
GetID() int64
SetID(int64)
}
type ListSpec interface {
api.ListSpec
Spec
}
type AttributeMeta struct {
CommonConfigID int64 `read:"-" id:"1,required"`
}
func (s *AttributeMeta) GetGroup() string { return groupName }
func (s *AttributeMeta) SetCommonConfigID(id int64) { s.CommonConfigID = id }
func (s *AttributeMeta) GetCommonConfigID() int64 { return s.CommonConfigID }
func GetPathMethodForChildSpec(action api.Action, s ChildSpec) (string, string) {
switch action {
case api.ActionCreate:
return action.ToMethod(), fmt.Sprintf("/common_configs/%d/%s", s.GetCommonConfigID(), s.GetName())
case api.ActionRead, api.ActionUpdate, api.ActionDelete:
return action.ToMethod(), fmt.Sprintf("/common_configs/%d/%s/%d", s.GetCommonConfigID(), s.GetName(), s.GetID())
}
return "", ""
}
func GetPathMethodForListSpec(action api.Action, s ListSpec) (string, string) {
if action == api.ActionList {
return action.ToMethod(), fmt.Sprintf("/common_configs/%d/%s", s.GetCommonConfigID(), s.GetName())
}
return "", ""
}
|