handlers

package
v0.0.0-...-c00eb94 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2025 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugService

func DebugService() *fiber.App

DebugService creates and configures debug app

func Service

func Service(log *zap.Logger, db *sqlx.DB, cfg appconf.Cfg) (*fiber.App, error)

Service creates and configures auth app

Types

type Auth

type Auth interface {
	GenerateToken(claims jwt.Claims) (string, error)
	ValidateToken(tokenStr string) (auth.Claims, error)
	CreateClaims(user database.User) jwt.Claims
}

Auth provides authentication methods

type AuthAPI

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

AuthAPI describes dependencies for auth endpoints

func NewAuthAPI

func NewAuthAPI(log *zap.Logger, cfg *appconf.Cfg, auth Auth, userRepo UserRepo, googleTokenValidator GoogleTokenValidator) (*AuthAPI, error)

NewAuthAPI return new instance of auth api

func (*AuthAPI) DeleteAccountHandler

func (a *AuthAPI) DeleteAccountHandler(c *fiber.Ctx) error

DeleteAccountHandler godoc @Summary Delete user account @Description Deletes a user account @Tags auth @Produce json @Param Authorization header string true "Bearer token" @Success 204 "Successfully deleted account" @Failure 401 {object} web.ErrResp "Unauthorized" @Failure 500 {object} web.ErrResp "Internal server error" @Router /account [delete]

func (*AuthAPI) GoogleOAuthHandler

func (a *AuthAPI) GoogleOAuthHandler(c *fiber.Ctx) error

GoogleOAuthHandler godoc @Summary Google OAuth sign in handler @Description Handles Google OAuth 2.0 authentication @Tags auth @Accept json @Produce json @Param token body GoogleOAuthRequest true "Google OAuth token" @Success 200 {object} TokenResp @Failure 400 {object} web.ErrResp @Failure 401 {object} web.ErrResp @Router /oauth/google [post]

func (*AuthAPI) SignInHandler

func (a *AuthAPI) SignInHandler(c *fiber.Ctx) error

SignInHandler godoc @Summary Sign in @Description Authenticate a user and return an access token @Tags auth @Accept json @Produce json @Param signin body SignInReq true "User credentials" @Success 200 {object} TokenResp @Failure 400 {object} web.ErrResp @Failure 401 {object} web.ErrResp @Failure 500 {object} web.ErrResp @Router /signin [post]

func (*AuthAPI) SignUpHandler

func (a *AuthAPI) SignUpHandler(c *fiber.Ctx) error

SignUpHandler godoc @Summary Register a new user @Description Create a new user account with the provided information @Tags auth @Accept json @Produce json @Param signup body SignUpReq true "User signup information" @Success 200 {object} SignUpResp "Successfully registered user" @Failure 400 {object} web.ErrResp "Invalid input data" @Failure 409 {object} web.ErrResp "Username or publisher name already exists" @Failure 500 {object} web.ErrResp "Internal server error" @Router /signup [post]

func (*AuthAPI) UpdateProfileHandler

func (a *AuthAPI) UpdateProfileHandler(c *fiber.Ctx) error

UpdateProfileHandler godoc @Summary Update user profile @Description Updates the profile information of a user @Tags auth @Accept json @Produce json @Param Authorization header string true "Bearer token" @Param profile body UpdateProfileReq true "Update profile parameters" @Success 200 {object} TokenResp "Returns new access token" @Failure 400 {object} web.ErrResp "Bad request" @Failure 401 {object} web.ErrResp "Invalid password or token" @Failure 404 {object} web.ErrResp "User not found" @Failure 500 {object} web.ErrResp "Internal server error" @Router /account [patch]

func (*AuthAPI) VerifyTokenHandler

func (a *AuthAPI) VerifyTokenHandler(c *fiber.Ctx) error

VerifyTokenHandler godoc @Summary Verify JWT token @Description Validates a JWT token and returns if it's valid @Tags auth @Accept json @Produce json @Param token body VerifyTokenReq true "Token to verify" @Success 200 {object} VerifyTokenResp @Failure 400 {object} web.ErrResp @Router /token/verify [post]

type CheckAPI

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

CheckAPI has methods for readiness and liveness checking

func NewCheckAPI

func NewCheckAPI(db *sqlx.DB) *CheckAPI

NewCheckAPI returns new instance of healthcheck api

func (*CheckAPI) Liveness

func (a *CheckAPI) Liveness(c *fiber.Ctx) error

Liveness determines whether service is up

func (*CheckAPI) Readiness

func (a *CheckAPI) Readiness(c *fiber.Ctx) error

Readiness determines whether service is ready

type GoogleOAuthRequest

type GoogleOAuthRequest struct {
	IDToken string `json:"idToken" validate:"required"`
}

GoogleOAuthRequest represents Google OAuth request

type GoogleTokenValidator

type GoogleTokenValidator interface {
	Validate(ctx context.Context, idToken string, audience string) (*idtoken.Payload, error)
}

GoogleTokenValidator provides methods for validating Google ID tokens

type SignInReq

type SignInReq struct {
	Username string `json:"username" validate:"required"`
	Password string `json:"password" validate:"required,min=8,max=64"`
}

SignInReq represents user sign in request

type SignUpReq

type SignUpReq struct {
	Username        string `json:"username" validate:"required"`
	DisplayName     string `json:"name" validate:"required"`
	Password        string `json:"password" validate:"required,min=8,max=64"`
	ConfirmPassword string `json:"confirmPassword" validate:"eqfield=Password"`
	IsPublisher     bool   `json:"isPublisher"`
}

SignUpReq represents user sign up request

type SignUpResp

type SignUpResp struct {
	ID uuid.UUID `json:"id"`
}

SignUpResp represents sign up response

type TokenResp

type TokenResp struct {
	AccessToken string `json:"accessToken"`
}

TokenResp represents response with JWT

type UpdateProfileReq

type UpdateProfileReq struct {
	Name               *string `json:"name"`
	Password           *string `json:"password" validate:"omitempty,min=8,max=64"`
	NewPassword        *string `json:"newPassword" validate:"omitempty,min=8,max=64"`
	ConfirmNewPassword *string `json:"confirmNewPassword" validate:"omitempty,min=8,max=64"`
}

UpdateProfileReq represents update profile request

type UserRepo

type UserRepo interface {
	CreateUser(ctx context.Context, user database.User) error
	UpdateUser(ctx context.Context, user database.User) error
	DeleteUser(ctx context.Context, userID string) error
	GetUserByID(ctx context.Context, userID string) (database.User, error)
	GetUserByUsername(ctx context.Context, username string) (database.User, error)
	GetUserByOAuth(ctx context.Context, provider string, oauthID string) (database.User, error)
	CheckUserExists(ctx context.Context, name string, role database.Role) (bool, error)
}

UserRepo provides methods for working with user repo

type VerifyTokenReq

type VerifyTokenReq struct {
	Token string `json:"token" validate:"jwt"`
}

VerifyTokenReq represents verify JWT request

type VerifyTokenResp

type VerifyTokenResp struct {
	Valid bool `json:"valid"`
}

VerifyTokenResp represents verify JWT response

Directories

Path Synopsis
Package handlers_mocks is a generated GoMock package.
Package handlers_mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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