Skip to content

Refactoring the Graph Methods #1566

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

Merged

Conversation

matt-dahlgren
Copy link
Contributor

@matt-dahlgren matt-dahlgren commented Jun 4, 2025

Proposed Changes

In the process of refactoring Courseography into a MVC architecture I Moved the getGraph (from app/Database/CourseQueries) and getGraphJSON (from app/Controllers/Graph) methods into a new module Graph.hs within app/Models. I also updated calls to these functions to reference the correct file and introduced the new module to the courseography.cabal file.

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality) X
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.
  • I have updated the project Changelog (this is required for all changes).

After opening your pull request:

  • I have verified that the CircleCI checks have passed.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

@coveralls
Copy link

coveralls commented Jun 4, 2025

Pull Request Test Coverage Report for Build 7d325cb3-a229-44a6-87a3-c0e37be35244

Details

  • 0 of 50 (0.0%) changed or added relevant lines in 2 files are covered.
  • 5 unchanged lines in 1 file lost coverage.
  • Overall coverage remained the same at 32.165%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app/Controllers/Graph.hs 0 9 0.0%
app/Models/Graph.hs 0 41 0.0%
Files with Coverage Reduction New Missed Lines %
app/Database/CourseInsertion.hs 5 0.0%
Totals Coverage Status
Change from base Build 0e0a2aa9-c01b-48dd-acdb-e0a0312e05be: 0.0%
Covered Lines: 640
Relevant Lines: 1915

💛 - Coveralls

insertMany_ $ map (\text -> text {textGraph = gId}) texts
insertMany_ $ map (\shape -> shape {shapeGraph = gId}) shapes
insertMany_ $ map (\path -> path {pathGraph = gId}) paths
-- Commented out function from before refactoring process to MVC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can delete this comment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matt-dahlgren I think you missed this part of my last review (about deleting the comment in the source code). Please delete this before I merge in this PR (everything else looks great).

return (Just response)

-- | Inserts SVG graph data into Texts, Shapes, and Paths tables
saveGraphJSON :: ServerPart Response
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You did what I asked you to do, but now that I'm looking at the code more closely, I realized that the best approach was to actually to split up this function into two: saveGraphJSON should go into the Controllers.Graph module, while the main helper insertGraph should go into here. This is the cleanest way to adhere to the MVC architecture: basically, any function with a ServerPart Response type should really be a controller function, while the part that interacts with the database is categorized as a model.

By the way, while you're at it you can change the type of insertGraph to insertGraph :: T.Text -> SvgJSON -> SqlPersistM (); that is, the components of the SvgJSON don't need to be unpacked in the controller function, they can be unpacked in the model function only.

@david-yz-liu david-yz-liu merged commit 8613c18 into Courseography:master Jun 13, 2025
3 checks passed
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

Successfully merging this pull request may close these issues.

3 participants