octoposprime / op-be-dlr

OctopOS Prime Backend Dlr Service
http://www.octoposprime.com
MIT License
8 stars 0 forks source link

UpdateDlrBase method fixed #16

Closed Maraza25 closed 3 months ago

Maraza25 commented 4 months ago

The UpdateDlrBase method has been fixed. closes #6

husamettinarabaci commented 3 months ago

Our Phase 1 should not have a non-working version. Implementing the errors in that way may be a better approach.


// UpdateDlrBase sends the given base values of the dlr to the repository of the infrastructure layer for updating base values of dlr data.

func (a *Service) UpdateDlrBase(ctx context.Context, dlr me.Dlr) (me.Dlr, error) {

  if dlr.Id.String() == "" || dlr.Id == (uuid.UUID{}) {

      // err := mo.ErrorDlrIdIsEmpty //TODO : implement ErrorDlrIdIsEmpty

      err := errors.New("Dlr Id is empty")

      dlrId, _ := ctx.Value(smodel.QueryKeyUid).(string)

      go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateDlrBase", dlrId, err.Error()))

      return me.Dlr{}, err

  }

  var dlrFilter me.DlrFilter

  dlrFilter.Id = dlr.Id

  dlrs, err := a.GetDlrsByFilter(ctx, dlrFilter)

  if err != nil {

      dlrId, _ := ctx.Value(smodel.QueryKeyUid).(string)

      go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateDlrBase", dlrId, err.Error()))

      return me.Dlr{}, err

  }

  if dlrs.TotalRows > 0 {

      dbDlr := dlrs.Dlrs[0]

      dbDlr.Tags = dlr.Tags

      dbDlr.DlrType = dlr.DlrType

      if err := a.ValidateDlr(&dbDlr); err != nil {

          dlrId, _ := ctx.Value(smodel.QueryKeyUid).(string)

          go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateDlrBase", dlrId, err.Error()))

          return me.Dlr{}, err

      }

      return a.DbPort.SaveDlr(ctx, dbDlr)

  } else {

      // return dlr, mo.ErrorDlrNotFound //TODO : implement ErrorDlrNotFound

      return dlr, errors.New("Dlr not found")

  }

}

Please remember the following: "You need to open issues for those error implementations."

It is not correct approach in golang. You can not use any strigns wth starting uppercase when creating error and you should not use any string value in code. you should add it to const or var in library.

Sddilora commented 3 months ago

Our Phase 1 should not have a non-working version. Implementing the errors in that way may be a better approach.

// UpdateDlrBase sends the given base values of the dlr to the repository of the infrastructure layer for updating base values of dlr data.

func (a *Service) UpdateDlrBase(ctx context.Context, dlr me.Dlr) (me.Dlr, error) {

    if dlr.Id.String() == "" || dlr.Id == (uuid.UUID{}) {

        // err := mo.ErrorDlrIdIsEmpty //TODO : implement ErrorDlrIdIsEmpty

        err := errors.New("Dlr Id is empty")

        dlrId, _ := ctx.Value(smodel.QueryKeyUid).(string)

        go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateDlrBase", dlrId, err.Error()))

        return me.Dlr{}, err

    }

    var dlrFilter me.DlrFilter

    dlrFilter.Id = dlr.Id

    dlrs, err := a.GetDlrsByFilter(ctx, dlrFilter)

    if err != nil {

        dlrId, _ := ctx.Value(smodel.QueryKeyUid).(string)

        go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateDlrBase", dlrId, err.Error()))

        return me.Dlr{}, err

    }

    if dlrs.TotalRows > 0 {

        dbDlr := dlrs.Dlrs[0]

        dbDlr.Tags = dlr.Tags

        dbDlr.DlrType = dlr.DlrType

        if err := a.ValidateDlr(&dbDlr); err != nil {

            dlrId, _ := ctx.Value(smodel.QueryKeyUid).(string)

            go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateDlrBase", dlrId, err.Error()))

            return me.Dlr{}, err

        }

        return a.DbPort.SaveDlr(ctx, dbDlr)

    } else {

        // return dlr, mo.ErrorDlrNotFound //TODO : implement ErrorDlrNotFound

        return dlr, errors.New("Dlr not found")

    }

}

