refactor(resource-app)[Backend] Refactor Resource Domain to Domain-Driven Design (DDD)#51
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request completes a significant refactor of the Resource domain, aligning it with Domain-Driven Design (DDD) principles. The primary goal was to introduce a clear separation of concerns by establishing a dedicated repository layer, thereby decoupling the resource service from direct GORM interactions. This change enhances maintainability and testability without altering the external behavior of the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request does a great job of introducing a repository layer to abstract data access for the resource domain, which is a foundational step in a Domain-Driven Design refactor. The separation of concerns is much clearer now.
My review includes a couple of suggestions to further align the implementation with DDD principles. Specifically, I've pointed out opportunities to move business logic from the HTTP handlers into the newly created resource.Service. This will make the service layer more meaningful by having it orchestrate the domain logic (like generating IDs), rather than just acting as a simple pass-through to the repository. This will strengthen the domain layer and make the handlers cleaner.
Overall, this is a solid refactoring. Addressing the feedback will help complete the transition to a more robust, domain-centric design.
There was a problem hiding this comment.
Pull request overview
This PR completes the DDD refactor for the Resource bounded context by introducing a repository + service layer in the resource package and rewiring the server to use it, while migrating the Resource model out of internal/models.
Changes:
- Introduces
resource.Repository+resource.GormRepositoryand refactorsresource.Serviceto depend on the repository interface. - Moves resource CRUD HTTP handlers into the
resourcepackage and wires/api/resourcesroutes to the new service incmd/server/main.go. - Migrates the
Resourcemodel frominternal/modelstoresourceand updates DB auto-migration + booking-time row-locking to use the new model.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| resource-app/backend/resource/services.go | Adds Service that delegates to a repository interface. |
| resource-app/backend/resource/repository.go | Adds repository interface and GORM-backed implementation. |
| resource-app/backend/resource/models.go | Defines the resource.Resource GORM model. |
| resource-app/backend/resource/handlers.go | Implements /api/resources handlers using *resource.Service. |
| resource-app/backend/internal/store/db_store.go | Removes resource CRUD from DBStore; updates booking locking to use resource.Resource; stats code commented out. |
| resource-app/backend/internal/models/models.go | Removes models.Resource (resource model moved to resource package). |
| resource-app/backend/internal/db/db.go | Auto-migrates resource.Resource instead of models.Resource. |
| resource-app/backend/internal/api/handlers.go | Removes legacy resource handlers; stats handler commented out. |
| resource-app/backend/cmd/server/main.go | Composes GormRepository -> Service -> resource handlers; stats route commented out. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
…pository layers refactor(resource): remove redundant comment from Resource model
8a1500f to
b00da67
Compare
refactor(resource): remove redundant resource creation logic in HandleAddResource
Overview
This PR completes the Domain-Driven Design (DDD) refactor for the Resource bounded context. It introduces a proper repository layer, decouples
resource.Servicefrom GORM, and keeps existing/api/resourcesbehavior unchanged.What Changed
✅ Core Refactor
resource.Repositoryinterface to abstract data accessGormRepositoryas the concrete GORM-backed repositoryresource.Serviceto depend on the repository interface instead of*gorm.DB✅ Route/Handler Wiring
cmd/server/main.goto compose:GormRepository→resource.Service→ handler functions/api/resourceshandler signatures unchanged✅ Database Migration
internal/db/db.goto auto-migrateresource.ResourceHow to Test Locally
cd resource-app/backend go run ./cmd/server/main.goGET http://localhost:8082/api/resourcesPOST http://localhost:8082/api/resourcesPUT http://localhost:8082/api/resources/{id}DELETE http://localhost:8082/api/resources/{id}Closes #50