models

package
v2.1.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2017 License: MIT Imports: 19 Imported by: 24

Documentation

Index

Constants

View Source
const (
	//GameUpdatedHook happens when a game is updated
	GameUpdatedHook = 0

	//PlayerCreatedHook happens when a new player is created
	PlayerCreatedHook = 1

	//PlayerUpdatedHook happens when a player is updated
	PlayerUpdatedHook = 2

	//ClanCreatedHook happens when a clan is created
	ClanCreatedHook = 3

	//ClanUpdatedHook happens when a clan is updated
	ClanUpdatedHook = 4

	//ClanLeftHook happens when a clan owner rage quits
	ClanLeftHook = 5

	//ClanOwnershipTransferredHook happens when a clan owner transfers ownership to another player
	ClanOwnershipTransferredHook = 6

	//MembershipApplicationCreatedHook happens when a new application or invite to a clan is created
	MembershipApplicationCreatedHook = 7

	//MembershipApprovedHook happens when a clan membership is approved
	MembershipApprovedHook = 8

	//MembershipDeniedHook happens when a clan membership is denied
	MembershipDeniedHook = 9

	//MembershipPromotedHook happens when a clan member is promoted
	MembershipPromotedHook = 10

	//MembershipDemotedHook happens when a clan member is demoted
	MembershipDemotedHook = 11

	//MembershipLeftHook happens when a player leaves a clan
	MembershipLeftHook = 12
)

Variables

View Source
var ClanFactory = configureFactory(factory.NewFactory(
	&Clan{},
))

ClanFactory is responsible for constructing test clan instances

View Source
var GameFactory = factory.NewFactory(
	&Game{
		MinLevelToAcceptApplication:   2,
		MinLevelToCreateInvitation:    2,
		MinLevelToRemoveMember:        2,
		MinLevelOffsetToRemoveMember:  1,
		MinLevelOffsetToPromoteMember: 2,
		MinLevelOffsetToDemoteMember:  1,
		MaxClansPerPlayer:             1,
		MaxMembers:                    100,
		CooldownAfterDeny:             0,
		CooldownAfterDelete:           0,
		CooldownBeforeApply:           3600,
		CooldownBeforeInvite:          0,
		MaxPendingInvites:             20,
	},
).Attr("PublicID", func(args factory.Args) (interface{}, error) {
	return uuid.NewV4().String(), nil
}).Attr("Name", func(args factory.Args) (interface{}, error) {
	return uuid.NewV4().String(), nil
}).Attr("Metadata", func(args factory.Args) (interface{}, error) {
	return map[string]interface{}{}, nil
}).Attr("MembershipLevels", func(args factory.Args) (interface{}, error) {
	return map[string]interface{}{"Member": 1, "Elder": 2, "CoLeader": 3}, nil
})

GameFactory is responsible for constructing test game instances

View Source
var HookFactory = factory.NewFactory(
	&Hook{EventType: GameUpdatedHook, URL: "http://test/game-created"},
)

HookFactory is responsible for constructing event hook instances

View Source
var MembershipFactory = factory.NewFactory(
	&Membership{},
).SeqInt("GameID", func(n int) (interface{}, error) {
	return fmt.Sprintf("game-%d", n), nil
}).Attr("ApproverID", func(args factory.Args) (interface{}, error) {
	membership := args.Instance().(*Membership)
	approverID := 0
	valid := false
	if membership.Approved {
		approverID = membership.RequestorID
		valid = true
	}
	return sql.NullInt64{Int64: int64(approverID), Valid: valid}, nil
}).Attr("DenierID", func(args factory.Args) (interface{}, error) {
	membership := args.Instance().(*Membership)
	denierID := 0
	valid := false
	if membership.Denied {
		denierID = membership.RequestorID
		valid = true
	}
	return sql.NullInt64{Int64: int64(denierID), Valid: valid}, nil
})

MembershipFactory is responsible for constructing test membership instances

View Source
var PlayerFactory = configureFactory(factory.NewFactory(
	&Player{},
))

