mirror of
https://github.com/ThisTine/Snip.git
synced 2026-08-18 23:18:47 +07:00
70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package api
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/snip/backend/internal/domain"
|
|
)
|
|
|
|
// linkDTO is the JSON shape returned to the SPA. It intentionally matches the
|
|
// frontend's `ShortLink` type so the mock API is a drop-in swap. PinHash is
|
|
// never included.
|
|
type linkDTO struct {
|
|
ID string `json:"id"`
|
|
Code string `json:"code"`
|
|
LongURL string `json:"longUrl"`
|
|
Mode string `json:"mode"`
|
|
HasPin bool `json:"hasPin"`
|
|
CreatedAt string `json:"createdAt"`
|
|
TotalClicks int64 `json:"totalClicks"`
|
|
Last7Days []domain.DayCount `json:"last7Days"`
|
|
Owned bool `json:"owned"`
|
|
}
|
|
|
|
func toDTO(l *domain.Link) linkDTO {
|
|
week := l.Last7Days
|
|
if week == nil {
|
|
week = []domain.DayCount{}
|
|
}
|
|
return linkDTO{
|
|
ID: l.ID,
|
|
Code: l.Code,
|
|
LongURL: l.LongURL,
|
|
Mode: string(l.Mode),
|
|
HasPin: l.HasPin,
|
|
CreatedAt: l.CreatedAt.Format(time.RFC3339),
|
|
TotalClicks: l.TotalClicks,
|
|
Last7Days: week,
|
|
Owned: l.OwnerID != "",
|
|
}
|
|
}
|
|
|
|
// listResponse is the paginated link listing returned to the dashboard.
|
|
type listResponse struct {
|
|
Items []linkDTO `json:"items"`
|
|
Total int `json:"total"`
|
|
Page int `json:"page"`
|
|
PageSize int `json:"pageSize"`
|
|
}
|
|
|
|
type createReq struct {
|
|
LongURL string `json:"longUrl"`
|
|
Mode string `json:"mode"`
|
|
CustomAlias string `json:"customAlias"`
|
|
Pin string `json:"pin"`
|
|
}
|
|
|
|
type updateReq struct {
|
|
LongURL string `json:"longUrl"`
|
|
}
|
|
|
|
type pinReq struct {
|
|
Pin string `json:"pin"`
|
|
}
|
|
|
|
type userDTO struct {
|
|
ID string `json:"id"`
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
}
|