Skip to content

Commit

Permalink
Task completion without required order. STAGING task prize informatio…
Browse files Browse the repository at this point in the history
…n. (#50)
  • Loading branch information
ice-myles authored Aug 26, 2024
1 parent 3d4de0f commit 8cc0698
Show file tree
Hide file tree
Showing 40 changed files with 694 additions and 125 deletions.
24 changes: 24 additions & 0 deletions application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ cmd/santa-sleigh:
keyPath: cmd/santa-sleigh/.testdata/localhost.key
wintr/auth/ice:
jwtSecret: bogus
tasksList: &tasksList
- type: claim_username
prize: 100
icon: https://app.sunwavestoken.com/web/images/Components/Overview/nikename.svg
- type: start_mining
prize: 200
icon: https://app.sunwavestoken.com/web/images/Components/Overview/mining.svg
- type: upload_profile_picture
prize: 300
icon: https://app.sunwavestoken.com/web/images/Components/Overview/profile-waiting.svg
- type: follow_us_on_twitter
prize: 400
icon: https://app.sunwavestoken.com/web/images/Components/Overview/twitter-follow.svg
- type: join_telegram
prize: 500
icon: https://app.sunwavestoken.com/web/images/Components/Overview/join-telegram-waiting.svg
- type: invite_friends
prize: 600
icon: https://app.sunwavestoken.com/web/images/Components/Overview/invite.svg
friends-invited: &friends-invited
wintr/connectors/storage/v2:
runDDL: true
Expand Down Expand Up @@ -200,6 +219,7 @@ badges_test:
consumingTopics: *badgesMessageBrokerTopics
consumerGroup: santa-local-badges-test
tasks: &tasks
tasksV2Enabled: false
requiredFriendsInvited: 5
wintr/connectors/storage/v2:
runDDL: true
Expand Down Expand Up @@ -245,13 +265,16 @@ tasks: &tasks
- name: users-table
- name: mining-sessions-table
- name: friends-invited
tasksList: *tasksList
tenantName: sunwaves
tasks_test:
<<: *tasks
messageBroker:
<<: *tasksMessageBroker
consumingTopics: *tasksMessageBrokerTopics
consumerGroup: santa-local-tasks-test
levels-and-roles: &levels-and-roles
tasksV2Enabled: false
requiredInvitedFriendsToBecomeAmbassador: 3
roleNames:
- Snowman
Expand Down Expand Up @@ -289,6 +312,7 @@ levels-and-roles: &levels-and-roles
password: pass
replicaURLs:
- postgresql://root:pass@localhost:5432/santa
tasksList: *tasksList
messageBroker: &levels-and-rolesMessageBroker
consumerGroup: levels-and-roles-testing
createTopics: true
Expand Down
39 changes: 39 additions & 0 deletions cmd/santa-sleigh/api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,13 @@ const docTemplate = `{
"in": "path",
"required": true
},
{
"type": "string",
"description": "language to get tasks translation",
"name": "language",
"in": "path",
"required": true
},
{
"description": "Request params. Set it only if task completion requires additional data.",
"name": "request",
Expand Down Expand Up @@ -579,6 +586,31 @@ const docTemplate = `{
"twitterUserHandle": {
"type": "string",
"example": "jdoe2"
},
"verificationCode": {
"type": "string",
"example": "ABC"
}
}
},
"tasks.Metadata": {
"type": "object",
"properties": {
"iconUrl": {
"type": "string",
"example": "https://app.ice.com/web/invite.svg"
},
"longDescription": {
"type": "string",
"example": "Long description"
},
"shortDescription": {
"type": "string",
"example": "Short description"
},
"title": {
"type": "string",
"example": "Claim username"
}
}
},
Expand All @@ -592,6 +624,13 @@ const docTemplate = `{
"data": {
"$ref": "#/definitions/tasks.Data"
},
"metadata": {
"$ref": "#/definitions/tasks.Metadata"
},
"prize": {
"type": "number",
"example": 200
},
"type": {
"allOf": [
{
Expand Down
39 changes: 39 additions & 0 deletions cmd/santa-sleigh/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,13 @@
"in": "path",
"required": true
},
{
"type": "string",
"description": "language to get tasks translation",
"name": "language",
"in": "path",
"required": true
},
{
"description": "Request params. Set it only if task completion requires additional data.",
"name": "request",
Expand Down Expand Up @@ -572,6 +579,31 @@
"twitterUserHandle": {
"type": "string",
"example": "jdoe2"
},
"verificationCode": {
"type": "string",
"example": "ABC"
}
}
},
"tasks.Metadata": {
"type": "object",
"properties": {
"iconUrl": {
"type": "string",
"example": "https://app.ice.com/web/invite.svg"
},
"longDescription": {
"type": "string",
"example": "Long description"
},
"shortDescription": {
"type": "string",
"example": "Short description"
},
"title": {
"type": "string",
"example": "Claim username"
}
}
},
Expand All @@ -585,6 +617,13 @@
"data": {
"$ref": "#/definitions/tasks.Data"
},
"metadata": {
"$ref": "#/definitions/tasks.Metadata"
},
"prize": {
"type": "number",
"example": 200
},
"type": {
"allOf": [
{
Expand Down
28 changes: 28 additions & 0 deletions cmd/santa-sleigh/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ definitions:
twitterUserHandle:
example: jdoe2
type: string
verificationCode:
example: ABC
type: string
type: object
tasks.Metadata:
properties:
iconUrl:
example: https://app.ice.com/web/invite.svg
type: string
longDescription:
example: Long description
type: string
shortDescription:
example: Short description
type: string
title:
example: Claim username
type: string
type: object
tasks.Task:
properties:
Expand All @@ -104,6 +122,11 @@ definitions:
type: boolean
data:
$ref: '#/definitions/tasks.Data'
metadata:
$ref: '#/definitions/tasks.Metadata'
prize:
example: 200
type: number
type:
allOf:
- $ref: '#/definitions/tasks.Type'
Expand Down Expand Up @@ -377,6 +400,11 @@ paths:
name: userId
required: true
type: string
- description: language to get tasks translation
in: path
name: language
required: true
type: string
- description: Request params. Set it only if task completion requires additional
data.
in: body
Expand Down
5 changes: 3 additions & 2 deletions cmd/santa-sleigh/santa.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (

type (
GetTasksArg struct {
UserID string `uri:"userId" example:"edfd8c02-75e0-4687-9ac2-1ce4723865c4" swaggerignore:"true" required:"true"`
UserID string `uri:"userId" example:"edfd8c02-75e0-4687-9ac2-1ce4723865c4" swaggerignore:"true" required:"true"`
Language string `uri:"language" example:"en" swaggerignore:"true" required:"false"`
}
GetLevelsAndRolesSummaryArg struct {
UserID string `uri:"userId" example:"edfd8c02-75e0-4687-9ac2-1ce4723865c4" allowForbiddenGet:"true" swaggerignore:"true" required:"true"`
Expand Down Expand Up @@ -186,7 +187,7 @@ func (s *service) GetTasks( //nolint:gocritic // False negative.
if req.Data.UserID != req.AuthenticatedUser.UserID {
return nil, server.Forbidden(errors.Errorf("not allowed. %v != %v", req.Data.UserID, req.AuthenticatedUser.UserID))
}
resp, err := s.tasksProcessor.GetTasks(ctx, req.Data.UserID)
resp, err := s.tasksProcessor.GetTasks(ctx, req.Data.UserID, req.Data.Language)
if err != nil {
err = errors.Wrapf(err, "failed to GetTasks for data:%#v", req.Data)

Expand Down
14 changes: 1 addition & 13 deletions cmd/santa-sleigh/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (s *service) setupTasksRoutes(router *server.Router) {
// @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>)
// @Param taskType path string true "the type of the task" enums(claim_username,start_mining,upload_profile_picture,follow_us_on_twitter,join_telegram,invite_friends)
// @Param userId path string true "the id of the user that completed the task"
// @Param language path string true "language to get tasks translation"
// @Param request body CompleteTaskRequestBody false "Request params. Set it only if task completion requires additional data."
// @Success 200 "ok"
// @Failure 400 {object} server.ErrorResponse "if validations fail"
Expand All @@ -41,9 +42,6 @@ func (s *service) PseudoCompleteTask( //nolint:gocritic // False negative.
ctx context.Context,
req *server.Request[CompleteTaskRequestBody, any],
) (*server.Response[any], *server.Response[server.ErrorResponse]) {
if err := req.Data.validate(); err != nil {
return nil, server.UnprocessableEntity(errors.Wrap(err, "validations failed"), invalidPropertiesErrorCode)
}
if req.Data.TaskType == tasks.JoinTelegramType && (req.Data.Data == nil || req.Data.Data.TelegramUserHandle == "") {
return nil, server.UnprocessableEntity(errors.Errorf("`data`.`telegramUserHandle` required"), invalidPropertiesErrorCode)
}
Expand All @@ -67,13 +65,3 @@ func (s *service) PseudoCompleteTask( //nolint:gocritic // False negative.

return server.OK[any](), nil
}

func (arg *CompleteTaskRequestBody) validate() error {
for _, taskType := range &tasks.AllTypes {
if taskType == arg.TaskType {
return nil
}
}

return errors.Errorf("invalid type `%v`", arg.TaskType)
}
32 changes: 32 additions & 0 deletions cmd/santa/api/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,31 @@ const docTemplate = `{
"twitterUserHandle": {
"type": "string",
"example": "jdoe2"
},
"verificationCode": {
"type": "string",
"example": "ABC"
}
}
},
"tasks.Metadata": {
"type": "object",
"properties": {
"iconUrl": {
"type": "string",
"example": "https://app.ice.com/web/invite.svg"
},
"longDescription": {
"type": "string",
"example": "Long description"
},
"shortDescription": {
"type": "string",
"example": "Short description"
},
"title": {
"type": "string",
"example": "Claim username"
}
}
},
Expand All @@ -483,6 +508,13 @@ const docTemplate = `{
"data": {
"$ref": "#/definitions/tasks.Data"
},
"metadata": {
"$ref": "#/definitions/tasks.Metadata"
},
"prize": {
"type": "number",
"example": 200
},
"type": {
"allOf": [
{
Expand Down
32 changes: 32 additions & 0 deletions cmd/santa/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,31 @@
"twitterUserHandle": {
"type": "string",
"example": "jdoe2"
},
"verificationCode": {
"type": "string",
"example": "ABC"
}
}
},
"tasks.Metadata": {
"type": "object",
"properties": {
"iconUrl": {
"type": "string",
"example": "https://app.ice.com/web/invite.svg"
},
"longDescription": {
"type": "string",
"example": "Long description"
},
"shortDescription": {
"type": "string",
"example": "Short description"
},
"title": {
"type": "string",
"example": "Claim username"
}
}
},
Expand All @@ -477,6 +502,13 @@
"data": {
"$ref": "#/definitions/tasks.Data"
},
"metadata": {
"$ref": "#/definitions/tasks.Metadata"
},
"prize": {
"type": "number",
"example": 200
},
"type": {
"allOf": [
{
Expand Down
Loading

0 comments on commit 8cc0698

Please sign in to comment.