blog

package
v0.0.0-...-823892c Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitSearchIndex

func InitSearchIndex(blogCollection *mongo.Collection) error

Types

type BlogController

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

func NewBlogController

func NewBlogController(service BlogServices) *BlogController

func (*BlogController) CreateBlogPost

func (controller *BlogController) CreateBlogPost(c *gin.Context)

func (*BlogController) DeleteBlogPost

func (controller *BlogController) DeleteBlogPost(c *gin.Context)

func (*BlogController) GetBlogPostByID

func (controller *BlogController) GetBlogPostByID(c *gin.Context)

func (*BlogController) GetBlogPostBySlug

func (controller *BlogController) GetBlogPostBySlug(c *gin.Context)

func (*BlogController) GetBlogPosts

func (controller *BlogController) GetBlogPosts(c *gin.Context)

func (*BlogController) GetComment

func (controller *BlogController) GetComment(c *gin.Context)

func (*BlogController) GetComments

func (controller *BlogController) GetComments(c *gin.Context)

func (*BlogController) LikeOrUnlikeComment

func (controller *BlogController) LikeOrUnlikeComment(c *gin.Context)

func (*BlogController) LikeOrUnlikePost

func (controller *BlogController) LikeOrUnlikePost(c *gin.Context)

func (*BlogController) PostComment

func (controller *BlogController) PostComment(c *gin.Context)

func (*BlogController) Search

func (controller *BlogController) Search(c *gin.Context)

func (*BlogController) UpdateBlogPost

func (controller *BlogController) UpdateBlogPost(c *gin.Context)

func (*BlogController) UpdateComment

func (controller *BlogController) UpdateComment(c *gin.Context)

type BlogPost

type BlogPost struct {
	Id          primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	Title       string             `json:"title,omitempty" bson:"title,omitempty"`
	Slug        string             `json:"slug,omitempty" bson:"slug,omitempty"`
	Description string             `json:"description,omitempty" bson:"description,omitempty"`
	Content     string             `json:"content,omitempty" bson:"content,omitempty"`
	Likes       []Like             `json:"likes,omitempty" bson:"likes,omitempty"`
	CreatedAt   time.Time          `json:"created_at,omitempty" bson:"created_at,omitempty"`
	UpdatedAt   time.Time          `json:"updated_at,omitempty" bson:"updated_at,omitempty"`
}

type BlogRepo

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

func NewBlogRepo

func NewBlogRepo(blogCollection, commentCollection *mongo.Collection) *BlogRepo

func (*BlogRepo) CreateBlogPost

func (repo *BlogRepo) CreateBlogPost(blogPost *BlogPost) (*mongo.InsertOneResult, error)

func (*BlogRepo) DeleteBlogPost

func (repo *BlogRepo) DeleteBlogPost(filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*BlogRepo) DeleteComment

func (repo *BlogRepo) DeleteComment(filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*BlogRepo) GetBlogPost

func (repo *BlogRepo) GetBlogPost(filter interface{}, opts ...*options.FindOneOptions) (*BlogPost, error)

func (*BlogRepo) GetBlogPosts

func (rep *BlogRepo) GetBlogPosts(filter interface{}, opts ...*options.FindOptions) ([]*BlogPost, error)

func (*BlogRepo) GetComment

func (repo *BlogRepo) GetComment(filter interface{}, opts ...*options.FindOneOptions) (*Comment, error)

func (*BlogRepo) GetComments

func (rep *BlogRepo) GetComments(filter interface{}, opts ...*options.FindOptions) ([]*Comment, error)

func (*BlogRepo) PostComment

func (repo *BlogRepo) PostComment(comment *Comment) (*mongo.InsertOneResult, error)

func (*BlogRepo) SearchBlogPosts

func (repo *BlogRepo) SearchBlogPosts(query string) ([]*BlogPost, error)

func (*BlogRepo) UpdateBlogPost

func (repo *BlogRepo) UpdateBlogPost(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*BlogRepo) UpdateComment

