- Restructure hierarchy: Month → Event → Expense (new months table, FK) - Add MonthHandler with CRUD, monthly reports, dropdown create form - Events now scoped under months with extended ownership chain - AI extraction: 16 specific expense categories (Airfare, Meals, etc.) - UI: category dropdown, button-consistent cards, centered mobile shell on desktop - Dashboard/month views show claim totals per card - Description field now mandatory, forms simplified - Months sorted by name chronologically (latest first)
28 lines
824 B
Go
28 lines
824 B
Go
package handlers
|
|
|
|
import (
|
|
"database/sql"
|
|
"strings"
|
|
|
|
"github.com/cclohmar/NextExpense/internal/database"
|
|
)
|
|
|
|
// normalizeImagePath strips a legacy "storage/" prefix if present, so that
|
|
// the template can safely build "/storage/{filename}" URLs regardless of
|
|
// whether the database entry was stored as "uuid.jpg" or "storage/uuid.jpg".
|
|
func normalizeImagePath(path string) string {
|
|
return strings.TrimPrefix(path, "storage/")
|
|
}
|
|
|
|
// verifyMonthOwnership checks that a month exists and belongs to the given user.
|
|
// Returns true if the month is owned by the user, false otherwise.
|
|
func verifyMonthOwnership(db *sql.DB, monthID, userID string) bool {
|
|
if monthID == "" {
|
|
return false
|
|
}
|
|
month, err := database.GetMonthByID(db, monthID)
|
|
if err != nil || month == nil {
|
|
return false
|
|
}
|
|
return month.UserID == userID
|
|
}
|