limit the number of orders that someone can add to a query (3)

This commit is contained in:
Dawid Wysokiński 2021-05-09 11:59:37 +02:00
parent 89ec5586f0
commit a7308c1080
8 changed files with 18 additions and 0 deletions

View File

@ -3,4 +3,5 @@ package profession
const (
FetchDefaultLimit = 100
MaxNameLength = 100
MaxOrders = 3
)

View File

@ -64,6 +64,10 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg *profession.FetchConfig) ([
Count: true,
}
}
if len(cfg.Sort) > profession.MaxOrders {
cfg.Sort = cfg.Sort[0:profession.MaxOrders]
}
return ucase.professionRepository.Fetch(ctx, cfg)
}

View File

@ -3,4 +3,5 @@ package qualification
const (
FetchDefaultLimit = 100
MaxNameLength = 200
MaxOrders = 3
)

View File

@ -64,6 +64,9 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg *qualification.FetchConfig)
Count: true,
}
}
if len(cfg.Sort) > qualification.MaxOrders {
cfg.Sort = cfg.Sort[0:qualification.MaxOrders]
}
return ucase.qualificationRepository.Fetch(ctx, cfg)
}

View File

@ -4,4 +4,5 @@ const (
FetchDefaultLimit = 100
FetchMaxLimit = 500
TestMaxLimit = 40
MaxOrders = 3
)

View File

@ -3,6 +3,7 @@ package usecase
import (
"context"
"github.com/pkg/errors"
"github.com/zdam-egzamin-zawodowy/backend/internal/models"
"github.com/zdam-egzamin-zawodowy/backend/internal/question"
)
@ -72,6 +73,9 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg *question.FetchConfig) ([]*
if cfg.Limit > question.FetchMaxLimit {
cfg.Limit = question.FetchMaxLimit
}
if len(cfg.Sort) > question.MaxOrders {
cfg.Sort = cfg.Sort[0:question.MaxOrders]
}
return ucase.questionRepository.Fetch(ctx, cfg)
}

View File

@ -6,4 +6,5 @@ const (
MaxDisplayNameLength = 32
MinPasswordLength = 6
MaxPasswordLength = 64
MaxOrders = 3
)

View File

@ -81,6 +81,9 @@ func (ucase *usecase) Fetch(ctx context.Context, cfg *user.FetchConfig) ([]*mode
if cfg.Limit > user.FetchMaxLimit || cfg.Limit <= 0 {
cfg.Limit = user.FetchMaxLimit
}
if len(cfg.Sort) > user.MaxOrders {
cfg.Sort = cfg.Sort[0:user.MaxOrders]
}
return ucase.userRepository.Fetch(ctx, cfg)
}