44 lines
839 B
Go
44 lines
839 B
Go
|
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)
|
||
|
}
|