user

package
v0.0.0-...-1967991 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BanController

type BanController struct {
	Service BanService
}

func (BanController) ListRoutes

func (controller BanController) ListRoutes() []route.Route

type BanService

type BanService interface {
	BanUser(bannedId string, bannerId string) error
	UnbanUser(bannedId string, bannerId string) error
	IsUserBanned(bannedId string, bannerId string) (bool, error)
	AddBanListener(tag string, listener banListener)
}

type BanServiceImpl

type BanServiceImpl struct {
	Db Dao
	// contains filtered or unexported fields
}

func (*BanServiceImpl) AddBanListener

func (service *BanServiceImpl) AddBanListener(tag string, listener banListener)

func (*BanServiceImpl) BanUser

func (service *BanServiceImpl) BanUser(bannedId string, bannerId string) error

func (*BanServiceImpl) IsUserBanned

func (service *BanServiceImpl) IsUserBanned(bannedId string, bannerId string) (bool, error)

func (*BanServiceImpl) UnbanUser

func (service *BanServiceImpl) UnbanUser(bannedId string, bannerId string) error

type Controller

type Controller struct {
	// Dependencies
	Service Service
}

func (Controller) ListRoutes

func (controller Controller) ListRoutes() []route.Route

type Dao

type Dao interface {
	GetUserById(id uuid.UUID) (*ModelUser, error)
	InsertOrGetUserId(user ModelUser) (id uuid.UUID, isNew bool, err error)
	IsUserBannedBy(bannedId uuid.UUID, bannerId uuid.UUID) (bool, error)
	GetUserByIdAs(id uuid.UUID, searchAsId uuid.UUID) (*ModelUserWithCustom, error)
	BanUser(bannedId uuid.UUID, bannerId uuid.UUID) (bool, error)
	UnbanUser(bannedUuid uuid.UUID, bannerUuid uuid.UUID) (bool, error)
	EditUser(userUuid uuid.UUID, user ModelUser) error
	EditUsername(userUuid uuid.UUID, username string) error
	GetUserByUsernameAs(username string, searchAsId uuid.UUID) (*ModelUserWithCustom, error)
	ListUsersByUsernameAs(username string, searchAsId uuid.UUID, afterUsername string, afterId uuid.UUID) ([]ModelUserWithCustom, error)
}

type DbDao

type DbDao struct {
	Db database.AppDatabase
}

func (DbDao) BanUser

func (dao DbDao) BanUser(bannedId uuid.UUID, bannerId uuid.UUID) (bool, error)

func (DbDao) EditUser

func (dao DbDao) EditUser(userUuid uuid.UUID, user ModelUser) error

func (DbDao) EditUsername

func (dao DbDao) EditUsername(userUuid uuid.UUID, username string) error

func (DbDao) GetUserById

func (dao DbDao) GetUserById(id uuid.UUID) (*ModelUser, error)

func (DbDao) GetUserByIdAs

func (dao DbDao) GetUserByIdAs(id uuid.UUID, searchAsId uuid.UUID) (*ModelUserWithCustom, error)

GetUserByIdAs also adds personal fields such as "banned" which are relative to the actual user looking for this data

func (DbDao) GetUserByUsernameAs

func (dao DbDao) GetUserByUsernameAs(username string, searchAsId uuid.UUID) (*ModelUserWithCustom, error)

func (DbDao) InsertOrGetUserId

func (dao DbDao) InsertOrGetUserId(user ModelUser) (uuid.UUID, bool, error)

InsertOrGetUserId tries to insert the new given user, or returns the ID of the existing one in case of conflicts (e.g.: on username).

Since concurrency issues may happen, a transaction is used. Boolean return value indicates whether the user is new

func (DbDao) IsUserBannedBy

func (dao DbDao) IsUserBannedBy(bannedId uuid.UUID, bannerId uuid.UUID) (bool, error)

func (DbDao) ListUsersByUsernameAs

func (dao DbDao) ListUsersByUsernameAs(username string, searchAsId uuid.UUID, afterUsername string, afterId uuid.UUID) ([]ModelUserWithCustom, error)

func (DbDao) UnbanUser

func (dao DbDao) UnbanUser(bannedUuid uuid.UUID, bannerUuid uuid.UUID) (bool, error)

type IdParams

type IdParams struct {
	UserId string `json:"userId" validate:"required,uuid"`
}

type IdUserCursor

type IdUserCursor struct {
	api.PaginationInfo
	IdParams
}

type ModelUser

type ModelUser struct {
	Id       []byte `json:"id"`
	Name     string `json:"name"`
	Surname  string `json:"surname"`
	Username string `json:"username"`
}

ModelUser is the entity for the User database table

type ModelUserInfo

type ModelUserInfo struct {
	ModelUser
	FollowersCount  uint `json:"followersCount"`
	FollowingsCount uint `json:"followingsCount"`
	PostsCount      uint `json:"photosCount"`
}

ModelUserInfo represents the actual database entity UserInfo (Data Layer in our architecture)

type ModelUserWithCustom

type ModelUserWithCustom struct {
	ModelUserInfo
	Banned    int64 `json:"banned"`
	Following int64 `json:"following"`
}

ModelUserWithCustom is ModelUserInfo with all fields which depend on the actual user performing the query.

func ParseUserEntities

func ParseUserEntities(rows database.StructRows) ([]ModelUserWithCustom, error)

func (ModelUserWithCustom) ToDto

func (user ModelUserWithCustom) ToDto() User

type Service

type Service interface {
	GetUserAs(searchedId string, searchAsId string) (*User, error)
	UpdateUserDetails(id string, newUser newUser) (User, error)
	UpdateUsername(id string, username string) (User, error)
	GetUserByUsernameAs(username string, searchAsId string) (*User, error)
	ListUsersByUsernameAs(username string, searchAsId string, pageCursor string) ([]User, *string, error)
}

type ServiceImpl

type ServiceImpl struct {
	Db Dao
}

func (ServiceImpl) GetUserAs

func (service ServiceImpl) GetUserAs(searchedId string, searchAsId string) (*User, error)

func (ServiceImpl) GetUserByUsernameAs

func (service ServiceImpl) GetUserByUsernameAs(username string, searchAsId string) (*User, error)

func (ServiceImpl) ListUsersByUsernameAs

func (service ServiceImpl) ListUsersByUsernameAs(username string, searchAsId string, pageCursor string) ([]User, *string, error)

func (ServiceImpl) UpdateUserDetails

func (service ServiceImpl) UpdateUserDetails(id string, newUser newUser) (User, error)

func (ServiceImpl) UpdateUsername

func (service ServiceImpl) UpdateUsername(id string, username string) (User, error)

type User

type User struct {
	Id              string `json:"id"`
	FollowersCount  uint   `json:"followersCount"`
	FollowingsCount uint   `json:"followingsCount"`
	PostsCount      uint   `json:"postsCount"`
	Banned          bool   `json:"banned"`
	Following       bool   `json:"following"`
	// contains filtered or unexported fields
}

func DbUsersListToPage

func DbUsersListToPage(dbUsers []ModelUserWithCustom) (users []User, pageCursor *string)

Jump to

Keyboard shortcuts

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