-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8d7269
commit 05929b9
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |