mongo

package
v0.0.0-...-187a358 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDatabase

func InitDatabase(ctx context.Context, opts Opts) (*mongo.Database, error)

Types

type LangModel

type LangModel struct {
	ID       string `bson:"_id"`
	Name     string `bson:"name"`
	AuthorID string `bson:"author_id"`
}

type LangRepo

type LangRepo struct {
	// contains filtered or unexported fields
}

func NewLangRepo

func NewLangRepo(db *mongo.Database) (*LangRepo, error)

func (*LangRepo) Create

func (r *LangRepo) Create(l *lang.Lang) error

func (*LangRepo) Delete

func (r *LangRepo) Delete(id, authorID string) error

func (*LangRepo) DeleteByAuthorID

func (r *LangRepo) DeleteByAuthorID(authorID string) (int, error)

func (*LangRepo) Exist

func (r *LangRepo) Exist(id, authorID string) (bool, error)

func (*LangRepo) Get

func (r *LangRepo) Get(id, authorID string) (*lang.Lang, error)

func (*LangRepo) GetAllViews

func (r *LangRepo) GetAllViews(authorID string) ([]query.LangView, error)

func (*LangRepo) GetView

func (r *LangRepo) GetView(id, authorID string) (query.LangView, error)

func (*LangRepo) Update

func (r *LangRepo) Update(l *lang.Lang) error

type Opts

type Opts struct {
	Database string
	Host     string
	Port     int
	Username string
	Passwd   string
}

type TagModel

type TagModel struct {
	ID       string `bson:"_id"`
	Name     string `bson:"name"`
	AuthorID string `bson:"author_id"`
}

TagModel represents mongo tag document

type TagRepo

type TagRepo struct {
	// contains filtered or unexported fields
}

TagRepo Mongo DB implementation for domain tag entity

func NewTagRepo

func NewTagRepo(db *mongo.Database) (*TagRepo, error)

NewTagRepo creates TagRepo

func (*TagRepo) AllExist

func (r *TagRepo) AllExist(ids []string, authorID string) (bool, error)

AllExist checks that all tags exist in DB with passed ids and authorId

func (*TagRepo) Create

func (r *TagRepo) Create(t *tag.Tag) error

Create saves new tag to DB

func (*TagRepo) Delete

func (r *TagRepo) Delete(id, authorID string) error

Delete removes tag with id and authorId

func (*TagRepo) DeleteByAuthorID

func (r *TagRepo) DeleteByAuthorID(authorID string) (int, error)

func (*TagRepo) Get

func (r *TagRepo) Get(id, authorID string) (*tag.Tag, error)

Get searches for tag with id and authorId

func (*TagRepo) GetAllViews

func (r *TagRepo) GetAllViews(authorID string) ([]query.TagView, error)

GetAllViews returns all existing tag views for passed authorId

func (*TagRepo) GetView

func (r *TagRepo) GetView(id, authorID string) (query.TagView, error)

GetView searches for tag with id and authorId

func (*TagRepo) GetViews

func (r *TagRepo) GetViews(ids []string, authorID string) ([]query.TagView, error)

GetViews returns tag views for passed ids and authorId

func (*TagRepo) Update

func (r *TagRepo) Update(t *tag.Tag) error

Update updates already existed tag

type TranslationModel

type TranslationModel struct {
	ID            string    `bson:"_id"`
	AuthorID      string    `bson:"author_id"`
	CreatedAt     time.Time `bson:"created_at"`
	UpdatedAt     time.Time `bson:"updatedAt"`
	Transcription string    `bson:"transcription,omitempty"`
	Target        string    `bson:"target"`
	Source        string    `bson:"source"`
	Example       string    `bson:"example,omitempty"`
	TagIDs        []string  `bson:"tag_ids,omitempty"`
	LangID        string    `bson:"lang_id"`
}

TranslationModel represents mongo translation document

type TranslationRepo

type TranslationRepo struct {
	// contains filtered or unexported fields
}

TranslationRepo Mongo DB implementation for domain translation entity

func NewTranslationRepo

func NewTranslationRepo(db *mongo.Database, tagRepo query.TagViewRepository, langRepo query.LangViewRepository) (*TranslationRepo, error)

NewTranslationRepo creates new TranslationRepo

func (*TranslationRepo) Create

Create saves new translation to DB

func (*TranslationRepo) Delete

func (r *TranslationRepo) Delete(id, authorID string) error

func (*TranslationRepo) DeleteByAuthorID

func (r *TranslationRepo) DeleteByAuthorID(authorID string) (int, error)

func (*TranslationRepo) ExistByLang

func (r *TranslationRepo) ExistByLang(langID, authorID string) (bool, error)

func (*TranslationRepo) ExistByTag

func (r *TranslationRepo) ExistByTag(tagID, authorID string) (bool, error)

func (*TranslationRepo) Get

func (r *TranslationRepo) Get(id, authorID string) (*translation.Translation, error)

Get performs search request based on translation id and author id parameters and returns domain translation entity

func (*TranslationRepo) GetLastViewsBySourcePart

func (r *TranslationRepo) GetLastViewsBySourcePart(authorID, langID, sourcePart string, pageSize, page int) (query.LastTranslationViews, error)

func (*TranslationRepo) GetLastViewsByTags

func (r *TranslationRepo) GetLastViewsByTags(authorID, langID string, pageSize, page int, tagIds []string) (query.LastTranslationViews, error)

func (*TranslationRepo) GetLastViewsByTargetPart

func (r *TranslationRepo) GetLastViewsByTargetPart(authorID, langID, targetPart string, pageSize, page int) (query.LastTranslationViews, error)

func (*TranslationRepo) GetRandomViews

func (r *TranslationRepo) GetRandomViews(authorID, langID string, tagIds []string, limit int) (query.RandomViews, error)

func (*TranslationRepo) GetView

func (r *TranslationRepo) GetView(id, authorID string) (query.TranslationView, error)

func (*TranslationRepo) Update

Update updates already existed translation

type UserModel

type UserModel struct {
	ID            string `bson:"_id"`
	Name          string `bson:"name"`
	Email         string `bson:"email"`
	Password      string `bson:"password"`
	Role          int    `bson:"role"`
	DefaultLangID string `bson:"default_lang_id"`
}

UserModel represents mongo user document

type UserRepo

type UserRepo struct {
	// contains filtered or unexported fields
}

UserRepo Mongo DB implementation for domain user entity

func NewUserRepo

func NewUserRepo(db *mongo.Database, langRepo query.LangViewRepository, roleMapper *query.RoleConverter) (*UserRepo, error)

NewUserRepo creates new UserRepo

func (*UserRepo) Create

func (r *UserRepo) Create(usr *user.User) error

func (*UserRepo) Delete

func (r *UserRepo) Delete(id string) (int, error)

func (*UserRepo) Get

func (r *UserRepo) Get(id string) (*user.User, error)

func (*UserRepo) GetAllViews

func (r *UserRepo) GetAllViews() ([]query.UserView, error)

func (*UserRepo) GetByEmail

func (r *UserRepo) GetByEmail(email string) (*user.User, error)

GetByEmail returns User for email

func (*UserRepo) GetView

func (r *UserRepo) GetView(id string) (query.UserView, error)

func (*UserRepo) Update

func (r *UserRepo) Update(usr *user.User) error

Jump to

Keyboard shortcuts

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