2026-08-03 05:52:02 +00:00
|
|
|
|
package radar
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
|
|
"apps/backend/internal/middleware"
|
|
|
|
|
|
"apps/backend/internal/response"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
ownerUID 取登入 uid,是 radar 全部資源的隔離依據。
|
|
|
|
|
|
|
|
|
|
|
|
request 若帶了 uid 一律忽略:整個 group 只讀寫自己的資料(spec §5.1、§7),
|
|
|
|
|
|
少了這道就等於開放任意越權讀寫。
|
|
|
|
|
|
*/
|
|
|
|
|
|
func ownerUID(ctx context.Context) (int64, error) {
|
|
|
|
|
|
uid, ok := middleware.UIDFrom(ctx)
|
|
|
|
|
|
if !ok || uid <= 0 {
|
|
|
|
|
|
return 0, response.Biz(401, 401001, "missing authorization")
|
|
|
|
|
|
}
|
|
|
|
|
|
return uid, nil
|
|
|
|
|
|
}
|
2026-08-27 05:35:07 +00:00
|
|
|
|
|
|
|
|
|
|
func intHours(in []int64) []int {
|
|
|
|
|
|
out := make([]int, 0, len(in))
|
|
|
|
|
|
for _, h := range in {
|
|
|
|
|
|
out = append(out, int(h))
|
|
|
|
|
|
}
|
|
|
|
|
|
return out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func int64Hours(in []int) []int64 {
|
|
|
|
|
|
out := make([]int64, 0, len(in))
|
|
|
|
|
|
for _, h := range in {
|
|
|
|
|
|
out = append(out, int64(h))
|
|
|
|
|
|
}
|
|
|
|
|
|
return out
|
|
|
|
|
|
}
|