Skip to content

Commit

Permalink
Update AuthwithToken 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
fchrgrib committed Jun 15, 2023
1 parent 34e39ac commit f8561f7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
9 changes: 2 additions & 7 deletions controllers/profile/UpdatePhotoProfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
}
Expand Down
9 changes: 2 additions & 7 deletions controllers/profile/UploadPhotoProfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
}
Expand Down
10 changes: 2 additions & 8 deletions controllers/wallpaperpage/UploadWallpaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
})
}
Expand Down
9 changes: 7 additions & 2 deletions handlers/routers/Profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
7 changes: 6 additions & 1 deletion handlers/routers/WallpaperPage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

3 comments on commit f8561f7

@vercel
Copy link

@vercel vercel bot commented on f8561f7 Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on f8561f7 Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on f8561f7 Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.