(db *sql.DB, table string)
| 32 | } |
| 33 | |
| 34 | func listAttachments(db *sql.DB, table string) http.HandlerFunc { |
| 35 | return func(w http.ResponseWriter, r *http.Request) { |
| 36 | eventUUID := r.PathValue("uuid") |
| 37 | |
| 38 | rows, err := db.QueryContext(r.Context(), |
| 39 | "SELECT uuid, name, path, size, mime FROM "+table+" WHERE event_uuid = ?", eventUUID) |
| 40 | if err != nil { |
| 41 | writeError(w, err.Error(), 500) |
| 42 | return |
| 43 | } |
| 44 | defer rows.Close() |
| 45 | |
| 46 | var attachments []map[string]any |
| 47 | for rows.Next() { |
| 48 | var uuid, name, path, mime string |
| 49 | var size int |
| 50 | rows.Scan(&uuid, &name, &path, &size, &mime) |
| 51 | attachments = append(attachments, map[string]any{ |
| 52 | "uuid": uuid, "name": name, "path": path, "size": size, "mime": mime, |
| 53 | }) |
| 54 | } |
| 55 | if attachments == nil { |
| 56 | attachments = []map[string]any{} |
| 57 | } |
| 58 | |
| 59 | writeJSON(w, map[string]any{"data": attachments, "meta": map[string]any{}}) |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | func downloadAttachment(db *sql.DB, store *storage.AttachmentStore, table string) http.HandlerFunc { |
| 64 | return func(w http.ResponseWriter, r *http.Request) { |
no test coverage detected