[API] Remove redundant checks (#150)

Remove redundant nil checks in `api/handlers/governor/repository.go`.
This commit is contained in:
agodnic 2023-02-10 15:57:11 -03:00 committed by GitHub
parent e2195d420e
commit e85fa82784
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 0 additions and 26 deletions

View File

@ -77,9 +77,6 @@ func (q *GovernorQuery) toBSON() *bson.D {
// FindGovConfigurations get a list of *GovConfig.
func (r *Repository) FindGovConfigurations(ctx context.Context, q *GovernorQuery) ([]*GovConfig, error) {
if q == nil {
q = QueryGovernor()
}
sort := bson.D{{Key: q.SortBy, Value: q.GetSortInt()}}
projection := bson.D{
{Key: "createdAt", Value: 1},
@ -110,9 +107,6 @@ func (r *Repository) FindGovConfigurations(ctx context.Context, q *GovernorQuery
// FindGovConfiguration get a *GovConfig. The q parameter define the filter to apply to the query.
func (r *Repository) FindGovConfiguration(ctx context.Context, q *GovernorQuery) (*GovConfig, error) {
if q == nil {
return nil, errs.ErrMalformedQuery
}
var govConfig GovConfig
projection := bson.D{
{Key: "createdAt", Value: 1},
@ -138,9 +132,6 @@ func (r *Repository) FindGovConfiguration(ctx context.Context, q *GovernorQuery)
// FindGovernorStatus get a list of *GovStatus.
func (r *Repository) FindGovernorStatus(ctx context.Context, q *GovernorQuery) ([]*GovStatus, error) {
if q == nil {
q = QueryGovernor()
}
sort := bson.D{{Key: q.SortBy, Value: q.GetSortInt()}}
projection := bson.D{
{Key: "createdAt", Value: 1},
@ -169,9 +160,6 @@ func (r *Repository) FindGovernorStatus(ctx context.Context, q *GovernorQuery) (
// FindOneGovernorStatus get a *GovStatus. The q parameter define the filter to apply to the query.
func (r *Repository) FindOneGovernorStatus(ctx context.Context, q *GovernorQuery) (*GovStatus, error) {
if q == nil {
return nil, errs.ErrMalformedQuery
}
var govConfig GovStatus
projection := bson.D{
{Key: "createdAt", Value: 1},

View File

@ -35,9 +35,6 @@ func NewRepository(db *mongo.Database, logger *zap.Logger) *Repository {
// Find get a list of ObservationDoc pointers.
// The input parameter [q *ObservationQuery] define the filters to apply in the query.
func (r *Repository) Find(ctx context.Context, q *ObservationQuery) ([]*ObservationDoc, error) {
if q == nil {
q = Query()
}
sort := bson.D{{q.SortBy, q.GetSortInt()}}
cur, err := r.collections.observations.Find(ctx, q.toBSON(), options.Find().SetLimit(q.Limit).SetSkip(q.Skip).SetSort(sort))
if err != nil {
@ -60,9 +57,6 @@ func (r *Repository) Find(ctx context.Context, q *ObservationQuery) ([]*Observat
// Find get ObservationDoc pointer.
// The input parameter [q *ObservationQuery] define the filters to apply in the query.
func (r *Repository) FindOne(ctx context.Context, q *ObservationQuery) (*ObservationDoc, error) {
if q == nil {
return nil, errs.ErrMalformedQuery
}
var obs ObservationDoc
err := r.collections.observations.FindOne(ctx, q.toBSON()).Decode(&obs)
if err != nil {

View File

@ -43,10 +43,6 @@ func NewRepository(db *mongo.Database, logger *zap.Logger) *Repository {
// The input parameter [q *VaaQuery] define the filters to apply in the query.
func (r *Repository) Find(ctx context.Context, q *VaaQuery) ([]*VaaDoc, error) {
if q == nil {
q = Query()
}
var err error
var cur *mongo.Cursor
if q.chainId == vaa.ChainIDPythNet {
@ -218,10 +214,6 @@ func (r *Repository) FindVaasWithPayload(
// GetVaaCount get a count of vaa by chainID.
func (r *Repository) GetVaaCount(ctx context.Context, q *VaaQuery) ([]*VaaStats, error) {
if q == nil {
q = Query()
}
cur, err := r.collections.vaaCount.Find(ctx, q.toBSON(), q.findOptions())
if err != nil {
requestID := fmt.Sprintf("%v", ctx.Value("requestid"))