fix: remove 500 error responses from upload endpoints; fix: return validation error strings instead of error lists; fix: handle invalid avatar upload IDs with 400 Bad Request response; fix: add missing S3Controller to controller initialization; fix: change avatar_upload_id to string type and update validation rules; chore: add license header to smtp.go; refactor: replace manual proxy implementation with httputil.ReverseProxy; fix: inject S3Service dependency into ProfileService; fix: set color and color_grad fields during profile update; fix: correct DTO mapping for profile and settings; fix: check object existence before copying in SaveUpload; fix: adjust profile DTO mapping function for proper pointer handling
75 lines
2.1 KiB
Go
75 lines
2.1 KiB
Go
// Copyright (c) 2025 Nikolai Papin
|
|
//
|
|
// This file is part of Easywish
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
|
// the GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
package controllers
|
|
|
|
import (
|
|
"easywish/internal/dto"
|
|
"easywish/internal/middleware"
|
|
"easywish/internal/services"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/fx"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type SetupControllersParams struct {
|
|
fx.In
|
|
Controllers []Controller `group:"controllers"`
|
|
Log *zap.Logger
|
|
Auth services.AuthService
|
|
Group *gin.Engine
|
|
}
|
|
|
|
func setupControllers(p SetupControllersParams) {
|
|
|
|
apiGroup := p.Group.Group("/api")
|
|
apiGroup.Use(middleware.AuthMiddleware(p.Log, p.Auth))
|
|
apiGroup.Use(gin.HandlerFunc(func(c *gin.Context) {
|
|
ip := c.ClientIP()
|
|
userAgent := c.Request.UserAgent()
|
|
sessionInfoFromCtx, ok := c.Get("session_info"); if !ok {
|
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"error": "Invalid or missing session data"})
|
|
return
|
|
}
|
|
|
|
sessionInfo := sessionInfoFromCtx.(dto.SessionInfo)
|
|
|
|
c.Set("client_info", dto.ClientInfo{
|
|
SessionInfo: sessionInfo,
|
|
IP: ip,
|
|
UserAgent: userAgent,
|
|
})
|
|
|
|
c.Next()
|
|
}))
|
|
for _, ctrl := range p.Controllers {
|
|
ctrl.Setup(apiGroup, p.Log, p.Auth)
|
|
}
|
|
}
|
|
|
|
var Module = fx.Module("controllers",
|
|
fx.Provide(
|
|
fx.Annotate(NewServiceController, fx.ResultTags(`group:"controllers"`)),
|
|
fx.Annotate(NewAuthController, fx.ResultTags(`group:"controllers"`)),
|
|
fx.Annotate(NewProfileController, fx.ResultTags(`group:"controllers"`)),
|
|
fx.Annotate(NewS3Controller, fx.ResultTags(`group:"controllers"`)),
|
|
),
|
|
fx.Invoke(setupControllers),
|
|
)
|