schools
import "github.com/Ask-Atlas/AskAtlas/api/internal/schools"
Index
- Constants
- func EncodeCursor(c Cursor) (string, error)
- type Cursor
- type GetSchoolParams
- type ListSchoolsParams
- type ListSchoolsResult
- type Repository
- type School
- type Service
Constants
const (
// DefaultPageLimit is applied when the caller does not specify page_limit
// (or specifies 0). Matches the openapi.yaml default.
DefaultPageLimit int32 = 25
// MaxPageLimit caps the per-page result count. Matches the openapi.yaml maximum.
MaxPageLimit int32 = 100
// MaxSearchLength caps the q parameter length. Matches the openapi.yaml maxLength.
// Typed int (not int32) because it's compared against len(string) at the
// HTTP-boundary validator.
MaxSearchLength int = 200
)
func EncodeCursor
func EncodeCursor(c Cursor) (string, error)
EncodeCursor serializes a Cursor into a base64-encoded string token.
type Cursor
Cursor is the opaque pagination token. Sorting is fixed on (name ASC, id ASC), so the cursor only needs the last consumed row's name and id.
type Cursor struct {
Name string `json:"name"`
ID uuid.UUID `json:"id"`
}
func DecodeCursor
func DecodeCursor(s string) (Cursor, error)
DecodeCursor parses a base64-encoded string token back into a Cursor.
type GetSchoolParams
GetSchoolParams is the input to Service.GetSchool.
type GetSchoolParams struct {
SchoolID uuid.UUID
}
type ListSchoolsParams
ListSchoolsParams is the input to Service.ListSchools.
type ListSchoolsParams struct {
Q *string
Limit int32
Cursor *Cursor
}
type ListSchoolsResult
ListSchoolsResult is the output of Service.ListSchools.
type ListSchoolsResult struct {
Schools []School
HasMore bool
NextCursor *string
}
type Repository
Repository is the data-access surface required by Service.
type Repository interface {
ListSchools(ctx context.Context, arg db.ListSchoolsParams) ([]db.School, error)
GetSchool(ctx context.Context, id pgtype.UUID) (db.School, error)
}
func NewSQLCRepository
func NewSQLCRepository(queries *db.Queries) Repository
NewSQLCRepository returns a Repository backed by sqlc-generated Postgres queries.
type School
School represents a university or college that hosts courses.
type School struct {
ID uuid.UUID
Name string
Acronym string
Domain *string
URL *string
City *string
State *string
Country *string
CreatedAt time.Time
}
type Service
Service is the business-logic layer for the schools feature.
type Service struct {
// contains filtered or unexported fields
}
func NewService
func NewService(repo Repository) *Service
NewService creates a new Service backed by the given Repository.
func (*Service) GetSchool
func (s *Service) GetSchool(ctx context.Context, p GetSchoolParams) (School, error)
GetSchool returns a single school by its UUID. Returns an error wrapping apperrors.ErrNotFound when no row matches; the handler maps that to a 404 with a school-specific message.
func (*Service) ListSchools
func (s *Service) ListSchools(ctx context.Context, p ListSchoolsParams) (ListSchoolsResult, error)
ListSchools returns a paginated, optionally-filtered list of schools. The HTTP boundary is the primary validator (openapi enforces 1..MaxPageLimit), but the service also clamps defensively so internal Go callers can't ask Postgres for an unbounded number of rows.
Generated by gomarkdoc