158 lines
5.7 KiB
Go
158 lines
5.7 KiB
Go
package v1
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/ogen-go/ogen/ogenerrors"
|
|
|
|
"lincodex/backend/internal/adapter/primary/http/api"
|
|
"lincodex/backend/internal/adapter/primary/http/problem"
|
|
"lincodex/backend/internal/usecase/identity"
|
|
)
|
|
|
|
// Handler is the composite implementation of the generated api.Handler.
|
|
// Unimplemented operations stay on ogen's embedded fallback until a business
|
|
// handler is added for them.
|
|
type Handler struct {
|
|
api.UnimplementedHandler
|
|
|
|
health *HealthHandler
|
|
identity *IdentityHandler
|
|
consent *ConsentHandler
|
|
profile *ProfileHandler
|
|
questionnaire *QuestionnaireHandler
|
|
catalog *CatalogHandler
|
|
organization *OrganizationHandler
|
|
need *NeedHandler
|
|
invitation *InvitationHandler
|
|
support *SupportHandler
|
|
assessment *AssessmentHandler
|
|
assessmentSignals *AssessmentSignalHandler
|
|
practice *PracticeHandler
|
|
privacy *PrivacyHandler
|
|
evidence *EvidenceHandler
|
|
matches *MatchHandler
|
|
notifications *NotificationHandler
|
|
problems *problem.Responder
|
|
}
|
|
|
|
var _ api.Handler = (*Handler)(nil)
|
|
|
|
// HandlerOption adds a business-area handler to Handler.
|
|
type HandlerOption func(*Handler)
|
|
|
|
// WithIdentity serves the configured identity operations.
|
|
func WithIdentity(identity *IdentityHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.identity = identity }
|
|
}
|
|
|
|
// WithConsent serves the published texts and ledger operations.
|
|
func WithConsent(consent *ConsentHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.consent = consent }
|
|
}
|
|
|
|
// WithProfile serves the candidate's private profile.
|
|
func WithProfile(profile *ProfileHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.profile = profile }
|
|
}
|
|
|
|
// WithQuestionnaire serves the candidate's questionnaire and self-assessment.
|
|
func WithQuestionnaire(questionnaire *QuestionnaireHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.questionnaire = questionnaire }
|
|
}
|
|
|
|
// WithCatalog serves the public specialization catalog and bank availability.
|
|
func WithCatalog(catalog *CatalogHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.catalog = catalog }
|
|
}
|
|
|
|
// WithOrganization serves company profiles and owner operations.
|
|
func WithOrganization(organization *OrganizationHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.organization = organization }
|
|
}
|
|
|
|
// WithNeed serves organization-scoped hiring needs.
|
|
func WithNeed(need *NeedHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.need = need }
|
|
}
|
|
|
|
// WithInvitation serves the organization side of invitation drafts.
|
|
func WithInvitation(invitation *InvitationHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.invitation = invitation }
|
|
}
|
|
|
|
// WithSupport serves account-owned support cases.
|
|
func WithSupport(support *SupportHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.support = support }
|
|
}
|
|
|
|
// WithAssessment serves candidate-owned assessment attempts and sessions.
|
|
func WithAssessment(assessment *AssessmentHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.assessment = assessment }
|
|
}
|
|
|
|
// WithAssessmentSignals serves bounded candidate assessment event receipts.
|
|
func WithAssessmentSignals(signals *AssessmentSignalHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.assessmentSignals = signals }
|
|
}
|
|
|
|
// WithPractice serves the debug runs of code practices.
|
|
func WithPractice(practice *PracticeHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.practice = practice }
|
|
}
|
|
|
|
// WithPrivacy serves current publication and candidate-card visibility operations.
|
|
func WithPrivacy(privacy *PrivacyHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.privacy = privacy }
|
|
}
|
|
|
|
// WithEvidence serves the skill evidence of a candidate and its permitted
|
|
// organization projection.
|
|
func WithEvidence(evidence *EvidenceHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.evidence = evidence }
|
|
}
|
|
|
|
// WithNotifications serves the inbox of the candidate cabinet and of one
|
|
// organization cabinet.
|
|
func WithNotifications(notifications *NotificationHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.notifications = notifications }
|
|
}
|
|
|
|
// WithMatches serves the deterministic match search of the visible bank.
|
|
func WithMatches(matches *MatchHandler) HandlerOption {
|
|
return func(handler *Handler) { handler.matches = matches }
|
|
}
|
|
|
|
func NewHandler(health *HealthHandler, problems *problem.Responder, options ...HandlerOption) *Handler {
|
|
handler := &Handler{health: health, problems: problems}
|
|
for _, option := range options {
|
|
option(handler)
|
|
}
|
|
return handler
|
|
}
|
|
|
|
// NewError maps security failures to fixed public problems. Other errors are
|
|
// passed to the responder, which logs them and does not expose their text.
|
|
func (handler *Handler) NewError(ctx context.Context, err error) *api.ProblemStatusCode {
|
|
var securityError *ogenerrors.SecurityError
|
|
if errors.As(err, &securityError) {
|
|
switch {
|
|
case errors.Is(securityError.Err, errCsrfCheckFailed):
|
|
return problem.New(ctx, api.ProblemCodeCsrfCheckFailed)
|
|
case errors.Is(securityError.Err, ogenerrors.ErrSecurityRequirementIsNotSatisfied):
|
|
if _, ok := PrincipalFromContext(ctx); ok {
|
|
return problem.New(ctx, api.ProblemCodeCsrfCheckFailed)
|
|
}
|
|
return problem.New(ctx, api.ProblemCodeUnauthenticated)
|
|
case errors.Is(securityError.Err, ogenerrors.ErrSkipServerSecurity),
|
|
errors.Is(securityError.Err, identity.ErrUnauthenticated),
|
|
errors.Is(securityError.Err, errSessionsNotImplemented):
|
|
return problem.New(ctx, api.ProblemCodeUnauthenticated)
|
|
default:
|
|
return handler.problems.HandlerError(ctx, securityError.Err)
|
|
}
|
|
}
|
|
return handler.problems.HandlerError(ctx, err)
|
|
}
|