models

package
v0.0.0-...-b40b27b Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2023 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package models config models.

Index

Constants

View Source
const (
	PUBLIC    visibilty = 255
	PROTECTED visibilty = 175
	PRIVATE   visibilty = 0
)

Variables

Db global db var

Functions

func CreatePheme

func CreatePheme(pheme Pheme) (uint, error)

CreatePheme adds a pheme to the DB.

func DeleteByID

func DeleteByID(userID uint) error

DeleteByID deletes the user by the ID.

func DeletePheme

func DeletePheme(phemeID uint, userID uint) (uint, error)

DeletePheme removes a pheme from a user.

func FetchAllPhemes

func FetchAllPhemes(userID uint) (*[]Pheme, error)

FetchAllPhemes returns all the phemes of a user, friends and followers with equal or higher visibility.

func FetchPhemes

func FetchPhemes(phemeID uint, userID uint, visibility byte) (*[]Pheme, error)

FetchPhemes returns the phemes if are visible to the user.

func FetchUserPhemes

func FetchUserPhemes(userID uint, visibility byte) (*[]Pheme, error)

FetchUserPhemes returns all the phemes of the logged user with equal or higher visibility.

func FindByName

func FindByName(userName string) (*[]User, error)

FindByName returns the users that contains the name.

func GetFollowers

func GetFollowers(userID uint) (*[]uint, error)

GetFollowers returns the followers of a user.

func GetFollowings

func GetFollowings(userID uint) (*[]User, error)

GetFollowings returns the users following of a user.

func GetFriends

func GetFriends(userID uint) (*[]uint, error)

GetFriends returns the friends of a user.

func GetUsers

func GetUsers() (*[]User, error)

GetUsers returns the users.

func IsFriend

func IsFriend(userID uint, friendID uint) (bool, error)

IsFriend returns if it is friend or not.

func PhemeVersion

func PhemeVersion() uint

PhemeVersion returns the version of the Pheme schema.

func RemoveFollower

func RemoveFollower(userID uint, followerID uint) error

RemoveFollower removes a follower for a user.

func RemoveFriend

func RemoveFriend(userID uint, friendID uint) error

RemoveFriend removes a friends for a user.

func UserVersion

func UserVersion() uint

UserVersion returns the current version of the user schema.

func UsersToUsersPublicData

func UsersToUsersPublicData(users *[]User) *[]UserPublicData

UsersToUsersPublicData convert a users array to a data public users array

Types

type DbConfig

type DbConfig struct {
	Host   string `yaml:"host"`
	User   string `yaml:"user"`
	Dbname string `yaml:"dbname"`
}

DbConfig database configuration.

type Message

type Message struct {
	Message string `json:"message"`
}

Message JSON model info

type Network

type Network struct {
	Server ServerConfig `yaml:"server"`
	Db     DbConfig     `yaml:"db"`
}

Network configuration.

type Pheme

type Pheme struct {
	ID         uint      `json:"id"`
	Version    uint      `json:"version" gorm:"not null" validate:"required"`
	CreatedAt  time.Time `json:"createdAt" gorm:"not null"`
	UpdatedAt  time.Time `json:"updatedAt"`
	Visibility byte      `json:"visibility" sql:"visibility" gorm:"not null" validate:"required"`
	Category   string    `json:"category" gorm:"not null" validate:"required"`
	Text       string    `json:"text" gorm:"not null" validate:"required"`
	CreatedBy  uint      `json:"createdBy" gorm:"not null"`
	UserID     uint      `json:"userId" gorm:"not null" validate:"required"`
}

Pheme model info @Description Pheme content

func FetchPheme

func FetchPheme(phemeID uint, userID uint) (*Pheme, error)

FetchPheme returns the pheme if is visible to the user.

func UpdatePheme

func UpdatePheme(pheme PhemeParamsPost, phemeID uint, userID uint) (Pheme, error)

UpdatePheme updates the data of a pheme.

type PhemeParamsID

type PhemeParamsID struct {
	ID uint `json:"id" query:"id" validate:"required"`
}

PhemeParamsID param @Description id param

type PhemeParamsPost

type PhemeParamsPost struct {
	Visibilty byte   `json:"visibility" validate:"min=0,max=255"`
	Category  string `json:"category" validate:"required"`
	Text      string `json:"text" validate:"required"`
	UserID    uint   `json:"userID" validate:"required"`
}

PhemeParamsPost params @Description post params

type ServerConfig

type ServerConfig struct {
	IP   string `yaml:"ip"`
	Port int    `yaml:"port"`
}

ServerConfig server configuration.

type StandardClaims

type StandardClaims struct {
	Audience  string `json:"aud,omitempty"`
	ExpiresAt int64  `json:"exp,omitempty"`
	Id        string `json:"jti,omitempty"`
	IssuedAt  int64  `json:"iat,omitempty"`
	Issuer    string `json:"iss,omitempty"`
	NotBefore int64  `json:"nbf,omitempty"`
	Subject   string `json:"sub,omitempty"`
}

StandardClaims from jwt

type User

type User struct {
	ID           uint      `json:"id"`
	Version      uint      `json:"version" gorm:"not null"`
	UserName     string    `json:"username" gorm:"not null"`
	Email        string    `json:"email" gorm:"unique;not null"`
	Avatar       string    `json:"avatar"`
	Password     []byte    `json:"-"  gorm:"not null"`
	PasswordDate time.Time `json:"-" gorm:"not null"`
	CreatedAt    time.Time `json:"createdAt" gorm:"not null"`
	Followers    []User    `json:"-" gorm:"many2many:followship;association_jointable_foreignkey:follow_id"`
	Friends      []User    `json:"-" gorm:"many2many:friendship;association_jointable_foreignkey:friend_id"`
}

User model info @Description User account

func AddFollower

func AddFollower(userID uint, followerID uint) (*User, error)

AddFollower adds a follower to a user.

func AddFriend

func AddFriend(userID uint, friendID uint) (*User, error)

AddFriend adds a friends to a user.

func FindByID

func FindByID(userID uint) (*User, error)

FindByID returns the user from the ID.

func GetUser

func GetUser(c *fiber.Ctx, secretKey string) (*User, error)

GetUser returns the logged user.

func GetUserByEmail

func GetUserByEmail(email string) (*User, error)

GetUserByEmail Gets the user of the email.

func RegisterUser

func RegisterUser(username string, email string, avatar string, password string) (*User, error)

RegisterUser create a new user.

type UserParamsID

type UserParamsID struct {
	ID uint `query:"id" validate:"required"`
}

UserParamsID user id param. @Description name param

type UserParamsLogin

type UserParamsLogin struct {
	Email    string `query:"email" validate:"required"`
	Password string `query:"password" validate:"required"`
}

UserParamsLogin login user params.

type UserParamsName

type UserParamsName struct {
	UserName string `query:"username" validate:"required"`
}

UserParamsName user name param.

type UserParamsNew

type UserParamsNew struct {
	UserName string `query:"username" validate:"required"`
	Email    string `query:"email" validate:"required"`
	Avatar   string `query:"avatar"`
	Password string `query:"password" validate:"required"`
}

UserParamsNew new user params.

type UserPublicData

type UserPublicData struct {
	ID        uint      `json:"id" validate:"required"`
	UserName  string    `json:"username" validate:"required"`
	Avatar    string    `json:"avatar" validate:"required"`
	CreatedAt time.Time `json:"createdAt" validate:"required"`
}

UserPublicData User public data.

func UserToUserPublicData

func UserToUserPublicData(user *User) *UserPublicData

UserToUserPublicData convert a user to a data public user

Jump to

Keyboard shortcuts

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