-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backward compability endpoints. Conversation resolving. Fix bug with …
…claim be_referred event for user which doesn't scan passport. Now events add for user in create_balance endpoint against active_balance
- Loading branch information
Showing
10 changed files
with
330 additions
and
68 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
docs/spec/paths/integrations@geo-points-svc@v2@[email protected]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
post: | ||
tags: | ||
- Points balance | ||
summary: Create points balance V2 | ||
description: | | ||
Create an empty balance inactive for authorized user who makes the request. | ||
If balance already exists, but it is disabled (it was not referred by another user, | ||
but has fulfilled some event), you should use PATCH balances/ endpoint as well. | ||
operationId: createPointsBalance | ||
requestBody: | ||
content: | ||
application/vnd.api+json: | ||
schema: | ||
type: object | ||
required: | ||
- data | ||
properties: | ||
data: | ||
$ref: '#/components/schemas/ActivateBalanceKey' | ||
responses: | ||
204: | ||
description: Created | ||
400: | ||
$ref: '#/components/responses/invalidParameter' | ||
401: | ||
$ref: '#/components/responses/invalidAuth' | ||
409: | ||
description: Balance already exists for provided nullifier | ||
content: | ||
application/vnd.api+json: | ||
schema: | ||
$ref: '#/components/schemas/Errors' | ||
500: | ||
$ref: '#/components/responses/internalError' |
47 changes: 47 additions & 0 deletions
47
docs/spec/paths/integrations@geo-points-svc@v2@public@balances@{nullifier}.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
patch: | ||
tags: | ||
- Points balance | ||
summary: Activate points balance | ||
description: | | ||
Activate points balance for authorized user who makes the request. Rank is included | ||
in response. | ||
This operation might be time-consuming, because `open` events should be added for | ||
the new account synchronously (to display them right after the request). | ||
operationId: activatePointsBalance | ||
requestBody: | ||
content: | ||
application/vnd.api+json: | ||
schema: | ||
type: object | ||
required: | ||
- data | ||
properties: | ||
data: | ||
$ref: '#/components/schemas/ActivateBalance' | ||
responses: | ||
200: | ||
description: Created | ||
content: | ||
application/vnd.api+json: | ||
schema: | ||
type: object | ||
required: | ||
- data | ||
properties: | ||
data: | ||
$ref: '#/components/schemas/Balance' | ||
400: | ||
$ref: '#/components/responses/invalidParameter' | ||
401: | ||
$ref: '#/components/responses/invalidAuth' | ||
404: | ||
$ref: '#/components/responses/notFound' | ||
409: | ||
description: Balance already activated | ||
content: | ||
application/vnd.api+json: | ||
schema: | ||
$ref: '#/components/schemas/Errors' | ||
500: | ||
$ref: '#/components/responses/internalError' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package handlers | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/rarimo/geo-auth-svc/pkg/auth" | ||
"github.com/rarimo/geo-points-svc/internal/data" | ||
"github.com/rarimo/geo-points-svc/internal/service/requests" | ||
"gitlab.com/distributed_lab/ape" | ||
"gitlab.com/distributed_lab/ape/problems" | ||
) | ||
|
||
func CreateBalanceV2(w http.ResponseWriter, r *http.Request) { | ||
req, err := requests.NewCreateBalanceV2(r) | ||
if err != nil { | ||
ape.RenderErr(w, problems.BadRequest(err)...) | ||
return | ||
} | ||
|
||
nullifier := req.Data.ID | ||
if !auth.Authenticates(UserClaims(r), auth.UserGrant(nullifier)) { | ||
ape.RenderErr(w, problems.Unauthorized()) | ||
return | ||
} | ||
|
||
balance, err := BalancesQ(r).FilterByNullifier(nullifier).Get() | ||
if err != nil { | ||
Log(r).WithError(err).Error("Failed to get balance by nullifier") | ||
ape.RenderErr(w, problems.InternalError()) | ||
return | ||
} | ||
|
||
if balance != nil { | ||
ape.RenderErr(w, problems.Conflict()) | ||
return | ||
} | ||
|
||
err = EventsQ(r).Transaction(func() error { | ||
events := prepareEventsWithRef(nullifier, "", false, r) | ||
Log(r).Debugf("%d events will be added for nullifier=%s", len(events), nullifier) | ||
if err = EventsQ(r).Insert(events...); err != nil { | ||
return fmt.Errorf("add open events: %w", err) | ||
} | ||
|
||
if err = BalancesQ(r).Insert(data.Balance{Nullifier: nullifier}); err != nil { | ||
return fmt.Errorf("failed to insert balance: %w", err) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
Log(r).WithError(err).Error("Failed to create balance") | ||
ape.RenderErr(w, problems.InternalError()) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusNoContent) | ||
} |
Oops, something went wrong.