blog

package
v0.0.0-...-6237511 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	// Identifier of the category
	ID primitive.ObjectID `bson:"_id" json:"id" graphql:"-"`

	// Name of the category
	Name string `bson:"name" json:"name" graphql:"name"`

	// Valid URL string composes with name and ID
	Slug string `bson:"slug" json:"slug" graphql:"slug"`
}

Category is a group of posts regarded as having particular shared characteristics

func (Category) MarshalJSON

func (cat Category) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaling function of category entity

type CategoryRepository

type CategoryRepository interface {
	FindAll(ctx context.Context) ([]Category, error)
	FindAllByIDs(ctx context.Context, ids interface{}) ([]Category, error)
	FindByID(ctx context.Context, id interface{}) (Category, error)
}

A CategoryRepository interface

type Engagement

type Engagement struct {
	// Total object shared counter
	ShareCount int `bson:"-" json:"shareCount" graphql:"shareCount"`
}

Engagement represents social network engagement of the object

type MongoCategoryRepository

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

MongoCategoryRepository implements CategoryRepository interface

func NewCategoryRepository

func NewCategoryRepository(db mongo.Database) MongoCategoryRepository

NewCategoryRepository returns a MongoCategoryRepository instance

func (MongoCategoryRepository) FindAll

func (repo MongoCategoryRepository) FindAll(ctx context.Context) ([]Category, error)

FindAll returns list of categories

func (MongoCategoryRepository) FindAllByIDs

func (repo MongoCategoryRepository) FindAllByIDs(ctx context.Context, ids interface{}) ([]Category, error)

FindAllByIDs returns list of categories from list of IDs

func (MongoCategoryRepository) FindByID

func (repo MongoCategoryRepository) FindByID(ctx context.Context, id interface{}) (Category, error)

FindByID returns a single category from its ID

type MongoPostRepository

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

MongoPostRepository implements PostRepository interface

func NewPostRepository

func NewPostRepository(db mongo.Database) MongoPostRepository

NewPostRepository returns a MongoPostRepository instance

func (MongoPostRepository) Create

func (repo MongoPostRepository) Create(ctx context.Context, authorID string) (Post, error)

Create inserts a new empty post which belongs to the author with "Draft" status

func (MongoPostRepository) FindAll

func (repo MongoPostRepository) FindAll(ctx context.Context, q PostQuery) ([]Post, error)

FindAll returns list of posts filtered by post query

func (MongoPostRepository) FindByID

func (repo MongoPostRepository) FindByID(ctx context.Context, id interface{}) (Post, error)

FindByID returns a single post from its ID

func (MongoPostRepository) Save

func (repo MongoPostRepository) Save(ctx context.Context, id interface{}, q PostQuery) (Post, error)

Save does updating a single post

type MongoTagRepository

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

MongoTagRepository implements TagRepository interface

func NewTagRepository

func NewTagRepository(db mongo.Database) MongoTagRepository

NewTagRepository returns a MongoTagRepository instance

func (MongoTagRepository) FindAll

func (repo MongoTagRepository) FindAll(ctx context.Context) ([]Tag, error)

FindAll returns list of tags

func (MongoTagRepository) FindAllByIDs

func (repo MongoTagRepository) FindAllByIDs(ctx context.Context, ids interface{}) ([]Tag, error)

FindAllByIDs returns list of tags from list of IDs

func (MongoTagRepository) FindByID

func (repo MongoTagRepository) FindByID(ctx context.Context, id interface{}) (Tag, error)

FindByID returns a single tag from its ID

type Post