PlayerFactory is responsible for constructing test player instances

Functions

func CreatePlayerFactory

func CreatePlayerFactory(db DB, gameID string, skipCreateGame ...bool) (*Game, *Player, error)

CreatePlayerFactory is responsible for creating a test player instance with the associated game

func GetClanAndOwnerByPublicID

func GetClanAndOwnerByPublicID(db DB, gameID, publicID string) (*Clan, *Player, error)

GetClanAndOwnerByPublicID returns the clan as well as the owner of a clan by clan's public id

func GetClanDetails

func GetClanDetails(db DB, gameID string, clan *Clan, maxClansPerPlayer int) (map[string]interface{}, error)

GetClanDetails returns all details for a given clan by its game id and public id

func GetClanReachedMaxMemberships

func GetClanReachedMaxMemberships(db DB) (*Game, *Clan, *Player, []*Player, []*Membership, error)

GetClanReachedMaxMemberships returns a clan with one approved membership, one unapproved membership and game MaxMembers=1

func GetClanSummary

func GetClanSummary(db DB, gameID, publicID string) (map[string]interface{}, error)

GetClanSummary returns a summary of the clan details for a given clan by its game id and public id

func GetClanWithMemberships

func GetClanWithMemberships(
	db DB, approvedMemberships, deniedMemberships, bannedMemberships, pendingMemberships int, gameID string, clanPublicID string, options ...bool) (*Game, *Clan, *Player, []*Player, []*Membership, error)

GetClanWithMemberships returns a clan filled with the number of memberships specified

func GetClansSummaries

func GetClansSummaries(db DB, gameID string, publicIDs []string) ([]map[string]interface{}, error)

GetClansSummaries returns a summary of the clans details for a given list of clans by their game id and public ids

func GetLevelByLevelInt

func GetLevelByLevelInt(levelInt int, levels map[string]interface{}) string

GetLevelByLevelInt returns the level string given the level int

func GetLevelIntByLevel

func GetLevelIntByLevel(level string, levels map[string]interface{}) int

GetLevelIntByLevel returns the level string given the level int

func GetNumberOfPendingInvites

func GetNumberOfPendingInvites(db DB, player *Player) (int, error)

GetNumberOfPendingInvites gets total number of pending invites for player

func GetPlayerDetails

func GetPlayerDetails(db DB, gameID, publicID string) (map[string]interface{}, error)

GetPlayerDetails returns detailed information about a player and their memberships

func GetPlayerMembershipDetails

func GetPlayerMembershipDetails(db DB, gameID, publicID string) (map[string]interface{}, error)

GetPlayerMembershipDetails returns detailed information about a player and their memberships

func GetPlayerOwnershipDetails

func GetPlayerOwnershipDetails(db DB, gameID, publicID string) (map[string]interface{}, error)

GetPlayerOwnershipDetails returns detailed information about a player owned clans

func GetTestClanWithStaleData added in v0.12.0

func GetTestClanWithStaleData(db DB, staleApplications, staleInvites, staleDenies, staleDeletes int) (string, error)

GetTestClanWithStaleData returns a player with approved, rejected and banned memberships

func GetTestClans

func GetTestClans(db DB, gameID string, publicIDTemplate string, numberOfClans int) (*Player, []*Clan, error)

GetTestClans returns a list of clans for tests

func LeaveClan

func LeaveClan(db DB, gameID, publicID string) (*Clan, *Player, *Player, error)

LeaveClan allows the clan owner to leave the clan and transfer the clan ownership to the next player in line

func RemoveHook

func RemoveHook(db DB, gameID string, publicID string) error

RemoveHook removes a hook by public ID

func TransferClanOwnership

func TransferClanOwnership(db DB, gameID, clanPublicID, playerPublicID string, levels map[string]interface{}, maxLevel int) (*Clan, *Player, *Player, error)

TransferClanOwnership allows the clan owner to transfer the clan ownership to the a clan member

