结构调整

This commit is contained in:
Shikong 2022-11-13 18:14:50 +08:00
parent d12286939f
commit 89f547a3bf
17 changed files with 244 additions and 183 deletions

View File

@ -6,7 +6,7 @@ import (
"gofiber.study.skcks.cn/common/response" "gofiber.study.skcks.cn/common/response"
"gofiber.study.skcks.cn/controller/types" "gofiber.study.skcks.cn/controller/types"
"gofiber.study.skcks.cn/global" "gofiber.study.skcks.cn/global"
"gofiber.study.skcks.cn/model/dto" auth2 "gofiber.study.skcks.cn/model/auth"
"gofiber.study.skcks.cn/services/auth" "gofiber.study.skcks.cn/services/auth"
) )
@ -31,13 +31,13 @@ func NewController(app *fiber.App) *Controller {
// @Tags Auth // @Tags Auth
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param vo body dto.Login true "用户登录" // @Param vo body auth.LoginDTO true "用户登录"
// @Success 200 {object} response.Response{data=vo.Login} // @Success 200 {object} response.Response{data=auth.LoginVO}
// @Failure default {object} errorx.CodeErrorResponse // @Failure default {object} errorx.CodeErrorResponse
// @Router /auth/login [post] // @Router /auth/login [post]
func (c *Controller) Login() { func (c *Controller) Login() {
c.Router.Post("login", func(ctx *fiber.Ctx) error { c.Router.Post("login", func(ctx *fiber.Ctx) error {
login := &dto.Login{} login := &auth2.LoginDTO{}
err := ctx.BodyParser(login) err := ctx.BodyParser(login)
if err = errorx.ParseError(err); err != nil { if err = errorx.ParseError(err); err != nil {
return ctx.JSON(err) return ctx.JSON(err)
@ -59,13 +59,13 @@ func (c *Controller) Login() {
// @Tags Auth // @Tags Auth
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param vo body dto.RefreshToken true "刷新令牌" // @Param vo body auth.RefreshToken true "刷新令牌"
// @Success 200 {object} response.Response{data=vo.Login} // @Success 200 {object} response.Response{data=auth.LoginVO}
// @Failure default {object} errorx.CodeErrorResponse // @Failure default {object} errorx.CodeErrorResponse
// @Router /auth/refreshToken [post] // @Router /auth/refreshToken [post]
func (c *Controller) RefreshToken() { func (c *Controller) RefreshToken() {
c.Router.Post("refreshToken", func(ctx *fiber.Ctx) error { c.Router.Post("refreshToken", func(ctx *fiber.Ctx) error {
refresh := &dto.RefreshToken{} refresh := &auth2.RefreshToken{}
err := ctx.BodyParser(refresh) err := ctx.BodyParser(refresh)
if err = errorx.ParseErrorWithCode(fiber.StatusInternalServerError, err); err != nil { if err = errorx.ParseErrorWithCode(fiber.StatusInternalServerError, err); err != nil {
return ctx.JSON(err) return ctx.JSON(err)

View File

@ -8,8 +8,7 @@ import (
"gofiber.study.skcks.cn/common/response" "gofiber.study.skcks.cn/common/response"
"gofiber.study.skcks.cn/controller/types" "gofiber.study.skcks.cn/controller/types"
"gofiber.study.skcks.cn/global" "gofiber.study.skcks.cn/global"
"gofiber.study.skcks.cn/model/dto" "gofiber.study.skcks.cn/model/captcha"
"gofiber.study.skcks.cn/model/vo"
"gofiber.study.skcks.cn/services/waf" "gofiber.study.skcks.cn/services/waf"
"gofiber.study.skcks.cn/services/wol" "gofiber.study.skcks.cn/services/wol"
"strconv" "strconv"
@ -135,7 +134,7 @@ func (c *Controller) NanoIdTest() {
// @Tags Test // @Tags Test
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Success 200 {object} response.Response{data=vo.Captcha} // @Success 200 {object} response.Response{data=captcha.Captcha}
// @Failure default {object} errorx.CodeErrorResponse // @Failure default {object} errorx.CodeErrorResponse
// @Router /test/captcha/get [get] // @Router /test/captcha/get [get]
func (c *Controller) GetCaptchaTest() { func (c *Controller) GetCaptchaTest() {
@ -147,7 +146,7 @@ func (c *Controller) GetCaptchaTest() {
return ctx.JSON(errorx.NewDefaultError("验证码生成失败")) return ctx.JSON(errorx.NewDefaultError("验证码生成失败"))
} }
return ctx.JSON(response.NewResponse(vo.Captcha{ return ctx.JSON(response.NewResponse(captcha.Captcha{
Id: id, Id: id,
Base64: item.EncodeB64string(), Base64: item.EncodeB64string(),
Expire: time.Now().Add(time.Duration(global.Config.Captcha.Expire) * time.Second).Unix(), Expire: time.Now().Add(time.Duration(global.Config.Captcha.Expire) * time.Second).Unix(),
@ -162,13 +161,13 @@ func (c *Controller) GetCaptchaTest() {
// @Tags Test // @Tags Test
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param vo body dto.VerifyCaptcha true "验证码验证" // @Param vo body captcha.VerifyCaptcha true "验证码验证"
// @Success 200 {object} response.Response{data=string} // @Success 200 {object} response.Response{data=string}
// @Failure default {object} errorx.CodeErrorResponse // @Failure default {object} errorx.CodeErrorResponse
// @Router /test/captcha/verify [post] // @Router /test/captcha/verify [post]
func (c *Controller) VerifyCaptchaTest() { func (c *Controller) VerifyCaptchaTest() {
c.Router.Add(fiber.MethodPost, "/captcha/verify", func(ctx *fiber.Ctx) error { c.Router.Add(fiber.MethodPost, "/captcha/verify", func(ctx *fiber.Ctx) error {
verifyCaptcha := &dto.VerifyCaptcha{} verifyCaptcha := &captcha.VerifyCaptcha{}
if err := errorx.ParseError(ctx.BodyParser(verifyCaptcha)); err != nil { if err := errorx.ParseError(ctx.BodyParser(verifyCaptcha)); err != nil {
return ctx.JSON(err) return ctx.JSON(err)

View File

@ -5,6 +5,7 @@ import (
"gofiber.study.skcks.cn/common/errorx" "gofiber.study.skcks.cn/common/errorx"
"gofiber.study.skcks.cn/common/response" "gofiber.study.skcks.cn/common/response"
"gofiber.study.skcks.cn/controller/types" "gofiber.study.skcks.cn/controller/types"
"gofiber.study.skcks.cn/global"
"gofiber.study.skcks.cn/middleware" "gofiber.study.skcks.cn/middleware"
"gofiber.study.skcks.cn/services/user" "gofiber.study.skcks.cn/services/user"
) )
@ -25,19 +26,20 @@ func NewController(app *fiber.App) *Controller {
// GetByAccount 根据 账号 获取用户信息 // GetByAccount 根据 账号 获取用户信息
// //
// @Summary 根据 账号 获取用户信息 // @Summary 获取当前用户信息
// @Description 根据 账号 获取用户信息 // @Description 获取当前用户信息
// @Tags User // @Tags User
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param account query string true "账号名称"
// @Success 200 {object} response.Response{data=models.User} // @Success 200 {object} response.Response{data=models.User}
// @Failure default {object} errorx.CodeErrorResponse // @Failure default {object} errorx.CodeErrorResponse
// @Router /user/account [get] // @Router /user/account [get]
// @Security Token // @Security Token
func (c *Controller) GetByAccount() { func (c *Controller) GetByAccount() {
c.Router.Get("/account", func(ctx *fiber.Ctx) error { c.Router.Get("/account", func(ctx *fiber.Ctx) error {
account := ctx.Query("account") token := ctx.GetReqHeaders()["Token"]
claim, _ := global.ParseToken(token)
account := claim.Account
u, err := user.Services.GetUserByAccount(account) u, err := user.Services.GetUserByAccount(account)
if err != nil { if err != nil {

View File

@ -44,7 +44,7 @@ const docTemplate = `{
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.Login" "$ref": "#/definitions/auth.LoginDTO"
} }
} }
], ],
@ -60,7 +60,7 @@ const docTemplate = `{
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "data": {
"$ref": "#/definitions/vo.Login" "$ref": "#/definitions/auth.LoginVO"
} }
} }
} }
@ -96,7 +96,7 @@ const docTemplate = `{
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.RefreshToken" "$ref": "#/definitions/auth.RefreshToken"
} }
} }
], ],
@ -112,7 +112,7 @@ const docTemplate = `{
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "data": {
"$ref": "#/definitions/vo.Login" "$ref": "#/definitions/auth.LoginVO"
} }
} }
} }
@ -467,7 +467,7 @@ const docTemplate = `{
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "data": {
"$ref": "#/definitions/vo.Captcha" "$ref": "#/definitions/captcha.Captcha"
} }
} }
} }
@ -503,7 +503,7 @@ const docTemplate = `{
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.VerifyCaptcha" "$ref": "#/definitions/captcha.VerifyCaptcha"
} }
} }
], ],
@ -815,7 +815,7 @@ const docTemplate = `{
"Token": [] "Token": []
} }
], ],
"description": "根据 账号 获取用户信息", "description": "获取当前用户信息",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -825,16 +825,7 @@ const docTemplate = `{
"tags": [ "tags": [
"User" "User"
], ],
"summary": "根据 账号 获取用户信息", "summary": "获取当前用户信息",
"parameters": [
{
"type": "string",
"description": "账号名称",
"name": "account",
"in": "query",
"required": true
}
],
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -865,7 +856,7 @@ const docTemplate = `{
} }
}, },
"definitions": { "definitions": {
"dto.Login": { "auth.LoginDTO": {
"type": "object", "type": "object",
"required": [ "required": [
"account", "account",
@ -882,7 +873,22 @@ const docTemplate = `{
} }
} }
}, },
"dto.RefreshToken": { "auth.LoginVO": {
"type": "object",
"properties": {
"refreshToken": {
"description": "refreshToken 刷新令牌",
"type": "string",
"example": "0123456789ABCDEFG"
},
"token": {
"description": "token 用户令牌",
"type": "string",
"example": "0123456789ABCDEFG"
}
}
},
"auth.RefreshToken": {
"type": "object", "type": "object",
"required": [ "required": [
"refreshToken" "refreshToken"
@ -894,7 +900,27 @@ const docTemplate = `{
} }
} }
}, },
"dto.VerifyCaptcha": { "captcha.Captcha": {
"type": "object",
"properties": {
"base64": {
"description": "验证码图片 base64",
"type": "string",
"example": "data:image/png;base64,iVBO..."
},
"expire": {
"description": "过期时间 unix",
"type": "integer",
"example": 10000000
},
"id": {
"description": "验证码 id",
"type": "string",
"example": "abcdefg123456"
}
}
},
"captcha.VerifyCaptcha": {
"type": "object", "type": "object",
"properties": { "properties": {
"captcha": { "captcha": {
@ -1010,41 +1036,6 @@ const docTemplate = `{
"example": "OK" "example": "OK"
} }
} }
},
"vo.Captcha": {
"type": "object",
"properties": {
"base64": {
"description": "验证码图片 base64",
"type": "string",
"example": "data:image/png;base64,iVBO..."
},
"expire": {
"description": "过期时间 unix",
"type": "integer",
"example": 10000000
},
"id": {
"description": "验证码 id",
"type": "string",
"example": "abcdefg123456"
}
}
},
"vo.Login": {
"type": "object",
"properties": {
"refreshToken": {
"description": "refreshToken 刷新令牌",
"type": "string",
"example": "0123456789ABCDEFG"
},
"token": {
"description": "token 用户令牌",
"type": "string",
"example": "0123456789ABCDEFG"
}
}
} }
}, },
"securityDefinitions": { "securityDefinitions": {

View File

@ -36,7 +36,7 @@
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.Login" "$ref": "#/definitions/auth.LoginDTO"
} }
} }
], ],
@ -52,7 +52,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "data": {
"$ref": "#/definitions/vo.Login" "$ref": "#/definitions/auth.LoginVO"
} }
} }
} }
@ -88,7 +88,7 @@
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.RefreshToken" "$ref": "#/definitions/auth.RefreshToken"
} }
} }
], ],
@ -104,7 +104,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "data": {
"$ref": "#/definitions/vo.Login" "$ref": "#/definitions/auth.LoginVO"
} }
} }
} }
@ -459,7 +459,7 @@
"type": "object", "type": "object",
"properties": { "properties": {
"data": { "data": {
"$ref": "#/definitions/vo.Captcha" "$ref": "#/definitions/captcha.Captcha"
} }
} }
} }
@ -495,7 +495,7 @@
"in": "body", "in": "body",
"required": true, "required": true,
"schema": { "schema": {
"$ref": "#/definitions/dto.VerifyCaptcha" "$ref": "#/definitions/captcha.VerifyCaptcha"
} }
} }
], ],
@ -807,7 +807,7 @@
"Token": [] "Token": []
} }
], ],
"description": "根据 账号 获取用户信息", "description": "获取当前用户信息",
"consumes": [ "consumes": [
"application/json" "application/json"
], ],
@ -817,16 +817,7 @@
"tags": [ "tags": [
"User" "User"
], ],
"summary": "根据 账号 获取用户信息", "summary": "获取当前用户信息",
"parameters": [
{
"type": "string",
"description": "账号名称",
"name": "account",
"in": "query",
"required": true
}
],
"responses": { "responses": {
"200": { "200": {
"description": "OK", "description": "OK",
@ -857,7 +848,7 @@
} }
}, },
"definitions": { "definitions": {
"dto.Login": { "auth.LoginDTO": {
"type": "object", "type": "object",
"required": [ "required": [
"account", "account",
@ -874,7 +865,22 @@
} }
} }
}, },
"dto.RefreshToken": { "auth.LoginVO": {
"type": "object",
"properties": {
"refreshToken": {
"description": "refreshToken 刷新令牌",
"type": "string",
"example": "0123456789ABCDEFG"
},
"token": {
"description": "token 用户令牌",
"type": "string",
"example": "0123456789ABCDEFG"
}
}
},
"auth.RefreshToken": {
"type": "object", "type": "object",
"required": [ "required": [
"refreshToken" "refreshToken"
@ -886,7 +892,27 @@
} }
} }
}, },
"dto.VerifyCaptcha": { "captcha.Captcha": {
"type": "object",
"properties": {
"base64": {
"description": "验证码图片 base64",
"type": "string",
"example": "data:image/png;base64,iVBO..."
},
"expire": {
"description": "过期时间 unix",
"type": "integer",
"example": 10000000
},
"id": {
"description": "验证码 id",
"type": "string",
"example": "abcdefg123456"
}
}
},
"captcha.VerifyCaptcha": {
"type": "object", "type": "object",
"properties": { "properties": {
"captcha": { "captcha": {
@ -1002,41 +1028,6 @@
"example": "OK" "example": "OK"
} }
} }
},
"vo.Captcha": {
"type": "object",
"properties": {
"base64": {
"description": "验证码图片 base64",
"type": "string",
"example": "data:image/png;base64,iVBO..."
},
"expire": {
"description": "过期时间 unix",
"type": "integer",
"example": 10000000
},
"id": {
"description": "验证码 id",
"type": "string",
"example": "abcdefg123456"
}
}
},
"vo.Login": {
"type": "object",
"properties": {
"refreshToken": {
"description": "refreshToken 刷新令牌",
"type": "string",
"example": "0123456789ABCDEFG"
},
"token": {
"description": "token 用户令牌",
"type": "string",
"example": "0123456789ABCDEFG"
}
}
} }
}, },
"securityDefinitions": { "securityDefinitions": {

View File

@ -1,6 +1,6 @@
basePath: / basePath: /
definitions: definitions:
dto.Login: auth.LoginDTO:
properties: properties:
account: account:
example: root example: root
@ -12,7 +12,18 @@ definitions:
- account - account
- password - password
type: object type: object
dto.RefreshToken: auth.LoginVO:
properties:
refreshToken:
description: refreshToken 刷新令牌
example: 0123456789ABCDEFG
type: string
token:
description: token 用户令牌
example: 0123456789ABCDEFG
type: string
type: object
auth.RefreshToken:
properties: properties:
refreshToken: refreshToken:
example: 0123456789ABCDEFG example: 0123456789ABCDEFG
@ -20,7 +31,22 @@ definitions:
required: required:
- refreshToken - refreshToken
type: object type: object
dto.VerifyCaptcha: captcha.Captcha:
properties:
base64:
description: 验证码图片 base64
example: data:image/png;base64,iVBO...
type: string
expire:
description: 过期时间 unix
example: 10000000
type: integer
id:
description: 验证码 id
example: abcdefg123456
type: string
type: object
captcha.VerifyCaptcha:
properties: properties:
captcha: captcha:
example: abcde example: abcde
@ -100,32 +126,6 @@ definitions:
example: OK example: OK
type: string type: string
type: object type: object
vo.Captcha:
properties:
base64:
description: 验证码图片 base64
example: data:image/png;base64,iVBO...
type: string
expire:
description: 过期时间 unix
example: 10000000
type: integer
id:
description: 验证码 id
example: abcdefg123456
type: string
type: object
vo.Login:
properties:
refreshToken:
description: refreshToken 刷新令牌
example: 0123456789ABCDEFG
type: string
token:
description: token 用户令牌
example: 0123456789ABCDEFG
type: string
type: object
info: info:
contact: contact:
email: 919411476@qq.com email: 919411476@qq.com
@ -149,7 +149,7 @@ paths:
name: vo name: vo
required: true required: true
schema: schema:
$ref: '#/definitions/dto.Login' $ref: '#/definitions/auth.LoginDTO'
produces: produces:
- application/json - application/json
responses: responses:
@ -160,7 +160,7 @@ paths:
- $ref: '#/definitions/response.Response' - $ref: '#/definitions/response.Response'
- properties: - properties:
data: data:
$ref: '#/definitions/vo.Login' $ref: '#/definitions/auth.LoginVO'
type: object type: object
default: default:
description: "" description: ""
@ -180,7 +180,7 @@ paths:
name: vo name: vo
required: true required: true
schema: schema:
$ref: '#/definitions/dto.RefreshToken' $ref: '#/definitions/auth.RefreshToken'
produces: produces:
- application/json - application/json
responses: responses:
@ -191,7 +191,7 @@ paths:
- $ref: '#/definitions/response.Response' - $ref: '#/definitions/response.Response'
- properties: - properties:
data: data:
$ref: '#/definitions/vo.Login' $ref: '#/definitions/auth.LoginVO'
type: object type: object
default: default:
description: "" description: ""
@ -412,7 +412,7 @@ paths:
- $ref: '#/definitions/response.Response' - $ref: '#/definitions/response.Response'
- properties: - properties:
data: data:
$ref: '#/definitions/vo.Captcha' $ref: '#/definitions/captcha.Captcha'
type: object type: object
default: default:
description: "" description: ""
@ -432,7 +432,7 @@ paths:
name: vo name: vo
required: true required: true
schema: schema:
$ref: '#/definitions/dto.VerifyCaptcha' $ref: '#/definitions/captcha.VerifyCaptcha'
produces: produces:
- application/json - application/json
responses: responses:
@ -618,13 +618,7 @@ paths:
get: get:
consumes: consumes:
- application/json - application/json
description: 根据 账号 获取用户信息 description: 获取当前用户信息
parameters:
- description: 账号名称
in: query
name: account
required: true
type: string
produces: produces:
- application/json - application/json
responses: responses:
@ -643,7 +637,7 @@ paths:
$ref: '#/definitions/errorx.CodeErrorResponse' $ref: '#/definitions/errorx.CodeErrorResponse'
security: security:
- Token: [] - Token: []
summary: 根据 账号 获取用户信息 summary: 获取当前用户信息
tags: tags:
- User - User
securityDefinitions: securityDefinitions:

View File

@ -1,9 +1,9 @@
package dto package auth
// Login // LoginDTO
// @Param account body string true "用户账号(account)" // @Param account body string true "用户账号(account)"
// @Param password body string true "用户密码" // @Param password body string true "用户密码"
type Login struct { type LoginDTO struct {
Account string `json:"account" example:"root" validate:"required"` Account string `json:"account" example:"root" validate:"required"`
Password string `json:"password" example:"12341234" validate:"required"` Password string `json:"password" example:"12341234" validate:"required"`
} }

View File

@ -1,6 +1,6 @@
package vo package auth
type Login struct { type LoginVO struct {
// token 用户令牌 // token 用户令牌
Token string `json:"token" example:"0123456789ABCDEFG"` Token string `json:"token" example:"0123456789ABCDEFG"`
// refreshToken 刷新令牌 // refreshToken 刷新令牌

View File

@ -1,4 +1,4 @@
package dto package captcha
// VerifyCaptcha // VerifyCaptcha
// @Param id body string true "验证码 id" // @Param id body string true "验证码 id"

View File

@ -1,4 +1,4 @@
package vo package captcha
type Captcha struct { type Captcha struct {
// 验证码 id // 验证码 id

View File

@ -12,6 +12,8 @@ targets:
include_tables: # tables included, you can use ** include_tables: # tables included, you can use **
- user - user
- waf - waf
- topical
- reply
table_prefix: "" table_prefix: ""
multiple_files: true # generate multiple files or one multiple_files: true # generate multiple files or one
template: | # template for code file, it has higher perior than template_path template: | # template for code file, it has higher perior than template_path

View File

@ -0,0 +1,21 @@
package models
import (
"gofiber.study.skcks.cn/common/time"
)
type Reply struct {
Id string `xorm:"not null pk VARCHAR(32)" json:"id"`
Active bool `xorm:"not null index BIT(1)" json:"active"`
Content string `xorm:"not null index LONGTEXT(4294967295)" json:"content"`
CreateTime time.Time `xorm:"not null index DATETIME(6) created" json:"CreateTime"`
ModifyTime time.Time `xorm:"not null index DATETIME(6) updated" json:"modifyTime"`
ModifyTimes int64 `xorm:"not null index BIGINT" json:"modifyTimes"`
Top int `xorm:"not null index BIT(1)" json:"top"`
UserId string `xorm:"not null index VARCHAR(32)" json:"userId"`
TopicalId string `xorm:"not null index VARCHAR(32)" json:"topicalId"`
}
func (m *Reply) TableName() string {
return "reply"
}

View File

@ -0,0 +1,20 @@
package models
import (
"gofiber.study.skcks.cn/common/time"
)
type Topical struct {
Id string `xorm:"not null pk VARCHAR(32)" json:"id"`
Active bool `xorm:"not null index BIT(1)" json:"active"`
Content string `xorm:"not null index LONGTEXT(4294967295)" json:"content"`
CreateTime time.Time `xorm:"not null index DATETIME(6) created" json:"createTime"`
ModifyTime time.Time `xorm:"not null index DATETIME(6) updated" json:"modifyTime"`
ModifyTimes int64 `xorm:"not null index BIGINT" json:"modifyTimes"`
Title string `xorm:"not null VARCHAR(255)" json:"title"`
UserId string `xorm:"not null index VARCHAR(32)" json:"userId"`
}
func (m *Topical) TableName() string {
return "topical"
}

1
model/topical/dto.go Normal file
View File

@ -0,0 +1 @@
package topical

View File

@ -9,9 +9,8 @@ import (
"gofiber.study.skcks.cn/common/utils" "gofiber.study.skcks.cn/common/utils"
"gofiber.study.skcks.cn/global" "gofiber.study.skcks.cn/global"
"gofiber.study.skcks.cn/middleware" "gofiber.study.skcks.cn/middleware"
"gofiber.study.skcks.cn/model/dto" "gofiber.study.skcks.cn/model/auth"
"gofiber.study.skcks.cn/model/generic/models" "gofiber.study.skcks.cn/model/generic/models"
"gofiber.study.skcks.cn/model/vo"
"time" "time"
) )
@ -91,7 +90,7 @@ func (s *Service) getUserClaims(user *models.User) global.UserClaims {
} }
} }
func (s *Service) Login(login *dto.Login) (result *vo.Login, err error) { func (s *Service) Login(login *auth.LoginDTO) (result *auth.LoginVO, err error) {
err = global.ValidateStruct(login) err = global.ValidateStruct(login)
if err != nil { if err != nil {
return nil, err return nil, err
@ -117,13 +116,13 @@ func (s *Service) Login(login *dto.Login) (result *vo.Login, err error) {
_, _ = global.DataSources.Update(user) _, _ = global.DataSources.Update(user)
return &vo.Login{ return &auth.LoginVO{
Token: token, Token: token,
RefreshToken: refreshToken, RefreshToken: refreshToken,
}, err }, err
} }
func (s *Service) RefreshToken(refreshTokenB64 string) (result *vo.Login, err error) { func (s *Service) RefreshToken(refreshTokenB64 string) (result *auth.LoginVO, err error) {
user, err := s.fromRefreshTokenGetUserCache(refreshTokenB64) user, err := s.fromRefreshTokenGetUserCache(refreshTokenB64)
if err != nil { if err != nil {
return return
@ -137,7 +136,7 @@ func (s *Service) RefreshToken(refreshTokenB64 string) (result *vo.Login, err er
refreshToken, err := s.generateAndSaveRefreshToken(user) refreshToken, err := s.generateAndSaveRefreshToken(user)
return &vo.Login{ return &auth.LoginVO{
Token: token, Token: token,
RefreshToken: refreshToken, RefreshToken: refreshToken,
}, err }, err

View File

@ -2,6 +2,7 @@ package services
import ( import (
"gofiber.study.skcks.cn/services/auth" "gofiber.study.skcks.cn/services/auth"
"gofiber.study.skcks.cn/services/topical"
"gofiber.study.skcks.cn/services/user" "gofiber.study.skcks.cn/services/user"
"gofiber.study.skcks.cn/services/waf" "gofiber.study.skcks.cn/services/waf"
"gofiber.study.skcks.cn/services/wol" "gofiber.study.skcks.cn/services/wol"
@ -12,4 +13,5 @@ func Init() {
user.InitService() user.InitService()
waf.InitService() waf.InitService()
wol.InitService() wol.InitService()
topical.InitService()
} }

View File

@ -0,0 +1,39 @@
package topical
import (
"gofiber.study.skcks.cn/global"
"gofiber.study.skcks.cn/model/generic/models"
"strconv"
)
type Service struct {
}
var Services *Service
func InitService() {
Services = &Service{}
}
type CreateTopicalDTO struct {
Title string
Content string
}
func (s *Service) CreateTopical(dto CreateTopicalDTO, userId string) error {
id, _ := global.SonyFlake.NextID()
_, err := global.DataSources.Insert(&models.Topical{
Id: strconv.FormatUint(id, 10),
Active: true,
Content: dto.Content,
ModifyTimes: 0,
Title: dto.Title,
UserId: userId,
})
if err != nil {
return err
}
return nil
}