feat(transaction): #85 replace datetime with date #89

Merged
tim merged 1 commits from 85-replace-timestamp-with-date into prod 2025-05-16 20:57:25 +00:00
6 changed files with 17 additions and 33 deletions

View File

@@ -132,13 +132,12 @@ func (h TransactionImpl) handleUpdateTransaction() http.HandlerFunc {
err error err error
) )
input := types.TransactionInput{ input := types.TransactionInput{
Id: r.PathValue("id"), Id: r.PathValue("id"),
AccountId: r.FormValue("account-id"), AccountId: r.FormValue("account-id"),
TreasureChestId: r.FormValue("treasure-chest-id"), TreasureChestId: r.FormValue("treasure-chest-id"),
Value: r.FormValue("value"), Value: r.FormValue("value"),
Timestamp: r.FormValue("timestamp"), Timestamp: r.FormValue("timestamp"),
TimezoneOffsetMinutes: r.FormValue("timezone-offset"), Note: r.FormValue("note"),
Note: r.FormValue("note"),
} }
if input.Id == "new" { if input.Id == "new" {

View File

@@ -911,7 +911,7 @@ func TestIntegrationAuth(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode) assert.Equal(t, http.StatusOK, resp.StatusCode)
formData = url.Values{ formData = url.Values{
"timestamp": {"2006-01-02T15:04"}, "timestamp": {"2006-01-02"},
"value": {"100.00"}, "value": {"100.00"},
"csrf-token": {csrfToken}, "csrf-token": {csrfToken},
} }

View File

@@ -440,20 +440,12 @@ func (s TransactionImpl) validateAndEnrichTransaction(oldTransaction *types.Tran
} }
valueInt := int64(valueFloat * 100) valueInt := int64(valueFloat * 100)
timestampTime, err := time.Parse("2006-01-02T15:04", input.Timestamp) timestamp, err := time.Parse("2006-01-02", input.Timestamp)
if err != nil { if err != nil {
log.Error("transaction validate: %v", err) log.Error("transaction validate: %v", err)
return nil, fmt.Errorf("could not parse timestamp: %w", ErrBadRequest) return nil, fmt.Errorf("could not parse timestamp: %w", ErrBadRequest)
} }
if input.TimezoneOffsetMinutes != "" {
timezoneOffsetMinutes, err := strconv.Atoi(input.TimezoneOffsetMinutes)
if err != nil {
return nil, fmt.Errorf("could not parse timezone offset: %w", ErrBadRequest)
}
timestampTime = timestampTime.Add(time.Duration(-1*timezoneOffsetMinutes) * time.Minute)
}
if input.Note != "" { if input.Note != "" {
err = validateString(input.Note, "note") err = validateString(input.Note, "note")
if err != nil { if err != nil {
@@ -468,7 +460,7 @@ func (s TransactionImpl) validateAndEnrichTransaction(oldTransaction *types.Tran
AccountId: accountUuid, AccountId: accountUuid,
TreasureChestId: treasureChestUuid, TreasureChestId: treasureChestUuid,
Value: valueInt, Value: valueInt,
Timestamp: timestampTime, Timestamp: timestamp,
Note: input.Note, Note: input.Note,
CreatedAt: createdAt, CreatedAt: createdAt,

View File

@@ -9,17 +9,12 @@ document.addEventListener("DOMContentLoaded", () => {
}) })
function updateTime(e) { function updateTime(e) {
const timezoneOffset = - new Date().getTimezoneOffset();
e.querySelectorAll("#timezone-offset").forEach((el) => {
el.value = timezoneOffset;
});
document.querySelectorAll(".datetime").forEach((el) => { document.querySelectorAll(".datetime").forEach((el) => {
if (el.textContent !== "") { if (el.textContent !== "") {
el.textContent = el.textContent.includes("UTC") ? new Date(el.textContent).toLocaleString([], { day: 'numeric', month: 'short', year: 'numeric', hour: '2-digit', minute: '2-digit' }) : el.textContent; el.textContent = el.textContent.includes("UTC") ? new Date(el.textContent).toLocaleString([], { day: 'numeric', month: 'short', year: 'numeric' }) : el.textContent;
} else if (el.attributes['value'] !== "") { } else if (el.attributes['value'] !== "") {
const value = el.attributes['value'].value; const value = el.attributes['value'].value;
const newDate = value.includes("UTC") ? new Date(value) : value; const newDate = value.includes("UTC") ? new Date(value) : value;
newDate.setTime(newDate.getTime() + timezoneOffset * 60 * 1000);
el.valueAsDate = newDate; el.valueAsDate = newDate;
} }
}) })

View File

@@ -70,11 +70,10 @@ templ EditTransaction(transaction *types.Transaction, accounts []*types.Account,
<input <input
autofocus autofocus
name="timestamp" name="timestamp"
type="datetime-local" type="date"
value={ timestamp.String() } value={ timestamp.String() }
class="bg-white input datetime" class="bg-white input datetime"
/> />
<input class="hidden" id="timezone-offset" name="timezone-offset" type="text"/>
<label for="note" class="text-sm text-gray-500">Note</label> <label for="note" class="text-sm text-gray-500">Note</label>
<input <input
name="note" name="note"

View File

@@ -35,11 +35,10 @@ type Transaction struct {
} }
type TransactionInput struct { type TransactionInput struct {
Id string Id string
AccountId string AccountId string
TreasureChestId string TreasureChestId string
Value string Value string
Timestamp string Timestamp string
TimezoneOffsetMinutes string Note string
Note string
} }