func UpdateClanMembershipCount added in v0.10.0

func UpdateClanMembershipCount(db DB, id int) error

UpdateClanMembershipCount updates the clan membership count

func UpdatePlayerMembershipCount added in v0.10.0

func UpdatePlayerMembershipCount(db DB, id int) error

UpdatePlayerMembershipCount updates the player membership count

func UpdatePlayerOwnershipCount added in v0.10.0

func UpdatePlayerOwnershipCount(db DB, id int) error

UpdatePlayerOwnershipCount updates the player ownership count

Types

type AlreadyHasValidMembershipError

type AlreadyHasValidMembershipError struct {
	PlayerID string
	ClanID   string
}

AlreadyHasValidMembershipError identifies that a player already has a valid membership for the given clan

func (*AlreadyHasValidMembershipError) Error

type CannotApproveOrDenyMembershipAlreadyProcessedError

type CannotApproveOrDenyMembershipAlreadyProcessedError struct {
	Action string
}

CannotApproveOrDenyMembershipAlreadyProcessedError identifies that a membership that is already processed cannot be approved or denied

func (*CannotApproveOrDenyMembershipAlreadyProcessedError) Error

type CannotPromoteOrDemoteInvalidMemberError

type CannotPromoteOrDemoteInvalidMemberError struct {
	Action string
}

CannotPromoteOrDemoteInvalidMemberError identifies that a given player is not allowed to promote/demote a member

func (*CannotPromoteOrDemoteInvalidMemberError) Error

type CannotPromoteOrDemoteMemberLevelError

type CannotPromoteOrDemoteMemberLevelError struct {
	Action string
	Level  int
}

CannotPromoteOrDemoteMemberLevelError identifies that a given member is already max level and cannot be promoted

func (*CannotPromoteOrDemoteMemberLevelError) Error

type Clan

type Clan struct {
	ID               int                    `db:"id" json:"id"`
	GameID           string                 `db:"game_id" json:"gameId"`
	PublicID         string                 `db:"public_id" json:"publicId"`
	Name             string                 `db:"name" json:"name"`
	OwnerID          int                    `db:"owner_id" json:"ownerId"`
	MembershipCount  int                    `db:"membership_count" json:"membershipCount"`
	Metadata         map[string]interface{} `db:"metadata" json:"metadata"`
	AllowApplication bool                   `db:"allow_application" json:"allowApplication"`
	AutoJoin         bool                   `db:"auto_join" json:"autoJoin"`
	CreatedAt        int64                  `db:"created_at" json:"createdAt"`
	UpdatedAt        int64                  `db:"updated_at" json:"updatedAt"`
	DeletedAt        int64                  `db:"deleted_at" json:"deletedAt"`
}

Clan identifies uniquely one clan in a given game

func CreateClan

func CreateClan(db DB, gameID, publicID, name, ownerPublicID string, metadata map[string]interface{}, allowApplication, autoJoin bool, maxClansPerPlayer int) (*Clan, error)

CreateClan creates a new clan

func GetAllClans

func GetAllClans(db DB, gameID string) ([]Clan, error)

GetAllClans returns a list of all clans in a given game

func GetClanByID

func GetClanByID(db DB, id int) (*Clan, error)

GetClanByID returns a clan by id

func GetClanByPublicID

func GetClanByPublicID(db DB, gameID, publicID string) (*Clan, error)

GetClanByPublicID returns a clan by its public id

func GetClanByPublicIDAndOwnerPublicID

func GetClanByPublicIDAndOwnerPublicID(db DB, gameID, publicID, ownerPublicID string) (*Clan, error)

GetClanByPublicIDAndOwnerPublicID returns a clan by its public id and the owner public id

func GetClanFromJSON added in v0.9.15

func GetClanFromJSON(data []byte) (*Clan, error)

GetClanFromJSON unmarshals the clan from the specified JSON

func GetClansByPublicIDs

func GetClansByPublicIDs(db DB, gameID string, publicIDs []string) ([]Clan, error)

