api

package
v0.0.0-...-887dbeb Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type URLHandler

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

URLHandler 处理URL相关的HTTP请求

func NewURLHandler

func NewURLHandler(urlService URLServicer) *URLHandler

NewURLHandler 创建新的URL处理器

func (*URLHandler) CreateURL

func (h *URLHandler) CreateURL(c echo.Context) error

CreateURL godoc @Summary 创建短链接 @Description 将长URL转换为短URL @Tags URL @Accept json @Produce json @Param Authorization header string true "Bearer JWT token" @Param request body model.CreateURLRequest true "创建短链接请求" @Success 201 {object} model.CreateURLResponse @Failure 400 {object} echo.HTTPError @Failure 500 {object} echo.HTTPError @Router /api/url [post]

func (*URLHandler) DeleteURL

func (h *URLHandler) DeleteURL(c echo.Context) error

DeleteURL godoc @Summary 删除短链接 @Description 删除指定的短链接 @Tags URL @Accept json @Produce json @Param Authorization header string true "Bearer JWT token" @Param code path string true "短链接代码" @Success 204 "No Content" @Failure 500 {object} echo.HTTPError @Router /api/url/{code} [delete]

func (*URLHandler) GetURLs

func (h *URLHandler) GetURLs(c echo.Context) error

GetURLs godoc @Summary 获取用户的所有短链接 @Description 分页获取当前用户创建的所有短链接 @Tags URL @Accept json @Produce json @Param Authorization header string true "Bearer JWT token" @Param page query int false "页码" default(1) @Param size query int false "每页数量" default(10) @Success 200 {object} model.GetURLsResponse @Failure 500 {object} echo.HTTPError @Router /api/urls [get]

func (*URLHandler) RedirectURL

func (h *URLHandler) RedirectURL(c echo.Context) error

RedirectURL godoc @Summary 重定向到原始URL @Description 通过短链接代码重定向到原始URL @Tags URL @Accept json @Produce json @Param code path string true "短链接代码" @Success 301 {string} string "重定向到原始URL" @Failure 500 {object} echo.HTTPError @Router /{code} [get]

func (*URLHandler) UpdateURLDuration

func (h *URLHandler) UpdateURLDuration(c echo.Context) error

UpdateURLDuration godoc @Summary 更新短链接有效期 @Description 更新指定短链接的有效期 @Tags URL @Accept json @Produce json @Param Authorization header string true "Bearer JWT token" @Param code path string true "短链接代码" @Param request body model.UpdateURLDurationReq true "更新有效期请求" @Success 204 "No Content" @Failure 500 {object} echo.HTTPError @Router /api/url/{code} [patch]

type URLServicer

type URLServicer interface {
	CreateURL(ctx context.Context, req model.CreateURLRequest) (shortURL string, err error)
	GetURL(ctx context.Context, shortCode string) (originalURL string, err error)
	IncreViews(ctx context.Context, shortCode string) error
	GetURLs(ctx context.Context, req model.GetURLsRequest) (*model.GetURLsResponse, error)
	DeleteURL(ctx context.Context, shortCode string) error
	UpdateURLDuration(ctx context.Context, req model.UpdateURLDurationReq) error
}

type UserHandler

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

UserHandler 处理用户相关的HTTP请求

func NewUserHandler

func NewUserHandler(userService UserServicer) *UserHandler

NewUserHandler 创建新的用户处理器

func (*UserHandler) ForgetPassword

func (h *UserHandler) ForgetPassword(c echo.Context) error

ForgetPassword godoc @Summary 忘记密码 @Description 通过邮箱验证码重置密码 @Tags 用户 @Accept json @Produce json @Param request body model.ForgetPasswordReqeust true "重置密码请求" @Success 200 {object} model.LoginResponse @Failure 400 {object} echo.HTTPError @Failure 500 {object} echo.HTTPError @Router /api/auth/forget [post]

func (*UserHandler) Login

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

Login godoc @Summary 用户登录 @Description 用户通过邮箱和密码登录 @Tags 用户 @Accept json @Produce json @Param request body model.LoginRequest true "登录请求" @Success 200 {object} model.LoginResponse @Failure 400 {object} echo.HTTPError @Failure 500 {object} echo.HTTPError @Router /api/auth/login [post]

func (*UserHandler) Register

func (h *UserHandler) Register(c echo.Context) error

Register godoc @Summary 用户注册 @Description 新用户注册 @Tags 用户 @Accept json @Produce json @Param request body model.RegisterReqeust true "注册请求" @Success 201 {object} model.LoginResponse @Failure 400 {object} echo.HTTPError @Failure 500 {object} echo.HTTPError @Router /api/auth/register [post]

func (*UserHandler) SendEmailCode

func (h *UserHandler) SendEmailCode(c echo.Context) error

SendEmailCode godoc @Summary 发送邮箱验证码 @Description 向指定邮箱发送验证码 @Tags 用户 @Accept json @Produce json @Param email path string true "邮箱地址" @Success 204 "No Content" @Failure 400 {object} echo.HTTPError @Failure 500 {object} echo.HTTPError @Router /api/auth/register/{email} [get]

type UserServicer

type UserServicer interface {
	Login(ctx context.Context, req model.LoginRequest) (*model.LoginResponse, error)
	IsEmailAvaliable(ctx context.Context, email string) error
	Register(ctx context.Context, req model.RegisterReqeust) (*model.LoginResponse, error)
	SendEmailCode(ctx context.Context, email string) error
	ResetPassword(ctx context.Context, req model.ForgetPasswordReqeust) (*model.LoginResponse, error)
}

Jump to

Keyboard shortcuts

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