fix: allow clearing contest end/start time on edit - #239
Merged
Conversation
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.
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Editing a contest to remove its end time (
{"endAt": null}) did not clear the DB value.EditContestused*time.Timewithomitempty; an explicit JSONnulldecoded to a nil pointer that was indistinguishable from an absent field, so the service skipped the update.Fix
New
schemas.OptionalTimetype with presence tracking (Setflag +Value) and customUnmarshalJSON/MarshalJSON:Set=false, field not updatednull→Set=true,Value=nil, column set toNULLSet=true,ValuesetEditContest.StartAt/EndAtswitched from*time.Timeto value-typeOptionalTime(value type required sonulltriggersUnmarshalJSON; verified a pointer-to-pointer field does not). Service writesend_at/start_atinto the update map whenSet, and GORMUpdatesappliesnilas NULL (verified).Also fixed the dead
updateModelhelper for the same semantics.Tests
TestContestServiceEdit_ClearEndAt— null EndAt lands in update map as nilTestContestServiceEdit_KeepEndAtWhenAbsent— absent EndAt not in update map{"endAt":null}decodes toSet=true,Value=nilAll packages + lint + pre-commit green.