Files
geo/server/internal/ops/transport/router.go
T
root c091ad7aed feat(server/ops-api): add operations console backend
Stand up an internal ops-api service with operator account, auth, and
audit log subsystems backed by a dedicated migrations_ops migration set.
Wire Makefile targets and the migrate Dockerfile stage so the new schema
ships alongside the existing tenant + monitoring databases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-28 11:32:50 +08:00

63 lines
1.8 KiB
Go

package transport
import (
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v5/pgxpool"
"go.uber.org/zap"
"github.com/geo-platform/tenant-api/internal/ops/app"
"github.com/geo-platform/tenant-api/internal/shared/middleware"
"github.com/geo-platform/tenant-api/internal/shared/response"
)
type Deps struct {
Engine *gin.Engine
Logger *zap.Logger
DB *pgxpool.Pool
Issuer *app.TokenIssuer
Auth *app.AuthService
Accounts *app.AccountService
Audits *app.AuditService
}
func RegisterRoutes(d Deps) {
d.Engine.Use(
middleware.Recovery(d.Logger),
middleware.RequestID(),
middleware.Logger(d.Logger),
middleware.CORS(),
)
d.Engine.GET("/api/health/live", func(c *gin.Context) {
response.Success(c, gin.H{"status": "alive"})
})
d.Engine.GET("/api/health/ready", func(c *gin.Context) {
if err := d.DB.Ping(c.Request.Context()); err != nil {
response.Error(c, response.ErrServiceUnavailable(50301, "postgres_unavailable", "数据库不可达"))
return
}
response.Success(c, gin.H{"status": "ready"})
})
api := d.Engine.Group("/api/ops")
{
api.POST("/auth/login", loginHandler(d.Auth))
}
authed := api.Group("")
authed.Use(authMiddleware(d.Issuer))
{
authed.GET("/auth/me", meHandler(d.Accounts))
authed.POST("/auth/password", changeOwnPasswordHandler(d.Accounts))
authed.GET("/accounts", listAccountsHandler(d.Accounts))
authed.POST("/accounts", createAccountHandler(d.Accounts))
authed.GET("/accounts/:id", getAccountHandler(d.Accounts))
authed.PATCH("/accounts/:id", updateAccountProfileHandler(d.Accounts))
authed.POST("/accounts/:id/status", setAccountStatusHandler(d.Accounts))
authed.POST("/accounts/:id/password", resetAccountPasswordHandler(d.Accounts))
authed.GET("/audits", listAuditsHandler(d.Audits))
}
}