Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PostsRoutes ¶
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.
Click to show internal directories.
Click to hide internal directories.