databaserepo

package
v0.0.0-...-a448e87 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2019 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusMatched = 21
)

Like and dislike status

Variables

View Source
var ErrInsufficentMessages = errors.New("insufficent messages to load")

ErrInsufficentMessages indicate there are not enough messages to load base on provided length

View Source
var (
	ErrNoRows = errors.New("Error no rows")
)

Functions

This section is empty.

Types

type CachedRepo

type CachedRepo struct {
	Conn               *gorm.DB
	LikeAndDislikeRepo ILikeAndDislikeRepo
}

func (*CachedRepo) FindRelevant

func (r *CachedRepo) FindRelevant(user *model.User, hobbies []model.Hobby, exceptUser []cachemodels.CachedUser, nUser int) ([]cachemodels.CachedUser, error)

func (*CachedRepo) Get

func (r *CachedRepo) Get(limit int) ([]cachemodels.CachedUser, error)

func (*CachedRepo) GetByUsername

func (r *CachedRepo) GetByUsername(username string) (*cachemodels.CachedUser, error)

type DatabaseRepo

type DatabaseRepo struct {
	UserRepo           IUserRepo
	HobbyRepo          IHobbyRepo
	UserHobbyRepo      IUserHobbyRepo
	UserImgRepo        IUserImgRepo
	LikeAndDislikeRepo ILikeAndDislikeRepo
	CachedRepo         ICachedRepo
	ConversationRepo   IConversationRepo
	ParticipantRepo    IParticipantRepo
	MessageRepo        IMessageRepo
}

DatabaseRepo is a struct that contains ALL repositories that use databse connection. This is use to group repositories' creation to one function NewDatabaseRepo

func NewDatabaseRepo

func NewDatabaseRepo(conn *gorm.DB) *DatabaseRepo

NewDatabaseRepo is a function to create all database (MySQL) repositories from one database connection

type ICachedRepo

type ICachedRepo interface {
	Get(limit int) ([]cachemodels.CachedUser, error)
	GetByUsername(username string) (*cachemodels.CachedUser, error)
	FindRelevant(user *model.User, hobbies []model.Hobby, exceptUser []cachemodels.CachedUser, nUser int) ([]cachemodels.CachedUser, error)
}

func NewCahedRepo

func NewCahedRepo(conn *gorm.DB) ICachedRepo

type IConversationRepo

type IConversationRepo interface {
	Create(c *model.Conversation) (*model.Conversation, error)
	GetByUserIds(userId1, userId2 int) (*model.Conversation, error)
}

type IHobbyRepo

type IHobbyRepo interface {
	GetAll() ([]model.Hobby, error)
	GetByID(id int) (*model.Hobby, error)
	GetByUser(user *model.User) (hobbies []model.Hobby, err error)
}

IHobbyRepo is an interface for interest repo to follow

func NewMySQLHobbyRepo

func NewMySQLHobbyRepo(conn *gorm.DB) IHobbyRepo

type ILikeAndDislikeRepo

type ILikeAndDislikeRepo interface {
	Create(likeDislike *model.LikeAndDislike) error
	Update(likeDislike *model.LikeAndDislike) error
	GetByUserIDs(userID1, userID2 int) (*model.LikeAndDislike, error)
}

func NewMySQLLikeAndDislikeRepo

func NewMySQLLikeAndDislikeRepo(conn *gorm.DB) ILikeAndDislikeRepo

NewMySQLLikeAndDislikeRepo return an instance of type MySQLUserRepo

type IMessageRepo

type IMessageRepo interface {
	Create(c *model.Message) error
	GetByConversation(c *model.Conversation, offset, length int) ([]model.Message, error)
}

type IParticipantRepo

type IParticipantRepo interface {
	Create(c *model.Participant) error
	JoinConversation(p *model.User, c *model.Conversation) (*model.Participant, error)
}

type IUserHobbyRepo

type IUserHobbyRepo interface {
	Create(*model.UserHobby) error
	DeleteHobby(*model.UserHobby) error
}

func NewMySQLUserHobbyRepo

func NewMySQLUserHobbyRepo(conn *gorm.DB) IUserHobbyRepo

NewMySQLUserRepo return an instance of type MySQLUserRepo

type IUserImgRepo

type IUserImgRepo interface {
	Create(*model.UserImg) error
	AllByUser(*model.User) ([]model.UserImg, error)
	GetById(id int) (*model.UserImg, error)
	Delete(usrimg *model.UserImg) error
}

func NewMySQLUserImgRepo

func NewMySQLUserImgRepo(conn *gorm.DB) IUserImgRepo

type IUserRepo

type IUserRepo interface {
	UpdatePassword(userID int, password string) error
	GetByID(id int) (*model.User, error)
	Count() int
	GetAll() ([]model.User, error)
	GetByEmail(email string) (*model.User, error)
	GetByUsername(username string) (*model.User, error)
	Create(user *model.User) error
	RenewSecretKey(userID int) error
	FindSecretKey(uname string) ([]byte, error)
	UpdateAvatar(username, pathImg string) error
	UpdateLastSeen(username string) error
	GetMatches(userID int) ([]model.User, error)
	Update(*model.User) error
}

IUserRepo is an interface for user repositories to follow. This repository's purpose is to provide functions for CRUD database on `users` table.

func NewMySQLUserRepo

func NewMySQLUserRepo(conn *gorm.DB) IUserRepo

NewMySQLUserRepo return an instance of type MySQLUserRepo

type MySQLConversationRepo

type MySQLConversationRepo struct {
	Conn *gorm.DB
}

func NewMySQLConversationRepo

func NewMySQLConversationRepo(conn *gorm.DB) *MySQLConversationRepo

func (*MySQLConversationRepo) Create

func (*MySQLConversationRepo) GetByUserIds

