repository

package
v0.0.0-...-5b4c5eb Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Transaction

func Transaction(ctx context.Context, txb TxBeginner, f func(tx Executor) error) error

func TransactionWithOptions

func TransactionWithOptions(ctx context.Context, txb TxBeginner, opts *sql.TxOptions, f func(tx Executor) error) error

Types

type DB

type DB interface {
	Transaction(ctx context.Context, f func(exec Executor) error) error
	TransactionWithOptions(ctx context.Context, opts *sql.TxOptions, f func(exec Executor) error) error
}

type EmailSender

type EmailSender interface {
	Send(ctx context.Context, email *email.Email) error
}

func NewNopEmailSender

func NewNopEmailSender() EmailSender

type ErrorRecorder

type ErrorRecorder interface {
	Record(ctx context.Context, err error, userID string)
}

type Executor

type Executor interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

Executor can perform SQL queries. It's for abstraction of database/sql.DB

type FollowingTeacher

type FollowingTeacher interface {
	CountFollowingTeachersByUserID(ctx context.Context, userID uint) (int, error)
	Create(ctx context.Context, followingTeacher *model2.FollowingTeacher) error
	DeleteByUserIDAndTeacherIDs(ctx context.Context, userID uint, teacherIDs []uint) error
	FindTeacherIDsByUserID(ctx context.Context, userID uint, fetchErrorCount int, lastLessonAt time.Time) ([]uint, error)
	FindTeachersByUserID(ctx context.Context, userID uint) ([]*model2.Teacher, error)
	FindByUserID(ctx context.Context, userID uint) ([]*model2.FollowingTeacher, error)
	FindByUserIDAndTeacherID(ctx context.Context, userID uint, teacherID uint) (*model2.FollowingTeacher, error)
}

type GAMeasurement

type GAMeasurement interface {
	SendEvent(
		ctx context.Context,
		values *model2.GAMeasurementEvent,
		category,
		action,
		label string,
		value int64,
		userID uint32,
	) error
}

type Lesson

type Lesson interface {
	Create(ctx context.Context, lesson *model2.Lesson, reload bool) error
	FindAllByTeacherIDsDatetimeBetween(
		ctx context.Context, teacherID uint, fromDate, toDate time.Time,
	) ([]*model2.Lesson, error)
	FindAllByTeacherIDAndDatetimeAsMap(
		ctx context.Context, teacherID uint, lessonsArgs []*model2.Lesson,
	) (map[string]*model2.Lesson, error)
	FindByID(ctx context.Context, id uint64) (*model2.Lesson, error)
	FindOrCreate(ctx context.Context, lesson *model2.Lesson, reload bool) (*model2.Lesson, error)
	GetNewAvailableLessons(ctx context.Context, oldLessons, newLessons []*model2.Lesson) []*model2.Lesson
	UpdateStatus(ctx context.Context, id uint64, newStatus string) (int64, error)
}

type LessonFetcher

type LessonFetcher interface {
	Close()
	Fetch(ctx context.Context, teacherID uint) (*model2.Teacher, []*model2.Lesson, error)
}

type LessonFetcherMock

type LessonFetcherMock struct {
	// CloseFunc mocks the Close method.
	CloseFunc func()

	// FetchFunc mocks the Fetch method.
	FetchFunc func(ctx context.Context, teacherID uint) (*model2.Teacher, []*model2.Lesson, error)
	// contains filtered or unexported fields
}

LessonFetcherMock is a mock implementation of LessonFetcher.

func TestSomethingThatUsesLessonFetcher(t *testing.T) {

	// make and configure a mocked LessonFetcher
	mockedLessonFetcher := &LessonFetcherMock{
		CloseFunc: func()  {
			panic("mock out the Close method")
		},
		FetchFunc: func(ctx context.Context, teacherID uint) (*model2.Teacher, []*model2.Lesson, error) {
			panic("mock out the Fetch method")
		},
	}

	// use mockedLessonFetcher in code that requires LessonFetcher
	// and then make assertions.

}

func (*LessonFetcherMock) Close

func (mock *LessonFetcherMock) Close()

Close calls CloseFunc.

