posts

package
v0.45.36 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Posts routes and controllers logic package for the backend.

Index

Constants

View Source
const (
	LOGGER_WORKER_NAME = "postController"
)

Variables

This section is empty.

Functions

func NewPostRepository added in v0.44.22

func NewPostRepository(cache db.Cacher) models.PostRepositoryInterface

func NewPostRouter added in v0.45.32

func NewPostRouter(postController *PostController) chi.Router

func NewPostService added in v0.44.26

func NewPostService(
	postRepository models.PostRepositoryInterface,
	userRepository models.UserRepositoryInterface,
) models.PostServiceInterface

Types

type PostController added in v0.45.32

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

Structure contents definition for the controller.

func NewPostController added in v0.45.32

func NewPostController(
	postService models.PostServiceInterface,
) *PostController

NewPostController return a pointer to the new controller instance, that has to be populated with the Post service.

func (*PostController) Create added in v0.45.32

func (c *PostController) Create(w http.ResponseWriter, r *http.Request)

Create handles a new post creation request to the post service, which adds the post to the database.

@Summary		Add new post
@Description		This function call is to be used to create a new post.
@Tags			posts
@Accept			json
@Produce		json
@Param			request	body	posts.PostCreateRequest			true				"Post body."
@Success		201		{object}	common.APIResponse{data=posts.Create.responseData}	"New post has been added to the database and published."
@Failure		400		{object}	common.APIResponse{data=models.Stub}			"Invalid input data."
@Failure		401		{object}	common.APIResponse{data=models.Stub}			"User unauthorized."
@Failure		429		{object}	common.APIResponse{data=models.Stub}			"Too many requests, try again later."
@Failure		403		{object}	common.APIResponse{data=models.Stub}			"Forbidden action occurred."
@Failure		500		{object}	common.APIResponse{data=models.Stub}			"Internal server problem occurred while processing the request."
@Router			/posts [post]

func (*PostController) Delete added in v0.45.32

func (c *PostController) Delete(w http.ResponseWriter, r *http.Request)

Delete removes the specified post.

@Summary		Delete specified post
@Description		This function call ensures that the specified post is purged from the database. Associated items like figures are deleted as well.
@Tags			posts
@Produce		json
@Param			postID		path		string		true			"Post ID to delete."
@Success		200		{object}	common.APIResponse{data=models.Stub}	"Specified post has been deleted."
@Failure		400		{object}	common.APIResponse{data=models.Stub}	"Invalid data input."
@Failure		403		{object}	common.APIResponse{data=models.Stub}	"Forbidden action occurred (e.g. caller tried to delete a foreign post)."
@Failure		401		{object}	common.APIResponse{data=models.Stub}	"User unauthorized."
@Failure		429		{object}	common.APIResponse{data=models.Stub}	"Too many requests, try again later."
@Failure		500		{object}	common.APIResponse{data=models.Stub}	"Internal server problem occurred while processing the request."
@Router			/posts/{postID} [delete]

func (*PostController) GetAll added in v0.45.32

func (c *PostController) GetAll(w http.ResponseWriter, r *http.Request)

GetAll fetches a list of posts, a page number is specified by the X-Page-No header.

@Summary		Get posts
@Description		This function call retrieves a page of posts. The page number is to be specified using the `X-Page-No` header (default is 0 = latest).
@Tags			posts
@Produce		json
@Param			X-Page-No		header		integer	false		"A page number (default is 0)."
@Param			X-Hide-Replies		header		bool	false		"An optional boolean to show only root posts without any reply (default is false)."
@Success		200				{object}	common.APIResponse{data=posts.GetAll.responseData}	"Paginated list of posts."
@Failure		400				{object}	common.APIResponse{data=models.Stub}			"Invalid input data."
@Failure		401				{object}	common.APIResponse{data=models.Stub}			"User unauthorized."
@Failure		429				{object}	common.APIResponse{data=models.Stub}			"Too many requests, try again later."
@Failure		500				{object}	common.APIResponse
@Router			/posts [get]

func (*PostController) GetByHashtag added in v0.45.32

func (c *PostController) GetByHashtag(w http.ResponseWriter, r *http.Request)

GetByHashtag fetches all posts tagged with the specified hashtag.

@Summary		Get hashtagged post list
@Description		This function call fetches all posts tagged with specified hashtag phrase (`#phrase` => `phrase`).
@Tags			posts
@Produce		json
@Param			X-Hide-Replies		header		bool		false							"hide replies"
@Param			X-Page-No		header		integer		false							"page number"
@Param			hashtag			path		string		true							"hashtag string"
@Success		200			{object}	common.APIResponse{data=posts.GetByHashtag.responseData}		"Data fetched successfully."
@Failure		400			{object}	common.APIResponse{data=models.Stub}					"Invalid input data."
@Failure		401			{object}	common.APIResponse{data=models.Stub}					"User unauthorized."
@Failure		429			{object}	common.APIResponse{data=models.Stub}					"Too many requests, try again later."
@Failure		500			{object}	common.APIResponse{data=models.Stub}
@Router			/posts/hashtags/{hashtag} [get]

