Skip to content

Refactor Building functions into Model#1715

Open
AngelsandDevsLOL wants to merge 4 commits into
Courseography:masterfrom
AngelsandDevsLOL:refactor-building-into-Model
Open

Refactor Building functions into Model#1715
AngelsandDevsLOL wants to merge 4 commits into
Courseography:masterfrom
AngelsandDevsLOL:refactor-building-into-Model

Conversation

@AngelsandDevsLOL
Copy link
Copy Markdown
Contributor

@AngelsandDevsLOL AngelsandDevsLOL commented May 24, 2026

Proposed Changes

Moves Building-related functions out of Database/Tables.hs and WebParsing/ArtSciParser.hs into a new Models/Building.hs, following a similar pattern as Models/Course.hs and Models/Meeting.hs.

buildingsCSV, parseBuildings, getBuildingsFromCSV are moved from WebParsing/ArtSciParser.hs.
getBuilding, buildTime, and buildTimes are moved from Database/Tables.hs.
All imports using the functions were updated to find the corresponding functions in Models/Building.hs. This includes the following files: Models/Meeting.hs, Controllers/Timetable.hs, and WebParsing/UtsgJsonParser.hs.
...

Screenshots of your changes (if applicable)

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

When I moved getBuilding from Database/Tables.hs, I noticed that buildTime used getBuilding as a helper function. I wasn't sure whether I should move buildTime to Models/Building.hs as well because it seems more related to the Time datatype than the Building datatype. However, there was no Models/Time.hs, and by leaving the method in Database/Tables.hs, then using getBuilding would need to import the method from Models/Building.hs. However, Models/Building.hs must import Database/Tables.hs because it needs to reference the Building datatype. Thus, I decided to move buildTime inside Models/Building.hs, even though it feels a little bit weird.

buildTimes was moved along with buildTime, because I thought it would be better to keep these two functions together. However, I think keeping it in Database/Tables.hs isn't a problem.

@AngelsandDevsLOL AngelsandDevsLOL force-pushed the refactor-building-into-Model branch from 38f70c3 to 6fbc319 Compare May 24, 2026 16:16
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 0

Coverage decreased (-0.01%) to 58.267%

Details

  • Coverage decreased (-0.01%) from the base build.
  • Patch coverage: 20 uncovered changes across 1 file (20 of 40 lines covered, 50.0%).
  • 28 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
app/Models/Building.hs 40 20 50.0%

Coverage Regressions

28 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
app/WebParsing/ArtSciParser.hs 28 0.0%

Coverage Stats

Coverage Status
Relevant Lines: 3941
Covered Lines: 2355
Line Coverage: 59.76%
Relevant Branches: 964
Covered Branches: 503
Branch Coverage: 52.18%
Branches in Coverage %: Yes
Coverage Strength: 163.67 hits per line

💛 - Coveralls

@AngelsandDevsLOL AngelsandDevsLOL marked this pull request as ready for review May 24, 2026 17:28
Copy link
Copy Markdown
Contributor

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

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

@AngelsandDevsLOL nice work. In addition to the inline comment I left, please take this opportunity to also add new tests for parseBuildings. This will involve creating tests that use the database, so is a nice extension of the previous testing work you've done.

Comment thread app/Models/Building.hs
Just entBuilding -> return $ Just (entityVal entBuilding)

-- | Convert a Times record into a Time by resolving room codes to Buildings
buildTime :: Times -> SqlPersistM Time
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Leave buildTime and buildTimes in the Tables.hs module. You're correct that there's no Time model, which is something we can improve on later.

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