34 lines
962 B
Go
34 lines
962 B
Go
package handlers
|
|
|
|
import (
|
|
"context"
|
|
"go-backend/internal/database/sqlc"
|
|
"go-backend/internal/services"
|
|
)
|
|
|
|
// UserService and AuthService are defined here, on the consumer side, so
|
|
// handlers depend only on the methods they actually use and tests can swap
|
|
// in fakes without touching the services package.
|
|
|
|
type UserService interface {
|
|
FindByID(ctx context.Context, id string) (*sqlc.UserAuth, error)
|
|
FindByUsername(ctx context.Context, username string) (*sqlc.UserAuth, error)
|
|
CreateUser(ctx context.Context, userInput sqlc.InsertUserParams) (*sqlc.UserAuth, error)
|
|
}
|
|
|
|
type AuthService interface {
|
|
CreateSession(ctx context.Context, userID string) (*services.SessionWithToken, error)
|
|
ValidateSessionToken(ctx context.Context, token string) (*sqlc.UserSession, error)
|
|
}
|
|
|
|
type Handler struct {
|
|
users UserService
|
|
auth AuthService
|
|
}
|
|
|
|
func NewHandler(users UserService, auth AuthService) *Handler {
|
|
return &Handler{
|
|
users: users,
|
|
auth: auth,
|
|
}
|
|
}
|