catface_backend_go/app/http/controller/web/encounter_controller.go

44 lines
1.7 KiB
Go
Raw Normal View History

2024-10-17 22:43:20 +08:00
package web
import (
2024-10-20 12:10:17 +08:00
"catface/app/global/consts"
2024-10-20 11:50:26 +08:00
"catface/app/global/variable"
"catface/app/http/validator/core/data_transfer"
2024-10-20 12:10:17 +08:00
"catface/app/service/upload_file"
"catface/app/utils/response"
"path/filepath"
2024-10-20 12:16:35 +08:00
"strconv"
2024-10-20 11:50:26 +08:00
2024-10-17 22:43:20 +08:00
"github.com/gin-gonic/gin"
)
type Encounters struct {
}
2024-10-18 10:04:01 +08:00
func (e *Encounters) Create(context *gin.Context) {
// TODO 处理 Photos 文件,然后处理出 Avatar并获取压缩后的 宽高,以及文件的存储路径。
2024-10-20 11:50:26 +08:00
photos := data_transfer.GetStringSlice(context, "photos")
if len(photos) > 0 {
2024-10-20 12:16:35 +08:00
userId := strconv.Itoa(int(context.GetFloat64(consts.ValidatorPrefix + "user_id")))
2024-10-20 11:50:26 +08:00
avatar := photos[0]
avatarWidth := variable.ConfigYml.GetFloat64("FileUploadSetting.AvatarWidth")
2024-10-17 22:43:20 +08:00
2024-10-20 12:30:12 +08:00
srcPath := filepath.Join(variable.BasePath, variable.ConfigYml.GetString("FileUploadSetting.UploadFileSavePath"), "encounterPhotos", "hum_"+userId, avatar)
dstPath := filepath.Join(variable.BasePath, variable.ConfigYml.GetString("FileUploadSetting.UploadFileSavePath"), "encounterAvatar", "hum_"+userId, avatar)
2024-10-20 12:10:17 +08:00
avatarHeight, err := upload_file.ResizeImage(srcPath, dstPath, int(avatarWidth))
if err != nil {
response.Fail(context, consts.FilesUploadFailCode, consts.FilesUploadFailMsg, "")
return
}
context.Set(consts.ValidatorPrefix+"avatar", avatar)
context.Set(consts.ValidatorPrefix+"avatar_height", avatarHeight)
context.Set(consts.ValidatorPrefix+"avatar_width", int(avatarWidth))
2024-10-20 11:50:26 +08:00
}
2024-10-18 10:04:01 +08:00
// Real Insert
2024-10-18 20:28:34 +08:00
// if model.CreateEncounterFactory("").InsertDate(context) {
// response.Success(context, consts.CurdStatusOkMsg, "")
// } else {
// response.Fail(context, consts.CurdCreatFailCode, consts.CurdCreatFailMsg+",新增错误", "")
// }
2024-10-17 22:43:20 +08:00
}