GetClansByPublicIDs returns clans by their public ids

func SearchClan

func SearchClan(db DB, gameID, term string) ([]Clan, error)

SearchClan returns a list of clans for a given term (by name or publicID)

func UpdateClan

func UpdateClan(db DB, gameID, publicID, name, ownerPublicID string, metadata map[string]interface{}, allowApplication, autoJoin bool) (*Clan, error)

UpdateClan updates an existing clan

func (*Clan) DeleteClanFromElasticSearch added in v0.9.13

func (c *Clan) DeleteClanFromElasticSearch() error

DeleteClanFromElasticSearch after deletion in PG

func (*Clan) IndexClanIntoElasticSearch added in v0.9.13

func (c *Clan) IndexClanIntoElasticSearch() error

IndexClanIntoElasticSearch after operation in PG

func (Clan) MarshalEasyJSON added in v0.9.15

func (v Clan) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (*Clan) PostDelete added in v0.9.13

func (c *Clan) PostDelete(s gorp.SqlExecutor) error

PostDelete deletes clan from elasticsearch after deleting from PG

func (*Clan) PostInsert added in v0.9.13

func (c *Clan) PostInsert(s gorp.SqlExecutor) error

PostInsert indexes clan in ES after creation in PG

func (*Clan) PostUpdate added in v0.9.13

func (c *Clan) PostUpdate(s gorp.SqlExecutor) error

PostUpdate indexes clan in ES after update in PG

func (*Clan) PreInsert

func (c *Clan) PreInsert(s gorp.SqlExecutor) error

PreInsert populates fields before inserting a new clan

func (*Clan) PreUpdate

func (c *Clan) PreUpdate(s gorp.SqlExecutor) error

PreUpdate populates fields before updating a clan

func (*Clan) Serialize

func (c *Clan) Serialize() map[string]interface{}

Serialize returns a JSON with clan details

func (*Clan) ToJSON added in v0.9.15

func (c *Clan) ToJSON() ([]byte, error)

ToJSON returns the clan as JSON

func (*Clan) UnmarshalEasyJSON added in v0.9.15

func (v *Clan) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

type ClanByName

type ClanByName []*Clan

ClanByName allows sorting clans by name

func (ClanByName) Len

func (a ClanByName) Len() int

func (ClanByName) Less

func (a ClanByName) Less(i, j int) bool

func (ClanByName) Swap

func (a ClanByName) Swap(i, j int)

type ClanHasNoMembersError

type ClanHasNoMembersError struct {
	ClanID interface{}
}

ClanHasNoMembersError identifies that a clan has no members

func (*ClanHasNoMembersError) Error

func (e *ClanHasNoMembersError) Error() string

type ClanReachedMaxMembersError

type ClanReachedMaxMembersError struct {
	ID interface{}
}

ClanReachedMaxMembersError identifies that a given clan already reached the max number of members allowed

func (*ClanReachedMaxMembersError) Error

type CouldNotFindAllClansError

type CouldNotFindAllClansError struct {
	// contains filtered or unexported fields
}

CouldNotFindAllClansError identifies that one or more of the requested clans do not exist

func (*CouldNotFindAllClansError) Error

func (e *CouldNotFindAllClansError) Error() string

type DB

type DB interface {
	Get(interface{}, ...interface{}) (interface{}, error)
	Select(interface{}, string, ...interface{}) ([]interface{}, error)
	SelectOne(interface{}, string, ...interface{}) error
	SelectInt(string, ...interface{}) (int64, error)
	Insert(...interface{}) error
	Update(...interface{}) (int64, error)
	Delete(...interface{}) (int64, error)
	Exec(string, ...interface{}) (sql.Result, error)
}

DB is the contract for all the operations we use from either a connection or transaction This is required for automatic transactions

func GetDB

func GetDB(host string, user string, port int, sslmode string, dbName string, password string) (DB, error)

GetDB returns a DbMap connection to the database specified in the arguments

func GetDefaultDB

