Compare commits

..

No commits in common. "c7798c5784e3acb9cb15c0f5b7d7a6e911ac4c2f" and "e1df2dea3b9397ce934b09349dfc38e2986aa989" have entirely different histories.

2 changed files with 36 additions and 74 deletions

View File

@ -51,10 +51,8 @@ type Project struct {
func (p Project) String() string {
return fmt.Sprintf("%d: %s (%s)", p.ID, p.Name, p.CustomerName)
}
func (p Project) GetID() int { return p.ID }
func (p Project) GetName() string {
return p.Name + " (" + p.CustomerName + ")"
}
func (p Project) GetID() int { return p.ID }
func (p Project) GetName() string { return p.Name + " (" + p.CustomerName + ")" }
func (a APIClient) GetProjects() (Projects, error) {
// GET /projects.json
@ -240,9 +238,7 @@ type requestAddTimeEntry struct {
} `json:"time_entry"`
}
type apiPostTimeEntry timeEntryHolder
func (a APIClient) AddTimeEntry(date string, minutes int, notes string, projectId, serviceId int) (int, error) {
func (a APIClient) AddTimeEntry(date string, minutes int, notes string, projectId, serviceId int) error {
// POST /time_entries.json
// {
// "time_entry": {
@ -258,10 +254,8 @@ func (a APIClient) AddTimeEntry(date string, minutes int, notes string, projectI
req.RequestTimeEntryHolder.ProjectID = projectId
req.RequestTimeEntryHolder.ServiceID = serviceId
res := apiPostTimeEntry{}
err := a.post("/time_entries.json", req, &res)
return res.TimeEntry.ID, err
err := a.post("/time_entries.json", req)
return err
}
type apiTimeTrackerEntry struct {
@ -404,9 +398,9 @@ func (a APIClient) patch(path string, data any) error {
return nil
}
func (a APIClient) post(path string, dataIn any, dataOut any) error {
func (a APIClient) post(path string, data any) error {
b, err := json.Marshal(dataIn)
b, err := json.Marshal(data)
if err != nil {
return err
}
@ -427,11 +421,6 @@ func (a APIClient) post(path string, dataIn any, dataOut any) error {
return fmt.Errorf("expected 2XX, got %d", resp.StatusCode)
}
err = json.NewDecoder(resp.Body).Decode(&dataOut)
if err != nil {
return err
}
return nil
}

View File

@ -35,7 +35,6 @@ func (m model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
projectID := m.formData.form.GetString("project")
description := m.formData.form.GetString("description")
minutes := m.formData.form.GetString("minutes")
tracker := m.formData.form.GetBool("tracker")
minutesInt, err1 := strconv.ParseInt(minutes, 10, 64)
serviceIDInt, err2 := strconv.ParseInt(serviceID, 10, 64)
@ -46,27 +45,14 @@ func (m model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
m.tuiMode = MODE_CAL
} else {
id, err := m.miteAPI.AddTimeEntry(m.dest.Format(time.DateOnly), int(minutesInt), description, int(projectIDInt), int(serviceIDInt))
err := m.miteAPI.AddTimeEntry(m.dest.Format(time.DateOnly), int(minutesInt), description, int(projectIDInt), int(serviceIDInt))
if err != nil {
m.statusBarMessage = err.Error()
m.tuiMode = MODE_CAL
} else {
if tracker {
_, _, err = m.miteAPI.StartTimeTracker(id)
if err != nil {
m.statusBarMessage = err.Error()
m.tuiMode = MODE_CAL
} else {
m.statusBarMessage = "Successfully logged time and started tracker"
m.tuiMode = MODE_CAL
return m, m.fetchMiteData()
}
} else {
m.statusBarMessage = "Successfully logged time"
m.tuiMode = MODE_CAL
return m, m.fetchMiteData()
}
m.statusBarMessage = "Successfully logged time"
m.tuiMode = MODE_CAL
return m, m.fetchMiteData()
}
}
@ -115,51 +101,38 @@ func (m model) buildForm() *huh.Form {
Key("project").
Title("Project").
Options(projOptions...).
Height(6)
description := huh.NewText().
Key("description").
Title("description").
Validate(func(s string) error {
if s == "" {
return errors.New("must enter a description")
}
return nil
})
defMinutes := "0"
minutes := huh.NewInput().
Key("minutes").
CharLimit(5).
Validate(
func(s string) error {
h, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
if h < 0 {
return errors.New("must be positive")
}
return err
}).
Title("Minutes").
Value(&defMinutes)
confirmTracker := huh.NewConfirm().
Key("tracker").
Affirmative("Yes").
Negative("No").
Title("Start tracker")
Height(10)
form := huh.NewForm(
huh.NewGroup(
pl,
sl,
description,
),
huh.NewGroup(
minutes,
confirmTracker,
huh.NewText().
Key("description").
Title("description").
Validate(func(s string) error {
if s == "" {
return errors.New("must enter a description")
}
return nil
}),
huh.NewInput().
Key("minutes").
CharLimit(5).
Validate(
func(s string) error {
h, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return err
}
if h < 0 {
return errors.New("must be positive")
}
return err
}).
Title("Minutes"),
),
)
return form