user

package
v0.0.0-...-b985c81 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoMigrate

func AutoMigrate()

AutoMigrate ensures the database is migrated to the latest schema

Types

type DiscoverFilters

type DiscoverFilters struct {
	MinAge int
	MaxAge int
	Gender string
}

DiscoverFilters that we can use in the GetUnswipedUsers function.

type Location

type Location struct {
	Name      string  `json:"name"`
	Longitude float64 `json:"longitude"`
	Latitude  float64 `json:"latitude"`
}

Location is a struct that represents a high-level location

type User

type User struct {
	ID       int      `json:"id" gorm:"primaryKey"`
	Name     string   `json:"name"`
	Email    string   `json:"email,omitempty" gorm:"unique"`
	Gender   string   `json:"gender"`
	Age      int      `json:"age"`
	Password string   `json:"password,omitempty"`
	Location Location `json:"location" gorm:"embedded;embeddedPrefix:location_"`
}

User is a struct that represents a high-level user

func Create

func Create(newUser User) (User, error)

Create a new user, ensuring to hash the password and return it after creation

func CreateRandom

func CreateRandom() (User, error)

CreateRandom creates a user with random data, returning the user as if you had called 'Create'.

func GetByEmail

func GetByEmail(email string) (User, error)

GetByEmail returns a user by their email

func GetByID

func GetByID(id int) (User, error)

GetByID returns a user by their ID

type UserWithDistance

type UserWithDistance struct {
	User           `json:",inline"`
	DistanceFromMe float64 `json:"distance_from_me,omitempty" gorm:"column:distance_in_km"`
}

UserWithDistance is a struct that adds a distance field to the User struct

func GetUnswipedUsers

func GetUnswipedUsers(userID int, filters DiscoverFilters) ([]UserWithDistance, error)

Get all users that the user hasn't swiped on. (Ensuring the user is not included in the results.)

func (UserWithDistance) TableName

func (UserWithDistance) TableName() string

TableName is used to define the table name for the User struct in the database We want to continue using the 'users' table, as this struct just declares our calculated distance column.

Jump to

Keyboard shortcuts

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