Skip to content

Backend state consolidation and db function refactoring#264

Merged
MichaelZhao21 merged 5 commits intomasterfrom
refactor/state-db
Apr 23, 2025
Merged

Backend state consolidation and db function refactoring#264
MichaelZhao21 merged 5 commits intomasterfrom
refactor/state-db

Conversation

@MichaelZhao21
Copy link
Contributor

Description

  • Refactor state (logging, comps, db, etc) to be in a state object for passing into routes
  • Refactor database functions so that ctx is more consistent
  • Wrap database calls with transactions where previously needed
  • Update go to 1.23
  • Fix air installation location for dev dockerfile

Fixes #155

Fixes #97

Type of Change

Delete options that do not apply:

  • Refactor (code changes that doesn't affect functionality)

Is this a breaking change?

  • Yes
  • No

@MichaelZhao21 MichaelZhao21 requested a review from Copilot April 23, 2025 00:21
@vercel
Copy link

vercel bot commented Apr 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
jury ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 23, 2025 0:39am

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the backend by consolidating state into a unified object that’s passed into routes and refactors database functions to improve transaction and context handling. Key changes include:

  • Introducing a State struct to encapsulate db, logger, clock, comparisons, and limiter components.
  • Updating database function calls and transaction wrappers to use a consistent context.
  • Adjusting error handling and logging messages to reflect the new structure.

Reviewed Changes

Copilot reviewed 16 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
server/router/state.go Introduces the new State object for shared dependencies.
server/router/project.go Updates route handlers to use GetState(ctx) and transaction calls.
server/router/init.go Consolidates context variables by creating and attaching State.
server/router/admin.go Refactors admin routes to use the unified State for logging/db access.
Other server/database and server/judging files Refactors various database functions to accept context and transactions.
Files not reviewed (3)
  • Dockerfile: Language not supported
  • dev.Dockerfile: Language not supported
  • server/go.mod: Language not supported
Comments suppressed due to low confidence (2)

server/router/project.go:56

  • The error message refers to 'judges' even though the operation inserts projects. Please update the message to 'error inserting projects into database'.
ctx.JSON(http.StatusInternalServerError, gin.H{"error": "error inserting judges into database: " + err.Error()})

server/judging/judging_flow.go:140

  • [nitpick] The function name 'FindAvaliableItems' contains a spelling error. Consider renaming it to 'FindAvailableItems' for clarity.
func FindAvaliableItems(db *mongo.Database, ctx context.Context, judge *models.Judge, comps *Comparisons) ([]*models.Project, error) {

@MichaelZhao21 MichaelZhao21 merged commit 46112de into master Apr 23, 2025
2 checks passed
@MichaelZhao21 MichaelZhao21 deleted the refactor/state-db branch April 23, 2025 00:40
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.

Refactor all backend database functions to include ctx for transactions Clean up golang dependencies

2 participants