From 05929b9990118bea17de4d2dbc053ae8a387e3aa Mon Sep 17 00:00:00 2001 From: Aidan Traboulay Date: Sun, 15 Dec 2024 17:06:08 -0400 Subject: [PATCH] add interface types --- backend/internal/interfaces/types.go | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/backend/internal/interfaces/types.go b/backend/internal/interfaces/types.go index e69de29b..12a12434 100644 --- a/backend/internal/interfaces/types.go +++ b/backend/internal/interfaces/types.go @@ -0,0 +1,61 @@ +package interfaces + +import ( + "github.com/jackc/pgx/v5/pgxpool" + "github.com/labstack/echo/v4" + + "KonferCA/SPUR/db" + "KonferCA/SPUR/internal/middleware" + "KonferCA/SPUR/storage" +) + +/* +CoreServer defines the complete set of capabilities required by API versions. +This interface is implemented by the main server struct and provides access +to all core services and dependencies needed across the application. + +Usage: + - Implemented by the main server struct + - Used by API versioned packages to access core functionality + - Provides complete access to all server capabilities + +Example: + + func SetupRoutes(e *echo.Group, s CoreServer) { + // Use s.GetQueries() for database access + // Use s.GetStorage() for file operations + // etc. + } +*/ +type CoreServer interface { + GetDB() *pgxpool.Pool + GetQueries() *db.Queries + GetStorage() *storage.Storage + GetAuthLimiter() *middleware.RateLimiter + GetAPILimiter() *middleware.RateLimiter + GetEcho() *echo.Echo +} + +/* +HandlerDependencies defines a minimal interface for individual handlers. +This interface provides only the essential services needed for most handlers, +reducing coupling and making handlers easier to test. + +Usage: + - Used by individual route handlers + - Provides minimal required dependencies + - Makes handlers more testable with minimal mocking + +Example: + + func (h *Handler) HandleCreateUser(deps HandlerDependencies) echo.HandlerFunc { + return func(c echo.Context) error { + // Use deps.GetQueries() for database operations + // Use deps.GetStorage() for file operations + } + } +*/ +type HandlerDependencies interface { + GetQueries() *db.Queries + GetStorage() *storage.Storage +}