Skip to content

Commit

Permalink
add admin flow daily questions
Browse files Browse the repository at this point in the history
  • Loading branch information
kish1n committed Aug 26, 2024
1 parent dea9c03 commit 9ed3923
Show file tree
Hide file tree
Showing 28 changed files with 997 additions and 8 deletions.
15 changes: 15 additions & 0 deletions docs/spec/components/schemas/DailyQuestionDel.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
allOf:
- $ref: "#/components/schemas/DailyQuestionDelKey"
- type: object
required:
- attributes
properties:
attributes:
type: object
required:
- title
properties:
title:
type: string
description: Question title
example: Georgian capital
11 changes: 11 additions & 0 deletions docs/spec/components/schemas/DailyQuestionDelKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: object
required:
- id
- type
properties:
id:
type: string
description: Question id
type:
type: string
enum: [ daily_question_del ]
78 changes: 78 additions & 0 deletions docs/spec/components/schemas/DailyQuestionDetails.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
allOf:
- $ref: "#/components/schemas/DailyQuestionDetailsKey"
- type: object
required:
- attributes
properties:
attributes:
type: object
required:
- title
- reward
- options
- correct_answer
- time_for_answer
- starts_at
- created_at
- num_correct_answers
- num_incorrect_answers
- num_all_participants
properties:
title:
type: string
description: Question title
example: Georgian capital
reward:
type: integer
format: int
description: reward for a correct answer
options:
type: array
description: Answer options. Minimum 2, maximum 6
items:
$ref: "#/components/schemas/DailyQuestionOptions"
example: [
{
"id": 0,
"title": ""
},
{
"id": 1,
"title": ""
},
{
"id": 2,
"title": ""
}
]
correct_answer:
type: integer
format: int64
description: right answer index
time_for_answer:
type: integer
format: int64
description: time for answer
starts_at:
type: integer
format: time.Time
description: start date when this question is available, hours and minutes are always 0
example: "2024-08-26T00:00:00Z"
created_at:
type: integer
format: time.Time
description: start date when this question was create
num_correct_answers:
type: integer
format: int64
description: number of correct answers
num_incorrect_answers:
type: integer
format: int64
description: number of incorrect answers
num_all_participants:
type: integer
format: int64
description: |
users who received the question, those who answered and
those who did not answer in the time given to them
11 changes: 11 additions & 0 deletions docs/spec/components/schemas/DailyQuestionDetailsKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: object
required:
- id
- type
properties:
id:
type: string
description: Question id
type:
type: string
enum: [ daily_question_details ]
56 changes: 56 additions & 0 deletions docs/spec/components/schemas/DailyQuestionEdit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
allOf:
- $ref: "#/components/schemas/DailyQuestionEditKey"
- type: object
required:
- attributes
properties:
attributes:
type: object
required:
- title
- reward
- options
- correct_answer
- time_for_answer
- starts_at
properties:
title:
type: string
description: Question title
example: Georgian capital
reward:
type: integer
format: int
description: reward for a correct answer
options:
type: array
description: Answer options. Minimum 2, maximum 6
items:
$ref: "#/components/schemas/DailyQuestionOptions"
example: [
{
"id": 0,
"title": ""
},
{
"id": 1,
"title": ""
},
{
"id": 2,
"title": ""
}
]
correct_answer:
type: integer
format: int64
description: right answer index
time_for_answer:
type: integer
format: int64
description: time for answer
starts_at:
type: integer
format: time.Time
description: start date when this question is available, hours and minutes are always 0
example: "2024-08-23"
11 changes: 11 additions & 0 deletions docs/spec/components/schemas/DailyQuestionEditKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: object
required:
- id
- type
properties:
id:
type: string
description: Question id
type:
type: string
enum: [ daily_question_edit ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
post:
tags:
- Daily Questions
summary: Create daily question
description: |
Create Daily Question user must be superuser
operationId: createDailyQuestion
security:
- BearerAuth: []
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/DailyQuestionDetails'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
403:
description: Correct answer option outside the range of answer options
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/Errors'
409:
description: On this day, the daily question already exists
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/Errors'
500:
$ref: '#/components/responses/internalError'
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
delete:
tags:
- Daily Questions
summary: Delete daily question
description: |
Delete Daily Question user must be superuser
operationId: deleteDailyQuestion
security:
- BearerAuth: []
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/DailyQuestionDel'
400:
$ref: '#/components/responses/invalidParameter'
404:
description: Question with ID not found
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/Errors'
500:
$ref: '#/components/responses/internalError'
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
patch:
tags:
- Daily Questions
summary: Edit daily question
description: |
Edit Daily Question user must be superuser
operationId: editDailyQuestion
security:
- BearerAuth: []
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/DailyQuestionEdit'
400:
$ref: '#/components/responses/invalidParameter'
409:
description: On this day, the daily question already exists
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/Errors'
403:
description: Correct answer option outside the range of answer options
content:
application/vnd.api+json:
schema:
$ref: '#/components/schemas/Errors'
500:
$ref: '#/components/responses/internalError'
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
get:
tags:
- Daily Questions
summary: Filter Daily Question by start
description: |
Filtering of daily questions by their activation time
operationId: filterStartAtDailyQuestion
security:
- BearerAuth: []
responses:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
type: array
items:
$ref: '#/components/schemas/DailyQuestionDetails'
500:
$ref: '#/components/responses/internalError'
9 changes: 8 additions & 1 deletion internal/data/daily_questions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
)

const (
ColDailyQuestionTitle = "title"
ColTimeForAnswer = "time_for_answer"
ColDailyQuestionReward = "reward"
ColAnswerOption = "answer_options"
ColCorrectAnswerId = "correct_answer"

ColCorrectAnswers = "num_correct_answers"
ColIncorrectAnswers = "num_incorrect_answers"
ColAllParticipants = "num_all_participants"
Expand All @@ -33,7 +39,7 @@ type DailyQuestionsQ interface {
New() DailyQuestionsQ
Insert(DailyQuestion) error
Update(map[string]any) error

Delete() (int64, error)
Count() (int64, error)
Select() ([]DailyQuestion, error)
Get() (*DailyQuestion, error)
Expand All @@ -42,6 +48,7 @@ type DailyQuestionsQ interface {
FilterByCreatedAtAfter(date time.Time) DailyQuestionsQ
FilterByStartsAtAfter(date time.Time) DailyQuestionsQ
FilterByID(ID int64) DailyQuestionsQ
FilterDayQuestions(location *time.Location, day time.Time) DailyQuestionsQ

IncrementCorrectAnswer() error
IncrementIncorrectAnswer() error
Expand Down
Loading

0 comments on commit 9ed3923

Please sign in to comment.