func GetDefaultDB() (DB, error)

GetDefaultDB returns a connection to the default database

func GetPerfDB

func GetPerfDB() (DB, error)

GetPerfDB returns a connection to the perf database

func InitDb

func InitDb(host string, user string, port int, sslmode string, dbName string, password string) (DB, error)

InitDb initializes a connection to the database

type ESWorker

type ESWorker struct {
	Logger zap.Logger
	ES     *es.Client
}

ESWorker is the worker that will update elasticsearch

func NewESWorker

func NewESWorker(logger zap.Logger) *ESWorker

NewESWorker creates and returns a new elasticsearch worker

func (*ESWorker) PerformUpdateES

func (w *ESWorker) PerformUpdateES(m *workers.Msg)

PerformUpdateES updates the clan into elasticsearc

type EmptyGameIDError

type EmptyGameIDError struct {
	Type string
}

EmptyGameIDError identifies that a request was made for a model without the proper game id

func (*EmptyGameIDError) Error

func (e *EmptyGameIDError) Error() string

type EmptySearchTermError

type EmptySearchTermError struct{}

EmptySearchTermError identifies that a search term was not provided

func (*EmptySearchTermError) Error

func (e *EmptySearchTermError) Error() string

type Game

type Game struct {
	ID                                             int                    `db:"id"`
	PublicID                                       string                 `db:"public_id"`
	Name                                           string                 `db:"name"`
	MinMembershipLevel                             int                    `db:"min_membership_level"`
	MaxMembershipLevel                             int                    `db:"max_membership_level"`
	MinLevelToAcceptApplication                    int                    `db:"min_level_to_accept_application"`
	MinLevelToCreateInvitation                     int                    `db:"min_level_to_create_invitation"`
	MinLevelToRemoveMember                         int                    `db:"min_level_to_remove_member"`
	MinLevelOffsetToRemoveMember                   int                    `db:"min_level_offset_to_remove_member"`
	MinLevelOffsetToPromoteMember                  int                    `db:"min_level_offset_to_promote_member"`
	MinLevelOffsetToDemoteMember                   int                    `db:"min_level_offset_to_demote_member"`
	MaxMembers                                     int                    `db:"max_members"`
	MaxClansPerPlayer                              int                    `db:"max_clans_per_player"`
	MembershipLevels                               map[string]interface{} `db:"membership_levels"`
	Metadata                                       map[string]interface{} `db:"metadata"`
	CreatedAt                                      int64                  `db:"created_at"`
	UpdatedAt                                      int64                  `db:"updated_at"`
	CooldownAfterDeny                              int                    `db:"cooldown_after_deny"`
	CooldownAfterDelete                            int                    `db:"cooldown_after_delete"`
	CooldownBeforeApply                            int                    `db:"cooldown_before_apply"`
	CooldownBeforeInvite                           int                    `db:"cooldown_before_invite"`
	MaxPendingInvites                              int                    `db:"max_pending_invites"`
	ClanUpdateMetadataFieldsHookTriggerWhitelist   string                 `db:"clan_metadata_fields_whitelist"`
	PlayerUpdateMetadataFieldsHookTriggerWhitelist string                 `db:"player_metadata_fields_whitelist"`
}

Game identifies uniquely one game

func CreateGame

func CreateGame(
	db DB,
	publicID, name string,
	levels, metadata map[string]interface{},
	minLevelAccept, minLevelCreate, minLevelRemove,
	minOffsetRemove, minOffsetPromote, minOffsetDemote, maxMembers,
	maxClans, cooldownAfterDeny, cooldownAfterDelete, cooldownBeforeApply,
	cooldownBeforeInvite, maxPendingInvites int, upsert bool,
	clanUpdateMetadataFieldsHookTriggerWhitelist string,
	playerUpdateMetadataFieldsHookTriggerWhitelist string,
) (*Game, error)

CreateGame creates a new game

func GetAllGames

func GetAllGames(db DB) ([]*Game, error)

GetAllGames returns all games in the DB

