From 75f811bb9fd0e62fbe9d8706891688b538ea6c1f Mon Sep 17 00:00:00 2001 From: richjohnrambo Date: Mon, 28 Sep 2026 14:34:08 +0800 Subject: [PATCH] fix: filter daily reports by date --- internal/httpapi/api.go | 11 ++++++++++- internal/store/mysql.go | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/httpapi/api.go b/internal/httpapi/api.go index e22e2da..3bd542b 100644 --- a/internal/httpapi/api.go +++ b/internal/httpapi/api.go @@ -674,7 +674,16 @@ func (a *API) meetingNoteFileResource(w http.ResponseWriter, r *http.Request, p func (a *API) dailyReports(w http.ResponseWriter, r *http.Request, p *auth.Principal, st *store.Store) { switch r.Method { case http.MethodGet: - items, next, err := st.DailyReports(r.Context(), p.UserID, r.URL.Query().Get("cursor"), limit(r, 50, 100)) + reportDate := "" + if rawDate := strings.TrimSpace(r.URL.Query().Get("date")); rawDate != "" { + date, parseErr := parseDate(rawDate) + if parseErr != nil { + writeError(w, r, http.StatusBadRequest, 30000, reasonMalformedRequest, "malformed request", map[string]any{"field": "date"}) + return + } + reportDate = date.Format("2006-01-02") + } + items, next, err := st.DailyReports(r.Context(), p.UserID, reportDate, r.URL.Query().Get("cursor"), limit(r, 50, 100)) if err != nil { writeStoreError(w, r, err) return diff --git a/internal/store/mysql.go b/internal/store/mysql.go index ad7eb85..25c8e0d 100644 --- a/internal/store/mysql.go +++ b/internal/store/mysql.go @@ -827,10 +827,14 @@ func (s *Store) DeleteMeetingNoteFile(ctx context.Context, userID int64, meeting return s.meetingNoteFile(ctx, meetingID, noteFileID) } -func (s *Store) DailyReports(ctx context.Context, userID int64, cursor string, limit int) ([]DailyReport, string, error) { +func (s *Store) DailyReports(ctx context.Context, userID int64, reportDate, cursor string, limit int) ([]DailyReport, string, error) { var items []DailyReport query := `SELECT report_id,author_id,report_date,content,attachments,status,read_state,version,submitted_at,created_at,updated_at FROM im_daily_reports WHERE tenant_id=? AND author_id=?` args := []any{s.tenant(), userID} + if reportDate != "" { + query += ` AND report_date=?` + args = append(args, reportDate) + } if cursor != "" { query += ` AND report_id>?` args = append(args, cursor)