func (cr *MySQLConversationRepo) GetByUserIds(user_id1, user_id2 int) (*model.Conversation, error)

type MySQLHobbyRepo

type MySQLHobbyRepo struct {
	Conn *gorm.DB
}

func (MySQLHobbyRepo) GetAll

func (ir MySQLHobbyRepo) GetAll() ([]model.Hobby, error)

func (MySQLHobbyRepo) GetByID

func (ir MySQLHobbyRepo) GetByID(id int) (*model.Hobby, error)

func (MySQLHobbyRepo) GetByUser

func (ir MySQLHobbyRepo) GetByUser(user *model.User) (hobbies []model.Hobby, err error)

type MySQLLikeAndDislikeRepo

type MySQLLikeAndDislikeRepo struct {
	Conn *gorm.DB
}

MySQLLikeAndDislikeRepo contains gorm.DB connection

func (*MySQLLikeAndDislikeRepo) Create

func (l *MySQLLikeAndDislikeRepo) Create(likeDislike *model.LikeAndDislike) error

func (*MySQLLikeAndDislikeRepo) GetByUserIDs

func (l *MySQLLikeAndDislikeRepo) GetByUserIDs(userID1, userID2 int) (*model.LikeAndDislike, error)

func (*MySQLLikeAndDislikeRepo) Update

func (l *MySQLLikeAndDislikeRepo) Update(likeDislike *model.LikeAndDislike) error

type MySQLMessageRepo

type MySQLMessageRepo struct {
	Conn *gorm.DB
}

func NewMySQLMessageRepo

func NewMySQLMessageRepo(conn *gorm.DB) *MySQLMessageRepo

func (*MySQLMessageRepo) Create

func (mr *MySQLMessageRepo) Create(c *model.Message) error

func (*MySQLMessageRepo) GetByConversation

func (mr *MySQLMessageRepo) GetByConversation(c *model.Conversation, offset, length int) ([]model.Message, error)

type MySQLParticipantRepo

type MySQLParticipantRepo struct {
	Conn *gorm.DB
}

func NewMySQLParticipantRepo

func NewMySQLParticipantRepo(conn *gorm.DB) *MySQLParticipantRepo

func (*MySQLParticipantRepo) Create

func (*MySQLParticipantRepo) JoinConversation

func (pr *MySQLParticipantRepo) JoinConversation(p *model.User, c *model.Conversation) (*model.Participant, error)

type MySQLUserHobbyRepo

type MySQLUserHobbyRepo struct {
	Conn *gorm.DB
}

MySQLUserRepo contains gorm.DB connection

func (MySQLUserHobbyRepo) Create

func (uhr MySQLUserHobbyRepo) Create(uh *model.UserHobby) error

func (MySQLUserHobbyRepo) DeleteHobby

func (uhr MySQLUserHobbyRepo) DeleteHobby(uh *model.UserHobby) error

type MySQLUserImgRepo

type MySQLUserImgRepo struct {
	Conn *gorm.DB
}

func (*MySQLUserImgRepo) AllByUser

func (uiRepo *MySQLUserImgRepo) AllByUser(user *model.User) ([]model.UserImg, error)

func (*MySQLUserImgRepo) Create

func (userImgRepo *MySQLUserImgRepo) Create(userImg *model.UserImg) error

func (*MySQLUserImgRepo) Delete

func (uiRepo *MySQLUserImgRepo) Delete(usrimg *model.UserImg) error

func (*MySQLUserImgRepo) GetById

func (uiRepo *MySQLUserImgRepo) GetById(id int) (*model.UserImg, error)

type MySQLUserRepo

type MySQLUserRepo struct {
	Conn *gorm.DB
}

MySQLUserRepo contains gorm.DB connection

func (*MySQLUserRepo) Count

func (userRepo *MySQLUserRepo) Count() int

Count return number of User in database

func (*MySQLUserRepo) Create

func (userRepo *MySQLUserRepo) Create(user *model.User) error

Create save user to database

func (*MySQLUserRepo) FindSecretKey

func (userRepo *MySQLUserRepo) FindSecretKey(uname string) ([]byte, error)

FindSecretKey return secretkey of a user

func (*MySQLUserRepo) GetAll

func (userRepo *MySQLUserRepo) GetAll() ([]model.User, error)

GetAll return all of user exists in datatabse

func (*MySQLUserRepo) GetByEmail

func (userRepo *MySQLUserRepo) GetByEmail(email string) (*model.User, error)

GetByEmail return user have email is parameter email

func (*MySQLUserRepo) GetByID

func (userRepo *MySQLUserRepo) GetByID(id int) (*model.User, error)

GetByID return a user based on his ID

func (*MySQLUserRepo) GetByUsername

func (userRepo *MySQLUserRepo) GetByUsername(username string) (*model.User, error)

GetByUsername ...

func (*MySQLUserRepo) GetMatches

func (userRepo *MySQLUserRepo) GetMatches(userID int) ([]model.User, error)

func (*MySQLUserRepo) RenewSecretKey

func (userRepo *MySQLUserRepo) RenewSecretKey(userID int) error

RenewSecretKey create a new secretkey for user

func (*MySQLUserRepo) Update

func (userRepo *MySQLUserRepo) Update(u *model.User) error

func (*MySQLUserRepo) UpdateAvatar

func (userRepo *MySQLUserRepo) UpdateAvatar(username, pathImg string) error

func (*MySQLUserRepo) UpdateLastSeen

func (userRepo *MySQLUserRepo) UpdateLastSeen(username string) error

UpdateLastSeen update last seen of user

func (*MySQLUserRepo) UpdatePassword

func (userRepo *MySQLUserRepo) UpdatePassword(userID int, password string) error

UpdatePassword update password

Jump to

Keyboard shortcuts

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