[FIX]员工添加头像
This commit is contained in:
parent
ef2d1dbbc4
commit
3db41242da
12
docs/docs.go
12
docs/docs.go
|
@ -124,6 +124,12 @@ var doc = `{
|
|||
"in": "header",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "员工头像",
|
||||
"name": "avatar_url",
|
||||
"in": "formData"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "员工用户名",
|
||||
|
@ -226,6 +232,12 @@ var doc = `{
|
|||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "员工头像",
|
||||
"name": "avatar_url",
|
||||
"in": "formData"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "员工用户名",
|
||||
|
|
|
@ -104,6 +104,12 @@
|
|||
"in": "header",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "员工头像",
|
||||
"name": "avatar_url",
|
||||
"in": "formData"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "员工用户名",
|
||||
|
@ -206,6 +212,12 @@
|
|||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "员工头像",
|
||||
"name": "avatar_url",
|
||||
"in": "formData"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "员工用户名",
|
||||
|
|
|
@ -64,6 +64,10 @@ paths:
|
|||
name: Authorization
|
||||
required: true
|
||||
type: string
|
||||
- description: 员工头像
|
||||
in: formData
|
||||
name: avatar_url
|
||||
type: string
|
||||
- description: 员工用户名
|
||||
in: formData
|
||||
name: username
|
||||
|
@ -133,6 +137,10 @@ paths:
|
|||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
- description: 员工头像
|
||||
in: formData
|
||||
name: avatar_url
|
||||
type: string
|
||||
- description: 员工用户名
|
||||
in: formData
|
||||
name: username
|
||||
|
|
|
@ -64,6 +64,7 @@ func EditEmployee(id int, data interface{}) bool {
|
|||
|
||||
func AddArticle(data map[string]interface{}) bool {
|
||||
db.Create(&Employee{
|
||||
AvatarUrl: data["avatar_url"].(string),
|
||||
Username: data["username"].(string),
|
||||
Password: data["password"].(string),
|
||||
Department: data["department"].(string),
|
||||
|
|
|
@ -96,6 +96,7 @@ func GetEmployees(c *gin.Context) {
|
|||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Param Authorization header string true "auth by /admin/login"
|
||||
// @Param avatar_url formData string false "员工头像"
|
||||
// @Param username formData string true "员工用户名"
|
||||
// @Param password formData string true "员工密码"
|
||||
// @Param department formData string true "员工部门"
|
||||
|
@ -107,6 +108,7 @@ func AddEmployee(c *gin.Context) {
|
|||
password := c.PostForm("password")
|
||||
department := c.PostForm("department")
|
||||
position := c.PostForm("position")
|
||||
avatarUrl := c.PostForm("avatar_url")
|
||||
|
||||
valid := validation.Validation{}
|
||||
valid.Required(username, "username").Message("用户名不能为空")
|
||||
|
@ -124,6 +126,7 @@ func AddEmployee(c *gin.Context) {
|
|||
data["password"] = password
|
||||
data["department"] = department
|
||||
data["position"] = position
|
||||
data["avatar_url"] = avatarUrl
|
||||
code = e.SUCCESS
|
||||
} else {
|
||||
code = e.ErrorExistEmployee
|
||||
|
@ -148,6 +151,7 @@ func AddEmployee(c *gin.Context) {
|
|||
// @Produce json
|
||||
// @Param Authorization header string true "auth by /admin/login"
|
||||
// @Param id path int true "ID"
|
||||
// @Param avatar_url formData string false "员工头像"
|
||||
// @Param username formData string false "员工用户名"
|
||||
// @Param password formData string false "员工密码"
|
||||
// @Param department formData string false "员工部门"
|
||||
|
@ -157,6 +161,7 @@ func AddEmployee(c *gin.Context) {
|
|||
// @Router /admin/v1/employees/{id} [put]
|
||||
func EditEmployee(c *gin.Context) {
|
||||
id := com.StrTo(c.Param("id")).MustInt()
|
||||
avatarUrl := c.PostForm("avatar_url")
|
||||
username := c.PostForm("username")
|
||||
password := c.PostForm("password")
|
||||
department := c.PostForm("department")
|
||||
|
@ -173,6 +178,9 @@ func EditEmployee(c *gin.Context) {
|
|||
if ! valid.HasErrors() {
|
||||
if models.ExistEmployeeByID(id) {
|
||||
code = e.SUCCESS
|
||||
if avatarUrl != "" {
|
||||
data["avatar_url"] = avatarUrl
|
||||
}
|
||||
if username != "" {
|
||||
data["username"] = username
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
_ "github.com/go-pripro/shop/docs"
|
||||
"github.com/go-pripro/shop/pkg/setting"
|
||||
"github.com/go-pripro/shop/pkg/upload"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
"github.com/swaggo/gin-swagger/swaggerFiles"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func InitRouter() *gin.Engine {
|
||||
|
@ -28,6 +30,8 @@ func InitRouter() *gin.Engine {
|
|||
})
|
||||
})
|
||||
|
||||
r.StaticFS("/upload/images", http.Dir(upload.GetImageFullPath()))
|
||||
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
// 初始化admin
|
||||
|
|
Loading…
Reference in New Issue