Please remember the following: "You need to open issues for those error implementations."

It is not correct approach in golang. You can not use any strigns wth starting uppercase when creating error and you should not use any string value in code. you should add it to const or var in library.

We are working on modifying and improving one function logic in one pull request at a time. Therefore, I thought to implement those changes to the string errors to prevent "not found" errors for now.

Sddilora commented 3 months ago

Our Phase 1 should not have a non-working version. Implementing the errors in that way may be a better approach.

// UpdateDlrBase sends the given base values of the dlr to the repository of the infrastructure layer for updating base values of dlr data.

func (a *Service) UpdateDlrBase(ctx context.Context, dlr me.Dlr) (me.Dlr, error) {

    if dlr.Id.String() == "" || dlr.Id == (uuid.UUID{}) {

        // err := mo.ErrorDlrIdIsEmpty //TODO : implement ErrorDlrIdIsEmpty

        err := errors.New("Dlr Id is empty")

        dlrId, _ := ctx.Value(smodel.QueryKeyUid).(string)

        go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateDlrBase", dlrId, err.Error()))

        return me.Dlr{}, err

    }

    var dlrFilter me.DlrFilter

    dlrFilter.Id = dlr.Id

    dlrs, err := a.GetDlrsByFilter(ctx, dlrFilter)

    if err != nil {

        dlrId, _ := ctx.Value(smodel.QueryKeyUid).(string)

        go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateDlrBase", dlrId, err.Error()))

        return me.Dlr{}, err

    }

    if dlrs.TotalRows > 0 {

        dbDlr := dlrs.Dlrs[0]

        dbDlr.Tags = dlr.Tags

        dbDlr.DlrType = dlr.DlrType

        if err := a.ValidateDlr(&dbDlr); err != nil {

            dlrId, _ := ctx.Value(smodel.QueryKeyUid).(string)

            go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "UpdateDlrBase", dlrId, err.Error()))

            return me.Dlr{}, err

        }

        return a.DbPort.SaveDlr(ctx, dbDlr)

    } else {

        // return dlr, mo.ErrorDlrNotFound //TODO : implement ErrorDlrNotFound

        return dlr, errors.New("Dlr not found")

    }

}

Please remember the following: "You need to open issues for those error implementations."

It is not correct approach in golang. You can not use any strigns wth starting uppercase when creating error and you should not use any string value in code. you should add it to const or var in library.

@Maraza25 We have discussed the matter with our lead, @husamettinarabaci, and have reached a mutually agreeable solution. Please refrain from altering the error handling mechanism (err := mo.ErrorDlrIdIsEmpty - this should remain unchanged). Instead, create an issue to implement the necessary updates in the model object within the domain package. Set the implementation base to your branch, named "fix/agr/6/implement-updatedlrbase-method". Once you or another team member have made the necessary adjustments, we can merge it to your branch and then to phase 1 without encountering any errors.

Sddilora commented 3 months ago

I tried to explain the reasons with my current knowledge in this discussion: https://github.com/octoposprime/op-be-docs/discussions/60. However, I strongly believe that we should avoid using raw strings in our code, especially directly within a function body.

Maraza25 commented 3 months ago

Error messages seem to be fixed with pr in #21

Sddilora commented 3 months ago

perfecto

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣿⣿⣿⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⣿⣿⣿⣿⣷⣶⣶⣶⣤⣤⣀⡀⠀⠀ ⠀⣀⣀⣀⣀⡀⠀⢀⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡆⠀ ⢰⣿⣿⣿⣿⡇⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣅⠀ ⢸⣿⣿⣿⣿⡇⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠄ ⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠋⠀ ⣿⣿⣿⣿⣿⡇⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⠀ ⢸⣿⣿⣿⣿⡇⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠋⠀⠀ ⢸⣿⣿⣿⣿⡇⠀⠀⠙⠿⠿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠃⠀⠀⠀ ⠀⠛⠛⠛⠛⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