domain

package
v0.0.0-...-8f202a6 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Field names for validation messages
	TITLE_FIELD        = "title"
	CONTENT_FIELD      = "content"
	STATUS_FIELD       = "status"
	AUTHOR_ID_FIELD    = "author_id"
	CATEGORY_IDS_FIELD = "category_ids"
	PAGE_FIELD         = "page"
	LIMIT_FIELD        = "limit"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ID              uuid.UUID        `json:"id"`
	Title           string           `json:"title"`
	Slug            string           `json:"slug"`
	Content         string           `json:"content"`
	Excerpt         string           `json:"excerpt"`
	MainImage       string           `json:"main_image"`
	Status          string           `json:"status"` // published, draft, scheduled
	AuthorID        uuid.UUID        `json:"author_id"`
	VisitorCount    int              `json:"visitor_count"`
	Categories      []SimpleCategory `json:"categories"`
	PublishedAt     *time.Time       `json:"published_at"`
	CreatedAt       time.Time        `json:"created_at"`
	UpdatedAt       time.Time        `json:"updated_at"`
	MetaTitle       string           `json:"meta_title"`
	MetaDescription string           `json:"meta_description"`
	MetaKeywords    string           `json:"meta_keywords"`
	CanonicalURL    string           `json:"canonical_url"`
	FocusKeyphrase  string           `json:"focus_keyphrase"`
	OGTitle         string           `json:"og_title"`
	OGDescription   string           `json:"og_description"`
	OGImage         string           `json:"og_image"`
}

Article represents the article entity

type ArticleRepository

type ArticleRepository interface {
	GetByID(ctx context.Context, id uuid.UUID) (*Article, error)
	GetBySlug(ctx context.Context, slug string) (*Article, error)
	List(ctx context.Context, page, limit int, status string) ([]Article, int64, error)
	Create(ctx context.Context, article *Article) error
	Update(ctx context.Context, article *Article) error
	Delete(ctx context.Context, id uuid.UUID) error
	IncrementVisitorCount(ctx context.Context, id uuid.UUID) error
	GetCategories(ctx context.Context, articleID uuid.UUID) ([]Category, error)
	UpdateCategories(ctx context.Context, articleID uuid.UUID, categoryIDs []uuid.UUID) error
}

ArticleRepository defines the interface for article data operations

type ArticleResponse

type ArticleResponse struct {
	Data *Article `json:"data"`
}

ArticleResponse represents the response for a single article

type ArticleUsecase

type ArticleUsecase interface {
	GetByID(ctx context.Context, id uuid.UUID) (*Article, error)
	GetBySlug(ctx context.Context, slug string) (*Article, error)
	List(ctx context.Context, page, limit int, status string) ([]Article, int64, error)
	Create(ctx context.Context, req CreateArticleRequest) (*Article, error)
	Update(ctx context.Context, id uuid.UUID, userID uuid.UUID, req UpdateArticleRequest) (*Article, error)
	Delete(ctx context.Context, id uuid.UUID, userID uuid.UUID) error
	IncrementVisitorCount(ctx context.Context, id uuid.UUID) error
}

ArticleUsecase defines the interface for article business logic

type ArticlesResponse

type ArticlesResponse struct {
	Data []Article      `json:"data"`
	Meta PaginationMeta `json:"meta"`
}

ArticlesResponse represents the response for a list of articles

type Category

type Category struct {
	ID          uuid.UUID `json:"id"`
	Name        string    `json:"name"`
	Slug        string    `json:"slug"`
	Description string    `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Category represents the category entity

type CreateArticleRequest

type CreateArticleRequest struct {
	Title           string      `json:"title" validate:"required"`
	Content         string      `json:"content" validate:"required"`
	Excerpt         string      `json:"excerpt"`
	MainImage       string      `json:"main_image"`
	Status          string      `json:"status" validate:"required,oneof=published draft scheduled"`
	AuthorID        uuid.UUID   `json:"author_id" validate:"required"`
	CategoryIDs     []uuid.UUID `json:"category_ids" validate:"dive,required"`
	PublishedAt     *time.Time  `json:"published_at"`
	MetaTitle       string      `json:"meta_title"`
	MetaDescription string      `json:"meta_description"`
	MetaKeywords    string      `json:"meta_keywords"`
	CanonicalURL    string      `json:"canonical_url"`
	FocusKeyphrase  string      `json:"focus_keyphrase"`
	OGTitle         string      `json:"og_title"`
	OGDescription   string      `json:"og_description"`
	OGImage         string      `json:"og_image"`
}

CreateArticleRequest represents the request to create a new article

func (*CreateArticleRequest) Validate

func (r *CreateArticleRequest) Validate() []response.ErrorInfo

Validate validates CreateArticleRequest

type ListArticlesRequest

type ListArticlesRequest struct {
	Page       int        `query:"page" validate:"omitempty,min=1"`
	Limit      int        `query:"limit" validate:"omitempty,min=1,max=100"`
	Status     string     `query:"status" validate:"omitempty,oneof=published draft scheduled"`
	CategoryID *uuid.UUID `query:"category_id"`
}

ListArticlesRequest represents the request to list articles

func (*ListArticlesRequest) Validate

func (r *ListArticlesRequest) Validate() []response.ErrorInfo

Validate validates ListArticlesRequest

type PaginationMeta

type PaginationMeta struct {
	CurrentPage int   `json:"current_page"`
	TotalPages  int   `json:"total_pages"`
	TotalItems  int64 `json:"total_items"`
	PerPage     int   `json:"per_page"`
}

PaginationMeta represents pagination metadata

type SimpleCategory

type SimpleCategory struct {
	Name string `json:"name"`
	Slug string `json:"slug"`
}

SimpleCategory represents a simplified category structure

type UpdateArticleRequest

type UpdateArticleRequest struct {
	Title           string      `json:"title"`
	Content         string      `json:"content"`
	Excerpt         string      `json:"excerpt"`
	MainImage       string      `json:"main_image"`
	Status          string      `json:"status" validate:"omitempty,oneof=published draft scheduled"`
	AuthorID        uuid.UUID   `json:"author_id"`
	CategoryIDs     []uuid.UUID `json:"category_ids" validate:"omitempty,dive,required"`
	PublishedAt     *time.Time  `json:"published_at"`
	MetaTitle       string      `json:"meta_title"`
	MetaDescription string      `json:"meta_description"`
	MetaKeywords    string      `json:"meta_keywords"`
	CanonicalURL    string      `json:"canonical_url"`
	FocusKeyphrase  string      `json:"focus_keyphrase"`
	OGTitle         string      `json:"og_title"`
	OGDescription   string      `json:"og_description"`
	OGImage         string      `json:"og_image"`
}

UpdateArticleRequest represents the request to update an existing article

func (*UpdateArticleRequest) Validate

func (r *UpdateArticleRequest) Validate() []response.ErrorInfo

Validate validates UpdateArticleRequest

Jump to

Keyboard shortcuts

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