models

package
v0.0.0-...-1c15b68 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package models are the DB and data structures for the application

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func ConnectDatabase

func ConnectDatabase()

ConnectDatabase establishes a connection to the database and performs necessary migrations. It initializes the `DB` variable with the connected database. If an error occurs during the connection or migration, a fatal log is generated.

func FilterDuplicates

func FilterDuplicates[T IDer](items []T) []T

func GetPaginationQueryParams

func GetPaginationQueryParams(c *gin.Context) (int, int)

func Paginate

func Paginate(page, pageSize int) func(db *gorm.DB) *gorm.DB

Types

type EvolutionChain

type EvolutionChain struct {
	ID                uint               `gorm:"primary_key" json:"id,omitempty"`
	BabyTriggerItem   *Item              `gorm:"default:null;foreignkey:BabyTriggerItemId" json:"babyTriggerItem"`
	BabyTriggerItemId *uint              `json:"babyTriggerItemId,omitempty"`
	ChainLink         EvolutionChainLink `json:"chainLink,omitempty"`
	ChainLinkId       *uint              `json:"chainLinkId,omitempty"`
}
type EvolutionChainLink struct {
	ID               uint                 `gorm:"primary_key" json:"id,omitempty"`
	IsBaby           bool                 `json:"isBaby,omitempty"`
	PokemonSpecies   PokemonSpecies       `json:"pokemonSpecies,omitempty"`
	PokemonSpeciesId uint                 `gorm:"uniqueIndex" json:"pokemonSpeciesId"`
	EvolutionDetails []EvolutionDetails   `gorm:"foreignKey:EvolutionChainLinkID" json:"evolutionDetails,omitempty"`
	EvolvesTo        []EvolutionChainLink `gorm:"foreignKey:EvolvesFromId" json:"evolvesTo,omitempty"`
	EvolvesFrom      *EvolutionChainLink  `json:"evolvesFrom,omitempty"`
	EvolvesFromId    *uint                `json:"evolvesFromId,omitempty"`
}

type EvolutionDetails

type EvolutionDetails struct {
	ID                    uint             `gorm:"primary_key" json:"id,omitempty"`
	Item                  *Item            `gorm:"default:null;foreignkey:ItemID" json:"item,omitempty"`
	ItemID                *uint            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"itemId,omitempty"`
	EvolutionTrigger      EvolutionTrigger `gorm:"foreignkey:EvolutionTriggerId" json:"trigger,omitempty"`
	EvolutionTriggerId    *uint            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"triggerId,omitempty"`
	GenderId              *int             `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"genderId,omitempty"`
	HeldItem              *Item            `gorm:"default:null;foreignkey:HeldItemId" json:"heldItem,omitempty"`
	HeldItemId            *uint            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"heldItemId,omitempty"`
	KnownMove             *Move            `gorm:"default:null;foreignkey:KnownMoveID" json:"knownMove,omitempty"`
	KnownMoveID           *uint            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"knownMoveId,omitempty"`
	KnownMoveType         *MoveType        `gorm:"default:null;foreignkey:KnownMoveTypeID" json:"knownMoveType,omitempty"`
	KnownMoveTypeID       *uint            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"knownMoveTypeId,omitempty"`
	Location              *Location        `gorm:"default:null;foreignkey:LocationID" json:"location,omitempty"`
	LocationID            *uint            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"locationId,omitempty"`
	MinLevel              *int             `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"minLevel,omitempty"`
	MinHappiness          *int             `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"minHappiness,omitempty"`
	MinBeauty             *int             `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"minBeauty,omitempty"`
	MinAffection          *int             `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"minAffection,omitempty"`
	NeedsOverworldRain    *bool            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"needsOverworldRain,omitempty"`
	PartySpecies          *PokemonSpecies  `gorm:"default:null;foreignkey:PartySpeciesID" json:"partySpecies,omitempty"`
	PartySpeciesID        *uint            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"partySpeciesId,omitempty"`
	PartyType             *MoveType        `gorm:"default:null;foreignkey:PartyTypeId" json:"partyType,omitempty"`
	PartyTypeId           *uint            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"partyTypeId,omitempty"`
	RelativePhysicalStats *int             `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"relativePhysicalStats,omitempty"`
	TimeOfDay             *string          `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"timeOfDay,omitempty"`
	TradeSpecies          *PokemonSpecies  `gorm:"default:null;foreignkey:TradeSpeciesID" json:"tradeSpecies,omitempty"`
	TradeSpeciesID        *uint            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"tradeSpeciesId,omitempty"`
	TurnUpsideDown        *bool            `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"turnUpsideDown,omitempty"`
	EvolutionChainLinkID  uint             `gorm:"uniqueIndex:details_index,option:NULLS NOT DISTINCT" json:"chainLinkId,omitempty"`
}

func (EvolutionDetails) BeforeCreate

func (e EvolutionDetails) BeforeCreate(tx *gorm.DB) (err error)

type EvolutionTrigger

type EvolutionTrigger struct {
	ID   uint   `gorm:"primary_key" json:"id,omitempty"`
	Name string `json:"name,omitempty"`
}

type GenericId

type GenericId uint

func (GenericId) ID

func (g GenericId) ID() uint

type IDer

type IDer interface {
	ID() uint
}

type Item

type Item struct {
	GenericId `gorm:"primary_key;column:id" json:"id"`
	Name      string `json:"name"`
	SpriteUrl string `json:"spriteUrl"`
}

