diff --git a/controllers/profile/UpdatePhotoProfile.go b/controllers/profile/UpdatePhotoProfile.go index a9f6f6a..21507d2 100644 --- a/controllers/profile/UpdatePhotoProfile.go +++ b/controllers/profile/UpdatePhotoProfile.go @@ -4,14 +4,13 @@ import ( "github.com/database" "github.com/gin-gonic/gin" "github.com/google/uuid" - "github.com/libs/middleware" "github.com/libs/utils/data" "github.com/models" "net/http" "os" ) -func UpdatePhotoProfile(c *gin.Context, router *gin.Engine) { +func UpdatePhotoProfile(c *gin.Context, router *gin.RouterGroup) { var ( user models.UserDescDB photoProfileUser models.UserPhotoProfileDB @@ -104,11 +103,7 @@ func UpdatePhotoProfile(c *gin.Context, router *gin.Engine) { } if fileStat.Size() != 0 { - rProfile := router.Group("photo_profile") - rProfile.Use(func(c *gin.Context) { - middleware.AuthWithToken(c) - }) - rProfile.GET(uid, func(c *gin.Context) { + router.GET(uid, func(c *gin.Context) { c.File(path) }) } diff --git a/controllers/profile/UploadPhotoProfile.go b/controllers/profile/UploadPhotoProfile.go index c7e0cb8..21cc85d 100644 --- a/controllers/profile/UploadPhotoProfile.go +++ b/controllers/profile/UploadPhotoProfile.go @@ -4,14 +4,13 @@ import ( "github.com/database" "github.com/gin-gonic/gin" "github.com/google/uuid" - "github.com/libs/middleware" "github.com/libs/utils/data" models2 "github.com/models" "net/http" "os" ) -func PhotoProfileUpload(c *gin.Context, router *gin.Engine) { +func PhotoProfileUpload(c *gin.Context, router *gin.RouterGroup) { var ( ppUpload models2.PhotoProfile @@ -99,11 +98,7 @@ func PhotoProfileUpload(c *gin.Context, router *gin.Engine) { } if fileStat.Size() != 0 { - rProfile := router.Group("photo_profile") - rProfile.Use(func(c *gin.Context) { - middleware.AuthWithToken(c) - }) - rProfile.GET(uid, func(c *gin.Context) { + router.GET(uid, func(c *gin.Context) { c.File(path) }) } diff --git a/controllers/wallpaperpage/UploadWallpaper.go b/controllers/wallpaperpage/UploadWallpaper.go index b17f6b4..ede49ad 100644 --- a/controllers/wallpaperpage/UploadWallpaper.go +++ b/controllers/wallpaperpage/UploadWallpaper.go @@ -3,14 +3,13 @@ package wallpaperpage import ( "github.com/gin-gonic/gin" "github.com/google/uuid" - "github.com/libs/middleware" "github.com/libs/utils/data" "github.com/models" "net/http" "os" ) -func UploadWallpaper(c *gin.Context, router *gin.Engine) { +func UploadWallpaper(c *gin.Context, router *gin.RouterGroup) { var wallpaper models.Wallpaper if err := c.ShouldBind(&wallpaper); err != nil { @@ -62,12 +61,7 @@ func UploadWallpaper(c *gin.Context, router *gin.Engine) { } if fileStat.Size() != 0 { - - rImage := router.Group("/images") - rImage.Use(func(c *gin.Context) { - middleware.AuthWithToken(c) - }) - rImage.GET(uid, func(c *gin.Context) { + router.GET(uid, func(c *gin.Context) { c.File(path) }) } diff --git a/handlers/routers/Profile.go b/handlers/routers/Profile.go index 84025e1..1f5712a 100644 --- a/handlers/routers/Profile.go +++ b/handlers/routers/Profile.go @@ -7,15 +7,20 @@ import ( ) func Profile(routers *gin.Engine) { + privateRouters := routers.Group("/wallpaper") privateRouters.Use(middleware.JWT) profileRouter := privateRouters.Group("/profile") profileRouter.GET("", profile.Info) profileRouter.PUT("/update_profile_desc", profile.UpdateProfileDescription) + + rProfile := routers.Group("photo_profile") + rProfile.Use(middleware.AuthWithToken) + profileRouter.PUT("/update_profile_picture", func(c *gin.Context) { - profile.UpdatePhotoProfile(c, routers) + profile.UpdatePhotoProfile(c, rProfile) }) profileRouter.POST("/upload_profile_picture", func(c *gin.Context) { - profile.PhotoProfileUpload(c, routers) + profile.PhotoProfileUpload(c, rProfile) }) } diff --git a/handlers/routers/WallpaperPage.go b/handlers/routers/WallpaperPage.go index ed9f118..0b5c223 100644 --- a/handlers/routers/WallpaperPage.go +++ b/handlers/routers/WallpaperPage.go @@ -10,7 +10,12 @@ func WallpaperPage(routers *gin.Engine) { privateRouters := routers.Group("/wallpaper") privateRouters.Use(middleware.JWT) privateRouters.GET("", wallpaperpage.WallpaperCollection) + + rImage := routers.Group("/images") + rImage.Use(func(c *gin.Context) { + middleware.AuthWithToken(c) + }) privateRouters.POST("/upload", func(c *gin.Context) { - wallpaperpage.UploadWallpaper(c, routers) + wallpaperpage.UploadWallpaper(c, rImage) }) }