mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 16:21:16 +00:00
feat(backend): return "my" slug for personal org
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user