Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declouple Controller from MongoDB #8

Open
marcosvidolin opened this issue Jan 19, 2023 · 3 comments
Open

Declouple Controller from MongoDB #8

marcosvidolin opened this issue Jan 19, 2023 · 3 comments

Comments

@marcosvidolin
Copy link

marcosvidolin commented Jan 19, 2023

Hi,

We have a MongoDB dependency in the controller. You can see here: https://github.com/amitshekhariitbhu/go-backend-clean-architecture/blob/main/api/controller/task_controller.go#L8
Maybe we should consider move the code bellow to other layer:

task.ID = primitive.NewObjectID()
task.UserID, err = primitive.ObjectIDFromHex(userID)

What's your thoughts?

@amitshekhariitbhu
Copy link
Owner

Hi @marcosvidolin

Your point is valid. A few more developers also suggested making this change. I shall do it.

Thanks

@ZeusMode
Copy link

Hi @marcosvidolin

I understood your suggestion but makes me wonder how can we properly handle errors like this to not be generic InternalServerError?

Sorry for the late response here, I just found this project

@marcosvidolin
Copy link
Author

I would recommend moving this code to the MongoDB repository and also suggest creating a custom error in the following manner:

task, err := primitive.ObjectIDFromHex(userID)
if err != nil {
    return nil, ErrMyCustonIDGeneration("error message") // change the error name ;)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants