46 lines
985 B
Go
46 lines
985 B
Go
package service
|
|
|
|
import (
|
|
"database/sql"
|
|
"drive-linked/model"
|
|
"drive-linked/pkg/dto"
|
|
"drive-linked/pkg/serializer"
|
|
"github.com/kataras/iris/v12"
|
|
"net/http"
|
|
)
|
|
|
|
type UsersService struct {
|
|
Ctx iris.Context
|
|
}
|
|
|
|
var (
|
|
UserConditions = [...]string{"id", "name", "email", "nickname"}
|
|
)
|
|
|
|
func NewUsersService(ctx iris.Context) *UsersService {
|
|
return &UsersService{Ctx: ctx}
|
|
}
|
|
|
|
func (serv *UsersService) GetOneUser(conditions *map[string]interface{}) {
|
|
var err error
|
|
resp := dto.NewResponse(serv.Ctx)
|
|
user := &model.User{}
|
|
|
|
err = user.GetWithConditions(conditions)
|
|
|
|
switch err {
|
|
case nil:
|
|
// 复制到dto对象
|
|
var userResult dto.UserProfile
|
|
err = userResult.CopyOf(user)
|
|
if err != nil {
|
|
resp.Error(http.StatusInternalServerError, "service.users Error")
|
|
}
|
|
resp.Success(userResult)
|
|
case sql.ErrNoRows:
|
|
resp.Error(serializer.ErrNoUser, "找不到此用户")
|
|
default:
|
|
resp.Error(http.StatusInternalServerError, "获取用户信息失败,数据库异常")
|
|
}
|
|
}
|