gohorsejobs/backend/internal/api/controllers/storage_controller.go
Yamamoto 3cd52accfb feat: infrastructure updates, storage verification, and superadmin reset
1. Auth: Implemented forced password reset for SuperAdmin and updated login logic.

2. Infra: Switched backend to internal Postgres and updated .drone.yml.

3. Storage: Added Test Connection endpoint and UI in Backoffice.

4. CI/CD: Updated Forgejo deploy pipeline to include Seeder and use Internal Registry.
2026-01-02 16:36:31 -03:00

48 lines
1.5 KiB
Go

package controllers
import (
"encoding/json"
"net/http"
"github.com/rede5/gohorsejobs/backend/internal/services"
)
type StorageController struct {
storageService *services.StorageService
}
func NewStorageController(storageService *services.StorageService) *StorageController {
return &StorageController{storageService: storageService}
}
// TestConnection verifies if the configured Object Storage is accessible
// @Summary Test Object Storage Connection
// @Description Checks if the current configuration (DB or Env) allows access to the S3 bucket.
// @Tags admin
// @Accept json
// @Produce json
// @Success 200 {object} map[string]string
// @Failure 500 {object} map[string]string
// @Router /admin/storage/test-connection [post]
func (c *StorageController) TestConnection(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
err := c.storageService.TestConnection(ctx)
if err != nil {
sendError(w, http.StatusInternalServerError, "Connection failed: "+err.Error())
return
}
sendSuccess(w, map[string]string{"message": "Connection successful"})
}
func sendError(w http.ResponseWriter, code int, message string) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
json.NewEncoder(w).Encode(map[string]string{"error": message})
}
func sendSuccess(w http.ResponseWriter, data interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(data)
}