func GetGameByID

func GetGameByID(db DB, id int) (*Game, error)

GetGameByID returns a game by id

func GetGameByPublicID

func GetGameByPublicID(db DB, publicID string) (*Game, error)

GetGameByPublicID returns a game by their public id

func UpdateGame

func UpdateGame(
	db DB, publicID, name string, levels, metadata map[string]interface{},
	minLevelAccept, minLevelCreate, minLevelRemove, minOffsetRemove, minOffsetPromote,
	minOffsetDemote, maxMembers, maxClans, cooldownAfterDeny, cooldownAfterDelete,
	cooldownBeforeApply, cooldownBeforeInvite, maxPendingInvites int,
	clanUpdateMetadataFieldsHookTriggerWhitelist string,
	playerUpdateMetadataFieldsHookTriggerWhitelist string,
) (*Game, error)

UpdateGame updates an existing game

func (*Game) PreInsert

func (g *Game) PreInsert(s gorp.SqlExecutor) error

PreInsert populates fields before inserting a new game

func (*Game) PreUpdate

func (g *Game) PreUpdate(s gorp.SqlExecutor) error

PreUpdate populates fields before updating a game

type Hook

type Hook struct {
	ID        int    `db:"id"`
	GameID    string `db:"game_id"`
	PublicID  string `db:"public_id"`
	EventType int    `db:"event_type"`
	URL       string `db:"url"`
	CreatedAt int64  `db:"created_at"`
	UpdatedAt int64  `db:"updated_at"`
}

Hook identifies a webhook for a given event

func CreateHook

func CreateHook(db DB, gameID string, eventType int, url string) (*Hook, error)

CreateHook returns a newly created event hook

func CreateHookFactory

func CreateHookFactory(db DB, gameID string, eventType int, url string) (*Hook, error)

CreateHookFactory is responsible for creating a test hook instance with the associated game

func GetAllHooks

func GetAllHooks(db DB) ([]*Hook, error)

GetAllHooks returns all the available hooks

func GetHookByDetails

func GetHookByDetails(db DB, gameID string, eventType int, hookURL string) *Hook

GetHookByDetails returns a hook by its details (GameID, EventType and Hook URL) If no hook is found returns nil.

func GetHookByID

func GetHookByID(db DB, id int) (*Hook, error)

GetHookByID returns a hook by id

func GetHookByPublicID

func GetHookByPublicID(db DB, gameID string, publicID string) (*Hook, error)

GetHookByPublicID returns a hook by game id and public id

func GetHooksForRoutes

func GetHooksForRoutes(db DB, routes []string, eventType int) ([]*Hook, error)

GetHooksForRoutes gets hooks for all the specified routes

func GetTestHooks

func GetTestHooks(db DB, gameID string, numberOfHooks int) ([]*Hook, error)

GetTestHooks return a fixed number of hooks for each event available

func (*Hook) PreInsert

func (h *Hook) PreInsert(s gorp.SqlExecutor) error

PreInsert populates fields before inserting a new hook

func (*Hook) PreUpdate

func (h *Hook) PreUpdate(s gorp.SqlExecutor) error

PreUpdate populates fields before updating a hook

type InvalidLevelForGameError

type InvalidLevelForGameError struct {
	GameID string
	Level  interface{}
}

InvalidLevelForGameError identifies that a given level is not valid for the given game

func (*InvalidLevelForGameError) Error

func (e *InvalidLevelForGameError) Error() string

type InvalidMembershipActionError

type InvalidMembershipActionError struct {
	Action string
}

InvalidMembershipActionError identifies that a given action is not valid

func (*InvalidMembershipActionError) Error

type Membership

