question

package
v0.0.0-...-af438c1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	models.Model
	Title         string `gorm:"column:title" json:"title"`
	Body          string `gorm:"column:body" json:"body"`
	QuestionID    int64  `gorm:"column:question_id" json:"question_id"`
	ViewCount     int    `gorm:"column:view_count default:0" json:"view_count"`
	DownVoteCount int    `gorm:"column:down_vote_count default:0" json:"down_vote_count"`
	UpVoteCount   int    `grom:"column:up_vote_count default:0" json:"up_vote_count"`
	Score         int    `gorm:"column:score default:0" json:"score"`
}

type AnswerRequest

type AnswerRequest struct {
	Title string `gorm:"column:title" json:"title"`
	Body  string `gorm:"column:body" json:"body"`
}

type PaginatedQuestions

type PaginatedQuestions struct {
	Items []Question `json:"items"`
	Next  int        `json:"next_page_id"`
	Count int64      `json:"total"`
}

type Question

type Question struct {
	models.Model
	// QuestionID    int      `gorm:"column:question_id primaryKey" json:"question_id"`
	Title         string           `gorm:"column:title" json:"title"`
	Body          string           `gorm:"column:body" json:"body"`
	IsAnswered    bool             `gorm:"column:is_answered default:false" json:"is_answered"`
	ViewCount     int              `gorm:"column:view_count default:0" json:"view_count"`
	DownVoteCount int              `gorm:"column:down_vote_count default:0" json:"down_vote_count"`
	UpVoteCount   int              `grom:"column:up_vote_count default:0" json:"up_vote_count"`
	AnswerCount   int              `gorm:"column:answer_count default:0" json:"answer_count"`
	Score         int              `gorm:"column:score default:0" json:"score"`
	CreatedBy     uint64           `gorm:"column:created_by" json:"created_by" `
	Slug          string           `gorm:"column:slug" json:"slug"`
	Tags          []Tag            `gorm:"many2many:question_tags" json:"tags"`
	Answers       []Answer         `gor:"foreignKey:question_id;id" json:"answers"`
	UpvotedUsers  []UpVotedBy      `gorm:"many2many:question_id;id" json:"upvotedUsers"`
	Related       []models.TopWord `gorm:"many2many:question_related" json:"relatedtopics"`
}

type QuestionCreateRequest

type QuestionCreateRequest struct {
	Title string `json:"title"`
	Body  string `json:"body"`
	Tags  []Tag  `json:"tags"`
}

type QuestionService

type QuestionService interface {
	CreateNewQuestion(question Question) (Question, error)
	GetAllQuestions() []*Question
	CreateAnswer(answer Answer, question_id string) (Question, error)
	SearchQuestions(q string) []Question
	SearchQuestionsByTags(tag string) []Question

	// pagination
	GetQuestionsPaginate(pageID int) []Question

	//utils
	GetQuestionByID(id uint) Question
	UpdateQuestionViews(id uint)
	IsQuestionExist(id uint) bool

	// vote
	UpVotePost(user *user.User, question *Question)

	//fetch
	GetQuestionsBasedonTags(vals []string) []Question
	// contains filtered or unexported methods
}

QuestionService - interface for Question Service

type Service

type Service struct {
	DB *gorm.DB
}

func NewService

func NewService(db *gorm.DB) *Service

NewService - create a instance of this service and return a pointer to the servie

func (*Service) CreateAnswer

func (s *Service) CreateAnswer(answer Answer, question_id uint) (Question, error)

func (*Service) CreateNewQuestion

func (s *Service) CreateNewQuestion(question Question, topwords []types.TopWord) (Question, error)

create a new question

func (*Service) GetAllQuestions

func (s *Service) GetAllQuestions() []*Question

fetch all posts avaible

func (*Service) GetQuestionBasedonSlug

func (s *Service) GetQuestionBasedonSlug(slug string) Question

func (*Service) GetQuestionByID

func (s *Service) GetQuestionByID(id uint) Question

func (*Service) GetQuestionsBasedonTags

func (s *Service) GetQuestionsBasedonTags(vals []string) []Question

func (*Service) GetQuestionsPaginate

func (s *Service) GetQuestionsPaginate(pageID int) PaginatedQuestions

GetArticles returns all articles from the database

func (*Service) IsQuestionExist

func (s *Service) IsQuestionExist(id uint) bool

func (*Service) IsTitleExist

func (s *Service) IsTitleExist(title string) bool

func (*Service) SearchPosts

func (s *Service) SearchPosts(q string) []Question

seach for a post based on a keyword

func (*Service) SearchQuestionsByTagsv2

func (s *Service) SearchQuestionsByTagsv2(tag string) []*Question

func (*Service) SearchQuestionsByTagsv2PGStringArray

func (s *Service) SearchQuestionsByTagsv2PGStringArray(tags pq.StringArray) []*Question

func (*Service) UpVotePost

func (s *Service) UpVotePost(user user.User, question Question) (bool, []types.TopWord)

upvote a posttopwords

func (*Service) UpdateQuestionViews

func (s *Service) UpdateQuestionViews(question Question)

update question views

type Tag

type Tag struct {
	models.Model
	Name string `json:"name"`
}

type UpVotedBy

type UpVotedBy struct {
	models.Model
	UserId uint `json:"uuid"`
}

Jump to

Keyboard shortcuts

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