type Post struct {
	// Identifier of the post
	ID primitive.ObjectID `bson:"_id" json:"id" graphql:"-"`

	// Title of the post
	Title string `bson:"title" json:"title" graphql:"title"`

	// Valid URL string composes with title and ID
	Slug string `bson:"slug" json:"slug" graphql:"slug"`

	// Status of the post which could be...
	// - PUBLISHED
	// - DRAFT
	Status Status `bson:"status" json:"status" graphql:"status"`

	// Original content of the post in markdown syntax
	Markdown string `bson:"markdown" json:"markdown" graphql:"markdown"`

	// Content of the post in HTML format which will be translated from markdown
	HTML string `bson:"html" json:"html" graphql:"html"`

	// Date-time that the post was published
	PublishedAt time.Time `bson:"publishedAt" json:"publishedAt" graphql:"publishedAt"`

	// Identifier of the author
	AuthorID string `bson:"authorId" json:"authorId" graphql:"authorId"`

	// List of categories (in reference to the category collection) that the post belonging to
	Categories []mongo.DBRef `bson:"categories" json:"-" graphql:"-"`

	// List of tags that the post belonging to
	Tags []mongo.DBRef `bson:"tags" json:"-" graphql:"-"`

	// A featured image to be shown in the social network as a cover image
	FeaturedImage mongo.DBRef `bson:"featuredImage" json:"-" graphql:"-"`

	// List of attachments are belonging to the post
	Attachments []mongo.DBRef `bson:"attachments" json:"-" graphql:"-"`

	// A social network engagement of the post
	Engagement Engagement `bson:"-" json:"engagement" graphql:"engagement"`

	// Date-time that the post was created
	CreatedAt time.Time `bson:"createdAt" json:"createdAt" graphql:"createdAt"`

	// Date-time that the post was updated
	UpdatedAt time.Time `bson:"updatedAt" json:"updatedAt" graphql:"updatedAt"`
}

Post is a piece of content in the blog platform

func (Post) MarshalJSON

func (p Post) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaling function of post entity

type PostQuery

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

PostQuery uses as medium for communicating between repository and data-access object (DAO)

func (PostQuery) Attachments

func (q PostQuery) Attachments() *[]storage.File

Attachments returns list of files object

func (PostQuery) AuthorID

func (q PostQuery) AuthorID() *string

AuthorID returns author ID

func (PostQuery) Categories

func (q PostQuery) Categories() *[]Category

Categories returns list of categories

func (PostQuery) Category

func (q PostQuery) Category() *Category

Category returns category object

func (PostQuery) FeaturedImage

func (q PostQuery) FeaturedImage() *storage.File

FeaturedImage returns file object

func (PostQuery) HTML

func (q PostQuery) HTML() *string

HTML returns HTML value

func (PostQuery) Limit

func (q PostQuery) Limit() int64

Limit returns limit value

func (PostQuery) Markdown

func (q PostQuery) Markdown() *string

Markdown returns markdown value

func (PostQuery) Offset

func (q PostQuery) Offset() int64

Offset returns offset value

func (PostQuery) PublishedAt

func (q PostQuery) PublishedAt() *time.Time

PublishedAt returns date-time value

func (PostQuery) Slug

func (q PostQuery) Slug() *string

Slug returns slug value

func (PostQuery) Status

func (q PostQuery) Status() *Status

Status return status value

func (PostQuery) Tag

func (q PostQuery) Tag() *Tag

Tag returns tag object

func (PostQuery) Tags

func (q PostQuery) Tags() *[]Tag

Tags return list of tags

func (PostQuery) Title

func (q PostQuery) Title() *string

Title returns title value

type PostQueryBuilder

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

PostQueryBuilder a post object specific query builder

func NewPostQueryBuilder

func NewPostQueryBuilder() *PostQueryBuilder

NewPostQueryBuilder returns a query builder for building post query object

func (*PostQueryBuilder) Build

func (qb *PostQueryBuilder) Build() PostQuery

Build returns a post query object

func (*PostQueryBuilder) WithAttachments

func (qb *PostQueryBuilder) WithAttachments(attachments []storage.File) *PostQueryBuilder

WithAttachments allows to set list of attachments to the post query object

func (*PostQueryBuilder) WithAuthorID

func (qb *PostQueryBuilder) WithAuthorID(authorID string) *PostQueryBuilder

WithAuthorID allows to set an author ID to the post query object

func (*PostQueryBuilder) WithCategories

func (qb *PostQueryBuilder) WithCategories(categories []Category) *PostQueryBuilder

WithCategories allows to set list of categories to the post query object

func (*PostQueryBuilder) WithCategory

func (qb *PostQueryBuilder) WithCategory(category Category) *PostQueryBuilder

WithCategory allows to set category to the post query object

func (*PostQueryBuilder) WithFeaturedImage

func (qb *PostQueryBuilder) WithFeaturedImage(featuredImage storage.File) *PostQueryBuilder

WithFeaturedImage allows to set featured image to the post query object

func (*PostQueryBuilder) WithHTML

func (qb *PostQueryBuilder) WithHTML(html string) *PostQueryBuilder

WithHTML allows to set HTML to the post query object

func (*PostQueryBuilder) WithLimit

func (qb *PostQueryBuilder) WithLimit(limit int64) *PostQueryBuilder

WithLimit allows to set limit the post query object

func (*PostQueryBuilder) WithMarkdown

func (qb *PostQueryBuilder) WithMarkdown(markdown string) *PostQueryBuilder

WithMarkdown allows to set markdown to the post query object

func (*PostQueryBuilder) WithOffset

func (qb *PostQueryBuilder) WithOffset(offset int64) *PostQueryBuilder

WithOffset allows to set offset to the post query object

func (*PostQueryBuilder) WithPublishedAt

func (qb *PostQueryBuilder) WithPublishedAt(publishedAt time.Time) *PostQueryBuilder

WithPublishedAt allows to set a date-time which the post was published

func (*PostQueryBuilder) WithSlug

func (qb *PostQueryBuilder) WithSlug(slug string) *PostQueryBuilder

WithSlug allows to set slug to the post query object

func (*PostQueryBuilder) WithStatus

func (qb *PostQueryBuilder) WithStatus(status Status) *PostQueryBuilder

WithStatus allows to set status to the post query object

func (*PostQueryBuilder) WithTag

func (qb *PostQueryBuilder) WithTag(tag Tag) *PostQueryBuilder

WithTag allows to set tag to the post query object

func (*PostQueryBuilder) WithTags

func (qb *PostQueryBuilder) WithTags(tags []Tag) *PostQueryBuilder

WithTags allows to set list of tags to the post query object

func (*PostQueryBuilder) WithTitle

func (qb *PostQueryBuilder) WithTitle(title string) *PostQueryBuilder

WithTitle allows to set title to the post query object

type PostRepository

type PostRepository interface {
	Create(ctx context.Context, authorID string) (Post, error)
	FindAll(ctx context.Context, q PostQuery) ([]Post, error)
	FindByID(ctx context.Context, id interface{}) (Post, error)
	Save(ctx context.Context, id interface{}, q PostQuery) (Post, error)
}

A PostRepository interface

type Status

type Status string

Status for indicating the access level of the post

const StatusDraft Status = "DRAFT"

StatusDraft indicates that the post is private, can only be accessed by the author

const StatusPublished Status = "PUBLISHED"

StatusPublished indicates that post is public, accessible to everyone

func (Status) IsDraft

func (s Status) IsDraft() bool

IsDraft returns "true" if status is Draft

func (Status) IsPublished

func (s Status) IsPublished() bool

IsPublished returns "true" if status is Published

func (Status) String

func (s Status) String() string

type Tag

type Tag struct {
	// Identifier of the tag
	ID primitive.ObjectID `bson:"_id" json:"id" graphql:"-"`
	// Name of the tag
	Name string `bson:"name" json:"name" graphql:"name"`
	// Valid URL string composes with name and ID
	Slug string `bson:"slug" json:"slug" graphql:"slug"`
}

Tag is a label attached to the post for the purpose of identification

func (Tag) MarshalJSON

func (tag Tag) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshaling function of tag entity

type TagRepository

type TagRepository interface {
	FindAll(ctx context.Context) ([]Tag, error)
	FindAllByIDs(ctx context.Context, ids interface{}) ([]Tag, error)
	FindByID(ctx context.Context, id interface{}) (Tag, error)
}

A TagRepository interface

Directories

Path Synopsis
Package mock_blog is a generated GoMock package.
Package mock_blog is a generated GoMock package.

Jump to

Keyboard shortcuts

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