type Membership struct {
	ID          int           `db:"id"`
	GameID      string        `db:"game_id"`
	Level       string        `db:"membership_level"`
	Approved    bool          `db:"approved"`
	Denied      bool          `db:"denied"`
	Banned      bool          `db:"banned"`
	PlayerID    int           `db:"player_id"`
	ClanID      int           `db:"clan_id"`
	RequestorID int           `db:"requestor_id"`
	ApproverID  sql.NullInt64 `db:"approver_id"`
	DenierID    sql.NullInt64 `db:"denier_id"`
	CreatedAt   int64         `db:"created_at"`
	UpdatedAt   int64         `db:"updated_at"`
	DeletedBy   int           `db:"deleted_by"`
	DeletedAt   int64         `db:"deleted_at"`
	ApprovedAt  int64         `db:"approved_at"`
	DeniedAt    int64         `db:"denied_at"`
	Message     string        `db:"message"`
}

Membership relates a player to a clan

func ApproveOrDenyMembershipApplication

func ApproveOrDenyMembershipApplication(db DB, game *Game, gameID, playerPublicID, clanPublicID, requestorPublicID, action string) (*Membership, error)

ApproveOrDenyMembershipApplication sets Membership.Approved to true or Membership.Denied to true

func ApproveOrDenyMembershipInvitation

func ApproveOrDenyMembershipInvitation(db DB, game *Game, gameID, playerPublicID, clanPublicID, action string) (*Membership, error)

ApproveOrDenyMembershipInvitation sets Membership.Approved to true or Membership.Denied to true

func CreateMembership

func CreateMembership(db DB, game *Game, gameID, level, playerPublicID, clanPublicID, requestorPublicID, message string) (*Membership, error)

CreateMembership creates a new membership

func DeleteMembership

func DeleteMembership(db DB, game *Game, gameID, playerPublicID, clanPublicID, requestorPublicID string) (*Membership, error)

DeleteMembership soft deletes a membership

func GetDeletedMembershipByClanAndPlayerID added in v1.1.3

func GetDeletedMembershipByClanAndPlayerID(db DB, gameID string, clanID, playerID int) (*Membership, error)

GetDeletedMembershipByClanAndPlayerID returns a deleted membership for the player with the given ID and the clan ID

func GetMembershipByClanAndPlayerPublicID

func GetMembershipByClanAndPlayerPublicID(db DB, gameID, clanPublicID, playerPublicID string) (*Membership, error)

GetMembershipByClanAndPlayerPublicID returns a deleted membership for the clan and the player with the given publicIDs

func GetMembershipByID

func GetMembershipByID(db DB, id int) (*Membership, error)

GetMembershipByID returns a membership by id

func GetOldestMemberWithHighestLevel

func GetOldestMemberWithHighestLevel(db DB, gameID, clanPublicID string) (*Membership, error)

GetOldestMemberWithHighestLevel returns the member with highest level that has the oldest creation date

func GetValidMembershipByClanAndPlayerPublicID

func GetValidMembershipByClanAndPlayerPublicID(db DB, gameID, clanPublicID, playerPublicID string) (*Membership, error)

GetValidMembershipByClanAndPlayerPublicID returns a non deleted membership for the clan and the player with the given publicIDs

func PromoteOrDemoteMember

func PromoteOrDemoteMember(db DB, game *Game, gameID, playerPublicID, clanPublicID, requestorPublicID, action string) (*Membership, error)

PromoteOrDemoteMember increments or decrements Membership.LevelInt by one

func (*Membership) PreInsert

func (m *Membership) PreInsert(s gorp.SqlExecutor) error

PreInsert populates fields before inserting a new clan

func (*Membership) PreUpdate

func (m *Membership) PreUpdate(s gorp.SqlExecutor) error

PreUpdate populates fields before updating a clan

type ModelNotFoundError

type ModelNotFoundError struct {
	Type string
	ID   interface{}
}

ModelNotFoundError identifies that a given model was not found in the Database with the given ID

func (*ModelNotFoundError) Error

func (e *ModelNotFoundError) Error() string

type MustWaitMembershipCooldownError

type MustWaitMembershipCooldownError struct {
	Time     int
	PlayerID string
	ClanID   string
}

MustWaitMembershipCooldownError identifies that one must wait a number of seconds before creating the membership