func (*LessonFetcherMock) CloseCalls

func (mock *LessonFetcherMock) CloseCalls() []struct {
}

CloseCalls gets all the calls that were made to Close. Check the length with:

len(mockedLessonFetcher.CloseCalls())

func (*LessonFetcherMock) Fetch

func (mock *LessonFetcherMock) Fetch(ctx context.Context, teacherID uint) (*model2.Teacher, []*model2.Lesson, error)

Fetch calls FetchFunc.

func (*LessonFetcherMock) FetchCalls

func (mock *LessonFetcherMock) FetchCalls() []struct {
	Ctx       context.Context
	TeacherID uint
}

FetchCalls gets all the calls that were made to Fetch. Check the length with:

len(mockedLessonFetcher.FetchCalls())

type LessonStatusLog

type LessonStatusLog interface {
	Create(ctx context.Context, log *model2.LessonStatusLog) error
}

type MCountry

type MCountry interface {
	FindAll(ctx context.Context) ([]*model2.MCountry, error)
}

type NopEmailSender

type NopEmailSender struct{}

func (*NopEmailSender) Send

func (s *NopEmailSender) Send(ctx context.Context, email *email.Email) error

type NopErrorRecorder

type NopErrorRecorder struct{}

func (*NopErrorRecorder) Record

func (ner *NopErrorRecorder) Record(ctx context.Context, err error, userID string)

type NotificationTimeSpan

type NotificationTimeSpan interface {
	FindByUserID(ctx context.Context, userID uint) ([]*model2.NotificationTimeSpan, error)
	UpdateAll(ctx context.Context, userID uint, timeSpans []*model2.NotificationTimeSpan) error
}

type StatNotifier

type StatNotifier interface {
	CreateOrUpdate(ctx context.Context, statNotifier *model2.StatNotifier) error
}

type Teacher

type Teacher interface {
	Create(ctx context.Context, teacher *model2.Teacher) error
	CreateOrUpdate(ctx context.Context, teacher *model2.Teacher) error
	FindByID(ctx context.Context, id uint) (*model2.Teacher, error)
	FindByIDs(ctx context.Context, ids []uint) ([]*model2.Teacher, error)
	IncrementFetchErrorCount(ctx context.Context, id uint, value int) error
}

type TxBeginner

type TxBeginner interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	Begin() (*sql.Tx, error)
}

type User

type User interface {
	CreateWithExec(ctx context.Context, exec Executor, user *model2.User) error
	FindAllByEmailVerifiedIsTrue(ctx context.Context, notificationInterval int) ([]*model2.User, error)
	FindByAPIToken(ctx context.Context, apiToken string) (*model2.User, error)
	FindByEmail(ctx context.Context, email string) (*model2.User, error)
	FindByEmailWithExec(ctx context.Context, exec Executor, email string) (*model2.User, error)
	FindByGoogleID(ctx context.Context, googleID string) (*model2.User, error)
	FindByGoogleIDWithExec(ctx context.Context, exec Executor, googleID string) (*model2.User, error)
	FindAllByEmailVerified(ctx context.Context, notificationInterval int) ([]*model2.User, error)
	UpdateEmail(ctx context.Context, id uint, email string) error
	UpdateFollowedTeacherAt(ctx context.Context, id uint, time time.Time) error
	UpdateOpenNotificationAt(ctx context.Context, id uint, time time.Time) error
}

type UserAPIToken

type UserAPIToken interface {
	Create(ctx context.Context, userAPIToken *model2.UserAPIToken) error
	DeleteByUserIDAndToken(ctx context.Context, userID uint, token string) error
}

type UserGoogle

type UserGoogle interface {
	CreateWithExec(ctx context.Context, exec Executor, userGoogle *model2.UserGoogle) error
	DeleteByPKWithExec(ctx context.Context, exec Executor, googleID string) error
	FindByPKWithExec(ctx context.Context, exec Executor, googleID string) (*model2.UserGoogle, error)
	FindByUserIDWithExec(ctx context.Context, exec Executor, userID uint) (*model2.UserGoogle, error)
}

Jump to

Keyboard shortcuts

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