posts

package
v0.0.0-...-8699099 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PostsRoutes

func PostsRoutes(r chi.Router, dbPool *pgxpool.Pool)

PostsRoutes defines the routes for the posts store.

Types

type Post

type Post struct {
	ID        int64              `json:"id"`         // ID is the unique identifier for the post.
	Content   string             `json:"content"`    // Content holds the main body of the post.
	Title     string             `json:"title"`      // Title is the headline or title of the post.
	UserID    int64              `json:"user_id"`    // UserID links the post to the user who created it.
	Tags      []string           `json:"tags"`       // Tags are a list of keywords associated with the post.
	Comments  []comments.Comment `json:"comments"`   // Comments holds the list of comments associated with the post.
	CreatedAt time.Time          `json:"created_at"` // CreatedAt is the timestamp when the post was created.
	UpdatedAt time.Time          `json:"updated_at"` // UpdatedAt is the timestamp when the post was last updated.
}

Post represents a blog post with associated metadata.

type PostsHandler

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

PostsHandler is a struct that holds a reference to the PostsStore.

func NewPostsHandler

func NewPostsHandler(s PostsStore) *PostsHandler

NewPostsHandler creates and returns a new instance of PostsHandler.

func (*PostsHandler) CreatePost

func (h *PostsHandler) CreatePost(w http.ResponseWriter, r *http.Request)

CreatePost handles the post creation by calling the corresponding method.

func (*PostsHandler) GetPostByID

func (h *PostsHandler) GetPostByID(w http.ResponseWriter, r *http.Request)

GetPostByID retrieves a post by its ID and returns it as a JSON response.

type PostsStore

type PostsStore interface {
	// CreatePost handles the post creation.
	CreatePost(ctx context.Context, post *Post) error

	// GetPostByID retrieves a post by its ID.
	GetPostByID(ctx context.Context, postID int) (*Post, error)
}

PostsStore defines the contract for a posts store.

func NewPostsStore

func NewPostsStore(dbPool *pgxpool.Pool) PostsStore

NewPostsStore creates a new instance of postsStore, implementing the PostsStore interface.

Jump to

Keyboard shortcuts

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