api use
CI / lint-backend (push) Successful in 1m24s
CI / lint-mobile (push) Failing after 7m28s
CI / test-backend (push) Successful in 1m25s
CI / test-mobile (push) Successful in 9m9s
CI / build-backend (push) Successful in 45s
CI / docker (push) Successful in 33s

This commit is contained in:
venture
2026-09-25 17:34:35 +02:00
parent b869f70922
commit c642763035
41 changed files with 2270 additions and 138 deletions
+98
View File
@@ -0,0 +1,98 @@
package service
import (
"time"
"github.com/kazier/backend/repository"
)
// ShareGrantDTO serializes one active grant for GET /files/:id/shares.
// Milliseconds epoch (null = never), mirroring the permissions snapshot
// (docs/api-v1.md §6.2) for cheap client-side expiry checks.
type ShareGrantDTO struct {
GranteeUserID string `json:"granteeUserId"`
Username string `json:"username"`
Access string `json:"access"`
Inherit bool `json:"inherit"`
ExpiresAt *int64 `json:"expiresAt"`
UpdatedAt int64 `json:"updatedAt"`
}
// LinkDTO serializes one active public link for GET /files/:id/links —
// same shape as the public GET /shares/links/:token resolution.
type LinkDTO struct {
Token string `json:"token"`
ResourceID string `json:"resource_id"`
ResourceType string `json:"resourceType"`
Name string `json:"name"`
Access string `json:"access"`
ExpiresAt *string `json:"expiresAt"`
}
// ListShares returns the active grants on a resource the user OWNS.
// Non-owner (or unknown resource) → repository.ErrNotFound (no enumeration,
// same scoping as the share outbox ops).
func (s *Resources) ListShares(userID, resourceID string) ([]ShareGrantDTO, error) {
ownerID, err := s.Repo.GetResourceOwner(resourceID)
if err != nil {
return nil, err
}
if ownerID != userID {
return nil, repository.ErrNotFound
}
grants, err := s.Repository.Shares.ListActiveForResource(resourceID)
if err != nil {
return nil, err
}
out := make([]ShareGrantDTO, 0, len(grants))
for _, g := range grants {
var expires *int64
if g.ExpiresAt != nil {
ms := g.ExpiresAt.UnixMilli()
expires = &ms
}
out = append(out, ShareGrantDTO{
GranteeUserID: g.GranteeUserID,
Username: g.Username,
Access: g.Access,
Inherit: g.Inherit,
ExpiresAt: expires,
UpdatedAt: g.UpdatedAt.UnixMilli(),
})
}
return out, nil
}
// ListLinks returns the active public links of a resource the user OWNS.
// Same owner-only scoping as ListShares.
func (s *Resources) ListLinks(userID, resourceID string) ([]LinkDTO, error) {
ownerID, err := s.Repo.GetResourceOwner(resourceID)
if err != nil {
return nil, err
}
if ownerID != userID {
return nil, repository.ErrNotFound
}
links, err := s.Repository.Shares.ListActiveLinksForResource(resourceID)
if err != nil {
return nil, err
}
out := make([]LinkDTO, 0, len(links))
for _, l := range links {
var expires *string
if l.ExpiresAt != nil {
// Même forme que ShareLinkGet (time.Time marshaled en RFC3339).
str := l.ExpiresAt.UTC().Format(time.RFC3339)
expires = &str
}
out = append(out, LinkDTO{
Token: l.Token,
ResourceID: l.ResourceID,
ResourceType: l.ResourceType,
Name: l.Name,
Access: l.Access,
ExpiresAt: expires,
})
}
return out, nil
}