fix: filter daily reports by date
This commit is contained in:
+10
-1
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user