func (*PostController) GetByID added in v0.45.32

func (c *PostController) GetByID(w http.ResponseWriter, r *http.Request)

GetByID fetches specified post and its interaction.

@Summary		Get single post
@Description		This function call enables one to fetch a single post by its ID with all replies associated.
@Tags			posts
@Produce		json
@Param			X-Hide-Replies		header		bool		false						"Optional parameter to hide all replies (default is false)."
@Param			X-Page-No		header		integer		false						"Page number (default is 0)."
@Param			postID			path		string		true						"Post ID to fetch."
@Success		200			{object}	common.APIResponse{data=posts.GetByID.responseData}		"Data fetched successfully."
@Failure		400			{object}	common.APIResponse{data=models.Stub}				"Invalid input data."
@Failure		401			{object}	common.APIResponse{data=models.Stub}				"User unauthorized."
@Failure		429			{object}	common.APIResponse{data=models.Stub}				"Too many requests, try again later."
@Failure		500			{object}	common.APIResponse{data=models.Stub}				"Internal server problem occurred while processing the request."
@Router			/posts/{postID} [get]

func (*PostController) UpdateReactions added in v0.45.32

func (c *PostController) UpdateReactions(w http.ResponseWriter, r *http.Request)

UpdateReactions increases the star count for the given post.

@Summary		Update post's star count
@Description		This function call is used to increase the post reactions counter value. It add one (1) reaction to the current state of a post.
@Tags			posts
@Produce		json
@Param			postID	path			string		true						"Post ID to update."
@Success		200		{object}	common.APIResponse{data=posts.UpdateReactions.responseData}	"Counter value has been increased successfully."
@Failure		400		{object}	common.APIResponse{data=models.Stub}				"Invalid data input."
@Failure		403		{object}	common.APIResponse{data=models.Stub}				"Forbidden action happened (e.g. caller tried to increase the counter value of a post of theirs)."
@Failure		401		{object}	common.APIResponse{data=models.Stub}				"User unauthorized."
@Failure		429		{object}	common.APIResponse{data=models.Stub}				"Too many requests, try again later."
@Failure		500		{object}	common.APIResponse{data=models.Stub}				"Internal server problem occurred while processing the request."
@Router			/posts/{postID}/star [patch]

type PostCreateRequest added in v0.45.32

type PostCreateRequest struct {
	Type       string `json:"type" example:"post" enums:"post,poll,img"`
	ReplyToID  string `json:"reply_to_id" example:"1234567890000"`
	Content    string `json:"content" example:"a very random post's content"`
	FigureName string `json:"figure_name" example:"example.jpg"`
	FigureData []byte `json:"figure_data" swaggertype:"string" format:"base64" example:"base64 encoded data"`
}

type PostRepository added in v0.44.22

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

The implementation of pkg/models.PostRepositoryInterface.

func (*PostRepository) Delete added in v0.44.22

func (r *PostRepository) Delete(postID string) error

func (*PostRepository) GetAll added in v0.44.22

func (r *PostRepository) GetAll() (*map[string]models.Post, error)

func (*PostRepository) GetByID added in v0.44.22

func (r *PostRepository) GetByID(postID string) (*models.Post, error)

func (*PostRepository) GetPage added in v0.44.24

func (r *PostRepository) GetPage(pageOpts interface{}) (*map[string]models.Post, *map[string]models.User, error)

func (*PostRepository) Save added in v0.44.22

func (r *PostRepository) Save(post *models.Post) error

type PostService added in v0.44.26

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

func (*PostService) Create added in v0.44.26

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

func (*PostService) Delete added in v0.44.26

func (s *PostService) Delete(ctx context.Context, postID string) error

func (*PostService) FindAll added in v0.44.26

func (s *PostService) FindAll(ctx context.Context) (*map[string]models.Post, *models.User, error)

func (*PostService) FindByID added in v0.44.26

func (s *PostService) FindByID(ctx context.Context, postID string) (*models.Post, *models.User, error)

func (*PostService) FindPage added in v0.44.37

func (s *PostService) FindPage(ctx context.Context, opts interface{}) (*map[string]models.Post, *map[string]models.User, error)

func (*PostService) Update added in v0.44.26

func (s *PostService) Update(ctx context.Context, post *models.Post) error

Jump to

Keyboard shortcuts

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