.
This commit is contained in:
1 parent
90cff1ac5b
commit
6f6eea5529
7 files changed
+179
-105
No files matched your search
+40
-38
@@ -7,26 +7,28 @@ import (
|
||||
type ErrorCode int
|
||||
|
||||
const (
|
||||
// 400 variants
|
||||
|
||||
// 401 variants
|
||||
ErrCodeInvalidCredentials ErrorCode = 4011
|
||||
ErrCodeInvalidAuthToken ErrorCode = 4012
|
||||
ErrCodeAuthRequired ErrorCode = 4013
|
||||
errCodeInvalidCredentials ErrorCode = 4011
|
||||
errCodeInvalidAuthToken ErrorCode = 4012
|
||||
errCodeAuthRequired ErrorCode = 4013
|
||||
|
||||
// 403 variants
|
||||
ErrCodeInactiveAccount ErrorCode = 4031
|
||||
ErrCodeNotPermitted ErrorCode = 4032
|
||||
errCodeInactiveAccount ErrorCode = 4031
|
||||
errCodeNotPermitted ErrorCode = 4032
|
||||
|
||||
// 409 variants
|
||||
ErrCodeEditConflict ErrorCode = 4091
|
||||
ErrCodeAlreadyVoted ErrorCode = 4092
|
||||
ErrCodeAlreadyBlindSigned ErrorCode = 4093
|
||||
ErrCodeVoteAlreadyCast ErrorCode = 4094
|
||||
errCodeEditConflict ErrorCode = 4091
|
||||
errCodeAlreadyVoted ErrorCode = 4092
|
||||
errCodeAlreadyBlindSigned ErrorCode = 4093
|
||||
errCodeVoteAlreadyCast ErrorCode = 4094
|
||||
|
||||
// 422 variants
|
||||
ErrCodeValidationFailed ErrorCode = 4221
|
||||
ErrCodeBlindedVoteRange ErrorCode = 4222
|
||||
ErrCodeInvalidSignature ErrorCode = 4223
|
||||
ErrCodeHasNotStarted ErrorCode = 4224
|
||||
errCodeValidationFailed ErrorCode = 4221
|
||||
errCodeBlindedVoteRange ErrorCode = 4222
|
||||
errCodeInvalidSignature ErrorCode = 4223
|
||||
errCodeHasNotStarted ErrorCode = 4224
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
@@ -60,41 +62,41 @@ func New(httpCode int, code ErrorCode, text string) error {
|
||||
|
||||
var (
|
||||
// 400 Bad Request
|
||||
ErrFailedPEM = New(400, 0, "failed to decode PEM block")
|
||||
ErrBadlyFormedJSON = New(400, 0, "body contains badly-formed JSON")
|
||||
ErrBodyEmpty = New(400, 0, "body must not be empty")
|
||||
ErrSingleValue = New(400, 0, "body must only contain a single JSON value")
|
||||
ErrInvalidID = New(400, 0, "invalid id parameter")
|
||||
ErrBadRequest = New(400, 0, "the server cannot process the request due to a client error")
|
||||
ErrFailedPEM = New(400, 400, "failed to decode PEM block")
|
||||
ErrBadlyFormedJSON = New(400, 400, "body contains badly-formed JSON")
|
||||
ErrBodyEmpty = New(400, 400, "body must not be empty")
|
||||
ErrSingleValue = New(400, 400, "body must only contain a single JSON value")
|
||||
ErrInvalidID = New(400, 400, "invalid id parameter")
|
||||
ErrBadRequest = New(400, 400, "the server cannot process the request due to a client error")
|
||||
|
||||
// 401 Unauthorized
|
||||
ErrInvalidCredentials = New(401, 4011, "invalid credentials")
|
||||
ErrInvalidAuthToken = New(401, 4012, "invalid or missing authentication token")
|
||||
ErrNoToken = New(401, 4012, "token must be provided")
|
||||
ErrAuthRequired = New(401, 4013, "you must be authenticated to access this resource")
|
||||
ErrHasNotStarted = New(401, 4224, "the vote has not yet started")
|
||||
ErrInvalidCredentials = New(401, errCodeInvalidCredentials, "invalid credentials")
|
||||
ErrInvalidAuthToken = New(401, errCodeInvalidAuthToken, "invalid or missing authentication token")
|
||||
ErrNoToken = New(401, errCodeInvalidAuthToken, "token must be provided")
|
||||
ErrAuthRequired = New(401, errCodeAuthRequired, "you must be authenticated to access this resource")
|
||||
|
||||
// 403 Forbidden
|
||||
ErrInactiveAccount = New(403, 4031, "your user account must be activated to access this resource")
|
||||
ErrNotPermitted = New(403, 4032, "your user account doesn't have the necessary permissions to access this resource")
|
||||
ErrInactiveAccount = New(403, errCodeInactiveAccount, "your user account must be activated to access this resource")
|
||||
ErrNotPermitted = New(403, errCodeNotPermitted, "your user account doesn't have the necessary permissions to access this resource")
|
||||
|
||||
// 404 Not Found
|
||||
ErrRecordNotFound = New(404, 0, "record not found")
|
||||
ErrNoPath = New(404, 0, "path is required")
|
||||
ErrRecordNotFound = New(404, 404, "record not found")
|
||||
ErrNoPath = New(404, 404, "path is required")
|
||||
|
||||
// 409 Conflict
|
||||
ErrEditConflict = New(409, 4091, "edit conflict")
|
||||
ErrDuplicateVote = New(409, 4092, "this signature has already been used to cast a vote")
|
||||
ErrDuplicateBlindSign = New(409, 4093, "user has already requested a blind signature for this issue")
|
||||
ErrDuplicateSignature = New(409, 4094, "this signature has already been used to cast a vote")
|
||||
ErrDuplicateEmail = New(409, 0, "duplicate email")
|
||||
ErrDuplicateUser = New(409, 0, "duplicate username")
|
||||
ErrEditConflict = New(409, errCodeEditConflict, "edit conflict")
|
||||
ErrDuplicateVote = New(409, errCodeAlreadyVoted, "this signature has already been used to cast a vote")
|
||||
ErrDuplicateBlindSign = New(409, errCodeAlreadyBlindSigned, "user has already requested a blind signature for this issue")
|
||||
ErrDuplicateSignature = New(409, errCodeVoteAlreadyCast, "this signature has already been used to cast a vote")
|
||||
ErrDuplicateEmail = New(409, 409, "duplicate email")
|
||||
ErrDuplicateUser = New(409, 409, "duplicate username")
|
||||
|
||||
// 422 Unprocessable Entity
|
||||
ErrValidationFailed = New(422, 4221, "validation failed")
|
||||
ErrInvalidBlindedVote = New(422, 4222, "blinded_vote is out of valid range [1, n-1]")
|
||||
ErrInvalidSignature = New(422, 4223, "signature verification failed")
|
||||
ErrValidationFailed = New(422, errCodeValidationFailed, "validation failed")
|
||||
ErrInvalidBlindedVote = New(422, errCodeBlindedVoteRange, "blinded_vote is out of valid range [1, n-1]")
|
||||
ErrInvalidSignature = New(422, errCodeInvalidSignature, "signature verification failed")
|
||||
ErrHasNotStarted = New(422, errCodeHasNotStarted, "the vote has not yet started")
|
||||
|
||||
// 429 Too Many Requests
|
||||
ErrRateLimitExceeded = New(429, 0, "rate limit exceeded")
|
||||
ErrRateLimitExceeded = New(429, 429, "rate limit exceeded")
|
||||
)
|
||||
+34
-15
@@ -15,17 +15,17 @@ import (
|
||||
var AnonymousUser = &User{}
|
||||
|
||||
type User struct {
|
||||
ID int64 `json:"id"`
|
||||
Email string `json:"email"`
|
||||
PhoneNumber string `json:"phone_number"`
|
||||
Country string `json:"country"`
|
||||
Name string `json:"name"`
|
||||
AltName *string `json:"alt_name"`
|
||||
DateOfBirth time.Time `json:"date_of_birth"`
|
||||
Address string `json:"address"`
|
||||
Created time.Time `json:"created"`
|
||||
LastLogin time.Time `json:"last_login"`
|
||||
Activated bool `json:"activated"`
|
||||
ID int64 `json:"id,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
PhoneNumber string `json:"phone_number,omitempty"`
|
||||
Country string `json:"country,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
AltName *string `json:"alt_name,omitempty"`
|
||||
DateOfBirth time.Time `json:"date_of_birth,omitempty"`
|
||||
Address string `json:"address,omitempty"`
|
||||
Created time.Time `json:"created,omitempty"`
|
||||
LastLogin time.Time `json:"last_login,omitempty"`
|
||||
Activated bool `json:"activated,omitempty"`
|
||||
Version int32 `json:"-"`
|
||||
}
|
||||
|
||||
@@ -306,10 +306,29 @@ func (m UserModel) Update(user *User) error {
|
||||
|
||||
func (m UserModel) GetAll(filters Filters) ([]*User, Metadata, error) {
|
||||
query := fmt.Sprintf(`
|
||||
SELECT COUNT(*) OVER(), id, email, phone_number, country, name, alt_name, date_of_birth, address, created, last_login, activated, version
|
||||
FROM users
|
||||
ORDER BY %s %s, id ASC
|
||||
LIMIT $1 OFFSET $2`,
|
||||
SELECT
|
||||
COUNT(*) OVER(),
|
||||
id,
|
||||
email,
|
||||
phone_number,
|
||||
country,
|
||||
name,
|
||||
alt_name,
|
||||
date_of_birth,
|
||||
address,
|
||||
created,
|
||||
last_login,
|
||||
activated,
|
||||
version
|
||||
FROM
|
||||
users
|
||||
ORDER BY
|
||||
%s %s,
|
||||
id ASC
|
||||
LIMIT
|
||||
$1
|
||||
OFFSET
|
||||
$2`,
|
||||
filters.sortColumn(),
|
||||
filters.sortDirection(),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user