posts

package
v0.0.0-...-ebd03d0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorForbidden     = Response{Code: http.StatusForbidden, Message: "Forbidden"}
	ErrorUnauthorized  = Response{Code: http.StatusUnauthorized, Message: "Unauthorized"}
	ErrorRequiredField = Response{Code: http.StatusBadRequest, Message: "Required field"}
	ErrorInternal      = Response{Code: http.StatusInternalServerError, Message: "Internal Server Error"}
	ErrorBadRequest    = Response{Code: http.StatusBadRequest, Message: "Bad Request"}
	ErrorNoRecords     = Response{Code: http.StatusOK, Message: "No records found"}
	ErrorNotFound      = Response{Code: http.StatusNotFound, Message: "No records found"}
)
View Source
var (
	SuccessCreateResponse        = Response{Code: 200, Message: "Post created successfully"}
	SuccessCreateCommentResponse = Response{Code: 200, Message: "Comment created successfully"}
	SuccessListResponse          = Response{Code: 200, Message: "Posts fetched successfully"}
)

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID        uint64
	UserID    string
	PostID    string
	Content   string
	CreatedAt time.Time
}

type CreatePostCommentPayload

type CreatePostCommentPayload struct {
	UserID  string
	PostID  string `json:"postId"`
	Comment string `json:"comment"`
}

func (CreatePostCommentPayload) Validate

func (p CreatePostCommentPayload) Validate() error

type CreatePostPayload

type CreatePostPayload struct {
	UserID     string
	PostInHTML string   `json:"postInHtml"`
	Tags       []string `json:"tags"`
}

func (CreatePostPayload) Validate

func (p CreatePostPayload) Validate() error

type Handler

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

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) CreatePost

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

func (*Handler) CreatePostComment

func (h *Handler) CreatePostComment(w http.ResponseWriter, r *http.Request)

func (*Handler) ListPost

func (h *Handler) ListPost(w http.ResponseWriter, r *http.Request)

type ListPostPayload

type ListPostPayload struct {
	UserID     string
	Search     string   `schema:"search" binding:"omitempty"`
	SearchTags []string `schema:"searchTag" binding:"omitempty"`
	Limit      int
	Offset     int
}

type ListPostResponse

type ListPostResponse struct {
	PostID   string                     `json:"postId"`
	Post     PostResponse               `json:"post"`
	Comments []comments.CommentResponse `json:"comments"`
	User     user.UserGetResponse       `json:"creator"`
}

type PostResponse

type PostResponse struct {
	ID        string    `json:"-"`
	Content   string    `json:"postInHtml"`
	Tags      []string  `json:"tags"`
	CreatedAt time.Time `json:"createdAt"`
}

type Posts

type Posts struct {
	ID        string
	UserID    string
	Content   string
	Tags      []string
	CreatedAt time.Time
}

type Repository

type Repository interface {
	Create(ctx context.Context, post *Posts) error
	GetByID(ctx context.Context, id string) (*Posts, error)
	CreateComment(ctx context.Context, comment *Comment) error
	List(ctx context.Context, filter ListPostPayload) ([]ListPostResponse, *response.Pagination, error)
}

func NewRepository

func NewRepository(db *db.DB) Repository

type Response

type Response struct {
	Code    int
	Message string
	Data    any
	Meta    *response.Pagination
	Error   string
}

type Service

type Service interface {
	Create(ctx context.Context, req CreatePostPayload) Response
	CreatePostComment(ctx context.Context, req CreatePostCommentPayload) Response
	List(ctx context.Context, req ListPostPayload) Response
}

func NewService

func NewService(repository Repository, userFriendsRepository userfriends.Repository) Service

Jump to

Keyboard shortcuts

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