Made all types implement Identifiable

This commit is contained in:
Eduard Urbach 2019-09-09 09:18:34 +09:00
parent 8bfb1e0b4d
commit 85bd1441a6
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
4 changed files with 20 additions and 0 deletions

View File

@ -62,6 +62,11 @@ func (inventory *Inventory) SwapSlots(a, b int) error {
return nil return nil
} }
// GetID returns the ID.
func (inventory *Inventory) GetID() string {
return inventory.UserID
}
// NewInventory creates a new inventory with the default number of slots. // NewInventory creates a new inventory with the default number of slots.
func NewInventory(userID UserID) *Inventory { func NewInventory(userID UserID) *Inventory {
inventory := &Inventory{ inventory := &Inventory{

View File

@ -7,6 +7,11 @@ import (
"github.com/aerogo/api" "github.com/aerogo/api"
) )
// Force interface implementations
var (
_ Identifiable = (*Inventory)(nil)
)
// Actions // Actions
func init() { func init() {
API.RegisterActions("Inventory", []*api.Action{ API.RegisterActions("Inventory", []*api.Action{

View File

@ -5,3 +5,8 @@ type NickToUser struct {
Nick string `json:"nick" primary:"true"` Nick string `json:"nick" primary:"true"`
UserID UserID `json:"userId"` UserID UserID `json:"userId"`
} }
// GetID returns the primary key which is the nickname.
func (mapping *NickToUser) GetID() string {
return mapping.Nick
}

View File

@ -1,5 +1,10 @@
package arn package arn
// Force interface implementations
var (
_ Identifiable = (*ShopItem)(nil)
)
// Save saves the item in the database. // Save saves the item in the database.
func (item *ShopItem) Save() { func (item *ShopItem) Save() {
DB.Set("ShopItem", item.ID, item) DB.Set("ShopItem", item.ID, item)