api

package
v0.0.0-...-9eba30f Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InternalServerError = ErrorResponse{"Internal server error"} //nolint:gochecknoglobals // this is a constant response for internal server error
	BadRequestError     = ErrorResponse{"Bad request"}           //nolint:gochecknoglobals // this is a constant response for bad request
)

Functions

func AuthMiddleware

func AuthMiddleware(cookieProc *CookiesProcessor, jwtProc *JWTProcessor, log *slog.Logger) func(next echo.HandlerFunc) echo.HandlerFunc

func HTTPErrorHandler

func HTTPErrorHandler(log *slog.Logger) func(err error, c echo.Context)

func NewRouter

func NewRouter(ctx context.Context, conf *config.API, deps Dependencies) http.Handler

Types

type AuthDependencies

type AuthDependencies struct {
	Repo             dal.AuthConfirmationRepository
	JWTProcessor     *JWTProcessor
	CookiesProcessor *CookiesProcessor
	TelegramClient   TelegramClient
	AllowedChatIDs   []int64
	Logger           *slog.Logger
}

type AuthHandler

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

func NewAuthHandler

func NewAuthHandler(deps AuthDependencies) *AuthHandler

func (*AuthHandler) Info

func (h *AuthHandler) Info(c echo.Context) error

func (*AuthHandler) LogOut

func (h *AuthHandler) LogOut(c echo.Context) error

func (*AuthHandler) Login

func (h *AuthHandler) Login(c echo.Context) error

func (*AuthHandler) Status

func (h *AuthHandler) Status(c echo.Context) error

type Claims

type Claims struct {
	Username string `json:"username"`
	jwt.RegisteredClaims
}

type CookiesProcessor

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

func NewCookiesProcessor

func NewCookiesProcessor(conf config.Cookie) *CookiesProcessor

func (*CookiesProcessor) ExpireAccessTokenCookie

func (p *CookiesProcessor) ExpireAccessTokenCookie() *http.Cookie

func (*CookiesProcessor) ExpireAuthTokenCookie

func (p *CookiesProcessor) ExpireAuthTokenCookie() *http.Cookie

func (*CookiesProcessor) GetAccessToken

func (p *CookiesProcessor) GetAccessToken(c echo.Context) (string, bool)

func (*CookiesProcessor) GetAuthToken

func (p *CookiesProcessor) GetAuthToken(c echo.Context) (string, bool)

func (*CookiesProcessor) NewAccessTokenCookie

func (p *CookiesProcessor) NewAccessTokenCookie(token string) *http.Cookie

func (*CookiesProcessor) NewAuthTokenCookie

func (p *CookiesProcessor) NewAuthTokenCookie(token string) *http.Cookie

type CustomValidator

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

func NewCustomValidator

func NewCustomValidator() *CustomValidator

func (*CustomValidator) Validate

func (cv *CustomValidator) Validate(i interface{}) error

type DeleteWordRequest

type DeleteWordRequest struct {
	Word string `json:"word" validate:"required,min=1"`
}

type Dependencies

type Dependencies struct {
	Repo           dal.Repository
	TelegramClient TelegramClient
	Logger         *slog.Logger
}

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"error"`
}

type Guessed

type Guessed string
const (
	GuessedAll     Guessed = "all"
	GuessedLearned Guessed = "learned"
	GuessedBatched Guessed = "batched"
	GuessedToLearn Guessed = "to_learn"
)

type JWTProcessor

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

func NewJWTProcessor

func NewJWTProcessor(conf config.JWT, authExpireIn, accessExpireIn time.Duration) *JWTProcessor

func (*JWTProcessor) ParseAccessToken

func (p *JWTProcessor) ParseAccessToken(token string) (int64, error)

func (*JWTProcessor) ParseAuthToken

func (p *JWTProcessor) ParseAuthToken(token string) (int64, string, error)

func (*JWTProcessor) ToAccessToken

func (p *JWTProcessor) ToAccessToken(chatID int64) (string, error)

func (*JWTProcessor) ToAuthToken

func (p *JWTProcessor) ToAuthToken(chatID int64, key string) (string, error)

type MarkToReviewRequest

type MarkToReviewRequest struct {
	Word     string `json:"word" validate:"required,min=1"`
	ToReview bool   `json:"to_review"`
}

type StatsHandler

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

func NewStatsHandler

func NewStatsHandler(repo dal.StatsRepository, log *slog.Logger) *StatsHandler

func (*StatsHandler) GetStats

func (h *StatsHandler) GetStats(c echo.Context) error

func (*StatsHandler) GetStatsRange

func (h *StatsHandler) GetStatsRange(c echo.Context) error

func (*StatsHandler) TotalStats

func (h *StatsHandler) TotalStats(c echo.Context) error

type StatsQueryParams

type StatsQueryParams struct {
	From time.Time `query:"from" validate:"required"`
	To   time.Time `query:"to" validate:"required"`
}

type TelegramClient

type TelegramClient interface {
	AskAuthConfirmation(ctx context.Context, chatID int64, token string) error
}

type WordTranslation

type WordTranslation struct {
	Word          string `json:"word" validate:"required,min=1"`
	NewWord       string `json:"new_word,omitempty" validate:"omitempty,min=1"`
	Translation   string `json:"translation" validate:"required,min=1"`
	Description   string `json:"description"`
	ToReview      bool   `json:"to_review"`
	GuessedStreak int    `json:"guessed_streak,omitempty"`
}

type WordsHandler

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

func NewWordsHandler

func NewWordsHandler(repo dal.WordTranslationsRepository, log *slog.Logger) *WordsHandler

func (*WordsHandler) CreateWord

func (h *WordsHandler) CreateWord(c echo.Context) error

func (*WordsHandler) DeleteWord

func (h *WordsHandler) DeleteWord(c echo.Context) error

func (*WordsHandler) FindWords

func (h *WordsHandler) FindWords(c echo.Context) error

func (*WordsHandler) MarkToReview

func (h *WordsHandler) MarkToReview(c echo.Context) error

func (*WordsHandler) UpdateWord

func (h *WordsHandler) UpdateWord(c echo.Context) error

type WordsQueryParams

type WordsQueryParams struct {
	Search   string  `query:"search"`
	Guessed  Guessed `query:"guessed" validate:"omitempty,oneof=all learned batched to_learn"`
	ToReview bool    `query:"to_review"`
	Offset   uint64  `query:"offset" validate:"min=0"`
	Limit    uint64  `query:"limit" validate:"required,min=1,max=100"`
}

Jump to

Keyboard shortcuts

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