diff --git a/internal/service/handlers/delete_user.go b/internal/service/handlers/delete_user.go index 8363193..dd58ff5 100644 --- a/internal/service/handlers/delete_user.go +++ b/internal/service/handlers/delete_user.go @@ -8,7 +8,7 @@ import ( ) func DeleteUser(w http.ResponseWriter, r *http.Request) { - userID, err := requests.DeleteUserByID(r) + userID, err := requests.GetPathUserID(r) if err != nil { ape.RenderErr(w, problems.BadRequest(err)...) return diff --git a/internal/service/handlers/get_proof.go b/internal/service/handlers/get_proof.go index 53cd91c..a32609b 100644 --- a/internal/service/handlers/get_proof.go +++ b/internal/service/handlers/get_proof.go @@ -1,15 +1,16 @@ package handlers import ( + "net/http" + "github.com/rarimo/verificator-svc/internal/service/requests" "github.com/rarimo/verificator-svc/internal/service/responses" "gitlab.com/distributed_lab/ape" "gitlab.com/distributed_lab/ape/problems" - "net/http" ) func GetProofByUserID(w http.ResponseWriter, r *http.Request) { - userID, err := requests.GetProofByUserID(r) + userID, err := requests.GetPathUserID(r) if err != nil { ape.RenderErr(w, problems.BadRequest(err)...) return diff --git a/internal/service/handlers/get_user.go b/internal/service/handlers/get_user.go index e905c30..05d6e54 100644 --- a/internal/service/handlers/get_user.go +++ b/internal/service/handlers/get_user.go @@ -1,15 +1,16 @@ package handlers import ( + "net/http" + "github.com/rarimo/verificator-svc/internal/service/requests" "github.com/rarimo/verificator-svc/internal/service/responses" "gitlab.com/distributed_lab/ape" "gitlab.com/distributed_lab/ape/problems" - "net/http" ) func GetUser(w http.ResponseWriter, r *http.Request) { - userID, err := requests.DeleteUserByID(r) + userID, err := requests.GetPathUserID(r) if err != nil { ape.RenderErr(w, problems.BadRequest(err)...) return diff --git a/internal/service/handlers/get_verification_status.go b/internal/service/handlers/get_verification_status.go index a7341c5..f3529ad 100644 --- a/internal/service/handlers/get_verification_status.go +++ b/internal/service/handlers/get_verification_status.go @@ -1,15 +1,16 @@ package handlers import ( + "net/http" + "github.com/rarimo/verificator-svc/internal/service/requests" "github.com/rarimo/verificator-svc/internal/service/responses" "gitlab.com/distributed_lab/ape" "gitlab.com/distributed_lab/ape/problems" - "net/http" ) func GetVerificationStatusById(w http.ResponseWriter, r *http.Request) { - userID, err := requests.GetVerificationStatusByID(r) + userID, err := requests.GetPathUserID(r) if err != nil { ape.RenderErr(w, problems.BadRequest(err)...) return diff --git a/internal/service/handlers/proof_params.go b/internal/service/handlers/proof_params.go index bfde766..b5ee2fe 100644 --- a/internal/service/handlers/proof_params.go +++ b/internal/service/handlers/proof_params.go @@ -13,7 +13,7 @@ import ( ) func GetProofParamsById(w http.ResponseWriter, r *http.Request) { - userIDHash, err := requests.GetProofParamsByID(r) + userIDHash, err := requests.GetPathUserIDHash(r) if err != nil { ape.RenderErr(w, problems.BadRequest(err)...) return diff --git a/internal/service/handlers/proof_params_light.go b/internal/service/handlers/proof_params_light.go index 85b25ca..6df9f01 100644 --- a/internal/service/handlers/proof_params_light.go +++ b/internal/service/handlers/proof_params_light.go @@ -13,7 +13,7 @@ import ( ) func GetProofParamsLightById(w http.ResponseWriter, r *http.Request) { - userIDHash, err := requests.GetProofParamsByID(r) + userIDHash, err := requests.GetPathUserIDHash(r) if err != nil { ape.RenderErr(w, problems.BadRequest(err)...) return diff --git a/internal/service/requests/get_proof_parameters.go b/internal/service/requests/get_proof_parameters.go index 84712ed..9ceda7e 100644 --- a/internal/service/requests/get_proof_parameters.go +++ b/internal/service/requests/get_proof_parameters.go @@ -2,10 +2,12 @@ package requests import ( "fmt" + "net/http" + "strings" + val "github.com/go-ozzo/ozzo-validation/v4" "github.com/go-ozzo/ozzo-validation/v4/is" "gitlab.com/distributed_lab/urlval/v4" - "net/http" ) type UserInputs struct { @@ -21,14 +23,16 @@ func NewGetUserInputs(r *http.Request) (userInputs UserInputs, err error) { err = newDecodeError("query", err) return } + + userInputs.UserId = strings.ToLower(userInputs.UserId) + err = val.Errors{ - "user_id": val.Validate(userInputs.UserId, val.Required, is.Email), + "user_id": val.Validate(userInputs.UserId, val.Required), "age_lower_bound": val.Validate(userInputs.AgeLowerBound, val.Required), "uniqueness": val.Validate(val.Required), "nationality": val.Validate(userInputs.Nationality, val.Required), "event_id": val.Validate(userInputs.EventID, is.Hexadecimal), - }. - Filter() + }.Filter() return } diff --git a/internal/service/requests/user_id_hash_path.go b/internal/service/requests/user_id_hash_path.go new file mode 100644 index 0000000..623e2d6 --- /dev/null +++ b/internal/service/requests/user_id_hash_path.go @@ -0,0 +1,17 @@ +package requests + +import ( + "net/http" + + "github.com/go-chi/chi" + val "github.com/go-ozzo/ozzo-validation/v4" +) + +func GetPathUserIDHash(r *http.Request) (userIdHash string, err error) { + userIdHash = chi.URLParam(r, "user_id_hash") + + err = val.Errors{ + "user_id": val.Validate(userIdHash, val.Required), + }.Filter() + return +} diff --git a/internal/service/requests/get_verification_status.go b/internal/service/requests/user_id_path.go similarity index 61% rename from internal/service/requests/get_verification_status.go rename to internal/service/requests/user_id_path.go index aa60fec..512125e 100644 --- a/internal/service/requests/get_verification_status.go +++ b/internal/service/requests/user_id_path.go @@ -2,13 +2,14 @@ package requests import ( "net/http" + "strings" "github.com/go-chi/chi" val "github.com/go-ozzo/ozzo-validation/v4" ) -func GetVerificationStatusByID(r *http.Request) (userId string, err error) { - userId = chi.URLParam(r, "user_id") +func GetPathUserID(r *http.Request) (userId string, err error) { + userId = strings.ToLower(chi.URLParam(r, "user_id")) err = val.Errors{ "user_id": val.Validate(userId, val.Required),