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