Skip to content

Commit

Permalink
bad version
Browse files Browse the repository at this point in the history
  • Loading branch information
kish1n committed Aug 15, 2024
1 parent 86ce590 commit a4cf7ea
Show file tree
Hide file tree
Showing 39 changed files with 967 additions and 221 deletions.
8 changes: 8 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ event_types:
short_description: Short description
auto_claim: true
no_auto_open: true
- name: daily_question
title: Get daily question
reward: 0
frequency: unlimited
description: This event is used when a user get daily question
short_description: event for get daily question
auto_claim: true
no_auto_open: true

levels:
downgradeable: false
Expand Down
53 changes: 53 additions & 0 deletions docs/spec/components/schemas/DailyQuestion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
allOf:
- $ref: "#/components/schemas/DailyQuestionKey"
- type: object
x-go-is-request: true
required:
- attributes
properties:
attributes:
type: object
required:
- ID
- title
- time_for_answer
- reward
- answer_options
- active
- starts_at
- created_at
properties:
ID:
type: integer
format: int
description: ID question
example: 88
title:
type: string
description: Title question
example: Georgian capital
time_for_answer:
type: integer
format: int
description: Time for answer
example: 86400
reward:
type: integer
format: int
description: Reward for the right answer
example: 77
answer_options:
$ref: '#/components/schemas/DailyQuestionAnswers'
description: answer options
Active:
type: boolean
description: Status activity event
example: true
starts_at:
type: time.Time
format: int
description: Event start date, after which the event becomes active
created_at:
type: time.Time
format: int
description: Event add date
25 changes: 25 additions & 0 deletions docs/spec/components/schemas/DailyQuestionAnswer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
allOf:
- $ref: '#/components/schemas/DailyQuestionKey'
- type: object
required:
- attributes
properties:
attributes:
type: object
required:
- question_id
- nullifier
- answer
properties:
question_id:
type: integer
format: int
description: ID in table daily_question
nullifier:
type: string
description: Nullifier of the user who gave the answer
example: "0x123...abc"
pattern: '^0x[0-9a-fA-F]{64}$'
answer:
type: string
example: "That day is May 26, 2025"
5 changes: 5 additions & 0 deletions docs/spec/components/schemas/DailyQuestionAnswers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: object
properties:
type: string
format: json.RawMessage
description: Some events require dynamic data, which can be filled into `static` template.
12 changes: 12 additions & 0 deletions docs/spec/components/schemas/DailyQuestionKey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
type: object
required:
- id
properties:
id:
type: integer
format: int64
description: id question
example: 12
type:
type: string
enum: [daily_question ]
21 changes: 21 additions & 0 deletions docs/spec/components/schemas/DailyQuestionResult.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
allOf:
- $ref: '#/components/schemas/DailyQuestionKey'
- type: object
x-go-is-request: true
required:
- attributes
properties:
attributes:
type: object
required:
- time_to_next
- answer_status
properties:
time_to_next:
type: integer
format: int64
description: time to next question of the day
example: 312334324
answer_status:
type: boolean
description: Right or wrong answers
5 changes: 0 additions & 5 deletions docs/spec/components/schemas/DailyQuestionsStatus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,9 @@ allOf:
attributes:
type: object
required:
- availability
- already_done_for_user
- time_to_next
properties:
availability:
type: boolean
description: availability questions of the day
example: false
already_done_for_user:
type: boolean
description: question of the day already done for user
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
get:
description: daily question
parameters:
- $ref: '#/components/parameters/DailyQuestion'
name: Signature
description: Signature of the request
response:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/DailyQuestion'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
500:
$ref: '#/components/responses/internalError'

patch:
description: Send daily question answer
requestBody:
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/DailyQuestionAnswer'
response:
200:
description: Success
content:
application/vnd.api+json:
schema:
type: object
required:
- data
properties:
data:
$ref: '#/components/schemas/DailyQuestion'
400:
$ref: '#/components/responses/invalidParameter'
401:
$ref: '#/components/responses/invalidAuth'
500:
$ref: '#/components/responses/internalError'
9 changes: 5 additions & 4 deletions internal/assets/migrations/004_daily_questions_tabel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ CREATE TABLE IF NOT EXISTS daily_questions (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
time_for_answer INTEGER NOT NULL,
bounty INTEGER NOT NULL,
reward INTEGER NOT NULL,
answer_options JSONB NOT NULL,
active BOOLEAN DEFAULT TRUE,
starts_at INTEGER
starts_at TIMESTAMP NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT (NOW() AT TIME ZONE 'utc')
);