func (*MustWaitMembershipCooldownError) Error

type Player

type Player struct {
	ID              int                    `db:"id"`
	GameID          string                 `db:"game_id"`
	PublicID        string                 `db:"public_id"`
	Name            string                 `db:"name"`
	Metadata        map[string]interface{} `db:"metadata"`
	MembershipCount int                    `db:"membership_count"`
	OwnershipCount  int                    `db:"ownership_count"`
	CreatedAt       int64                  `db:"created_at"`
	UpdatedAt       int64                  `db:"updated_at"`
}

Player identifies uniquely one player in a given game

func CreatePlayer

func CreatePlayer(db DB, gameID, publicID, name string, metadata map[string]interface{}, upsert bool) (*Player, error)

CreatePlayer creates a new player

func GetPlayerByID

func GetPlayerByID(db DB, id int) (*Player, error)

GetPlayerByID returns a player by id

func GetPlayerByPublicID

func GetPlayerByPublicID(db DB, gameID string, publicID string) (*Player, error)

GetPlayerByPublicID returns a player by their public id

func GetTestPlayerWithMemberships

func GetTestPlayerWithMemberships(db DB, gameID string, approvedMemberships, rejectedMemberships, bannedMemberships, pendingMemberships int) (*Player, error)

GetTestPlayerWithMemberships returns a player with approved, rejected and banned memberships

func UpdatePlayer

func UpdatePlayer(db DB, gameID, publicID, name string, metadata map[string]interface{}) (*Player, error)

UpdatePlayer updates an existing player

func (*Player) PreInsert

func (p *Player) PreInsert(s gorp.SqlExecutor) error

PreInsert populates fields before inserting a new player

func (*Player) PreUpdate

func (p *Player) PreUpdate(s gorp.SqlExecutor) error

PreUpdate populates fields before updating a player

func (*Player) Serialize

func (p *Player) Serialize() map[string]interface{}

Serialize the player information to JSON

type PlayerCannotCreateMembershipError

type PlayerCannotCreateMembershipError struct {
	PlayerID interface{}
	ClanID   interface{}
}

PlayerCannotCreateMembershipError identifies that a given player is not allowed to create a membership

func (*PlayerCannotCreateMembershipError) Error

type PlayerCannotPerformMembershipActionError

type PlayerCannotPerformMembershipActionError struct {
	Action      string
	PlayerID    interface{}
	ClanID      interface{}
	RequestorID interface{}
}

PlayerCannotPerformMembershipActionError identifies that a given player is not allowed to promote/demote another member

func (*PlayerCannotPerformMembershipActionError) Error

type PlayerReachedMaxClansError

type PlayerReachedMaxClansError struct {
	ID interface{}
}

PlayerReachedMaxClansError identifies that a given player already reached the max number of clans allowed

func (*PlayerReachedMaxClansError) Error

type PlayerReachedMaxInvitesError

type PlayerReachedMaxInvitesError struct {
	ID string
}

PlayerReachedMaxInvitesError identifies that a given player already reached the max number of pending invites allowed

func (*PlayerReachedMaxInvitesError) Error

type PruneOptions added in v0.12.0

type PruneOptions struct {
	GameID                        string
	PendingApplicationsExpiration int
	PendingInvitesExpiration      int
	DeniedMembershipsExpiration   int
	DeletedMembershipsExpiration  int
}

PruneOptions has all the prunable memberships TTL

type PruneStats added in v0.12.0

type PruneStats struct {
	PendingApplicationsPruned int
	PendingInvitesPruned      int
	DeniedMembershipsPruned   int
	DeletedMembershipsPruned  int
}

PruneStats show stats about what has been pruned

func PruneStaleData added in v0.12.0

func PruneStaleData(options *PruneOptions, db DB, logger zap.Logger) (*PruneStats, error)

PruneStaleData off of Khan's database

func (*PruneStats) GetStats added in v0.12.0

func (ps *PruneStats) GetStats() string

GetStats returns a formatted message

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL