mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 14:41:18 +00:00
feat(backend): return "my" slug for personal org
This commit is contained in:
@@ -142,6 +142,9 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
if login.Organizations[0].Kind != string(organization.KindPersonal) {
|
||||
t.Fatalf("unexpected organization kind: %q", login.Organizations[0].Kind)
|
||||
}
|
||||
if login.Organizations[0].Slug != organization.ReservedSlug {
|
||||
t.Fatalf("unexpected personal organization slug: %q", login.Organizations[0].Slug)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("drives list", func(t *testing.T) {
|
||||
@@ -186,6 +189,9 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
if orgs[0].Kind != string(organization.KindPersonal) {
|
||||
t.Fatalf("unexpected organization kind: %q", orgs[0].Kind)
|
||||
}
|
||||
if orgs[0].Slug != organization.ReservedSlug {
|
||||
t.Fatalf("unexpected personal organization slug: %q", orgs[0].Slug)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("organizations/:orgSlug", func(t *testing.T) {
|
||||
@@ -199,6 +205,9 @@ func TestRegistrationFlow(t *testing.T) {
|
||||
if myOrg.Kind != string(organization.KindPersonal) {
|
||||
t.Fatalf("unexpected personal org kind: %q", myOrg.Kind)
|
||||
}
|
||||
if myOrg.Slug != organization.ReservedSlug {
|
||||
t.Fatalf("unexpected personal org slug: %q", myOrg.Slug)
|
||||
}
|
||||
|
||||
orgID, err := uuid.NewV7()
|
||||
if err != nil {
|
||||
|
||||
@@ -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