qa

package
v0.0.0-...-743d0d0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const QaKey = "qa"

Variables

This section is empty.

Functions

func NewQaService

func NewQaService(params ...interface{}) (interface{}, error)

Types

type Answer

type Answer struct {
	ID         int64          `gorm:"column:id;primaryKey"`
	QuestionID int64          `gorm:"column:question_id;index;comment:问题id;not null;default 0"`
	Context    string         `gorm:"column:context;comment:内容"`
	AuthorID   int64          `gorm:"column:author_id;comment:作者id;not null;default:0"`
	CreatedAt  time.Time      `gorm:"column:created_at;autoCreateTime;comment:创建时间"`
	UpdatedAt  time.Time      `gorm:"column:updated_at;autoUpdateTime;autoCreateTime;<-:false;comment:更新时间"`
	DeletedAt  gorm.DeletedAt `gorm:"index"`
	Author     *user.User     `gorm:"foreignKey:AuthorID"`
	Question   *Question      `gorm:"foreignKey:QuestionID"`
}

Answer 代表一个回答

type Pager

type Pager struct {
	Total int64 // 共有多少数据,只有返回值使用
	Start int   // 起始位置
	Size  int   // 每个页面个数
}

Pager 代表分页机制

type QaProvider

type QaProvider struct {
	framework.ServiceProvider
	// contains filtered or unexported fields
}

func (*QaProvider) Boot

func (sp *QaProvider) Boot(c framework.Container) error

func (*QaProvider) IsDefer

func (sp *QaProvider) IsDefer() bool

func (*QaProvider) Name

func (sp *QaProvider) Name() string

func (*QaProvider) Params

func (sp *QaProvider) Params(c framework.Container) []interface{}

func (*QaProvider) Register

type QaService

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

func (*QaService) AnswersLoadAuthor

func (q *QaService) AnswersLoadAuthor(ctx context.Context, answers *[]*Answer) error

func (*QaService) DeleteAnswer

func (q *QaService) DeleteAnswer(ctx context.Context, answer *Answer) error

func (*QaService) DeleteQuestion

func (q *QaService) DeleteQuestion(ctx context.Context, questionID int64) error

func (*QaService) GetAnswer

func (q *QaService) GetAnswer(ctx context.Context, answerId int64) (*Answer, error)

func (*QaService) GetQuestion

func (q *QaService) GetQuestion(ctx context.Context, questionID int64) (*Question, error)

func (*QaService) GetQuestions

func (q *QaService) GetQuestions(ctx context.Context, paper *Pager) ([]*Question, error)

func (*QaService) PostAnswer

func (q *QaService) PostAnswer(ctx context.Context, answer *Answer) error

func (*QaService) PostQuestion

func (q *QaService) PostQuestion(ctx context.Context, question *Question) error

func (*QaService) QuestionLoadAnswers

func (q *QaService) QuestionLoadAnswers(ctx context.Context, question *Question) error

func (*QaService) QuestionLoadAuthor

func (q *QaService) QuestionLoadAuthor(ctx context.Context, question *Question) error

func (*QaService) QuestionsLoadAuthor

func (q *QaService) QuestionsLoadAuthor(ctx context.Context, questions *[]*Question) error

func (*QaService) UpdateQuestion

func (q *QaService) UpdateQuestion(ctx context.Context, question *Question) error

type Question

type Question struct {
	ID        int64          `gorm:"column:id;primaryKey"`
	Title     string         `gorm:"column:title;comment:标题"`
	Context   string         `gorm:"column:context;comment:内容"`
	AuthorID  int64          `gorm:"column:author_id;comment:作者id;not null;default:0"`
	AnswerNum int            `gorm:"column:answer_num;comment:回答数;not null;default:0"`
	CreatedAt time.Time      `gorm:"column:created_at;autoCreateTime;comment:创建时间"`
	UpdatedAt time.Time      `gorm:"column:updated_at;autoUpdateTime;autoCreateTime;comment:更新时间"`
	DeletedAt gorm.DeletedAt `gorm:"index"`
	Author    *user.User     `gorm:"foreignKey:AuthorID"`
	Answers   []*Answer      `gorm:"foreignKey:QuestionID"`
}

Question 代表问题

type Service

type Service interface {
	// GetQuestions 获取问题列表,question简化结构
	GetQuestions(ctx context.Context, paper *Pager) ([]*Question, error)
	// GetQuestion 获取某个问题详情,question简化结构
	GetQuestion(ctx context.Context, questionID int64) (*Question, error)
	// PostQuestion 上传某个问题
	// ctx必须带上操作人id
	PostQuestion(ctx context.Context, question *Question) error
	// DeleteQuestion 删除问题,同时删除对应的回答
	// ctx必须带操作人信息
	DeleteQuestion(ctx context.Context, questionID int64) error
	// UpdateQuestion 代表更新问题, 只会对比其中的context,title两个字段,其他字段不会对比
	// ctx必须带操作人
	UpdateQuestion(ctx context.Context, question *Question) error
	// QuestionLoadAuthor 问题加载Author字段
	QuestionLoadAuthor(ctx context.Context, question *Question) error
	// QuestionLoadAnswers 单个问题加载Answers
	QuestionLoadAnswers(ctx context.Context, question *Question) error
	// QuestionsLoadAuthor 批量加载Author字段
	QuestionsLoadAuthor(ctx context.Context, questions *[]*Question) error

	// PostAnswer 上传某个回答
	// ctx必须带操作人信息
	PostAnswer(ctx context.Context, answer *Answer) error
	// GetAnswer 获取回答
	GetAnswer(ctx context.Context, answerID int64) (*Answer, error)
	// DeleteAnswer 删除某个回答
	// ctx必须带操作人信息
	DeleteAnswer(ctx context.Context, answer *Answer) error
	// AnswersLoadAuthor 批量加载Author字段
	AnswersLoadAuthor(ctx context.Context, answers *[]*Answer) error
}

Jump to

Keyboard shortcuts

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