Compare commits

..

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

2 changed files with 36 additions and 74 deletions

View File

@ -52,9 +52,7 @@ func (p Project) String() string {
return fmt.Sprintf("%d: %s (%s)", p.ID, p.Name, p.CustomerName) return fmt.Sprintf("%d: %s (%s)", p.ID, p.Name, p.CustomerName)
} }
func (p Project) GetID() int { return p.ID } func (p Project) GetID() int { return p.ID }
func (p Project) GetName() string { func (p Project) GetName() string { return p.Name + " (" + p.CustomerName + ")" }
return p.Name + " (" + p.CustomerName + ")"
}
func (a APIClient) GetProjects() (Projects, error) { func (a APIClient) GetProjects() (Projects, error) {
// GET /projects.json // GET /projects.json
@ -240,9 +238,7 @@ type requestAddTimeEntry struct {
} `json:"time_entry"` } `json:"time_entry"`
} }
type apiPostTimeEntry timeEntryHolder func (a APIClient) AddTimeEntry(date string, minutes int, notes string, projectId, serviceId int) error {
func (a APIClient) AddTimeEntry(date string, minutes int, notes string, projectId, serviceId int) (int, error) {
// POST /time_entries.json // POST /time_entries.json
// { // {
// "time_entry": { // "time_entry": {
@ -258,10 +254,8 @@ func (a APIClient) AddTimeEntry(date string, minutes int, notes string, projectI
req.RequestTimeEntryHolder.ProjectID = projectId req.RequestTimeEntryHolder.ProjectID = projectId
req.RequestTimeEntryHolder.ServiceID = serviceId req.RequestTimeEntryHolder.ServiceID = serviceId
res := apiPostTimeEntry{} err := a.post("/time_entries.json", req)
return err
err := a.post("/time_entries.json", req, &res)
return res.TimeEntry.ID, err
} }
type apiTimeTrackerEntry struct { type apiTimeTrackerEntry struct {
@ -404,9 +398,9 @@ func (a APIClient) patch(path string, data any) error {
return nil 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 { if err != nil {
return err 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) return fmt.Errorf("expected 2XX, got %d", resp.StatusCode)
} }
err = json.NewDecoder(resp.Body).Decode(&dataOut)
if err != nil {
return err
}
return nil 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") projectID := m.formData.form.GetString("project")
description := m.formData.form.GetString("description") description := m.formData.form.GetString("description")
minutes := m.formData.form.GetString("minutes") minutes := m.formData.form.GetString("minutes")
tracker := m.formData.form.GetBool("tracker")
minutesInt, err1 := strconv.ParseInt(minutes, 10, 64) minutesInt, err1 := strconv.ParseInt(minutes, 10, 64)
serviceIDInt, err2 := strconv.ParseInt(serviceID, 10, 64) serviceIDInt, err2 := strconv.ParseInt(serviceID, 10, 64)
@ -46,29 +45,16 @@ func (m model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
m.tuiMode = MODE_CAL m.tuiMode = MODE_CAL
} else { } 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 { if err != nil {
m.statusBarMessage = err.Error() m.statusBarMessage = err.Error()
m.tuiMode = MODE_CAL m.tuiMode = MODE_CAL
} else { } 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.statusBarMessage = "Successfully logged time"
m.tuiMode = MODE_CAL m.tuiMode = MODE_CAL
return m, m.fetchMiteData() return m, m.fetchMiteData()
} }
} }
}
} }
@ -115,9 +101,15 @@ func (m model) buildForm() *huh.Form {
Key("project"). Key("project").
Title("Project"). Title("Project").
Options(projOptions...). Options(projOptions...).
Height(6) Height(10)
description := huh.NewText(). form := huh.NewForm(
huh.NewGroup(
pl,
sl,
),
huh.NewGroup(
huh.NewText().
Key("description"). Key("description").
Title("description"). Title("description").
Validate(func(s string) error { Validate(func(s string) error {
@ -125,10 +117,8 @@ func (m model) buildForm() *huh.Form {
return errors.New("must enter a description") return errors.New("must enter a description")
} }
return nil return nil
}) }),
huh.NewInput().
defMinutes := "0"
minutes := huh.NewInput().
Key("minutes"). Key("minutes").
CharLimit(5). CharLimit(5).
Validate( Validate(
@ -142,24 +132,7 @@ func (m model) buildForm() *huh.Form {
} }
return err return err
}). }).
Title("Minutes"). Title("Minutes"),
Value(&defMinutes)
confirmTracker := huh.NewConfirm().
Key("tracker").
Affirmative("Yes").
Negative("No").
Title("Start tracker")
form := huh.NewForm(
huh.NewGroup(
pl,
sl,
description,
),
huh.NewGroup(
minutes,
confirmTracker,
), ),
) )
return form return form