29 lines
876 B
Go
29 lines
876 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.
|
|
// If monthID is empty (pre-migration events), returns true since event ownership
|
|
// was already verified by the caller.
|
|
func verifyMonthOwnership(db *sql.DB, monthID, userID string) bool {
|
|
if monthID == "" {
|
|
return true
|
|
}
|
|
month, err := database.GetMonthByID(db, monthID)
|
|
if err != nil || month == nil {
|
|
return false
|
|
}
|
|
return month.UserID == userID
|
|
}
|