func (repo *BlogRepo) UpdateComment(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

type BlogRepository

type BlogRepository interface {
	CreateBlogPost(blogPost *BlogPost) (*mongo.InsertOneResult, error)
	GetBlogPosts(filter interface{}, opts ...*options.FindOptions) ([]*BlogPost, error)
	GetBlogPost(filter interface{}, opts ...*options.FindOneOptions) (*BlogPost, error)
	UpdateBlogPost(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	DeleteBlogPost(filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
	SearchBlogPosts(query string) ([]*BlogPost, error)
	PostComment(comment *Comment) (*mongo.InsertOneResult, error)
	GetComments(filter interface{}, opts ...*options.FindOptions) ([]*Comment, error)
	GetComment(filter interface{}, opts ...*options.FindOneOptions) (*Comment, error)
	UpdateComment(filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	DeleteComment(filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
}

type BlogService

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

func NewBlogService

func NewBlogService(repo BlogRepository) *BlogService

func (*BlogService) CreateBlogPost

func (service *BlogService) CreateBlogPost(blogPost *BlogPost) error

func (*BlogService) DeleteBlogPost

func (service *BlogService) DeleteBlogPost(idStr string) error

func (*BlogService) DeleteComment

func (service *BlogService) DeleteComment(idStr string) error

func (*BlogService) GetBlogPostByID

func (service *BlogService) GetBlogPostByID(idStr string) (*BlogPost, error)

func (*BlogService) GetBlogPostBySlug

func (service *BlogService) GetBlogPostBySlug(slug string) (*BlogPost, error)

func (*BlogService) GetBlogPosts

func (service *BlogService) GetBlogPosts() ([]*BlogPost, error)

func (*BlogService) GetComment

func (service *BlogService) GetComment(idStr string) (*Comment, error)

func (*BlogService) GetComments

func (service *BlogService) GetComments(postIdStr string) ([]*Comment, error)

func (*BlogService) LikeOrUnlikeComment

func (service *BlogService) LikeOrUnlikeComment(commentIdStr, userId string, opt CommnentOption) error

func (*BlogService) LikeOrUnlikePost

func (service *BlogService) LikeOrUnlikePost(postIdStr, userId string, opt PostOption) error

func (*BlogService) PostComment

func (service *BlogService) PostComment(comment *Comment) error

func (*BlogService) SearchBlogPosts

func (service *BlogService) SearchBlogPosts(query string) ([]*BlogPost, error)

func (*BlogService) UpdateBlogPost

func (service *BlogService) UpdateBlogPost(blogPost *BlogPost) error

func (*BlogService) UpdateComment

func (service *BlogService) UpdateComment(comment *Comment) error

type BlogServices

type BlogServices interface {
	CreateBlogPost(blogPost *BlogPost) error
	GetBlogPosts() ([]*BlogPost, error)
	GetBlogPostByID(idStr string) (*BlogPost, error)
	GetBlogPostBySlug(slug string) (*BlogPost, error)
	UpdateBlogPost(blogPost *BlogPost) error
	DeleteBlogPost(idStr string) error
	SearchBlogPosts(query string) ([]*BlogPost, error)

	PostComment(comment *Comment) error
	GetComments(postIdStr string) ([]*Comment, error)
	GetComment(idStr string) (*Comment, error)
	UpdateComment(comment *Comment) error
	DeleteComment(idStr string) error
	LikeOrUnlikePost(postIdStr, userId string, opt PostOption) error
	LikeOrUnlikeComment(commentIdStr, userId string, opt CommnentOption) error
}

type Comment

type Comment struct {
	Id         primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	AuthorId   string             `json:"author_id,omitempty" bson:"author_id,omitempty"`
	BlogPostId primitive.ObjectID `json:"blog_post_id,omitempty" bson:"blog_post_id,omitempty"`
	ParentId   primitive.ObjectID `json:"parent_id,omitempty" bson:"parent_id,omitempty"`
	Content    string             `json:"content,omitempty" bson:"content,omitempty"`
	Likes      []Like             `json:"likes,omitempty" bson:"likes,omitempty"`
	CreatedAt  time.Time          `json:"created_at,omitempty" bson:"created_at,omitempty"`
	UpdatedAt  time.Time          `json:"updated_at,omitempty" bson:"updated_at,omitempty"`
}

type CommnentOption

type CommnentOption string
const LikeComment CommnentOption = "like"
const UnlikeComment CommnentOption = "unlike"

type Like

type Like struct {
	UserId string `json:"user_id,omitempty" bson:"user_id,omitempty"`
}

type PostOption

type PostOption string
const LikePost PostOption = "like"
const UnlikePost PostOption = "unlike"

Jump to

Keyboard shortcuts

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