mirror of
https://github.com/hay-kot/homebox.git
synced 2025-06-28 22:58:36 +00:00
fix: refactoring errors (#359)
* #352 - require one date to be set to save * fix many type regressions
This commit is contained in:
parent
4a8ba6231d
commit
97fb94d231
22 changed files with 164 additions and 289 deletions
|
@ -2,6 +2,7 @@ package repo
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
@ -18,15 +19,38 @@ import (
|
|||
type MaintenanceEntryRepository struct {
|
||||
db *ent.Client
|
||||
}
|
||||
type (
|
||||
MaintenanceEntryCreate struct {
|
||||
CompletedDate types.Date `json:"completedDate"`
|
||||
ScheduledDate types.Date `json:"scheduledDate"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Cost float64 `json:"cost,string"`
|
||||
}
|
||||
|
||||
type MaintenanceEntryCreate struct {
|
||||
CompletedDate types.Date `json:"completedDate"`
|
||||
ScheduledDate types.Date `json:"scheduledDate"`
|
||||
Name string `json:"name" validate:"required"`
|
||||
Description string `json:"description"`
|
||||
Cost float64 `json:"cost,string"`
|
||||
}
|
||||
|
||||
func (mc MaintenanceEntryCreate) Validate() error {
|
||||
if mc.CompletedDate.Time().IsZero() && mc.ScheduledDate.Time().IsZero() {
|
||||
return errors.New("either completedDate or scheduledDate must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type MaintenanceEntryUpdate struct {
|
||||
CompletedDate types.Date `json:"completedDate"`
|
||||
ScheduledDate types.Date `json:"scheduledDate"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Cost float64 `json:"cost,string"`
|
||||
}
|
||||
|
||||
func (mu MaintenanceEntryUpdate) Validate() error {
|
||||
if mu.CompletedDate.Time().IsZero() && mu.ScheduledDate.Time().IsZero() {
|
||||
return errors.New("either completedDate or scheduledDate must be set")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type (
|
||||
MaintenanceEntry struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
CompletedDate types.Date `json:"completedDate"`
|
||||
|
@ -36,14 +60,6 @@ type (
|
|||
Cost float64 `json:"cost,string"`
|
||||
}
|
||||
|
||||
MaintenanceEntryUpdate struct {
|
||||
CompletedDate types.Date `json:"completedDate"`
|
||||
ScheduledDate types.Date `json:"scheduledDate"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Cost float64 `json:"cost,string"`
|
||||
}
|
||||
|
||||
MaintenanceLog struct {
|
||||
ItemID uuid.UUID `json:"itemId"`
|
||||
CostAverage float64 `json:"costAverage"`
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue