Add start_date, end_date validation controller (#216)
This commit is contained in:
parent
2da5719d49
commit
a5df48c967
|
@ -298,3 +298,32 @@ func ExtractIsNotional(ctx *fiber.Ctx) (bool, error) {
|
||||||
}
|
}
|
||||||
return false, response.NewInvalidQueryParamError(ctx, "INVALID <by> QUERY PARAMETER", nil)
|
return false, response.NewInvalidQueryParamError(ctx, "INVALID <by> QUERY PARAMETER", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExtractTimeRange(ctx *fiber.Ctx) (*time.Time, *time.Time, error) {
|
||||||
|
startTime, err := ExtractTime(ctx, "start_time")
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
// check if start_time is in the future
|
||||||
|
if startTime != nil && startTime.After(time.Now()) {
|
||||||
|
return nil, nil, response.NewInvalidQueryParamError(ctx, "INVALID <start_time> QUERY PARAMETER, CANNOT BE GREATER THAN TODAYS DATE", nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
endTime, err := ExtractTime(ctx, "end_time")
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if startTime != nil && endTime != nil {
|
||||||
|
// check if start_time and end_time are equal
|
||||||
|
if startTime.Equal(*endTime) {
|
||||||
|
return nil, nil, response.NewInvalidQueryParamError(ctx, "INVALID <start_time>, <end_time> QUERY PARAMETER, <start_time> CANNOT BE EQUAL TO <end_time>", nil)
|
||||||
|
}
|
||||||
|
// check if start_time is greater than end_time
|
||||||
|
if startTime.After(*endTime) {
|
||||||
|
return nil, nil, response.NewInvalidQueryParamError(ctx, "INVALID <start_time>, <end_time> QUERY PARAMETER, <start_time> CANNOT BE GREATER THAN <end_time>", nil)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return startTime, endTime, nil
|
||||||
|
}
|
||||||
|
|
|
@ -71,11 +71,7 @@ func (c *Controller) GetLastTransactions(ctx *fiber.Ctx) error {
|
||||||
// @Failure 500
|
// @Failure 500
|
||||||
// @Router /api/v1/x-chain-activity [get]
|
// @Router /api/v1/x-chain-activity [get]
|
||||||
func (c *Controller) GetChainActivity(ctx *fiber.Ctx) error {
|
func (c *Controller) GetChainActivity(ctx *fiber.Ctx) error {
|
||||||
startTime, err := middleware.ExtractTime(ctx, "start_time")
|
startTime, endTime, err := middleware.ExtractTimeRange(ctx)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
endTime, err := middleware.ExtractTime(ctx, "end_time")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue