chore: remove direct avatar upload endpoint (POST /profile/avatar);
feat: add endpoints for presigned upload URLs (GET /upload/avatar, GET /upload/image); refactor: replace ProfileDto with NewProfileDto in update profile endpoint; feat: implement S3 integration for avatar management; fix: update database queries to handle new avatar upload flow; chore: add new dependencies for S3 handling (golang.org/x/time); refactor: rename UploadService to S3Service; refactor: change return type for func LocalizeS3Url(originalURL string) (*url.URL, error); feat: add custom validator for upload_id
This commit is contained in:
@@ -24,7 +24,6 @@ import (
|
||||
"easywish/internal/utils/enums"
|
||||
"errors"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
@@ -78,13 +77,6 @@ func NewProfileController(_log *zap.Logger, _ps services.ProfileService) Control
|
||||
Middleware: []gin.HandlerFunc{},
|
||||
Function: ctrl.updateProfileSettings,
|
||||
},
|
||||
{
|
||||
HttpMethod: POST,
|
||||
Path: "/avatar",
|
||||
Authorization: enums.UserRole,
|
||||
Middleware: []gin.HandlerFunc{},
|
||||
Function: ctrl.uploadAvatar,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -169,11 +161,11 @@ func (ctrl *ProfileController) getProfileSettings(c *gin.Context) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security JWT
|
||||
// @Param request body dto.ProfileDto true " "
|
||||
// @Param request body dto.NewProfileDto true " "
|
||||
// @Success 200 {object} bool " "
|
||||
// @Router /profile [put]
|
||||
func (ctrl *ProfileController) updateProfile(c *gin.Context) {
|
||||
request, err := GetRequest[dto.ProfileDto](c); if err != nil {
|
||||
request, err := GetRequest[dto.NewProfileDto](c); if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -206,33 +198,3 @@ func (ctrl *ProfileController) updateProfileSettings(c *gin.Context) {
|
||||
|
||||
c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
// XXX: untested
|
||||
// @Summary Upload an avatar
|
||||
// @Tags Profile
|
||||
// @Accept mpfd
|
||||
// @Produce json
|
||||
// @Security JWT
|
||||
// @Param file formData file true "Avatar image file"
|
||||
// @Success 200 {object} dto.UrlDto "Uploaded image url"
|
||||
// @Router /profile/avatar [post]
|
||||
func (ctrl *ProfileController) uploadAvatar(c *gin.Context) {
|
||||
cinfo := GetClientInfo(c)
|
||||
|
||||
allowedTypes := map[string]bool{
|
||||
"image/jpeg": true,
|
||||
"image/png": true,
|
||||
"image/webp": true,
|
||||
}
|
||||
fileName, err := GetFile(c, "file", 8*1024*1024, allowedTypes); if err != nil {
|
||||
return
|
||||
}
|
||||
defer os.Remove(*fileName)
|
||||
|
||||
link, err := ctrl.ps.UploadAvatar(cinfo, *fileName); if err != nil {
|
||||
c.Status(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, dto.UrlDto{Url: *link})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user