Documentation
¶
Index ¶
- type Service
- func (s Service) Close()
- func (s Service) DeleteWordsByCategory(userID string, category string) error
- func (s Service) ExistUser(user golearn.User) (bool, error)
- func (s Service) GetCategories(userID string) ([]golearn.Category, error)
- func (s Service) GetState(userKey string) (golearn.State, error)
- func (s Service) GetStatistics(userID string, year int, month int, week int, day int) (golearn.Statistics, error)
- func (s Service) GetUser(userID string) (golearn.User, error)
- func (s Service) InsertActivity(activity golearn.Activity) error
- func (s Service) InsertUser(user golearn.User) error
- func (s Service) InsertWord(w golearn.Row) error
- func (s Service) RandomAnswers(q golearn.Row, count int) ([]golearn.Row, error)
- func (s Service) RandomQuestion(category string) (golearn.Row, error)
- func (s Service) ResetState(userKey string) error
- func (s Service) SetState(state golearn.State) error
- func (s Service) SetUserCategory(userID string, category string) error
- func (s Service) SetUserMode(userID string, mode string) error
- func (s Service) UpdateUser(user golearn.User) error
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 (Service) DeleteWordsByCategory ¶
func (Service) GetCategories ¶
GetCategories returns list of unique categories based on words table.
func (Service) GetStatistics ¶
func (Service) InsertUser ¶
InsertUser inserts new user to users collection
func (Service) InsertWord ¶
InsertWord inserts new row to words collection
func (Service) RandomAnswers ¶
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 ¶
RandomQuestion returns random row
func (Service) ResetState ¶
ResetState resets user state
func (Service) SetUserCategory ¶
func (Service) SetUserMode ¶
SetUserMode sets new mode for passed user id