55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package command
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"git.loyso.art/frx/kurious/internal/common/decorator"
|
|
"git.loyso.art/frx/kurious/internal/common/nullable"
|
|
"git.loyso.art/frx/kurious/internal/kurious/domain"
|
|
)
|
|
|
|
type CreateCourse struct {
|
|
ID string
|
|
Name string
|
|
Description string
|
|
ExternalID nullable.Value[string]
|
|
SourceType domain.SourceType
|
|
SourceName nullable.Value[string]
|
|
OrganizationID string
|
|
OriginLink string
|
|
ImageLink string
|
|
FullPrice float64
|
|
Discount float64
|
|
Duration time.Duration
|
|
StartsAt time.Time
|
|
}
|
|
|
|
type CreateCourseHandler decorator.CommandHandler[CreateCourse]
|
|
|
|
type createCourseHandler struct {
|
|
repo domain.CourseRepository
|
|
}
|
|
|
|
func NewCreateCourseHandler(
|
|
repo domain.CourseRepository,
|
|
log *slog.Logger,
|
|
) CreateCourseHandler {
|
|
h := createCourseHandler{
|
|
repo: repo,
|
|
}
|
|
|
|
return decorator.ApplyCommandDecorators(h, log)
|
|
}
|
|
|
|
func (h createCourseHandler) Handle(ctx context.Context, cmd CreateCourse) error {
|
|
_, err := h.repo.Create(ctx, domain.CreateCourseParams(cmd))
|
|
if err != nil {
|
|
return fmt.Errorf("creating course: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|