feat(backend): return "my" slug for personal org

This commit is contained in:
2026-01-02 23:16:00 +00:00
parent 37056db77f
commit ceb4c9f23c
2 changed files with 36 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package organization
import (
"encoding/json"
"time"
"github.com/google/uuid"
@@ -26,6 +27,32 @@ type Organization struct {
UpdatedAt time.Time `bun:"updated_at,notnull,nullzero" json:"updatedAt"`
}
func (o Organization) MarshalJSON() ([]byte, error) {
type organizationJSON struct {
ID uuid.UUID `json:"id"`
Kind Kind `json:"kind"`
Name string `json:"name"`
Slug *string `json:"slug,omitempty"`
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
}
slug := o.Slug
if o.Kind == KindPersonal {
s := ReservedSlug
slug = &s
}
return json.Marshal(organizationJSON{
ID: o.ID,
Kind: o.Kind,
Name: o.Name,
Slug: slug,
CreatedAt: o.CreatedAt,
UpdatedAt: o.UpdatedAt,
})
}
func newOrganizationID() (uuid.UUID, error) {
return uuid.NewV7()
}