Skip to content

Commit 077ae90

Browse files
authored
Merge pull request #23 from simple-retro/feat/answer-vote
Add vote answer functionality
2 parents 11a010d + b61b502 commit 077ae90

11 files changed

Lines changed: 638 additions & 5 deletions

File tree

database/schema.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ CREATE TABLE IF NOT EXISTS answers (
2222
question_id TEXT,
2323
FOREIGN KEY(question_id) REFERENCES questions(id)
2424
);
25+
26+
-- Table for Answer Vote
27+
CREATE TABLE IF NOT EXISTS answer_votes (
28+
id TEXT PRIMARY KEY,
29+
answer_id TEXT,
30+
session_id TEXT,
31+
FOREIGN KEY(answer_id) REFERENCES answers(id),
32+
UNIQUE(answer_id, session_id)
33+
);

docs/docs.go

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,63 @@ const docTemplate = `{
6464
}
6565
}
6666
},
67+
"/answer/vote": {
68+
"post": {
69+
"consumes": [
70+
"application/json"
71+
],
72+
"produces": [
73+
"application/json"
74+
],
75+
"tags": [
76+
"Answer"
77+
],
78+
"summary": "Vote Answer",
79+
"parameters": [
80+
{
81+
"description": "Vote Answer",
82+
"name": "vote",
83+
"in": "body",
84+
"required": true,
85+
"schema": {
86+
"$ref": "#/definitions/types.AnswerVoteRequest"
87+
}
88+
}
89+
],
90+
"responses": {
91+
"200": {
92+
"description": "Vote recorded",
93+
"schema": {
94+
"type": "string"
95+
}
96+
},
97+
"400": {
98+
"description": "Invalid input",
99+
"schema": {
100+
"type": "string"
101+
}
102+
},
103+
"404": {
104+
"description": "Vote not found",
105+
"schema": {
106+
"type": "string"
107+
}
108+
},
109+
"409": {
110+
"description": "Vote already exists",
111+
"schema": {
112+
"type": "string"
113+
}
114+
},
115+
"500": {
116+
"description": "Internal error",
117+
"schema": {
118+
"type": "string"
119+
}
120+
}
121+
}
122+
}
123+
},
67124
"/answer/{id}": {
68125
"delete": {
69126
"consumes": [
@@ -213,6 +270,28 @@ const docTemplate = `{
213270
}
214271
}
215272
},
273+
"/limits": {
274+
"get": {
275+
"produces": [
276+
"application/json"
277+
],
278+
"summary": "Get API limits",
279+
"responses": {
280+
"200": {
281+
"description": "API limits",
282+
"schema": {
283+
"$ref": "#/definitions/types.ApiLimits"
284+
}
285+
},
286+
"500": {
287+
"description": "Internal error",
288+
"schema": {
289+
"type": "string"
290+
}
291+
}
292+
}
293+
}
294+
},
216295
"/question": {
217296
"post": {
218297
"consumes": [
@@ -564,8 +643,14 @@ const docTemplate = `{
564643
"position": {
565644
"type": "integer"
566645
},
646+
"question_id": {
647+
"type": "string"
648+
},
567649
"text": {
568650
"type": "string"
651+
},
652+
"votes": {
653+
"type": "integer"
569654
}
570655
}
571656
},
@@ -580,6 +665,31 @@ const docTemplate = `{
580665
}
581666
}
582667
},
668+
"types.AnswerVoteRequest": {
669+
"type": "object",
670+
"properties": {
671+
"action": {
672+
"$ref": "#/definitions/types.VoteAction"
673+
},
674+
"answer_id": {
675+
"type": "string"
676+
}
677+
}
678+
},
679+
"types.ApiLimits": {
680+
"type": "object",
681+
"properties": {
682+
"answer": {
683+
"$ref": "#/definitions/types.limits"
684+
},
685+
"question": {
686+
"$ref": "#/definitions/types.limits"
687+
},
688+
"retrospective": {
689+
"$ref": "#/definitions/types.limits"
690+
}
691+
}
692+
},
583693
"types.Question": {
584694
"type": "object",
585695
"properties": {
@@ -608,9 +718,15 @@ const docTemplate = `{
608718
"types.Retrospective": {
609719
"type": "object",
610720
"properties": {
721+
"created_at": {
722+
"type": "string"
723+
},
611724
"description": {
612725
"type": "string"
613726
},
727+
"expire_at": {
728+
"type": "string"
729+
},
614730
"id": {
615731
"type": "string"
616732
},
@@ -635,6 +751,31 @@ const docTemplate = `{
635751
"type": "string"
636752
}
637753
}
754+
},
755+
"types.VoteAction": {
756+
"type": "string",
757+
"enum": [
758+
"ADD_VOTE",
759+
"REMOVE_VOTE"
760+
],
761+
"x-enum-varnames": [
762+
"VoteAdd",
763+
"VoteRemove"
764+
]
765+
},
766+
"types.limits": {
767+
"type": "object",
768+
"properties": {
769+
"description": {
770+
"type": "integer"
771+
},
772+
"name": {
773+
"type": "integer"
774+
},
775+
"text": {
776+
"type": "integer"
777+
}
778+
}
638779
}
639780
}
640781
}`

docs/swagger.json

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,63 @@
5353
}
5454
}
5555
},
56+
"/answer/vote": {
57+
"post": {
58+
"consumes": [
59+
"application/json"
60+
],
61+
"produces": [
62+
"application/json"
63+
],
64+
"tags": [
65+
"Answer"
66+
],
67+
"summary": "Vote Answer",
68+
"parameters": [
69+
{
70+
"description": "Vote Answer",
71+
"name": "vote",
72+
"in": "body",
73+
"required": true,
74+
"schema": {
75+
"$ref": "#/definitions/types.AnswerVoteRequest"
76+
}
77+
}
78+
],
79+
"responses": {
80+
"200": {
81+
"description": "Vote recorded",
82+
"schema": {
83+
"type": "string"
84+
}
85+
},
86+
"400": {
87+
"description": "Invalid input",
88+
"schema": {
89+
"type": "string"
90+
}
91+
},
92+
"404": {
93+
"description": "Vote not found",
94+
"schema": {
95+
"type": "string"
96+
}
97+
},
98+
"409": {
99+
"description": "Vote already exists",
100+
"schema": {
101+
"type": "string"
102+
}
103+
},
104+
"500": {
105+
"description": "Internal error",
106+
"schema": {
107+
"type": "string"
108+
}
109+
}
110+
}
111+
}
112+
},
56113
"/answer/{id}": {
57114
"delete": {
58115
"consumes": [
@@ -202,6 +259,28 @@
202259
}
203260
}
204261
},
262+
"/limits": {
263+
"get": {
264+
"produces": [
265+
"application/json"
266+
],
267+
"summary": "Get API limits",
268+
"responses": {
269+
"200": {
270+
"description": "API limits",
271+
"schema": {
272+
"$ref": "#/definitions/types.ApiLimits"
273+
}
274+
},
275+
"500": {
276+
"description": "Internal error",
277+
"schema": {
278+
"type": "string"
279+
}
280+
}
281+
}
282+
}
283+
},
205284
"/question": {
206285
"post": {
207286
"consumes": [
@@ -553,8 +632,14 @@
553632
"position": {
554633
"type": "integer"
555634
},
635+
"question_id": {
636+
"type": "string"
637+
},
556638
"text": {
557639
"type": "string"
640+
},
641+
"votes": {
642+
"type": "integer"
558643
}
559644
}
560645
},
@@ -569,6 +654,31 @@
569654
}
570655
}
571656
},
657+
"types.AnswerVoteRequest": {
658+
"type": "object",
659+
"properties": {
660+
"action": {
661+
"$ref": "#/definitions/types.VoteAction"
662+
},
663+
"answer_id": {
664+
"type": "string"
665+
}
666+
}
667+
},
668+
"types.ApiLimits": {
669+
"type": "object",
670+
"properties": {
671+
"answer": {
672+
"$ref": "#/definitions/types.limits"
673+
},
674+
"question": {
675+
"$ref": "#/definitions/types.limits"
676+
},
677+
"retrospective": {
678+
"$ref": "#/definitions/types.limits"
679+
}
680+
}
681+
},
572682
"types.Question": {
573683
"type": "object",
574684
"properties": {
@@ -597,9 +707,15 @@
597707
"types.Retrospective": {
598708
"type": "object",
599709
"properties": {
710+
"created_at": {
711+
"type": "string"
712+
},
600713
"description": {
601714
"type": "string"
602715
},
716+
"expire_at": {
717+
"type": "string"
718+
},
603719
"id": {
604720
"type": "string"
605721
},
@@ -624,6 +740,31 @@
624740
"type": "string"
625741
}
626742
}
743+
},
744+
"types.VoteAction": {
745+
"type": "string",
746+
"enum": [
747+
"ADD_VOTE",
748+
"REMOVE_VOTE"
749+
],
750+
"x-enum-varnames": [
751+
"VoteAdd",
752+
"VoteRemove"
753+
]
754+
},
755+
"types.limits": {
756+
"type": "object",
757+
"properties": {
758+
"description": {
759+
"type": "integer"
760+
},
761+
"name": {
762+
"type": "integer"
763+
},
764+
"text": {
765+
"type": "integer"
766+
}
767+
}
627768
}
628769
}
629770
}

0 commit comments

Comments
 (0)