This commit is contained in:
43
router/controller/usersController.go
Normal file
43
router/controller/usersController.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"drive-linked/pkg/dto"
|
||||
"drive-linked/pkg/service"
|
||||
"encoding/json"
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
func UserProfile(ctx iris.Context) {
|
||||
serv := service.NewUsersService(ctx)
|
||||
resp := dto.NewResponse(ctx)
|
||||
|
||||
// 获取所有查询条件参数
|
||||
conditions := make(map[string]interface{})
|
||||
for _, field := range service.UserConditions {
|
||||
if ctx.URLParam(field) != "" {
|
||||
conditions[field] = ctx.URLParam(field)
|
||||
}
|
||||
}
|
||||
|
||||
if len(conditions) == 0 {
|
||||
resp.ErrBadRequest()
|
||||
return
|
||||
}
|
||||
|
||||
serv.GetOneUser(&conditions)
|
||||
}
|
||||
|
||||
func UserLogin(ctx iris.Context) {
|
||||
serv := service.NewUsersService(ctx)
|
||||
resp := dto.NewResponse(ctx)
|
||||
var loginParams dto.LoginParams
|
||||
|
||||
// 转换参数
|
||||
body, _ := ctx.GetBody()
|
||||
err := json.Unmarshal(body, &loginParams)
|
||||
if err != nil {
|
||||
resp.ErrBadRequest()
|
||||
}
|
||||
|
||||
serv.Login(loginParams)
|
||||
}
|
||||
@@ -2,8 +2,9 @@ package router
|
||||
|
||||
import (
|
||||
"drive-linked/pkg/middleware"
|
||||
"drive-linked/pkg/service/controller"
|
||||
"drive-linked/router/controller"
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/core/router"
|
||||
)
|
||||
|
||||
func Router() *iris.Application {
|
||||
@@ -16,6 +17,9 @@ func Router() *iris.Application {
|
||||
// 注册路由
|
||||
// v1
|
||||
v1 := app.Party("/v1")
|
||||
v1.PartyFunc("/auth", func(auth router.Party) {
|
||||
auth.Post("/login", controller.UserLogin)
|
||||
})
|
||||
v1.PartyFunc("/users", func(users iris.Party) {
|
||||
// 需要登录
|
||||
users.Use(middleware.SignRequired)
|
||||
|
||||
Reference in New Issue
Block a user