From 3db41242da1197d0f029be589a704528f580da1e Mon Sep 17 00:00:00 2001 From: viletyy Date: Sat, 26 Sep 2020 19:34:23 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=E5=91=98=E5=B7=A5=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs.go | 12 ++++++++++++ docs/swagger.json | 12 ++++++++++++ docs/swagger.yaml | 8 ++++++++ models/employee.go | 1 + routers/admin/v1/employee.go | 8 ++++++++ routers/router.go | 4 ++++ 6 files changed, 45 insertions(+) diff --git a/docs/docs.go b/docs/docs.go index a1a5fd2..fa69b1b 100644 --- a/docs/docs.go +++ b/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": "员工用户名", diff --git a/docs/swagger.json b/docs/swagger.json index aeaa11e..0a334a7 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -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": "员工用户名", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 18c4033..888efec 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -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 diff --git a/models/employee.go b/models/employee.go index 1144c00..19cc78c 100644 --- a/models/employee.go +++ b/models/employee.go @@ -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), diff --git a/routers/admin/v1/employee.go b/routers/admin/v1/employee.go index 6cfee9d..ab94811 100644 --- a/routers/admin/v1/employee.go +++ b/routers/admin/v1/employee.go @@ -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 } diff --git a/routers/router.go b/routers/router.go index 605bcdc..f87af50 100644 --- a/routers/router.go +++ b/routers/router.go @@ -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