Skip to content

fix: allow clearing contest end/start time on edit - #239

Merged
HermanPlay merged 3 commits into
masterfrom
fix/contest-edit-clear-endtime
Aug 11, 2026
Merged

fix: allow clearing contest end/start time on edit#239
HermanPlay merged 3 commits into
masterfrom
fix/contest-edit-clear-endtime

Conversation

@HermanPlay

Copy link
Copy Markdown
Member

Bug

Editing a contest to remove its end time ({"endAt": null}) did not clear the DB value. EditContest used *time.Time with omitempty; an explicit JSON null decoded to a nil pointer that was indistinguishable from an absent field, so the service skipped the update.

Fix

New schemas.OptionalTime type with presence tracking (Set flag + Value) and custom UnmarshalJSON/MarshalJSON:

  • key absent → Set=false, field not updated
  • nullSet=true, Value=nil, column set to NULL
  • value → Set=true, Value set

EditContest.StartAt/EndAt switched from *time.Time to value-type OptionalTime (value type required so null triggers UnmarshalJSON; verified a pointer-to-pointer field does not). Service writes end_at/start_at into the update map when Set, and GORM Updates applies nil as NULL (verified).

Also fixed the dead updateModel helper for the same semantics.

Tests

  • TestContestServiceEdit_ClearEndAt — null EndAt lands in update map as nil
  • TestContestServiceEdit_KeepEndAtWhenAbsent — absent EndAt not in update map
  • route test: raw {"endAt":null} decodes to Set=true,Value=nil

All packages + lint + pre-commit green.

EditContest used *time.Time with omitempty; an explicit JSON null for
endAt/startAt decoded to a nil pointer indistinguishable from an absent
field, so the service skipped it and the DB value was never cleared.

Introduce OptionalTime (Set flag + Value) with custom UnmarshalJSON:
- absent key -> Set=false, not updated
- null -> Set=true, Value=nil, column set to NULL
- value -> Set=true, Value set

Service now writes end_at/start_at into the update map when Set, and GORM
Updates applies nil as NULL.
@HermanPlay
HermanPlay requested a review from a team as a code owner August 11, 2026 22:06
Apply the presence-tracking OptionalTime to AddTaskToContest so explicit
null for startAt/endAt can clear a task's times (currently null is
indistinguishable from absent and falls back to contest defaults).
@HermanPlay
HermanPlay merged commit 7dada2f into master Aug 11, 2026
6 checks passed
@HermanPlay
HermanPlay deleted the fix/contest-edit-clear-endtime branch August 11, 2026 22:19
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.

1 participant