13 Commits

Author SHA1 Message Date
7e83e5a7e3 Fix #16: Repository layer code review: fix critical transaction bug and high-severity issues (#17) 2026-07-20 16:49:36 +00:00
590fed23ca refactor: use map[string]struct{} for allowedOrderBy whitelist
Per review feedback on PR #17, comment #137: use map[string]struct{}
(set semantics) instead of map[string]bool for the ORDER BY field
whitelist. Updates the lookup to comma-ok idiom.
2026-07-20 16:48:13 +00:00
frx
7bf95f136f fix(issue-16): fix critical transaction bug and high-severity repository issues 2026-07-09 13:55:55 +00:00
596e8bbc3f Merge pull request 'Fix #14: Describe project architecture and save it into docs/ARCHITECTURE.md' (#15) from fix/issue-14 into master 2026-07-09 13:16:54 +00:00
frx
74b162a9df fix(issue-14): describe project architecture and save it into docs/ARCHITECTURE.md 2026-07-09 10:57:32 +00:00
4fe6758b64 Merge pull request 'Fix #12: ydb course repository migrate to new v3' (#13) from fix/issue-12 into master 2026-07-09 10:51:06 +00:00
frx
1e8adb4da4 fix(issue-12): ydb course repository migrate to new v3 2026-07-05 17:11:50 +00:00
91c1778a5e Merge pull request 'Fix #1: Pagination resets filters' (#11) from fix/issue-1 into master 2026-07-03 16:19:55 +00:00
frx
6d1f526394 fix(issue-1): Pagination resets filters
Move pagination logic to preserve filter query parameters (school_id,
order_by, asc, per_page) when navigating between pages.

- Added QueryParams field to Pagination struct and pageURL() helper
- Server-side: buildListCoursesQueryParams() encodes active filters into
  pagination links as query string
- Client-side: setupPaginationLinks() intercepts pagination link clicks,
  reads current filter state from DOM selects, and constructs full URLs
  with all parameters preserved
- Added data-paginated/data-base-url/data-current-page attributes to
  pagination nav for JS targeting

Closes #1
2026-07-03 16:16:39 +00:00
e09a14cf10 Merge pull request 'Fix #9: No Dockerfile to build service' (#10) from fix/issue-9 into master 2026-07-01 17:22:14 +00:00
frx
c2cefe0d32 fix(issue-9): No Dockerfile to build service 2026-07-01 17:06:02 +00:00
6d6f5e19d1 Merge pull request 'Fix #7: AGENTS.md is absent in the repository' (#8) from fix/issue-7 into master 2026-07-01 09:53:11 +00:00
5c43740a04 fix(issue-7): AGENTS.md is absent in the repository 2026-07-01 09:02:44 +00:00
23 changed files with 1978 additions and 1078 deletions

26
.dockerignore Normal file
View File

@ -0,0 +1,26 @@
# Version control & tooling
.git
.gitignore
.gitattributes
# Local task runner state & binaries
.task
bin/
tags
# Local databases & logs
*.sqlite
*.log
# Editor / IDE
.zed
.idea
.vscode
# Docs & examples not needed to build the image
*.md
htmlexamples/
# Don't send the docker metadata itself (optional, keeps context lean)
Dockerfile
.dockerignore

250
AGENTS.md Normal file
View File

@ -0,0 +1,250 @@
# AGENTS.md
Guidance for AI agents (and humans) working in this repository.
## Project Overview
**kurious** (`git.loyso.art/frx/kurious`) is a course/education platform that
aggregates and serves educational course listings. It scrapes/syncs course data
from an external source (sravni.ru) via a rate-limited HTTP client, stores it
locally, and exposes it through a server-rendered web UI with filtering,
pagination, and statistics.
The project is written in Go and follows a hexagonal (ports & adapters)
architecture with a CQRS-flavored application layer.
## Tech Stack
- **Language:** Go 1.26 (toolchain `go1.26.4`; see `go.mod`)
- **HTTP routing:** `github.com/gorilla/mux`
- **HTTP client:** `github.com/go-resty/resty/v2` (sravni.ru scraper)
- **Database:** SQLite via `modernc.org/sqlite` (pure-Go, CGO disabled).
YDB was historically supported but is **no longer supported**
(`service.NewApplication` returns an error for the YDB engine).
- **DB access:** `github.com/jmoiron/sqlx` (named queries)
- **Templating:** `github.com/a-h/templ` (`.templ` files compile to Go)
- **Observability:** OpenTelemetry (`go.opentelemetry.io/otel`) — traces and
metrics with stdout / OTLP (HTTP & gRPC) exporters
- **Background jobs:** `github.com/robfig/cron/v3`
- **Logging:** standard `log/slog` (text or JSON, configurable)
- **Rate limiting:** `golang.org/x/time/rate`
- **Testing:** `github.com/stretchr/testify` (assert, require, mock)
- **Mocking:** `github.com/vektra/mockery/v2` (config in `.mockery.yaml`)
- **Linting:** `golangci-lint` v1.55.2
- **Build/task runner:** [Taskfile](https://taskfile.dev) (`Taskfile.yml`)
- **Build flags:** ldflags inject `version`, `commit`, `buildTime`
(see `kurious.go`)
## Architecture
The codebase implements a **hexagonal architecture** (ports & adapters) with a
CQRS-style separation between commands (writes) and queries (reads).
```
┌─────────────────────────────────────────────┐
delivery │ ports/ (HTTP server, cron jobs) │
mechanisms └──────────────────────┬──────────────────────┘
│ depends on
┌──────────────────────▼──────────────────────┐
application │ app/ (command/, query/) │
layer │ app.Application { Commands, Queries } │
│ decorator/ (logging decorators) │
└──────────────────────┬──────────────────────┘
│ depends on
┌──────────────────────▼──────────────────────┐
domain │ domain/ (entities, repository ports) │
└──────────────────────┬──────────────────────┘
│ implemented by
┌──────────────────────▼──────────────────────┐
adapters │ adapters/ (sqlite_*, memory_mapper, │
│ ydb_* legacy stub) │
└─────────────────────────────────────────────┘
```
- **`domain/`** — pure business entities (`Course`, `Organization`,
`LearningCategory`) and the **repository interfaces** (ports) that the
application depends on: `CourseRepository`, `OrganizationRepository`,
`LearningCategoryRepository`. No I/O or framework code lives here.
- **`app/`** — the application layer. `app.Application` aggregates a
`Commands` struct and a `Queries` struct. Handlers in `app/command/` perform
writes; handlers in `app/query/` perform reads. Each handler implements a
generic `decorator.CommandHandler[T]` or `decorator.QueryHandler[Q, U]`
interface and is wrapped with logging decorators at construction time.
- **`adapters/`** — concrete implementations of the domain repository ports.
`sqlite_course_repository.go`, `sqlite_organization_repository.go`, etc.
translate between domain types and SQL rows. `memory_mapper.go` is an
in-memory mapper translating external dictionary IDs to human-readable names.
- **`ports/`** — delivery mechanisms. `ports/http/` is the HTTP server (gorilla/mux
+ templ templates); `ports/background/` runs scheduled cron jobs (e.g.
`SyncSravniHandler`).
- **`service/`** — the **composition root**. `service.NewApplication` selects
the DB engine, constructs the SQLite connection, builds the adapters, and
wires everything into an `app.Application`. This is what binaries call.
Data flows: an HTTP request enters `ports/http`, calls a handler on
`service.Application` (which delegates to `app/command` or `app/query`), which
calls a `domain` repository interface implemented by an `adapters/*` repository.
## Directory Structure
```
.
├── kurious.go # Root package: version/commit/buildTime getters
├── Taskfile.yml # Build, test, lint, generate, run task definitions
├── .mockery.yaml # mockery config (with-expecter, keeptree)
├── go.mod / go.sum
├── cmd/ # Entry points (one package per binary)
│ ├── kuriweb/ # Main HTTP web server (config.go, main.go, http.go, trace.go)
│ ├── background/ # Background sync process (cron-driven sravni sync)
│ └── dev/sravnicli/ # Developer CLI for inspecting the sravni source
├── internal/
│ ├── kurious/ # Application core (the hexagon)
│ │ ├── domain/ # Entities + repository interface ports
│ │ ├── app/
│ │ │ ├── app.go # Application{Commands, Queries} aggregate
│ │ │ ├── command/ # Write-side handlers (Create, Delete, Update...)
│ │ │ └── query/ # Read-side handlers (List, Get, Stats...)
│ │ ├── adapters/ # Repository implementations + mocks/
│ │ ├── ports/
│ │ │ ├── http/ # HTTP server, course routes
│ │ │ │ └── bootstrap/ # templ templates (.templ) + generated _templ.go
│ │ │ ├── background/ # Cron job handlers
│ │ │ ├── background.go # BackgroundProcess (cron scheduler)
│ │ │ └── services.go # Services{HTTP, Background} aggregate
│ │ └── service/ # Composition root: NewApplication wiring
│ └── common/ # Shared, reusable utilities
│ ├── client/sravni/ # sravni.ru HTTP client + mocks/
│ ├── config/ # Config structs (HTTP, Log, Sqlite, Trace, YDB, Duration)
│ ├── decorator/ # Command/Query handler interfaces + logging decorators
│ ├── errors/ # SimpleError, ValidationError, sentinel errors
│ ├── generator/ # ID generators
│ ├── nullable/ # Generic nullable Value[T]
│ ├── xcontext/ # context helpers (request id, log fields)
│ ├── xlog/ # slog + cron logger adapters
│ └── xslices/ # slice helpers (Map, Filter, ForEach, LRU)
├── pkg/
│ └── xdefault/ # WithFallback helper (public-ish pkg)
├── migrations/
│ └── sqlite/ # SQL migrations (embed.FS) + migrator.go
├── assets/kurious/static/ # Static web assets (embedded via go:embed)
└── htmlexamples/ # Standalone HTML/templ prototyping examples
```
## Build, Test, and Lint Commands
All operations are driven by **Taskfile** (`task <name>`). The toolchain is
installed into a local `bin/` (`GOBIN={{.USER_WORKING_DIR}}/bin`) and
`CGO_ENABLED=0` is enforced.
| Command | What it does |
|--------------------------|--------------------------------------------------------------------|
| `task install_tools` | Install `golangci-lint`, `templ`, `mockery` into `bin/` |
| `task generate` | Run `templ generate` (compiles `.templ``_templ.go`) |
| `task mocks` | Run `go generate ./internal/...` (regenerate mockery mocks) |
| `task check` | Run `golangci-lint run ./...` (depends on `generate`) |
| `task test` | Run `go test ./internal/...` (depends on `generate`) |
| `task build_web` | Build `bin/kuriousweb` (depends on `check` + `test`) |
| `task build_background` | Build `bin/kuriousbg` (depends on `check` + `test`) |
| `task build_dev_cli` | Build `bin/sravnicli` (depends on `check` + `test`) |
| `task build` | Build all three binaries |
| `task run` | Build then run `bin/kuriousweb` |
Typical workflow before committing: `task check && task test`.
### Running the binaries
Binaries read a JSON config file path as their first argument, defaulting to
`config.json` (note: `*.json` is gitignored, so configs are local). Example
fields: `log`, `sqlite`, `http.listen_addr`, `db_engine`, `tracing`.
```bash
./bin/kuriousweb path/to/config.json
```
## Code Conventions
### Decorators / handler pattern
Command and query handlers implement generic interfaces and are wrapped with
logging decorators at construction time. When adding a new use case:
1. Define the command/query struct and a `*Handler` type alias of
`decorator.CommandHandler[T]` / `decorator.QueryHandler[Q, U]` in
`app/command/` or `app/query/`.
2. Implement a private `*Handler` struct holding its repository dependencies.
3. Expose a `New*Handler(deps..., log *slog.Logger)` constructor that returns
the decorated handler (`decorator.ApplyCommandDecorators` /
`decorator.AddQueryDecorators`).
4. Register the new handler on `app.Commands` / `app.Queries` in
`app/app.go` and wire it in `service/service.go`.
### Mock generation (mockery)
- Interfaces marked with `//go:generate mockery ...` directives (see
`domain/repository.go`, `common/client/sravni/client.go`) are mocked into
sibling `mocks/` packages (`keeptree: True`, `with-expecter: true`).
- Regenerate with `task mocks` (runs `go generate ./internal/...`).
- Mocks are committed to the repo.
### Templating (templ)
- HTML is authored as `.templ` files under
`internal/kurious/ports/http/bootstrap/`.
- `task generate` compiles them to `*_templ.go` (committed). Run it whenever a
`.templ` file changes; `task check` and `task test` both depend on it.
### Database / migrations
- SQLite migrations live in `migrations/sqlite/*.sql` and are embedded via
`go:embed`. The migrator (`migrations/sqlite/migrator.go`) applies them in
order inside a transaction.
- Repository adapters use `sqlx` named queries; domain ↔ row translation is
centralized via `AsDomain()` methods.
### Logging & observability
- Use `log/slog` with structured attributes. Request-scoped fields (e.g.
`request_id`) are propagated through `context` via `internal/common/xcontext`.
- HTTP handlers wrap requests in trace spans and record metrics
(request duration histogram). Database adapters emit spans tagged with
`db.*` attributes.
### Error handling
- Domain/repository errors use sentinels from `internal/common/errors`
(`ErrNotFound`, `ErrNotImplemented`) and `*ValidationError` (mapped to HTTP
400/404 in `ports/http/server.go`).
- Wrap errors with `fmt.Errorf("doing X: %w", err)` to add context while
preserving the underlying error for `errors.Is` / `errors.As`.
## Testing Patterns
- **Scope:** unit tests live next to the code they test
(`*_test.go`). `task test` runs `go test ./internal/...`.
- **Framework:** `github.com/stretchr/testify``require` for fatal
assertions, `assert` for non-fatal, `mock` for mock interactions.
- **Mocks:** generated mockery mocks with the **expecter** API:
```go
repo.EXPECT().Create(mock.Anything, expectedParams).
Return(domain.Course{ID: "c1"}, nil).Once()
```
Note: when the generated mock does not yet implement every interface method,
tests embed the mock and add the missing methods (see the `fullRepo` pattern
in `internal/kurious/app/command/command_test.go`).
- **Logger:** tests use a `quietLogger()` helper that discards output
(`slog.New(slog.NewTextHandler(io.Discard, nil))`).
- **Adapter tests:** `internal/kurious/adapters/sqlite_*_test.go` exercise the
real SQLite repositories against an in-memory/temp database.
- **Conventions:** table-driven where appropriate; use `context.Background()`
in tests; assert on wrapped errors with `assert.ErrorIs` and message
fragments with `assert.Contains`.
## Notes for Agents
- Run `task generate` before linting/testing if you touched any `.templ` file.
- Do not re-introduce YDB as a working engine without updating
`service.NewApplication` and the migration story (currently SQLite-only).
- Generated files (`*_templ.go`, `mocks/*.go`) are committed — regenerate and
commit them alongside source changes.
- `*.json`, `*.sqlite`, `bin/`, and `*.log` are gitignored; do not commit
local configs or databases.

55
Dockerfile Normal file
View File

@ -0,0 +1,55 @@
# syntax=docker/dockerfile:1
# ---- Build stage ----
FROM golang:1.26-alpine AS builder
ENV CGO_ENABLED=0 GOOS=linux
ARG VERSION=docker
ARG COMMIT=docker
ARG BUILD_TIME=unknown
ARG PROJECT=git.loyso.art/frx/kurious
WORKDIR /src
# Cache module downloads.
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the source.
# Generated files (templ *_templ.go, mockery mocks) are committed, so no
# generation step is required here.
COPY . .
# Build the web server and the healthcheck probe.
RUN go build -trimpath \
-ldflags "-X ${PROJECT}.version=${VERSION} -X ${PROJECT}.commit=${COMMIT} -X ${PROJECT}.buildTime=${BUILD_TIME}" \
-o /out/kuriweb ./cmd/kuriweb \
&& go build -trimpath -o /out/healthcheck ./cmd/healthcheck
# Bake a default config into the image (config files are gitignored locally,
# so the image must be self-contained).
RUN echo '{"log":{"level":"info","format":"json"},"http":{"listen_addr":":8080","mount_live":false},"sqlite":{"dsn":"/tmp/kurious.sqlite","shutdown_timeout":"10s"},"db_engine":"sqlite","tracing":{"type":"stdout","show_metrics":false}}' > /out/config.json
# ---- Final stage ----
FROM gcr.io/distroless/static-debian12
LABEL org.opencontainers.image.title="kuriousweb" \
org.opencontainers.image.source="git.loyso.art/frx/kurious"
COPY --from=builder /out/kuriweb /kuriweb
COPY --from=builder /out/healthcheck /healthcheck
COPY --from=builder /out/config.json /etc/kurious/config.json
# static-debian12 ships a "nonroot" user (uid 65532).
USER nonroot:nonroot
EXPOSE 8080
ENTRYPOINT ["/kuriweb"]
CMD ["/etc/kurious/config.json"]
# Distroless static has no shell/curl, so probing is done via the tiny
# healthcheck binary built above.
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD ["/healthcheck", "http://127.0.0.1:8080/healthz"]

View File

@ -67,6 +67,16 @@ tasks:
- task: build_background - task: build_background
- task: build_web - task: build_web
build_docker:
desc: "Build the kuriousweb Docker image locally (no push)"
cmds:
- >-
docker build
--build-arg VERSION={{.GIT_VERSION}}
--build-arg COMMIT={{.GIT_COMMIT}}
--build-arg BUILD_TIME={{.BUILD_TIME}}
-t kuriousweb .
run: run:
deps: [build] deps: [build]
cmds: cmds:

28
cmd/healthcheck/main.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"fmt"
"net/http"
"os"
"time"
)
func main() {
url := "http://127.0.0.1:8080/healthz"
if len(os.Args) > 1 {
url = os.Args[1]
}
client := &http.Client{Timeout: 3 * time.Second}
resp, err := client.Get(url)
if err != nil {
fmt.Fprintf(os.Stderr, "healthcheck error: %v\n", err)
os.Exit(1)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
fmt.Fprintf(os.Stderr, "healthcheck failed: status %s\n", resp.Status)
os.Exit(1)
}
}

View File

@ -63,6 +63,11 @@ func setupHTTP(cfg config.HTTP, srv xhttp.Server, log *slog.Logger) *http.Server
middlewareMetrics(), middlewareMetrics(),
) )
router.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
}).Methods(http.MethodGet)
setupCoursesHTTP(srv, router, log) setupCoursesHTTP(srv, router, log)
if cfg.MountLive { if cfg.MountLive {

349
docs/ARCHITECTURE.md Normal file
View File

@ -0,0 +1,349 @@
# Architecture
## Patterns
### Hexagonal Architecture (Ports & Adapters)
The project follows **hexagonal architecture** — business logic lives at the center
and all I/O (databases, HTTP, external APIs) is pushed to the periphery through
interfaces. The domain never imports infrastructure packages.
```
┌─────────────────────────────────────────────────────┐
│ Ports (delivery mechanisms) │
│ ports/http/ — HTTP server (gorilla/mux) │
│ ports/background/ — Cron jobs (robfig/cron) │
└──────────────────────┬──────────────────────────────┘
│ depends on
┌──────────────────────▼──────────────────────────────┐
│ Application layer (use cases) │
│ app/command/ — write-side handlers │
│ app/query/ — read-side handlers │
│ decorator/ — handler interfaces + logging │
└──────────────────────┬──────────────────────────────┘
│ depends on
┌──────────────────────▼──────────────────────────────┐
│ Domain (pure business rules) │
│ domain/ — entities (Course, Organization, ...) │
│ domain/ — repository interfaces (ports) │
│ domain/ — mapper interface (CourseMapper) │
└──────────────────────┬──────────────────────────────┘
│ implemented by
┌──────────────────────▼──────────────────────────────┐
│ Adapters (infrastructure) │
│ adapters/sqlite_*_repository.go — SQLite repos │
│ adapters/memory_mapper.go — in-memory mapper │
│ adapters/ydb_* — legacy YDB stubs │
│ adapters/not_implemented.go — sentinel stubs │
└─────────────────────────────────────────────────────┘
```
### CQRS (Command-Query Responsibility Segregation)
The application layer splits all use cases into **commands** (writes) and
**queries** (reads), each with its own handler type:
- **Commands** implement `decorator.CommandHandler[T]``Handle(ctx, params) error`
- **Queries** implement `decorator.QueryHandler[Q, U]``Handle(ctx, query) (result, error)`
Both are aggregated into `app.Application{Commands, Queries}` and exposed through
`service.Application`.
### Decorator Pattern
Every handler is wrapped with a logging + tracing decorator at construction time
(`decorator.ApplyCommandDecorators` / `decorator.AddQueryDecorators`). The
decorator:
1. Creates an OpenTelemetry span (`"command <Name>"` / `"query <Name>"`)
2. Logs structured fields (handler name, serialized args)
3. Measures elapsed time
4. Records errors on the span
5. Delegates to the base handler
The decorator is applied inside `New*Handler()` constructors — callers never
see the raw handler.
### Composition Root
`service.NewApplication` is the single place where all wiring happens: it selects
the DB engine, creates connections, instantiates adapters, registers handlers
on the `Application` struct, and injects the `CourseMapper`. Binaries in `cmd/`
call this function.
### Repository Interface Segregation
Each aggregate has its own repository interface defined in `domain/`:
| Interface | Methods (key) |
|---------------------------|---------------------------------------------|
| `CourseRepository` | List, Get, GetByExternalID, Create, CreateBatch, Delete, UpdateCourseDescription, ListStatistics |
| `OrganizationRepository` | List, Get, ListStats, Create, Delete |
| `LearningCategoryRepository` | List, Get, Upsert |
Adapters implement these interfaces. Unimplemented methods use
`ErrNotImplemented` sentinel stubs.
### External Client Abstraction
The sravni.ru HTTP client (`common/client/sravni/Client` interface) is abstracted
behind an interface with a `noop.Client` fallback. The background sync handler
depends on the interface, not the concrete HTTP implementation.
## Logic Placement
| Concern | Where it lives |
|-------------------------------|---------------------------------------------------|
| Business entities | `internal/kurious/domain/` |
| Repository interfaces (ports) | `internal/kurious/domain/repository.go` |
| Mapper interface | `internal/kurious/domain/mapper.go` |
| Write-side use cases | `internal/kurious/app/command/` |
| Read-side use cases | `internal/kurious/app/query/` |
| Handler interfaces + decorators| `internal/common/decorator/` |
| Repository implementations | `internal/kurious/adapters/` |
| HTTP routing + handlers | `internal/kurious/ports/http/` |
| Templ templates | `internal/kurious/ports/http/bootstrap/*.templ` |
| Background jobs | `internal/kurious/ports/background/` |
| Composition root | `internal/kurious/service/service.go` |
| HTTP client (sravni.ru) | `internal/common/client/sravni/` |
| Config structs | `internal/common/config/` |
| Error sentinels | `internal/common/errors/` |
| Logging helpers | `internal/common/xcontext/`, `common/xlog/` |
| Utility functions | `internal/common/xslices/`, `common/nullable/` |
| ID generation | `internal/common/generator/` |
| Entry points (binaries) | `cmd/kuriweb/`, `cmd/background/`, `cmd/dev/` |
| SQL migrations | `migrations/sqlite/` (embedded via `go:embed`) |
| Static web assets | `assets/kurious/static/` (embedded via `go:embed`) |
| Public package | `pkg/xdefault/` |
## Layers
### 1. Domain Layer (`internal/kurious/domain/`)
Pure Go types — no framework imports, no I/O. Contains:
- **Entities:** `Course`, `Organization`, `LearningCategory` — structs with
fields and no behavior beyond data representation.
- **Repository interfaces:** `CourseRepository`, `OrganizationRepository`,
`LearningCategoryRepository` — the ports that adapters must implement.
- **Mapper interface:** `CourseMapper` — maps external dictionary IDs to
human-readable names; implemented by `adapters/memory_mapper.go`.
- **Value objects:** `SourceType`, `ListCoursesParams`, `CreateCourseParams`,
etc. — parameter types used by repository interfaces.
### 2. Application Layer (`internal/kurious/app/`)
Orchestrates domain objects through repository ports:
- **`app.go`** — `Application{Commands, Queries}` aggregate struct. Groups all
handlers into a single type.
- **`command/`** — Write handlers: `CreateCourse`, `CreateCourses`,
`DeleteCourse`, `UpdateCourseDescription`, `CreateOrganization`. Each is a
struct holding repository dependencies, with a `New*Handler()` constructor
that wraps the base with decorators.
- **`query/`** — Read handlers: `GetCourse`, `ListCourses`, `ListLearningTypes`,
`ListCourseThematics`, `ListCoursesStats`, `ListOrganizations`,
`ListOrganizationsStats`, `GetOrganization`. Some queries (e.g. `ListCourses`)
implement cursor-based pagination with configurable batch sizes.
### 3. Common Infrastructure (`internal/common/`)
Shared packages used across the application:
- **`decorator/`** — Generic `CommandHandler[T]` and `QueryHandler[Q, U]`
interfaces + logging/tracing decorator implementations. Uses OpenTelemetry spans
and structured slog logging.
- **`client/sravni/`** — HTTP client for sravni.ru with `Client` interface,
`noop.Client` fallback, entities, and helpers. Uses `go-resty` internally.
- **`config/`** — Typed config structs: `Log`, `HTTP`, `Sqlite`, `Trace`, `YDB`,
`Duration`.
- **`errors/`** — `SimpleError`, `ValidationError`, sentinel errors
(`ErrNotFound`, `ErrNotImplemented`). Mapped to HTTP status codes in `ports/http`.
- **`xslices/`** — Generic slice utilities: `Map`, `Filter`, `ForEach`, `LRU`.
- **`nullable/`** — Generic `Value[T]` for nullable fields (wraps a value + valid flag).
- **`xcontext/`** — Context helpers for propagating request-scoped log fields.
- **`xlog/`** — Adapters bridging `slog` to `cron` logger interface.
- **`generator/`** — ID generators (`RandomInt64ID`).
### 4. Adapters Layer (`internal/kurious/adapters/`)
Concrete implementations of domain interfaces:
- **`sqlite_*_repository.go`** — SQLite-backed implementations using `sqlx`
named queries. Each defines a row type with `AsDomain()` for entity mapping.
- **`sqlite_connection.go`** — Connection factory; applies embedded migrations,
returns ready-to-use repository instances.
- **`memory_mapper.go`** — In-memory `CourseMapper` implementation; loads
dictionary counts from the course repository, maps IDs ↔ names.
- **`not_implemented.go`** — Sentinel adapter types returning `ErrNotImplemented`
for methods not yet wired up.
- **`ydb_*`** — Legacy YDB adapter stubs (engine no longer supported at runtime).
All DB operations create OpenTelemetry spans with `db.*` semantic attributes.
### 5. Ports Layer (`internal/kurious/ports/`)
Delivery mechanisms that drive the application:
- **`http/`** — HTTP server using `gorilla/mux`. `Server` struct holds
`service.Application` and delegates to handlers. `course.go` contains the main
`List` and `Index` handlers that call query handlers, map results to templ
params, and render HTML.
- **`http/bootstrap/`** — Templ (`.templ`) template files compiled to Go.
Defines view parameter structs and HTML rendering.
- **`background/`** — `BackgroundProcess` wrapping `robfig/cron`. Registers
scheduled handlers like `SyncSravniHandler`.
- **`background.go`** — Cron scheduler with job registration, shutdown, and
next-run stats.
- **`services.go`** — `Services{HTTP, Background}` aggregate — the outermost
composition point.
### 6. Service Layer (`internal/kurious/service/`)
The **composition root**:
- **`service.go`** — `NewApplication()` selects DB engine, creates connections,
builds adapter instances, constructs all command/query handlers (with logging
decorators), and assembles the `Application` struct. Also owns `Close()` for
resource cleanup.
### 7. Entry Points (`cmd/`)
Three binaries, each in its own package:
| Binary | Location | Purpose |
|--------|----------|---------|
| `kuriousweb` | `cmd/kuriweb/` | HTTP web server — starts server + optional background process |
| `kuriousbg` | `cmd/background/` | Background sync process — runs cron scheduler only |
| `sravnicli` | `cmd/dev/sravnicli/` | Developer CLI for inspecting sravni.ru data |
Each binary reads a JSON config file, constructs `service.Application` via
`service.NewApplication`, and starts its delivery mechanism.
## Structure
```
.
├── cmd/ # Entry points
│ ├── kuriweb/ # HTTP server binary
│ ├── background/ # Background sync binary
│ └── dev/sravnicli/ # Developer CLI
├── internal/
│ ├── kurious/ # Application core (hexagon)
│ │ ├── domain/ # Entities + repository ports
│ │ │ ├── course.go # Course entity
│ │ │ ├── organization.go # Organization entity
│ │ │ ├── category.go # LearningCategory entity
│ │ │ ├── kurious.go # SourceType enum, shared domain types
│ │ │ ├── mapper.go # CourseMapper interface
│ │ │ └── repository.go # Repository interfaces + params
│ │ │
│ │ ├── app/ # Application layer (use cases)
│ │ │ ├── app.go # Application{Commands, Queries}
│ │ │ ├── command/ # Write-side handlers
│ │ │ │ ├── createcourse.go # CreateCourse, CreateCourses
│ │ │ │ ├── createorganization.go
│ │ │ │ ├── deletecourse.go
│ │ │ │ └── updatecoursedescription.go
│ │ │ └── query/ # Read-side handlers
│ │ │ ├── getcourse.go
│ │ │ ├── getorganization.go
│ │ │ ├── listcourses.go
│ │ │ ├── listcoursesstats.go
│ │ │ ├── listcoursethematics.go
│ │ │ ├── listlearningtypes.go
│ │ │ ├── listorganizations.go
│ │ │ └── listorganizationstats.go
│ │ │
│ │ ├── adapters/ # Repository implementations
│ │ │ ├── sqlite_course_repository.go
│ │ │ ├── sqlite_organization_repository.go
│ │ │ ├── sqlite_learning_category_repository.go
│ │ │ ├── sqlite_connection.go # Connection factory + migrations
│ │ │ ├── memory_mapper.go # In-memory CourseMapper
│ │ │ ├── not_implemented.go # ErrNotImplemented stubs
│ │ │ ├── adapters.go # Shared DB helpers, tracing
│ │ │ └── ydb_course_repository.go # Legacy YDB stub
│ │ │
│ │ ├── ports/ # Delivery mechanisms
│ │ │ ├── http/ # HTTP server
│ │ │ │ ├── server.go # Server, error handling, pagination
│ │ │ │ ├── course.go # Course list/index handlers
│ │ │ │ └── bootstrap/ # Templ templates + params
│ │ │ ├── background/ # Cron job handlers
│ │ │ │ └── synchandler.go # Sravni sync handler
│ │ │ ├── background.go # Cron scheduler
│ │ │ └── services.go # Services aggregate
│ │ │
│ │ └── service/ # Composition root
│ │ └── service.go # NewApplication wiring
│ │
│ └── common/ # Shared infrastructure
│ ├── decorator/ # Handler interfaces + logging decorators
│ ├── client/sravni/ # Sravni.ru HTTP client
│ ├── config/ # Config structs
│ ├── errors/ # Error types + sentinels
│ ├── generator/ # ID generation
│ ├── nullable/ # Generic nullable Value[T]
│ ├── xcontext/ # Context log helpers
│ ├── xlog/ # Logger adapters
│ └── xslices/ # Slice utilities
├── pkg/xdefault/ # Public package (WithFallback helper)
├── migrations/sqlite/ # SQL migrations (go:embed)
├── assets/kurious/static/ # Static assets (go:embed)
├── docs/ # Documentation
│ └── ARCHITECTURE.md # This file
└── htmlexamples/ # Templ prototyping
```
## Data Flow
### HTTP Request (read path)
```
HTTP request
→ gorilla/mux router (ports/http/server.go)
→ handler method (ports/http/course.go)
→ parse query params + pagination
→ app.Queries.ListCourses.Handle() [application layer]
→ decorator: create span, log args [decorator]
→ courseHandler.Handle() [application handler]
→ domain.CourseRepository.List() [domain port]
→ sqlite_course_repository [adapter]
→ sqlx named query → SQLite [infrastructure]
← domain.ListCoursesResult
← result → map to templ params
← templ.Render(ctx, w) → HTML response
```
### Background Sync (write path)
```
cron tick
→ BackgroundProcess scheduler (ports/background.go)
→ syncSravniHandler.Handle() [port handler]
→ fill caches (known external IDs, orgs)
→ sravni.Client.GetMainPageState() [external API]
→ for each learning type:
→ client.ListEducationalProducts() [rate-limited]
→ deduplicate courses/orgs
→ app.Commands.InsertCourses.Handle() [application layer]
→ domain.CourseRepository.CreateBatch() [domain port]
→ sqlite_course_repository [adapter]
```
## Key Design Decisions
1. **Pure-Go SQLite** (`modernc.org/sqlite`) — no CGO dependency, builds anywhere.
2. **Embedded migrations** — SQL files in `migrations/sqlite/` are compiled into
the binary via `go:embed` and applied at startup in a transaction.
3. **Templ for HTML** — type-safe templates compiled to Go; generated `_templ.go`
files are committed to the repo.
4. **CGO_ENABLED=0 everywhere** — enforced by Taskfile and build flags.
5. **Go 1.26** — latest toolchain; see `go.mod`.
6. **OpenTelemetry** — spans and metrics on every command/query handler and DB
operation; exports to stdout or OTLP (HTTP/gRPC).
7. **Single composition root**`service.NewApplication` is the only place that
knows about concrete adapter types. Tests can swap adapters via interfaces.

12
go.mod
View File

@ -5,12 +5,12 @@ go 1.26.0
toolchain go1.26.4 toolchain go1.26.4
require ( require (
github.com/a-h/templ v0.2.707 github.com/a-h/templ v0.3.1020
github.com/go-resty/resty/v2 v2.13.1 github.com/go-resty/resty/v2 v2.13.1
github.com/gorilla/mux v1.8.1 github.com/gorilla/mux v1.8.1
github.com/jmoiron/sqlx v1.4.0 github.com/jmoiron/sqlx v1.4.0
github.com/robfig/cron/v3 v3.0.1 github.com/robfig/cron/v3 v3.0.1
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.10.0
github.com/teris-io/cli v1.0.1 github.com/teris-io/cli v1.0.1
github.com/ydb-platform/ydb-go-sdk/v3 v3.74.3 github.com/ydb-platform/ydb-go-sdk/v3 v3.74.3
github.com/ydb-platform/ydb-go-yc v0.12.1 github.com/ydb-platform/ydb-go-yc v0.12.1
@ -25,8 +25,8 @@ require (
go.opentelemetry.io/otel/sdk v1.30.0 go.opentelemetry.io/otel/sdk v1.30.0
go.opentelemetry.io/otel/sdk/metric v1.30.0 go.opentelemetry.io/otel/sdk/metric v1.30.0
go.opentelemetry.io/otel/trace v1.30.0 go.opentelemetry.io/otel/trace v1.30.0
golang.org/x/net v0.29.0 golang.org/x/net v0.51.0
golang.org/x/sync v0.8.0 golang.org/x/sync v0.19.0
golang.org/x/time v0.5.0 golang.org/x/time v0.5.0
google.golang.org/grpc v1.66.1 google.golang.org/grpc v1.66.1
modernc.org/sqlite v1.30.1 modernc.org/sqlite v1.30.1
@ -52,8 +52,8 @@ require (
github.com/ydb-platform/ydb-go-genproto v0.0.0-20240528144234-5d5a685e41f7 // indirect github.com/ydb-platform/ydb-go-genproto v0.0.0-20240528144234-5d5a685e41f7 // indirect
github.com/ydb-platform/ydb-go-yc-metadata v0.6.1 // indirect github.com/ydb-platform/ydb-go-yc-metadata v0.6.1 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/sys v0.25.0 // indirect golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.18.0 // indirect golang.org/x/text v0.34.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
google.golang.org/protobuf v1.34.2 // indirect google.golang.org/protobuf v1.34.2 // indirect

32
go.sum
View File

@ -517,8 +517,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk= github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/a-h/templ v0.2.707 h1:T1Gkd2ugbRglZ9rYw/VBchWOSZVKmetDbBkm4YubM7U= github.com/a-h/templ v0.3.1020 h1:ypAT/L5ySWEnZ6Zft/5yfoWXYYkhFNvEFOeeqecg4tw=
github.com/a-h/templ v0.2.707/go.mod h1:5cqsugkq9IerRNucNsI4DEamdHPsoGMQy99DzydLhM8= github.com/a-h/templ v0.3.1020/go.mod h1:A2DlK61v+K+NRoGnhmYbNYVmtYHcFO5/AisMvBdDxTM=
github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY= github.com/ajstarks/deck v0.0.0-20200831202436-30c9fc6549a9/go.mod h1:JynElWSGnm/4RlzPXRlREEwqTHAN3T56Bv2ITsFT3gY=
github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk= github.com/ajstarks/deck/generate v0.0.0-20210309230005-c3f852c02e19/go.mod h1:T13YZdzov6OU0A1+RfKZiZN9ca6VeKdBdyDV+BY97Tk=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
@ -808,8 +808,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/teris-io/cli v1.0.1 h1:J6jnVHC552uqx7zT+Ux0++tIvLmJQULqxVhCid2u/Gk= github.com/teris-io/cli v1.0.1 h1:J6jnVHC552uqx7zT+Ux0++tIvLmJQULqxVhCid2u/Gk=
github.com/teris-io/cli v1.0.1/go.mod h1:V9nVD5aZ873RU/tQXLSXO8FieVPQhQvuNohsdsKXsGw= github.com/teris-io/cli v1.0.1/go.mod h1:V9nVD5aZ873RU/tQXLSXO8FieVPQhQvuNohsdsKXsGw=
github.com/yandex-cloud/go-genproto v0.0.0-20211115083454-9ca41db5ed9e/go.mod h1:HEUYX/p8966tMUHHT+TsS0hF/Ca/NYwqprC5WXSDMfE= github.com/yandex-cloud/go-genproto v0.0.0-20211115083454-9ca41db5ed9e/go.mod h1:HEUYX/p8966tMUHHT+TsS0hF/Ca/NYwqprC5WXSDMfE=
@ -943,8 +943,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.7.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@ -1004,8 +1004,8 @@ golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@ -1050,8 +1050,8 @@ golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220929204114-8fcdb60fdcc0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@ -1131,8 +1131,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
@ -1161,8 +1161,8 @@ golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@ -1231,8 +1231,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k= golang.org/x/tools v0.3.0/go.mod h1:/rWhSS2+zyEVwoJf8YAX6L2f0ntZ7Kn/mGgAWcipA5k=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"time" "time"
cerrors "git.loyso.art/frx/kurious/internal/common/errors"
"git.loyso.art/frx/kurious/internal/common/nullable" "git.loyso.art/frx/kurious/internal/common/nullable"
"git.loyso.art/frx/kurious/internal/common/xslices" "git.loyso.art/frx/kurious/internal/common/xslices"
"git.loyso.art/frx/kurious/internal/kurious/domain" "git.loyso.art/frx/kurious/internal/kurious/domain"
@ -76,6 +77,20 @@ func (r *sqliteCourseRepository) List(
if !params.Ascending { if !params.Ascending {
direction = "DESC" direction = "DESC"
} }
allowedOrderBy := map[string]struct{}{
"id": {},
"name": {},
"created_at": {},
"updated_at": {},
"full_price": {},
"discount": {},
"duration": {},
}
if _, ok := allowedOrderBy[params.OrderBy]; !ok {
return result, fmt.Errorf("invalid order by field: %s", params.OrderBy)
}
query += " ORDER BY " + params.OrderBy + " " + direction query += " ORDER BY " + params.OrderBy + " " + direction
if params.Limit > 0 { if params.Limit > 0 {
@ -277,6 +292,9 @@ func (r *sqliteCourseRepository) Get(
var courseDB sqliteCourseDB var courseDB sqliteCourseDB
err = r.db.GetContext(ctx, &courseDB, query, id) err = r.db.GetContext(ctx, &courseDB, query, id)
if err != nil { if err != nil {
if errors.Is(err, sql.ErrNoRows) {
return course, cerrors.ErrNotFound
}
return course, fmt.Errorf("executing query: %w", err) return course, fmt.Errorf("executing query: %w", err)
} }
@ -289,7 +307,7 @@ func (r *sqliteCourseRepository) GetByExternalID(
return course, errors.New("not implemented") return course, errors.New("not implemented")
} }
func (r *sqliteCourseRepository) CreateBatch(ctx context.Context, params ...domain.CreateCourseParams) error { func (r *sqliteCourseRepository) CreateBatch(ctx context.Context, params ...domain.CreateCourseParams) (err error) {
tx, err := r.db.BeginTxx(ctx, &sql.TxOptions{Isolation: sql.LevelDefault}) tx, err := r.db.BeginTxx(ctx, &sql.TxOptions{Isolation: sql.LevelDefault})
if err != nil { if err != nil {
return fmt.Errorf("beginning tx: %w", err) return fmt.Errorf("beginning tx: %w", err)
@ -317,9 +335,9 @@ func (r *sqliteCourseRepository) CreateBatch(ctx context.Context, params ...doma
} }
for _, param := range params { for _, param := range params {
_, err := stmt.ExecContext(ctx, createCourseParamsAsValues(param)...) _, execErr := stmt.ExecContext(ctx, createCourseParamsAsValues(param)...)
if err != nil { if execErr != nil {
return fmt.Errorf("executing statement query: %w", err) return fmt.Errorf("executing statement query: %w", execErr)
} }
} }

View File

@ -1,10 +1,12 @@
package adapters package adapters
import ( import (
"errors"
"strconv" "strconv"
"testing" "testing"
"time" "time"
cerrors "git.loyso.art/frx/kurious/internal/common/errors"
"git.loyso.art/frx/kurious/internal/common/nullable" "git.loyso.art/frx/kurious/internal/common/nullable"
"git.loyso.art/frx/kurious/internal/kurious/domain" "git.loyso.art/frx/kurious/internal/kurious/domain"
@ -105,3 +107,33 @@ func (s *sqliteCourseRepositorySuite) TestListLimitOffset() {
s.NoError(err) s.NoError(err)
s.Empty(result.Courses) s.Empty(result.Courses)
} }
func (s *sqliteCourseRepositorySuite) TestCreateBatchPartialFailure() {
cr := s.connection.CourseRepository()
baseParams := domain.CreateCourseParams{
SourceType: domain.SourceTypeManual,
}
first := baseParams
first.ID = "dup-id"
duplicate := baseParams
duplicate.ID = "dup-id"
err := cr.CreateBatch(s.ctx, first, duplicate)
s.Require().Error(err)
result, listErr := cr.List(s.ctx, domain.ListCoursesParams{})
s.Require().NoError(listErr)
s.Empty(result.Courses, "partial batch should be rolled back, not committed")
s.Zero(result.Count, "partial batch should be rolled back, not committed")
}
func (s *sqliteCourseRepositorySuite) TestGetNotFound() {
cr := s.connection.CourseRepository()
_, err := cr.Get(s.ctx, "does-not-exist")
s.Require().Error(err)
s.True(errors.Is(err, cerrors.ErrNotFound), "expected ErrNotFound, got %v", err)
}

View File

@ -187,7 +187,7 @@ func (r *sqliteOrganizationRepository) List(ctx context.Context, params domain.L
}() }()
organizations := make([]organizationDB, 0, 1<<8) organizations := make([]organizationDB, 0, 1<<8)
err = r.db.SelectContext(ctx, &organizations, query) err = r.db.SelectContext(ctx, &organizations, query, args...)
if err != nil { if err != nil {
return nil, fmt.Errorf("executing query: %w", err) return nil, fmt.Errorf("executing query: %w", err)
} }

View File

@ -126,3 +126,45 @@ func (s *sqliteOrganzationRepositorySuite) TestCreate() {
expectedOrganization.UpdatedAt = gotOrganization.UpdatedAt expectedOrganization.UpdatedAt = gotOrganization.UpdatedAt
s.Equal(expectedOrganization, gotOrganization) s.Equal(expectedOrganization, gotOrganization)
} }
func (s *sqliteOrganzationRepositorySuite) TestListByIDs() {
const itemscount = 3
baseOrg := domain.Organization{
Alias: "test-alias",
Name: "test-name",
Site: "test-site",
LogoLink: "test-logo",
}
ids := make([]string, 0, itemscount)
for i := 0; i < itemscount; i++ {
iStr := strconv.Itoa(i)
id := "test-id-" + iStr
ids = append(ids, id)
_, err := s.connection.Organization().Create(s.ctx, domain.CreateOrganizationParams{
ID: id,
ExternalID: nullable.NewValue("test-ext-id-" + iStr),
Alias: baseOrg.Alias,
Name: baseOrg.Name,
Site: baseOrg.Site,
LogoLink: baseOrg.LogoLink,
})
s.Require().NoError(err)
}
wantedIDs := ids[:2]
gotOrgs, err := s.connection.Organization().List(s.ctx, domain.ListOrganizationsParams{
IDs: wantedIDs,
})
s.Require().NoError(err)
gotIDs := make([]string, 0, len(gotOrgs))
for _, o := range gotOrgs {
gotIDs = append(gotIDs, o.ID)
}
s.Len(gotOrgs, len(wantedIDs))
s.ElementsMatch(wantedIDs, gotIDs)
}

File diff suppressed because it is too large Load Diff

View File

@ -1,21 +1,27 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.707 // templ: version: v0.3.1020
package bootstrap package bootstrap
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ" import "github.com/a-h/templ"
import "context" import templruntime "github.com/a-h/templ/runtime"
import "io"
import "bytes"
func button(title string, attributes templ.Attributes) templ.Component { func button(title string, attributes templ.Attributes) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx) templ_7745c5c3_Var1 := templ.GetChildren(ctx)
@ -23,7 +29,7 @@ func button(title string, attributes templ.Attributes) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent templ_7745c5c3_Var1 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<button class=\"button\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<button class=\"button\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -31,7 +37,7 @@ func button(title string, attributes templ.Attributes) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, ">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -44,23 +50,28 @@ func button(title string, attributes templ.Attributes) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</button>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
func buttonRedirect(id, title string, linkTo string) templ.Component { func buttonRedirect(id, title string, linkTo string) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var3 := templ.GetChildren(ctx) templ_7745c5c3_Var3 := templ.GetChildren(ctx)
@ -68,20 +79,20 @@ func buttonRedirect(id, title string, linkTo string) templ.Component {
templ_7745c5c3_Var3 = templ.NopComponent templ_7745c5c3_Var3 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<button class=\"button\" id=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<button class=\"button\" id=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var4 string var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs("origin-link-" + id) templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.ResolveAttributeValue("origin-link-" + id)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/common.templ`, Line: 10, Col: 26} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/common.templ`, Line: 10, Col: 26}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var4)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -94,7 +105,7 @@ func buttonRedirect(id, title string, linkTo string) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</button>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</button>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -102,10 +113,7 @@ func buttonRedirect(id, title string, linkTo string) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
@ -120,3 +128,5 @@ func onclickRedirect(id, to string) templ.ComponentScript {
CallInline: templ.SafeScriptInline(`__templ_onclickRedirect_5c43`, id, to), CallInline: templ.SafeScriptInline(`__templ_onclickRedirect_5c43`, id, to),
} }
} }
var _ = templruntime.GeneratedTemplate

View File

@ -158,6 +158,44 @@ script elementScriptsLoad() {
} }
}; };
const buildFilterParams = () => {
const params = [];
const school_selector = document.getElementById('schoolSelect');
if (school_selector && school_selector.value) {
params.push('school_id=' + school_selector.value);
}
const order_by = document.getElementById('sortBySelect');
if (order_by && order_by.value) {
params.push('order_by=' + order_by.value);
}
const ascending = document.getElementById('sortByOrder');
if (ascending && ascending.checked) {
params.push('asc=true');
}
return params.join('&');
};
const setupPaginationLinks = () => {
document.querySelectorAll('a.page-link').forEach(link => {
link.addEventListener('click', (e) => {
const nav = link.closest('nav[data-paginated]');
if (!nav) return;
e.preventDefault();
const baseUrl = nav.getAttribute('data-base-url');
const href = link.getAttribute('href');
const pageMatch = href.match(/[?&]page=(\d+)/);
if (!pageMatch) return;
const page = pageMatch[1];
const filterParams = buildFilterParams();
let url = baseUrl + '?page=' + page;
if (filterParams) {
url += '&' + filterParams;
}
window.location.assign(url);
});
});
};
const formFilterOnSubmit = event => { const formFilterOnSubmit = event => {
event.preventDefault(); event.preventDefault();
@ -180,7 +218,6 @@ script elementScriptsLoad() {
const order_by = document.getElementById('sortBySelect'); const order_by = document.getElementById('sortBySelect');
const order_by_value = (order_by !== null && order_by.value !== '') ? order_by.value : ''; const order_by_value = (order_by !== null && order_by.value !== '') ? order_by.value : '';
const ascending = document.getElementById('sortByOrder'); const ascending = document.getElementById('sortByOrder');
const baseUrl = `${window.location.pathname}?`; const baseUrl = `${window.location.pathname}?`;
params = []; params = [];
@ -217,6 +254,8 @@ script elementScriptsLoad() {
const ob = document.getElementById('sortBySelect'); const ob = document.getElementById('sortBySelect');
if (ob) ob.onchange = filterBySchool; if (ob) ob.onchange = filterBySchool;
setupPaginationLinks();
}); });
} }

View File

@ -1,21 +1,27 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.707 // templ: version: v0.3.1020
package bootstrap package bootstrap
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ" import "github.com/a-h/templ"
import "context" import templruntime "github.com/a-h/templ/runtime"
import "io"
import "bytes"
func head(title string) templ.Component { func head(title string) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx) templ_7745c5c3_Var1 := templ.GetChildren(ctx)
@ -23,7 +29,7 @@ func head(title string) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent templ_7745c5c3_Var1 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<head><title>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<head><title>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -36,23 +42,28 @@ func head(title string) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN\" crossorigin=\"anonymous\"><link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css\"><script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL\" crossorigin=\"anonymous\">\n\t\t</script></head>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</title><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css\" rel=\"stylesheet\" integrity=\"sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN\" crossorigin=\"anonymous\"><link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css\"><script src=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js\" integrity=\"sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL\" crossorigin=\"anonymous\">\n\t\t</script></head>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
func headerNavbar(page PageKind) templ.Component { func headerNavbar(page PageKind) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var3 := templ.GetChildren(ctx) templ_7745c5c3_Var3 := templ.GetChildren(ctx)
@ -60,7 +71,7 @@ func headerNavbar(page PageKind) templ.Component {
templ_7745c5c3_Var3 = templ.NopComponent templ_7745c5c3_Var3 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<header><nav class=\"navbar navbar-expand-lg bg-body-tertiary w-auto\"><div class=\"container-fluid\"><a class=\"navbar-brand\" href=\"/htmlexamples/index.html\">Kurious</a> <button class=\"navbar-toggler\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#navbarSupportedContent\" aria-controls=\"navbarSupportedContent\" aria-expanded=\"false\" aria-label=\"Toggle navigation\"><span class=\"navbar-toggler-icon\"></span></button><div class=\"collapse navbar-collapse\" id=\"navbarSupportedContent\"><ul class=\"navbar-nav me-auto mb-2 mb-lg-0\"><li class=\"nav-item\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<header><nav class=\"navbar navbar-expand-lg bg-body-tertiary w-auto\"><div class=\"container-fluid\"><a class=\"navbar-brand\" href=\"/htmlexamples/index.html\">Kurious</a> <button class=\"navbar-toggler\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#navbarSupportedContent\" aria-controls=\"navbarSupportedContent\" aria-expanded=\"false\" aria-label=\"Toggle navigation\"><span class=\"navbar-toggler-icon\"></span></button><div class=\"collapse navbar-collapse\" id=\"navbarSupportedContent\"><ul class=\"navbar-nav me-auto mb-2 mb-lg-0\"><li class=\"nav-item\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -69,20 +80,20 @@ func headerNavbar(page PageKind) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<a class=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<a class=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var5 string var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var4).String()) templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.ResolveAttributeValue(templ.CSSClasses(templ_7745c5c3_Var4).String())
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/core.templ`, Line: 1, Col: 0} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/core.templ`, Line: 1, Col: 0}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var5)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" aria-current=\"page\" href=\"/\">Home</a></li><li class=\"nav-item\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "\" aria-current=\"page\" href=\"/\">Home</a></li><li class=\"nav-item\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -91,20 +102,20 @@ func headerNavbar(page PageKind) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<a class=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "<a class=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var7 string var templ_7745c5c3_Var7 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var6).String()) templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.ResolveAttributeValue(templ.CSSClasses(templ_7745c5c3_Var6).String())
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/core.templ`, Line: 1, Col: 0} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/core.templ`, Line: 1, Col: 0}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var7)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" aria-current=\"page\" href=\"/courses\">Courses</a></li><li class=\"nav-item\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "\" aria-current=\"page\" href=\"/courses\">Courses</a></li><li class=\"nav-item\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -113,36 +124,41 @@ func headerNavbar(page PageKind) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<a class=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<a class=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var9 string var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var8).String()) templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.ResolveAttributeValue(templ.CSSClasses(templ_7745c5c3_Var8).String())
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/core.templ`, Line: 1, Col: 0} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/core.templ`, Line: 1, Col: 0}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" href=\"/about\">About us</a></li></ul></div></div></nav></header>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" href=\"/about\">About us</a></li></ul></div></div></nav></header>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
func footer() templ.Component { func footer() templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var10 := templ.GetChildren(ctx) templ_7745c5c3_Var10 := templ.GetChildren(ctx)
@ -150,21 +166,18 @@ func footer() templ.Component {
templ_7745c5c3_Var10 = templ.NopComponent templ_7745c5c3_Var10 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<footer class=\"text-center text-lg-start bg-body-tertiary text-muted\"><section class=\"p-2\"><div class=\"container text-center text-md-start mt-5\"><div class=\"row mt-3\"><div class=\"col-md-3 col-lg-4 col-xl-3 mx-auto mb-4\"><h6 class=\"text-uppercase fw-bold mb-4\"><i class=\"fas fa-gem me-3\"></i>Courses</h6><p>Welcome to Courses, your gateway to learning! Explore a diverse range of courses and advance your skills with us. Join our community and transform your life through education.</p></div><div class=\"col-md-3 col-lg-2 col-xl-2 mx-auto mb-4\"><h6 class=\"text-uppercase fw-bold mb-4\">Useful links</h6><p><a href=\"#!\" class=\"text-reset\">Pricing</a></p><p><a href=\"#!\" class=\"text-reset\">Settings</a></p><p><a href=\"#!\" class=\"text-reset\">Orders</a></p><p><a href=\"#!\" class=\"text-reset\">Help</a></p></div><div class=\"col-md-4 col-lg-3 col-xl-3 mx-auto mb-md-0 mb-4\"><h6 class=\"text-uppercase fw-bold mb-4\">Contact</h6><p><i class=\"fas fa-home me-3\"></i> New York, NY 10012, US</p><p><i class=\"fas fa-envelope me-3\"></i> info@example.com</p><p><i class=\"fas fa-phone me-3\"></i> + 01 234 567 88</p><p><i class=\"fas fa-print me-3\"></i> + 01 234 567 89</p></div></div></div></section><div class=\"text-center p-4\" style=\"background-color: rgba(0, 0, 0, 0.05)\">© 2024 Copyright: <a class=\"text-reset fw-bold\" href=\"https://mdbootstrap.com/\">kursov.net</a></div></footer>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "<footer class=\"text-center text-lg-start bg-body-tertiary text-muted\"><section class=\"p-2\"><div class=\"container text-center text-md-start mt-5\"><div class=\"row mt-3\"><div class=\"col-md-3 col-lg-4 col-xl-3 mx-auto mb-4\"><h6 class=\"text-uppercase fw-bold mb-4\"><i class=\"fas fa-gem me-3\"></i>Courses</h6><p>Welcome to Courses, your gateway to learning! Explore a diverse range of courses and advance your skills with us. Join our community and transform your life through education.</p></div><div class=\"col-md-3 col-lg-2 col-xl-2 mx-auto mb-4\"><h6 class=\"text-uppercase fw-bold mb-4\">Useful links</h6><p><a href=\"#!\" class=\"text-reset\">Pricing</a></p><p><a href=\"#!\" class=\"text-reset\">Settings</a></p><p><a href=\"#!\" class=\"text-reset\">Orders</a></p><p><a href=\"#!\" class=\"text-reset\">Help</a></p></div><div class=\"col-md-4 col-lg-3 col-xl-3 mx-auto mb-md-0 mb-4\"><h6 class=\"text-uppercase fw-bold mb-4\">Contact</h6><p><i class=\"fas fa-home me-3\"></i> New York, NY 10012, US</p><p><i class=\"fas fa-envelope me-3\"></i> info@example.com</p><p><i class=\"fas fa-phone me-3\"></i> + 01 234 567 88</p><p><i class=\"fas fa-print me-3\"></i> + 01 234 567 89</p></div></div></div></section><div class=\"text-center p-4\" style=\"background-color: rgba(0, 0, 0, 0.05)\">© 2024 Copyright: <a class=\"text-reset fw-bold\" href=\"https://mdbootstrap.com/\">kursov.net</a></div></footer>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
func elementScriptsLoad() templ.ComponentScript { func elementScriptsLoad() templ.ComponentScript {
return templ.ComponentScript{ return templ.ComponentScript{
Name: `__templ_elementScriptsLoad_bfb1`, Name: `__templ_elementScriptsLoad_1bc4`,
Function: `function __templ_elementScriptsLoad_bfb1(){const loadInputValues = () => { Function: `function __templ_elementScriptsLoad_1bc4(){const loadInputValues = () => {
const lt = document.getElementById('learning-type-filter'); const lt = document.getElementById('learning-type-filter');
const ct = document.getElementById('course-thematic-filter'); const ct = document.getElementById('course-thematic-filter');
@ -200,6 +213,44 @@ func elementScriptsLoad() templ.ComponentScript {
} }
}; };
const buildFilterParams = () => {
const params = [];
const school_selector = document.getElementById('schoolSelect');
if (school_selector && school_selector.value) {
params.push('school_id=' + school_selector.value);
}
const order_by = document.getElementById('sortBySelect');
if (order_by && order_by.value) {
params.push('order_by=' + order_by.value);
}
const ascending = document.getElementById('sortByOrder');
if (ascending && ascending.checked) {
params.push('asc=true');
}
return params.join('&');
};
const setupPaginationLinks = () => {
document.querySelectorAll('a.page-link').forEach(link => {
link.addEventListener('click', (e) => {
const nav = link.closest('nav[data-paginated]');
if (!nav) return;
e.preventDefault();
const baseUrl = nav.getAttribute('data-base-url');
const href = link.getAttribute('href');
const pageMatch = href.match(/[?&]page=(\d+)/);
if (!pageMatch) return;
const page = pageMatch[1];
const filterParams = buildFilterParams();
let url = baseUrl + '?page=' + page;
if (filterParams) {
url += '&' + filterParams;
}
window.location.assign(url);
});
});
};
const formFilterOnSubmit = event => { const formFilterOnSubmit = event => {
event.preventDefault(); event.preventDefault();
@ -222,7 +273,6 @@ func elementScriptsLoad() templ.ComponentScript {
const order_by = document.getElementById('sortBySelect'); const order_by = document.getElementById('sortBySelect');
const order_by_value = (order_by !== null && order_by.value !== '') ? order_by.value : ''; const order_by_value = (order_by !== null && order_by.value !== '') ? order_by.value : '';
const ascending = document.getElementById('sortByOrder'); const ascending = document.getElementById('sortByOrder');
const baseUrl = ` + "`" + `${window.location.pathname}?` + "`" + `; const baseUrl = ` + "`" + `${window.location.pathname}?` + "`" + `;
params = []; params = [];
@ -259,19 +309,29 @@ func elementScriptsLoad() templ.ComponentScript {
const ob = document.getElementById('sortBySelect'); const ob = document.getElementById('sortBySelect');
if (ob) ob.onchange = filterBySchool; if (ob) ob.onchange = filterBySchool;
setupPaginationLinks();
}); });
}`, }`,
Call: templ.SafeScript(`__templ_elementScriptsLoad_bfb1`), Call: templ.SafeScript(`__templ_elementScriptsLoad_1bc4`),
CallInline: templ.SafeScriptInline(`__templ_elementScriptsLoad_bfb1`), CallInline: templ.SafeScriptInline(`__templ_elementScriptsLoad_1bc4`),
} }
} }
func root(page PageKind, _ stats) templ.Component { func root(page PageKind, _ stats) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var11 := templ.GetChildren(ctx) templ_7745c5c3_Var11 := templ.GetChildren(ctx)
@ -279,7 +339,7 @@ func root(page PageKind, _ stats) templ.Component {
templ_7745c5c3_Var11 = templ.NopComponent templ_7745c5c3_Var11 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html lang=\"ru\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "<!doctype html><html lang=\"ru\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -287,7 +347,7 @@ func root(page PageKind, _ stats) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<body>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<body>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -295,7 +355,7 @@ func root(page PageKind, _ stats) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"container\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "<div class=\"container\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -303,7 +363,7 @@ func root(page PageKind, _ stats) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -311,7 +371,7 @@ func root(page PageKind, _ stats) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</body>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "</body>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -319,13 +379,12 @@ func root(page PageKind, _ stats) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</html>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "</html>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
var _ = templruntime.GeneratedTemplate

View File

@ -1,21 +1,27 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.707 // templ: version: v0.3.1020
package bootstrap package bootstrap
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ" import "github.com/a-h/templ"
import "context" import templruntime "github.com/a-h/templ/runtime"
import "io"
import "bytes"
func listCoursesByCourseThematic(params ListCoursesParams) templ.Component { func listCoursesByCourseThematic(params ListCoursesParams) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx) templ_7745c5c3_Var1 := templ.GetChildren(ctx)
@ -23,7 +29,7 @@ func listCoursesByCourseThematic(params ListCoursesParams) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent templ_7745c5c3_Var1 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"container\"><h2>Здесь вы можете найти интересующие вас курсы по теме ") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"container\"><h2>Здесь вы можете найти интересующие вас курсы по теме ")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -36,21 +42,25 @@ func listCoursesByCourseThematic(params ListCoursesParams) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(":</h2><ul class=\"list-group\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, ":</h2><ul class=\"list-group\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for _, courseThematic := range params.FilterForm.AvailableCourseThematics { for _, courseThematic := range params.FilterForm.AvailableCourseThematics {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li class=\"list-group-item\"><a href=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "<li class=\"list-group-item\"><a href=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var3 templ.SafeURL = templ.SafeURL("/courses/" + params.FilterForm.ActiveLearningType.ID + "/" + courseThematic.ID) var templ_7745c5c3_Var3 templ.SafeURL
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var3))) templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL("/courses/" + params.FilterForm.ActiveLearningType.ID + "/" + courseThematic.ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/list_course_thematics.templ`, Line: 12, Col: 107}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -63,28 +73,33 @@ func listCoursesByCourseThematic(params ListCoursesParams) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></li>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "</a></li>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</ul></div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</ul></div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
func ListCourseThematics(pageType PageKind, s stats, params ListCoursesParams) templ.Component { func ListCourseThematics(pageType PageKind, s stats, params ListCoursesParams) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var5 := templ.GetChildren(ctx) templ_7745c5c3_Var5 := templ.GetChildren(ctx)
@ -92,17 +107,23 @@ func ListCourseThematics(pageType PageKind, s stats, params ListCoursesParams) t
templ_7745c5c3_Var5 = templ.NopComponent templ_7745c5c3_Var5 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var6 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Var6 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = listCoursesSectionHeader(params.FilterForm.BreadcrumbsParams).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = listCoursesSectionHeader(params.FilterForm.BreadcrumbsParams).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " ")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -110,7 +131,7 @@ func ListCourseThematics(pageType PageKind, s stats, params ListCoursesParams) t
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " ")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -118,18 +139,14 @@ func ListCourseThematics(pageType PageKind, s stats, params ListCoursesParams) t
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer)
}
return templ_7745c5c3_Err
}) })
templ_7745c5c3_Err = root(pageType, s).Render(templ.WithChildren(ctx, templ_7745c5c3_Var6), templ_7745c5c3_Buffer) templ_7745c5c3_Err = root(pageType, s).Render(templ.WithChildren(ctx, templ_7745c5c3_Var6), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
var _ = templruntime.GeneratedTemplate

File diff suppressed because it is too large Load Diff

View File

@ -54,27 +54,36 @@ templ courseCategory(items []IndexCourseCategoryItem) {
} }
type Pagination struct { type Pagination struct {
Page int Page int
TotalPages int TotalPages int
BaseURL string BaseURL string
QueryParams string
}
func (p Pagination) pageURL(page int) string {
url := p.BaseURL + "?page=" + strconv.Itoa(page)
if p.QueryParams != "" {
url += "&" + p.QueryParams
}
return url
} }
templ pagination(p Pagination) { templ pagination(p Pagination) {
if p.Page > 0 && p.TotalPages > 0 { if p.Page > 0 && p.TotalPages > 0 {
<nav aria-label="Page navigation"> <nav aria-label="Page navigation" data-paginated="true" data-base-url={ p.BaseURL } data-current-page={ strconv.Itoa(p.Page) }>
<ul class="pagination justify-content-center"> <ul class="pagination justify-content-center">
<li class={ "page-item" , templ.KV("disabled", p.Page==1), }> <li class={ "page-item" , templ.KV("disabled", p.Page==1), }>
<a href={ templ.URL(p.BaseURL + "?page=" + strconv.Itoa(p.Page-1)) } class="page-link">Previous</a> <a href={ templ.URL(p.pageURL(p.Page-1)) } class="page-link">Previous</a>
</li> </li>
for i := max(p.Page-2, 1); i < min(p.TotalPages, 10); i++ { for i := max(p.Page-2, 1); i < min(p.TotalPages, 10); i++ {
<li <li
class={ "page-item" , templ.KV("active", p.Page==i), } class={ "page-item" , templ.KV("active", p.Page==i), }
> >
<a href={ templ.URL(p.BaseURL + "?page=" + strconv.Itoa(i)) } class="page-link">{ strconv.Itoa(i) }</a> <a href={ templ.URL(p.pageURL(i)) } class="page-link">{ strconv.Itoa(i) }</a>
</li> </li>
} }
<li class={ "page-item" , templ.KV("disabled", p.Page==p.TotalPages), }> <li class={ "page-item" , templ.KV("disabled", p.Page==p.TotalPages), }>
<a href={ templ.URL(p.BaseURL + "?page=" + strconv.Itoa(p.Page+1)) } class="page-link">Next</a> <a href={ templ.URL(p.pageURL(p.Page+1)) } class="page-link">Next</a>
</li> </li>
</ul> </ul>
</nav> </nav>

View File

@ -1,14 +1,12 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.707 // templ: version: v0.3.1020
package bootstrap package bootstrap
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ" import "github.com/a-h/templ"
import "context" import templruntime "github.com/a-h/templ/runtime"
import "io"
import "bytes"
import "strconv" import "strconv"
@ -24,11 +22,19 @@ type IndexCourseCategoryItem struct {
// that holds multiple learning types. It expected to have a basic description // that holds multiple learning types. It expected to have a basic description
// and an amount of items. // and an amount of items.
func courseItemCard(item IndexCourseCategoryItem) templ.Component { func courseItemCard(item IndexCourseCategoryItem) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx) templ_7745c5c3_Var1 := templ.GetChildren(ctx)
@ -36,7 +42,7 @@ func courseItemCard(item IndexCourseCategoryItem) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent templ_7745c5c3_Var1 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"card\"><div class=\"card-body\"><h5 class=\"card-title\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<div class=\"card\"><div class=\"card-body\"><h5 class=\"card-title\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -49,7 +55,7 @@ func courseItemCard(item IndexCourseCategoryItem) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h5><hr><p>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, "</h5><hr><p>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -62,17 +68,17 @@ func courseItemCard(item IndexCourseCategoryItem) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "</p>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if len(item.ExampleThemes) > 0 { if len(item.ExampleThemes) > 0 {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p>В данной категории вы можете найти курсы по темам:</p><ul>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<p>В данной категории вы можете найти курсы по темам:</p><ul>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for _, exampleItem := range item.ExampleThemes { for _, exampleItem := range item.ExampleThemes {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li><span class=\"d-inline-block text-truncate col-8\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, "<li><span class=\"d-inline-block text-truncate col-8\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -85,26 +91,30 @@ func courseItemCard(item IndexCourseCategoryItem) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</span></li>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, "</span></li>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</ul>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, "</ul>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"d-flex justify-content-between align-items-center\"><a href=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, "<div class=\"d-flex justify-content-between align-items-center\"><a href=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var5 templ.SafeURL = templ.URL("/courses/" + item.ID) var templ_7745c5c3_Var5 templ.SafeURL
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var5))) templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinURLErrs(templ.URL("/courses/" + item.ID))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 33, Col: 46}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"btn btn-sm btn-outline-primary col-6\">Open</a> <small class=\"text-body-secondary\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, "\" class=\"btn btn-sm btn-outline-primary col-6\">Open</a> <small class=\"text-body-secondary\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -117,23 +127,28 @@ func courseItemCard(item IndexCourseCategoryItem) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" items.</small></div></div></div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, " items.</small></div></div></div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
func courseCategory(items []IndexCourseCategoryItem) templ.Component { func courseCategory(items []IndexCourseCategoryItem) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var7 := templ.GetChildren(ctx) templ_7745c5c3_Var7 := templ.GetChildren(ctx)
@ -141,12 +156,12 @@ func courseCategory(items []IndexCourseCategoryItem) templ.Component {
templ_7745c5c3_Var7 = templ.NopComponent templ_7745c5c3_Var7 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"container w-75 mb-4\"><div class=\"row g-4\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, "<div class=\"container w-75 mb-4\"><div class=\"row g-4\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for _, item := range items { for _, item := range items {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"col-12 col-md-8 col-lg-4\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "<div class=\"col-12 col-md-8 col-lg-4\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -154,34 +169,48 @@ func courseCategory(items []IndexCourseCategoryItem) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 13, "</div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div></div>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 14, "</div></div>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
type Pagination struct { type Pagination struct {
Page int Page int
TotalPages int TotalPages int
BaseURL string BaseURL string
QueryParams string
}
func (p Pagination) pageURL(page int) string {
url := p.BaseURL + "?page=" + strconv.Itoa(page)
if p.QueryParams != "" {
url += "&" + p.QueryParams
}
return url
} }
func pagination(p Pagination) templ.Component { func pagination(p Pagination) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var8 := templ.GetChildren(ctx) templ_7745c5c3_Var8 := templ.GetChildren(ctx)
@ -190,123 +219,158 @@ func pagination(p Pagination) templ.Component {
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
if p.Page > 0 && p.TotalPages > 0 { if p.Page > 0 && p.TotalPages > 0 {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<nav aria-label=\"Page navigation\"><ul class=\"pagination justify-content-center\">") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 15, "<nav aria-label=\"Page navigation\" data-paginated=\"true\" data-base-url=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var9 = []any{"page-item", templ.KV("disabled", p.Page == 1)} var templ_7745c5c3_Var9 string
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var9...) templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.ResolveAttributeValue(p.BaseURL)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 73, Col: 83}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var9)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li class=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 16, "\" data-current-page=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var10 string var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var9).String()) templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.ResolveAttributeValue(strconv.Itoa(p.Page))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 73, Col: 126}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var10)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 17, "\"><ul class=\"pagination justify-content-center\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var11 = []any{"page-item", templ.KV("disabled", p.Page == 1)}
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var11...)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 18, "<li class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var12 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.ResolveAttributeValue(templ.CSSClasses(templ_7745c5c3_Var11).String())
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 1, Col: 0} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 1, Col: 0}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var12)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><a href=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 19, "\"><a href=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var11 templ.SafeURL = templ.URL(p.BaseURL + "?page=" + strconv.Itoa(p.Page-1)) var templ_7745c5c3_Var13 templ.SafeURL
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var11))) templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinURLErrs(templ.URL(p.pageURL(p.Page - 1)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 76, Col: 45}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"page-link\">Previous</a></li>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 20, "\" class=\"page-link\">Previous</a></li>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
for i := max(p.Page-2, 1); i < min(p.TotalPages, 10); i++ { for i := max(p.Page-2, 1); i < min(p.TotalPages, 10); i++ {
var templ_7745c5c3_Var12 = []any{"page-item", templ.KV("active", p.Page == i)} var templ_7745c5c3_Var14 = []any{"page-item", templ.KV("active", p.Page == i)}
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var12...) templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var14...)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li class=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 21, "<li class=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var13 string
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var12).String())
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 1, Col: 0}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><a href=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var14 templ.SafeURL = templ.URL(p.BaseURL + "?page=" + strconv.Itoa(i))
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var14)))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"page-link\">")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var15 string var templ_7745c5c3_Var15 string
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(i)) templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.ResolveAttributeValue(templ.CSSClasses(templ_7745c5c3_Var14).String())
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 73, Col: 103} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 1, Col: 0}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></li>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 22, "\"><a href=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var16 templ.SafeURL
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinURLErrs(templ.URL(p.pageURL(i)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 82, Col: 39}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 23, "\" class=\"page-link\">")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var17 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(i))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 82, Col: 77}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 24, "</a></li>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
var templ_7745c5c3_Var16 = []any{"page-item", templ.KV("disabled", p.Page == p.TotalPages)} var templ_7745c5c3_Var18 = []any{"page-item", templ.KV("disabled", p.Page == p.TotalPages)}
templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var16...) templ_7745c5c3_Err = templ.RenderCSSItems(ctx, templ_7745c5c3_Buffer, templ_7745c5c3_Var18...)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<li class=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 25, "<li class=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var17 string var templ_7745c5c3_Var19 string
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(templ.CSSClasses(templ_7745c5c3_Var16).String()) templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.ResolveAttributeValue(templ.CSSClasses(templ_7745c5c3_Var18).String())
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 1, Col: 0} return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 1, Col: 0}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var19)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><a href=\"") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 26, "\"><a href=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var18 templ.SafeURL = templ.URL(p.BaseURL + "?page=" + strconv.Itoa(p.Page+1)) var templ_7745c5c3_Var20 templ.SafeURL
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var18))) templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinURLErrs(templ.URL(p.pageURL(p.Page + 1)))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `internal/kurious/ports/http/bootstrap/main.templ`, Line: 86, Col: 45}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"page-link\">Next</a></li></ul></nav>") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 27, "\" class=\"page-link\">Next</a></li></ul></nav>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
@ -317,29 +381,43 @@ type MainPageParams struct {
} }
func MainPage(pageType PageKind, s stats, params MainPageParams) templ.Component { func MainPage(pageType PageKind, s stats, params MainPageParams) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
return templ_7745c5c3_CtxErr
}
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var19 := templ.GetChildren(ctx) templ_7745c5c3_Var21 := templ.GetChildren(ctx)
if templ_7745c5c3_Var19 == nil { if templ_7745c5c3_Var21 == nil {
templ_7745c5c3_Var19 = templ.NopComponent templ_7745c5c3_Var21 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Var20 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { templ_7745c5c3_Var22 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = listCoursesSectionHeader(params.Breadcrumbs).Render(ctx, templ_7745c5c3_Buffer) templ_7745c5c3_Err = listCoursesSectionHeader(params.Breadcrumbs).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, " ")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -347,7 +425,7 @@ func MainPage(pageType PageKind, s stats, params MainPageParams) templ.Component
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ") templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, " ")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -355,18 +433,14 @@ func MainPage(pageType PageKind, s stats, params MainPageParams) templ.Component
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer)
}
return templ_7745c5c3_Err
}) })
templ_7745c5c3_Err = root(pageType, s).Render(templ.WithChildren(ctx, templ_7745c5c3_Var20), templ_7745c5c3_Buffer) templ_7745c5c3_Err = root(pageType, s).Render(templ.WithChildren(ctx, templ_7745c5c3_Var22), templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer { return nil
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
}) })
} }
var _ = templruntime.GeneratedTemplate

View File

@ -6,6 +6,7 @@ import (
"log/slog" "log/slog"
"net/http" "net/http"
"slices" "slices"
"strings"
"sync" "sync"
"git.loyso.art/frx/kurious/internal/common/xslices" "git.loyso.art/frx/kurious/internal/common/xslices"
@ -222,6 +223,8 @@ func (c courseTemplServer) List(w http.ResponseWriter, r *http.Request) {
currentPage = totalPages currentPage = totalPages
} }
queryParams := buildListCoursesQueryParams(pathParams)
params = bootstrap.ListCoursesParams{ params = bootstrap.ListCoursesParams{
FilterForm: bootstrap.FilterFormParams{ FilterForm: bootstrap.FilterFormParams{
Render: true, Render: true,
@ -242,10 +245,11 @@ func (c courseTemplServer) List(w http.ResponseWriter, r *http.Request) {
Courses: params.Courses, Courses: params.Courses,
Categories: params.Categories, Categories: params.Categories,
Pagination: bootstrap.Pagination{ Pagination: bootstrap.Pagination{
Page: currentPage, Page: currentPage,
TotalPages: totalPages, TotalPages: totalPages,
BaseURL: r.URL.Path, BaseURL: r.URL.Path,
}, QueryParams: queryParams,
},
} }
c.log.DebugContext( c.log.DebugContext(
@ -416,3 +420,20 @@ func newOrderableContainer(units ...orderableUnit) *orderableContainer {
fieldByID: fieldByID, fieldByID: fieldByID,
} }
} }
func buildListCoursesQueryParams(p listCoursesParams) string {
var parts []string
if p.School != "" {
parts = append(parts, "school_id="+p.School)
}
if p.OrderBy != "" && p.OrderBy != "pr" {
parts = append(parts, "order_by="+p.OrderBy)
}
if p.Ascending {
parts = append(parts, "asc=true")
}
if p.PerPage > 0 && p.PerPage != 20 {
parts = append(parts, fmt.Sprintf("per_page=%d", p.PerPage))
}
return strings.Join(parts, "&")
}

View File

@ -55,7 +55,14 @@ func NewApplication(ctx context.Context, cfg ApplicationConfig, mapper domain.Co
organizationrepo = sqliteConnection.Organization() organizationrepo = sqliteConnection.Organization()
repoCloser = sqliteConnection repoCloser = sqliteConnection
case RepositoryEngineYDB: case RepositoryEngineYDB:
return Application{}, errors.New("ydb is no longer supported") ydbConn, err := adapters.NewYDBConnection(ctx, cfg.YDB, log.With(slog.String("db", "ydb")))
if err != nil {
return Application{}, fmt.Errorf("making ydb connection: %w", err)
}
courseadapter = ydbConn.CourseRepository()
organizationrepo = ydbConn.Organization()
repoCloser = ydbConn
default: default:
return Application{}, errors.New("unable to decide which db engine to use") return Application{}, errors.New("unable to decide which db engine to use")
} }