-- +migrate Down
DROP TABLE IF EXISTS daily_questions;
-- +migrate Down 2024-08-14 11:42:56.462615
DROP TABLE IF EXISTS daily_questions;
13 changes: 13 additions & 0 deletions internal/config/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import (
"log"
"time"

"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-auth-svc/pkg/hmacsig"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
Expand All @@ -11,6 +14,8 @@ import (
"gitlab.com/distributed_lab/kit/pgdb"
)

const locationName = "Asia/Tbilisi"

type Config interface {
comfig.Logger
pgdb.Databaser
Expand All @@ -20,6 +25,7 @@ type Config interface {
evtypes.EventTypeser
hmacsig.SigCalculatorProvider
PollVerifierer
TimeZoneProvider

Levels() *Levels
Verifiers() Verifiers
Expand All @@ -35,6 +41,8 @@ type config struct {
hmacsig.SigCalculatorProvider
PollVerifierer

timeZone *time.Location

passport root.VerifierProvider

levels comfig.Once
Expand All @@ -43,6 +51,10 @@ type config struct {
}

func New(getter kv.Getter) Config {
location, err := time.LoadLocation(locationName)
if err != nil {
log.Fatalf("error loading location: %v", err)
}
return &config{
getter: getter,
Databaser: pgdb.NewDatabaser(getter),
Expand All @@ -54,5 +66,6 @@ func New(getter kv.Getter) Config {
passport: root.NewVerifierProvider(getter, root.PoseidonSMT),
EventTypeser: evtypes.NewConfig(getter),
SigCalculatorProvider: hmacsig.NewCalculatorProvider(getter),
timeZone: location,
}
}
16 changes: 16 additions & 0 deletions internal/config/utcTimeZone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package config

import "time"

type TimeZoneProvider interface {
UtcTimeZone() *time.Location
}

func (c *config) UtcTimeZone() *time.Location {
return c.timeZone
}

func NowTime() time.Time {
loc, _ := time.LoadLocation(locationName)
return time.Now().In(loc)
}
34 changes: 20 additions & 14 deletions internal/data/daily_questions.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package data

type DailyQuestions struct {
ID int `db:"id"`
Title string `db:"title"`
TimeForAnswer int `db:"time_for_answer"`
Bounty int `db:"bounty"`
AnswerOptions string `db:"answer_options"`
Active bool `db:"active"`
StartsAt int `db:"starts_at"`
import "time"

type DailyQuestion struct {
ID int `db:"id"`
Title string `db:"title"`
TimeForAnswer int `db:"time_for_answer"`
Reward int `db:"reward"`
AnswerOptions Jsonb `db:"answer_options"`
Active bool `db:"active"`
StartsAt time.Time `db:"starts_at"`
CreatedAt time.Time `db:"created_at"`
}

type DailyQuestionsQ interface {
New() DailyQuestionsQ
Insert(DailyQuestions) error
type DailyQuestionQ interface {
New() DailyQuestionQ
Insert(DailyQuestion) error
Update(map[string]any) error

Count() (int64, error)
Select() ([]DailyQuestions, error)
Select() ([]DailyQuestion, error)
Get() (*DailyQuestion, error)

FilteredActive(status bool) DailyQuestionsQ
FilteredStartAt(date int) DailyQuestionsQ
FilterByActive(status bool) DailyQuestionQ
FilterByStartAt(date time.Time) DailyQuestionQ
FilterByCreatedAt(date time.Time) DailyQuestionQ
FilterByID(ID int) DailyQuestionQ
}
2 changes: 2 additions & 0 deletions internal/data/evtypes/models/extra.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const (
TypeExternalPassportScan = "external_passport_scan"
TypePollParticipation = "poll_participation"
TypeEarlyTest = "early_test"
TypeDailyQuestion = "daily_question"
TypeDailyQuestionPost = "daily_question_post"
)

const (
Expand Down
Loading

0 comments on commit a4cf7ea

Please sign in to comment.