[API] Remove redundant checks (#150)
Remove redundant nil checks in `api/handlers/governor/repository.go`.
This commit is contained in:
parent
e2195d420e
commit
e85fa82784
|
@ -77,9 +77,6 @@ func (q *GovernorQuery) toBSON() *bson.D {
|
||||||
|
|
||||||
// FindGovConfigurations get a list of *GovConfig.
|
// FindGovConfigurations get a list of *GovConfig.
|
||||||
func (r *Repository) FindGovConfigurations(ctx context.Context, q *GovernorQuery) ([]*GovConfig, error) {
|
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()}}
|
sort := bson.D{{Key: q.SortBy, Value: q.GetSortInt()}}
|
||||||
projection := bson.D{
|
projection := bson.D{
|
||||||
{Key: "createdAt", Value: 1},
|
{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.
|
// 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) {
|
func (r *Repository) FindGovConfiguration(ctx context.Context, q *GovernorQuery) (*GovConfig, error) {
|
||||||
if q == nil {
|
|
||||||
return nil, errs.ErrMalformedQuery
|
|
||||||
}
|
|
||||||
var govConfig GovConfig
|
var govConfig GovConfig
|
||||||
projection := bson.D{
|
projection := bson.D{
|
||||||
{Key: "createdAt", Value: 1},
|
{Key: "createdAt", Value: 1},
|
||||||
|
@ -138,9 +132,6 @@ func (r *Repository) FindGovConfiguration(ctx context.Context, q *GovernorQuery)
|
||||||
|
|
||||||
// FindGovernorStatus get a list of *GovStatus.
|
// FindGovernorStatus get a list of *GovStatus.
|
||||||
func (r *Repository) FindGovernorStatus(ctx context.Context, q *GovernorQuery) ([]*GovStatus, error) {
|
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()}}
|
sort := bson.D{{Key: q.SortBy, Value: q.GetSortInt()}}
|
||||||
projection := bson.D{
|
projection := bson.D{
|
||||||
{Key: "createdAt", Value: 1},
|
{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.
|
// 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) {
|
func (r *Repository) FindOneGovernorStatus(ctx context.Context, q *GovernorQuery) (*GovStatus, error) {
|
||||||
if q == nil {
|
|
||||||
return nil, errs.ErrMalformedQuery
|
|
||||||
}
|
|
||||||
var govConfig GovStatus
|
var govConfig GovStatus
|
||||||
projection := bson.D{
|
projection := bson.D{
|
||||||
{Key: "createdAt", Value: 1},
|
{Key: "createdAt", Value: 1},
|
||||||
|
|
|
@ -35,9 +35,6 @@ func NewRepository(db *mongo.Database, logger *zap.Logger) *Repository {
|
||||||
// Find get a list of ObservationDoc pointers.
|
// Find get a list of ObservationDoc pointers.
|
||||||
// The input parameter [q *ObservationQuery] define the filters to apply in the query.
|
// The input parameter [q *ObservationQuery] define the filters to apply in the query.
|
||||||
func (r *Repository) Find(ctx context.Context, q *ObservationQuery) ([]*ObservationDoc, error) {
|
func (r *Repository) Find(ctx context.Context, q *ObservationQuery) ([]*ObservationDoc, error) {
|
||||||
if q == nil {
|
|
||||||
q = Query()
|
|
||||||
}
|
|
||||||
sort := bson.D{{q.SortBy, q.GetSortInt()}}
|
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))
|
cur, err := r.collections.observations.Find(ctx, q.toBSON(), options.Find().SetLimit(q.Limit).SetSkip(q.Skip).SetSort(sort))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -60,9 +57,6 @@ func (r *Repository) Find(ctx context.Context, q *ObservationQuery) ([]*Observat
|
||||||
// Find get ObservationDoc pointer.
|
// Find get ObservationDoc pointer.
|
||||||
// The input parameter [q *ObservationQuery] define the filters to apply in the query.
|
// The input parameter [q *ObservationQuery] define the filters to apply in the query.
|
||||||
func (r *Repository) FindOne(ctx context.Context, q *ObservationQuery) (*ObservationDoc, error) {
|
func (r *Repository) FindOne(ctx context.Context, q *ObservationQuery) (*ObservationDoc, error) {
|
||||||
if q == nil {
|
|
||||||
return nil, errs.ErrMalformedQuery
|
|
||||||
}
|
|
||||||
var obs ObservationDoc
|
var obs ObservationDoc
|
||||||
err := r.collections.observations.FindOne(ctx, q.toBSON()).Decode(&obs)
|
err := r.collections.observations.FindOne(ctx, q.toBSON()).Decode(&obs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -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.
|
// The input parameter [q *VaaQuery] define the filters to apply in the query.
|
||||||
func (r *Repository) Find(ctx context.Context, q *VaaQuery) ([]*VaaDoc, error) {
|
func (r *Repository) Find(ctx context.Context, q *VaaQuery) ([]*VaaDoc, error) {
|
||||||
|
|
||||||
if q == nil {
|
|
||||||
q = Query()
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
var cur *mongo.Cursor
|
var cur *mongo.Cursor
|
||||||
if q.chainId == vaa.ChainIDPythNet {
|
if q.chainId == vaa.ChainIDPythNet {
|
||||||
|
@ -218,10 +214,6 @@ func (r *Repository) FindVaasWithPayload(
|
||||||
// GetVaaCount get a count of vaa by chainID.
|
// GetVaaCount get a count of vaa by chainID.
|
||||||
func (r *Repository) GetVaaCount(ctx context.Context, q *VaaQuery) ([]*VaaStats, error) {
|
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())
|
cur, err := r.collections.vaaCount.Find(ctx, q.toBSON(), q.findOptions())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
requestID := fmt.Sprintf("%v", ctx.Value("requestid"))
|
requestID := fmt.Sprintf("%v", ctx.Value("requestid"))
|
||||||
|
|
Loading…
Reference in New Issue