type ListPokemonParams

type ListPokemonParams struct {
	PokemonName   string `form:"pokemonName" json:"pokemonName,omitempty"`
	PokemonTypeId int64  `form:"pokemonTypeId" json:"pokemonTypeId,omitempty"`
}

type ListPokemonResponse

type ListPokemonResponse struct {
	Pokemon  []PokemonSpecies  `json:"pokemon"`
	Page     int               `json:"page"`
	PageSize int               `json:"pageSize"`
	Total    int               `json:"total"`
	Params   ListPokemonParams `json:"params"`
	NextPage string            `json:"nextPage,omitempty"`
	PrevPage string            `json:"prevPage,omitempty"`
}

type Location

type Location struct {
	ID       uint   `gorm:"primary_key" json:"id"`
	Name     string `json:"name"`
	Region   Region `json:"region"`
	RegionID uint   `json:"region_id"`
}

type Move

type Move struct {
	Id               int       `json:"id"`
	Name             string    `json:"name"`
	Accuracy         int       `json:"accuracy"`
	Pp               int       `json:"pp"`
	Priority         int       `json:"priority"`
	Power            int       `json:"power"`
	MoveType         MoveType  `json:"moveType"`
	MoveTypeID       uint      `json:"moveTypeID"`
	LearnedByPokemon []Pokemon `gorm:"many2many:pokemon_move_sets;" json:"learnedByPokemon"`
}

type MoveType

type MoveType struct {
	GenericId `gorm:"primary_key;column:id" json:"id"`
	Name      string `gorm:"not null" json:"name"`
	//TODO: convert to manytomany table somehow
	DoubleDamageTo   pq.Int64Array `gorm:"type:integer[]" json:"double_damage_to,omitempty"`
	HalfDamageTo     pq.Int64Array `gorm:"type:integer[]"  json:"half_damage_to,omitempty"`
	NoDamageTo       pq.Int64Array `gorm:"type:integer[]"  json:"no_damage_to,omitempty"`
	DoubleDamageFrom pq.Int64Array `gorm:"type:integer[]" json:"double_damage_from,omitempty"`
	HalfDamageFrom   pq.Int64Array `gorm:"type:integer[]"  json:"half_damage_from,omitempty"`
	NoDamageFrom     pq.Int64Array `gorm:"type:integer[]"  json:"no_damage_from,omitempty"`
	ImgUrl           string        `json:"img_url,omitempty"`
}

MoveType represents a type in the application. It contains properties such as GenericId, Name, DoubleDamage, HalfDamage, and NoDamage. The GenericId field is the unique identifier of the type. The Name field represents the name of the type. The DoubleDamage field contains a list of type IDs that are super effective against this type. The HalfDamage field contains a list of type IDs that are not very effective against this type. The NoDamage field contains a list of type IDs that have no effect on this type.

type Pokemon

type Pokemon struct {
	ID               uint            `gorm:"primary_key" json:"id,omitempty"`
	Name             string          `gorm:"unique" json:"name,omitempty"`
	PrimaryType      *MoveType       `gorm:"foreignKey:PrimaryTypeId" json:"primary_type,omitempty"`
	PrimaryTypeId    *uint           `json:"primary_type_id,omitempty"`
	SecondaryType    *MoveType       `gorm:"foreignKey:SecondaryTypeId;" json:"secondary_type,omitempty"`
	SecondaryTypeId  *uint           `json:"secondary_type_id,omitempty"`
	PokemonSpecies   *PokemonSpecies `gorm:"foreignKey:PokemonSpeciesId" json:"pokemon_species,omitempty"`
	PokemonSpeciesId uint            `json:"pokemon_species_id,omitempty"`
	SpriteUrl        string          `json:"sprite_url,omitempty"`
	Cry              string          `json:"cry,omitempty"`
	Weight           int             `json:"weight,omitempty"`
	Height           int             `json:"height,omitempty"`
	IsDefault        bool            `json:"is_default,omitempty"`
	LearnableMoves   []Move          `gorm:"many2many:pokemon_move_sets;" json:"learnable_moves,omitempty"`
}

type PokemonSpecies

type PokemonSpecies struct {
	ID                   uint      `gorm:"primary_key" json:"id,omitempty"`
	HasGenderDifferences bool      `json:"has_gender_differences,omitempty"`
	HatchCounter         int       `json:"hatch_counter,omitempty"`
	IsBaby               bool      `json:"is_baby,omitempty"`
	IsLegendary          bool      `json:"is_legendary,omitempty"`
	IsMythical           bool      `json:"is_mythical,omitempty"`
	Name                 string    `json:"name,omitempty"`
	Varieties            []Pokemon `json:"varieties,omitempty"`
}

type Region

type Region struct {
	ID        uint       `gorm:"primary_key" json:"id"`
	Name      string     `json:"name"`
	Locations []Location `json:"locations"`
}

type Sprites

type Sprites struct {
	BackDefault      string `json:"back_default"`
	BackFemale       string `json:"back_female,omitempty"`
	BackShiny        string `json:"back_shiny"`
	BackShinyFemale  string `json:"back_shiny_female,omitempty"`
	FrontDefault     string `json:"front_default"`
	FrontFemale      string `json:"front_female,omitempty"`
	FrontShiny       string `json:"front_shiny"`
	FrontShinyFemale string `json:"front_shiny_female,omitempty"`
}

Jump to

Keyboard shortcuts

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