Documentation
¶
Index ¶
- Variables
- func DelAnswerHandler(res http.ResponseWriter, req *http.Request)
- func GetDocumentHandler(res http.ResponseWriter, req *http.Request)
- func GetQuestionHandler(res http.ResponseWriter, req *http.Request)
- func GetUserVote(res http.ResponseWriter, req *http.Request)
- func PostVote(res http.ResponseWriter, req *http.Request)
- func PutAnswerHandler(res http.ResponseWriter, req *http.Request)
- func PutDocumentHandler(res http.ResponseWriter, req *http.Request)
- type Answer
- type Coord
- type Document
- type PutAnswerRequest
- type PutDocumentRequest
- type PutVoteRequest
- type Question
- type Vote
- type VoteValue
Constants ¶
This section is empty.
Variables ¶
var ( VOTES_QUERY = fmt.Sprintf(` select votes.answer, count(case votes.vote when %d then 1 else null end) as upvotes, count(case votes.vote when %d then 1 else null end) as downvotes from votes where deleted_at is NULL group by answer `, VoteUp, VoteDown) ANSWERS_QUERY = fmt.Sprintf(` select * from answers full join (%s) on answer = answers.id where deleted_at is NULL and answers.parent is NULL and answers.question = ? `, VOTES_QUERY) REPLIES_QUERY = ` select * from answers where deleted_at is NULL and answers.parent IN ? ` )
Functions ¶
func DelAnswerHandler ¶
func DelAnswerHandler(res http.ResponseWriter, req *http.Request)
@Summary Delete an answer @Description Given an andwer ID, delete the answer @Tags answer @Param id path string true "Answer id" @Produce json @Success 200 {object} Answer @Failure 400 {object} util.ApiError @Router /answers/{id} [delete]
func GetDocumentHandler ¶
func GetDocumentHandler(res http.ResponseWriter, req *http.Request)
@Summary Get a document's divisions @Description Given a document's ID, return all the questions @Tags document @Param id path string true "document id" @Produce json @Success 200 {object} Document @Failure 400 {object} util.ApiError @Router /documents/{id} [get]
func GetQuestionHandler ¶
func GetQuestionHandler(res http.ResponseWriter, req *http.Request)
@Summary Get all answers given a question @Description Given a question ID, return the question and all its answers @Tags question @Param id path string true "Answer id" @Produce json @Success 200 {array} Answer @Failure 400 {object} util.ApiError @Router /questions/{id} [get]
func GetUserVote ¶
func GetUserVote(res http.ResponseWriter, req *http.Request)
get given vote to an answer
func PostVote ¶
func PostVote(res http.ResponseWriter, req *http.Request)
@Summary Insert a vote @Description Insert a new vote on a answer @Tags vote @Produce json @Param id path string true "code query parameter" @Success 200 {object} Vote @Failure 400 {object} httputil.ApiError @Router /answer/{id}/vote [post]
func PutAnswerHandler ¶
func PutAnswerHandler(res http.ResponseWriter, req *http.Request)
@Summary Insert a new answer @Description Insert a new answer under a question @Tags answer @Param answerReq body PutAnswerRequest true "Answer data to insert" @Produce json @Success 200 {object} Answer @Failure 400 {object} util.ApiError @Router /answers [put]
func PutDocumentHandler ¶
func PutDocumentHandler(res http.ResponseWriter, req *http.Request)
@Summary Insert a new document @Description Insert a new document with all the questions initialised @Tags document @Param docRequest body PutDocumentRequest true "Doc request body" @Produce json @Success 200 {object} Document @Failure 400 {object} util.ApiError @Router /documents [put]
Types ¶
type Answer ¶
type Answer struct { // taken from from gorm.Model, so we can json strigify properly ID uint `json:"id" gorm:"primarykey"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` Question uint `json:"question" gorm:"foreignKey:Question;references:ID"` Parent *uint `json:"parent"` User string `json:"user"` Content string `json:"content"` Upvotes uint32 `json:"upvotes" gorm:"->"` Downvotes uint32 `json:"downvotes" gorm:"->"` Replies []Answer `json:"replies" gorm:"foreignKey:Parent;references:ID"` Votes []Vote `json:"-" gorm:"foreignKey:Answer;references:ID"` }
type PutAnswerRequest ¶
type PutDocumentRequest ¶
type PutVoteRequest ¶
type PutVoteRequest struct {
Vote VoteValue `json:"vote"`
}
type Question ¶
type Question struct { // taken from from gorm.Model, so we can json strigify properly ID uint `json:"id" gorm:"primarykey"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `json:"-" gorm:"index"` Document string `json:"document"` Start uint32 `json:"start"` End uint32 `json:"end"` Answers []Answer `json:"answers" gorm:"foreignKey:Question;references:ID"` }