mongo

package
v0.0.0-...-56f048d Latest Latest
Warning

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

Go to latest
Published: May 26, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

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

Service of mongodb

func New

func New(cfg *golearn.Config) (*Service, error)

New returns new instance of mockService

func (Service) Close

func (s Service) Close()

Close terminates the mockService session

func (Service) DeleteWordsByCategory

func (s Service) DeleteWordsByCategory(userID string, category string) error

func (Service) ExistUser

func (s Service) ExistUser(user golearn.User) (bool, error)

ExistUser returns bool if user already exists in db

func (Service) GetCategories

func (s Service) GetCategories(userID string) ([]golearn.Category, error)

GetCategories returns list of unique categories based on words table.

func (Service) GetState

func (s Service) GetState(userKey string) (golearn.State, error)

GetState returns lastest saved user state

func (Service) GetStatistics

func (s Service) GetStatistics(userID string, year int, month int, week int, day int) (golearn.Statistics, error)

func (Service) GetUser

func (s Service) GetUser(userID string) (golearn.User, error)

GetUser returns user from db

func (Service) InsertActivity

func (s Service) InsertActivity(activity golearn.Activity) error

func (Service) InsertUser

func (s Service) InsertUser(user golearn.User) error

InsertUser inserts new user to users collection

func (Service) InsertWord

func (s Service) InsertWord(w golearn.Row) error

InsertWord inserts new row to words collection

func (Service) RandomAnswers

func (s Service) RandomAnswers(q golearn.Row, count int) ([]golearn.Row, error)

RandomAnswers returns random answers with passed count of total answers. q is right answer which will be appended to result slice and will be shuffled later. count is total amount of answers which is included the right one.

In order to get random rows function generates random number which is used as offset. In order to guarantee that function returns exactly passed "count" of words function calculated maximum allowed random number. If generated random number of greater that allowed function uses maximum number.

Example: In case if passed count is equal 4. Function has to find 3 random rows and 1 (the passed one) will be appended to result slice. Generated random number is equal 7, that means function returns just 1 rows (8). Function moves cursor to position 5 to return enough rows (6,7,8).

Moved         Generated
  +---------------+
  |               |
  v               v

+-------+-------+-------+-------+---+---+-------+---+---+-------+ | | | | | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | | | | | | | | | | +-------+-------+-------+-------+-------+-------+-------+-------+

func (Service) RandomQuestion

func (s Service) RandomQuestion(category string) (golearn.Row, error)

RandomQuestion returns random row

func (Service) ResetState

func (s Service) ResetState(userKey string) error

ResetState resets user state

func (Service) SetState

func (s Service) SetState(state golearn.State) error

SetState save latest given set of question and answers

func (Service) SetUserCategory

func (s Service) SetUserCategory(userID string, category string) error

func (Service) SetUserMode

func (s Service) SetUserMode(userID string, mode string) error

SetUserMode sets new mode for passed user id

func (Service) UpdateUser

func (s Service) UpdateUser(user golearn.User) error

UpdateUser updates user

Jump to

Keyboard shortcuts

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