news

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ID       int       `json:"id"`
	Title    string    `json:"title"`
	Content  string    `json:"content"`
	Date     time.Time `json:"date"`
	ImageURL string    `json:"imageUrl,omitempty"`
}

Article is a news article as the API returns it.

type CreateInput

type CreateInput struct {
	Title   string
	Content string
}

CreateInput is a new article. Content is HTML from the editor and is sanitised.

type Handlers

type Handlers struct {
	// contains filtered or unexported fields
}

Handlers serves /news.

func NewHandlers

func NewHandlers(svc *Service) *Handlers

func (*Handlers) Register

func (h *Handlers) Register(g *echo.Group, guards web.Guards)

Register mounts the news routes on the /api/v1 group.

type News

type News struct {
	ID       int         `db:"id" json:"id"`
	Title    string      `db:"title" json:"title"`
	FileName null.String `db:"file_name" json:"file_name"`
	Content  null.String `db:"content" json:"content"`
	Date     time.Time   `db:"date" json:"date"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the news business logic.

func NewService

func NewService(store store, files *upload.Files) *Service

func (*Service) Create

func (s *Service) Create(ctx context.Context, in CreateInput, image *upload.File) (Article, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, id int) (Article, error)

Delete removes the article and its image, returning what was deleted.

func (*Service) Get

func (s *Service) Get(ctx context.Context, id int) (Article, error)

func (*Service) Latest

func (s *Service) Latest(ctx context.Context) (Article, bool, error)

Latest returns the newest article; ok is false when there are none.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]Article, error)

func (*Service) Update

func (s *Service) Update(ctx context.Context, id int, in UpdateInput, image *upload.File) (Article, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store stores the dependencies

func NewNewsRepo

func NewNewsRepo(db *sqlx.DB) *Store

NewNewsRepo stores our dependency

func (*Store) AddNews

func (s *Store) AddNews(ctx context.Context, newsParam News) (News, error)

func (*Store) DeleteNews

func (s *Store) DeleteNews(ctx context.Context, newsParam News) error

func (*Store) EditNews

func (s *Store) EditNews(ctx context.Context, newsParam News) (News, error)

EditNews writes n as given. Callers load the row first and change only the fields they mean to, so empty values are deliberate (e.g. removing an image).

func (*Store) GetNews

func (s *Store) GetNews(ctx context.Context) ([]News, error)

func (*Store) GetNewsArticle

func (s *Store) GetNewsArticle(ctx context.Context, newsParam News) (News, error)

func (*Store) GetNewsLatest

func (s *Store) GetNewsLatest(ctx context.Context) (News, error)

type UpdateInput

type UpdateInput struct {
	Title       *string
	Content     *string
	RemoveImage bool
}

UpdateInput changes an article. Nil fields are left unchanged; an empty Content clears it. RemoveImage is ignored when a new image is uploaded.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL