dao

package
v0.0.0-...-831d999 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(s SourceID, d Dao, offset, limit int64) ([]*Comment, *CommentStatistics)

Get get comments by source id

Types

type Comment

type Comment struct {
	ID       primitive.ObjectID `bson:"_id"`                        //comment id
	Parent   primitive.ObjectID `bson:"parent" json:"parent"`       //parent comment id, reply comment
	SourceID SourceID           `bson:"source_id" json:"source_id"` //comment source id
	Content  string             `bson:"content" json:"content"`     //comment content
	Grade    float32            `bson:"grade" json:"grade"`         //source grade .5 - 5
	Ctime    time.Time          `bson:"c_time" json:"c_time"`       //create time
	Utime    time.Time          `bson:"u_time" json:"u_time"`       //update time
	User     `bson:",inline" json:",inline"`
}

Comment mongo fields

func New

func New() *Comment

New build new comment

func (*Comment) Save

func (c *Comment) Save(d Dao) bool

Save save comment to mongo

type CommentStatistics

type CommentStatistics struct {
	Count int     `bson:"count"`
	Grade float64 `bson:"grade"`
}

CommentStatistics statistics comments

type Dao

type Dao interface {
	AddComment(*Comment) bool
	GetComments(s SourceID, offset, limit int64) []*Comment
	Aggregate(s SourceID) *CommentStatistics
}

Dao comment db

type MongoService

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

MongoService the db service

func NewMongo

func NewMongo(cfg *config.Config) *MongoService

NewMongo return a new mongodb connect service

func (*MongoService) AddComment

func (m *MongoService) AddComment(c *Comment) bool

AddComment add comment to mongodb

func (*MongoService) Aggregate

func (m *MongoService) Aggregate(s SourceID) *CommentStatistics

Aggregate all comments count and average score

func (*MongoService) GetComments

func (m *MongoService) GetComments(s SourceID, offset, limit int64) []*Comment

GetComments get comments by sourceid

type SourceID

type SourceID string

SourceID comment source source id can build from page params or url it's must be unique identification

type User

type User struct {
	Avatar    string `bson:"avatar" json:"avatar"`
	NickName  string `bson:"nick_name" json:"nick_name"`
	IPAddress string `bson:"ip_address" json:"ip_address"`
}

User comment user

Jump to

Keyboard shortcuts

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