Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor gitBinaryMaskParam function #2634

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
85404b4
WIP
May 15, 2023
797e72f
WIP
May 15, 2023
c38f586
WIP
May 15, 2023
b920022
WIP
May 15, 2023
e6a5b9a
WIP
May 15, 2023
0222513
WIP
May 15, 2023
9c440cc
Merge branch 'main' into issue-2465-document-params-functions
May 15, 2023
76a67b8
WIP
May 16, 2023
c0d4b22
Merge remote-tracking branch 'origin/issue-2465-document-params-funct…
May 16, 2023
fa3aa04
WIP
May 16, 2023
7dcbf6a
WIP
May 16, 2023
5bdccc2
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
efa129a
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
931f091
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
38dc72b
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
e43473d
Merge branch 'main' into issue-2465-document-params-functions
May 17, 2023
0646a22
Merge branch 'issue-2465-document-params-functions' of https://github…
May 17, 2023
b760653
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
3bbe433
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
df743c8
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 17, 2023
3105a6b
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 18, 2023
95353cb
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 18, 2023
05dd793
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 18, 2023
a04e11d
Merge branch 'main' into issue-2465-document-params-functions
May 22, 2023
aea7ad4
WIP
May 22, 2023
d9f4a21
WIP
May 22, 2023
1f4a61e
WIP
May 22, 2023
ce2eb0d
WIP
May 22, 2023
b04cb3f
Merge branch 'main' into issue-2465-document-params-functions
mergify[bot] May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
Dmitry committed May 22, 2023
commit aea7ad448bbf3a94739a19f19a6ec346438da26f
29 changes: 0 additions & 29 deletions internal/handlers/common/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import (
)

// GetRequiredParam returns doc's value for key.
//
// It returns command errors with the following codes:
// - ErrBadValue if the document value is missing;
// - ErrBadValue if the document value is not of the expected type.
func GetRequiredParam[T types.Type](doc *types.Document, key string) (T, error) {
var zero T
w84thesun marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -50,8 +46,6 @@ func GetRequiredParam[T types.Type](doc *types.Document, key string) (T, error)
}

// GetOptionalParam returns doc's value for key or default value for missing parameter.
//
// It returns command error with the ErrTypeMismatch code if the document value is not of the expected type.
func GetOptionalParam[T types.Type](doc *types.Document, key string, defaultValue T) (T, error) {
v, _ := doc.Get(key)
if v == nil {
Expand All @@ -73,8 +67,6 @@ func GetOptionalParam[T types.Type](doc *types.Document, key string, defaultValu
}

// GetOptionalNullParam returns doc's value for key, default value for missing parameter or null.
//
// It returns command error with ErrTypeMismatch code if the document value is not of the expected type.
func GetOptionalNullParam[T types.Type](doc *types.Document, key string, defaultValue T) (T, error) {
v, err := GetOptionalParam(doc, key, defaultValue)
if err != nil {
Expand All @@ -95,8 +87,6 @@ func GetOptionalNullParam[T types.Type](doc *types.Document, key string, default
// if !ok {
// return commonerrors.NewCommandErrorMsg(commonerrors.ErrBadValue, "expected document")
// }
//
// It returns command error with ErrBadValue code if the value is not of the expected type.
func AssertType[T types.Type](value any) (T, error) {
res, ok := value.(T)
if !ok {
Expand All @@ -108,13 +98,6 @@ func AssertType[T types.Type](value any) (T, error) {
}

// GetLimitStageParam returns $limit stage argument from the provided value.
//
// It returns command errors with the following codes:
// - ErrStageLimitInvalidArg if the value type is not [int, long, double];
// - ErrStageLimitInvalidArg if the value is not a whole number or is NaN;
// - ErrStageLimitInvalidArg if the value is not in the range of int64;
// - ErrStageLimitInvalidArg if the value is negative;
// - ErrStageLimitZero if the value is zero.
func GetLimitStageParam(value any) (int64, error) {
limit, err := commonparams.GetWholeNumberParam(value)

Expand Down Expand Up @@ -161,12 +144,6 @@ func GetLimitStageParam(value any) (int64, error) {
}

// GetSkipStageParam returns $skip stage argument from the provided value.
//
// It returns command errors with the following codes:
// - ErrStageSkipBadValue if the value type is not [int, long, double];
// - ErrStageSkipBadValue if the value is not a whole number or is NaN;
// - ErrStageSkipBadValue if the value is not in the range of int64;
// - ErrStageSkipBadValue if the value is less than zero.
func GetSkipStageParam(value any) (int64, error) {
limit, err := commonparams.GetWholeNumberParam(value)

Expand Down Expand Up @@ -204,12 +181,6 @@ func GetSkipStageParam(value any) (int64, error) {

// getBinaryMaskParam matches value type, returning bit mask and error if match failed.
// Possible values are: position array ([1,3,5] == 010101), whole number value and types.Binary value.
//
// It returns command errors with the following codes:
// - ErrBadValue if positional argument is not a whole number of type [int, long, double];
// - ErrBadValue if positional argument is negative;
// - ErrFailedToParse if bitmask argument is not a whole number or negative;
// - ErrBadValue if the type of the value is not [int, long, double, binary, array];
func getBinaryMaskParam(operator string, mask any) (uint64, error) {
var bitmask uint64

Expand Down
12 changes: 1 addition & 11 deletions internal/handlers/commonparams/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ func GetWholeNumberParam(value any) (int64, error) {

// getWholeParamStrict validates the given value for find and count commands.
//
// # If the value is valid, it returns its int64 representation
//
// It returns command errors with the following codes:
// - ErrTypeMismatch if the value is not of types [int, long, double, null];
// - ErrValueNegative if the value is negative;
// If the value is valid, it returns its int64 representation
func getWholeParamStrict(command string, param string, value any) (int64, error) {
whole, err := GetWholeNumberParam(value)
if err != nil {
Expand Down Expand Up @@ -130,12 +126,6 @@ func getWholeParamStrict(command string, param string, value any) (int64, error)
}

// getOptionalPositiveNumber returns doc's value for key.
//
// It returns command errors with the following codes:
// - ErrBadValue if value is not a number;
// - ErrBadValue if value is not of types [int, long];
// - ErrBadValue if value exceeds int32 range;
// - ErrBadValue if value is negative;
func getOptionalPositiveNumber(key string, value any) (int64, error) {
whole, err := GetWholeNumberParam(value)
if err != nil {
Expand Down