Help us shape the future of Go! Take the 2026 Go Developer Survey

services

package
v0.0.0-...-59a70be Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package services is the framework-agnostic API surface for the blog. All business logic lives here; HTTP handlers (and gRPC/GraphQL/cron jobs) just call these methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PostService

type PostService struct {
	Conn *database.Connection
}

func NewPostService

func NewPostService(conn *database.Connection) *PostService

func (*PostService) Comments

func (s *PostService) Comments(ctx context.Context, postID uint64) ([]models.Comment, error)

Comments for a post.

func (*PostService) Create

func (s *PostService) Create(ctx context.Context, p *models.Post) error

Create persists a new post.

func (*PostService) Delete

func (s *PostService) Delete(ctx context.Context, p *models.Post) error

Delete removes the post from the database.

func (*PostService) Get

func (s *PostService) Get(ctx context.Context, id uint64) (*models.Post, error)

Get loads one post by primary key.

func (*PostService) IncrementViews

func (s *PostService) IncrementViews(ctx context.Context, id uint64) error

IncrementViews atomically bumps the views counter. Demonstrates a raw builder UPDATE without round-tripping through the ORM Save path.

func (*PostService) ListWithAuthor

func (s *PostService) ListWithAuthor(ctx context.Context, limit int) ([]models.Post, map[uint64]*models.User, error)

ListWithAuthor returns posts ordered by recency. Each post is enriched with its author via eager-loading — a single extra query instead of N.

func (*PostService) Pin

func (s *PostService) Pin(ctx context.Context, p *models.Post) error

Pin / Unpin toggle the pinned flag.

func (*PostService) Unpin

func (s *PostService) Unpin(ctx context.Context, p *models.Post) error

Jump to

Keyboard shortcuts

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