Files
easywish/backend/internal/controllers/profile.go
Nikolai Papin b72645852b refactor: profile controller;
experiment: figured out a way to add auth middleware to individual methods in controllers, bypassing route group middleware if needed
2025-06-20 17:53:11 +03:00

86 lines
2.0 KiB
Go

package controllers
import (
"easywish/internal/middleware"
"net/http"
"github.com/gin-gonic/gin"
)
type ProfileController interface {
GetProfile(c *gin.Context)
GetOwnProfile(c *gin.Context)
UpdateProfile(c *gin.Context)
GetPrivacySettings(c *gin.Context)
UpdatePrivacySettings(c *gin.Context)
Router
}
type profileControllerImpl struct {
}
func NewProfileController() ProfileController {
return &profileControllerImpl{}
}
// @Summary Get someone's profile details
// @Tags Profile
// @Accept json
// @Produce json
// @Param username path string true "Username"
// @Security JWT
// @Router /profile/{username} [get]
func (p *profileControllerImpl) GetProfile(c *gin.Context) {
c.Status(http.StatusNotImplemented)
}
// @Summary Get own profile when authorized
// @Tags Profile
// @Accept json
// @Produce json
// @Security JWT
// @Router /profile/me [get]
func (p *profileControllerImpl) GetOwnProfile(c *gin.Context) {
c.Status(http.StatusNotImplemented)
}
// @Summary Update profile
// @Tags Profile
// @Accept json
// @Produce json
// @Security JWT
// @Router /profile [patch]
func (p *profileControllerImpl) UpdateProfile(c *gin.Context) {
c.Status(http.StatusNotImplemented)
}
// @Summary Get profile privacy settings
// @Tags Profile
// @Accept json
// @Produce json
// @Security JWT
// @Router /profile/privacy [get]
func (p *profileControllerImpl) GetPrivacySettings(c *gin.Context) {
c.Status(http.StatusNotImplemented)
}
// @Summary Update profile privacy settings
// @Tags Profile
// @Accept json
// @Produce json
// @Security JWT
// @Router /profile/privacy [patch]
func (p *profileControllerImpl) UpdatePrivacySettings(c *gin.Context) {
c.Status(http.StatusNotImplemented)
}
func (p *profileControllerImpl) RegisterRoutes(group *gin.RouterGroup) {
protected := group.Group("")
protected.Use(middleware.JWTAuthMiddleware())
{
protected.GET("/me", p.GetOwnProfile)
protected.GET("/:username", p.GetProfile)
protected.GET("/privacy", p.GetPrivacySettings)
}
}