[GH-ISSUE #8] Declouple Controller from MongoDB #6

Open
opened 2026-03-01 14:36:45 +03:00 by kerem · 3 comments
Owner

Originally created by @marcosvidolin on GitHub (Jan 19, 2023).
Original GitHub issue: https://github.com/amitshekhariitbhu/go-backend-clean-architecture/issues/8

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?

Originally created by @marcosvidolin on GitHub (Jan 19, 2023). Original GitHub issue: https://github.com/amitshekhariitbhu/go-backend-clean-architecture/issues/8 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: ```go task.ID = primitive.NewObjectID() task.UserID, err = primitive.ObjectIDFromHex(userID) ``` What's your thoughts?
Author
Owner

@amitshekhariitbhu commented on GitHub (Jan 19, 2023):

Hi @marcosvidolin

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

Thanks

<!-- gh-comment-id:1397010311 --> @amitshekhariitbhu commented on GitHub (Jan 19, 2023): Hi @marcosvidolin Your point is valid. A few more developers also suggested making this change. I shall do it. Thanks
Author
Owner

@ZeusMode commented on GitHub (Aug 24, 2023):

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

<!-- gh-comment-id:1692171254 --> @ZeusMode commented on GitHub (Aug 24, 2023): 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
Author
Owner

@marcosvidolin commented on GitHub (Aug 29, 2023):

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 ;)
}
<!-- gh-comment-id:1697941269 --> @marcosvidolin commented on GitHub (Aug 29, 2023): > I would recommend moving this code to the MongoDB repository and also suggest creating a custom error in the following manner: ```go task, err := primitive.ObjectIDFromHex(userID) if err != nil { return nil, ErrMyCustonIDGeneration("error message") // change the error name ;) } ```
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/go-backend-clean-architecture#6
No description provided.