You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.1 KiB
Go

package manage
import (
"fmt"
"github.com/gin-gonic/gin"
"gold-shop/errors"
request "gold-shop/request/manage"
"gold-shop/service"
"gold-shop/utils/result"
)
func Login(c *gin.Context) (result.Data, error) {
loginRequest := request.LoginRequest{}
err := c.ShouldBindJSON(&loginRequest)
token, err := service.AdminService.Login(loginRequest.Username, loginRequest.Password)
return result.Data{"token": token}, err
}
func GetAdminInfo(c *gin.Context) (result.Data, error) {
admin := service.AdminService.GetAdminInfo(admin(c).ID)
data := result.Data{
"admin": admin,
}
return data, nil
}
func Logout(c *gin.Context) (result.Data, error) {
return nil, nil
}
func AddAdmin(c *gin.Context) (result.Data, error) {
addAdminRequest := request.AddAdminRequest{}
err := c.ShouldBindJSON(&addAdminRequest)
fmt.Println("addAdminRequest")
fmt.Println(addAdminRequest)
if err != nil {
return nil, errors.NewBusinessError("参数错误")
}
err = service.AdminService.Add(addAdminRequest.Username, addAdminRequest.Password)
if err != nil {
return nil, err
}
return nil, nil
}