From 5ded7d39493836e7e85cde14003144e730105761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Men=C3=A9ndez?= Date: Thu, 16 Jan 2025 13:09:03 +0100 Subject: [PATCH] return organization info when it is created, api docs updated --- api/docs.md | 92 +++++++++++++++++++++++++++++++++++--------- api/organizations.go | 10 +++-- 2 files changed, 80 insertions(+), 22 deletions(-) diff --git a/api/docs.md b/api/docs.md index 304d5e3..dbde912 100644 --- a/api/docs.md +++ b/api/docs.md @@ -317,7 +317,8 @@ This endpoint only returns the addresses of the organizations where the current "role": "admin", "organization": { "address": "0x...", - "name": "Test Organization", + "website": "", + "createdAt": "2025-01-16T11:56:04Z", "type": "community", "description": "My amazing testing organization", "size": 10, @@ -326,16 +327,25 @@ This endpoint only returns the addresses of the organizations where the current "subdomain": "mysubdomain", "timezone": "GMT+2", "active": true, + "communications": false, "parent": { - "...": "..." + "...": "..." }, - "subscription":{ - "PlanID":3, - "StartDate":"2024-11-07T15:25:49.218Z", - "RenewalDate":"2025-11-07T15:25:49.218Z", - "Active":true, - "MaxCensusSize":10 + "subscription": { + "planID": 2, + "startDate": "2025-01-16T11:56:04.079Z", + "renewalDate": "0001-01-01T00:00:00Z", + "lastPaymentDate": "0001-01-01T00:00:00Z", + "active": true, + "maxCensusSize": 50, + "email": "" }, + "counters": { + "sentSMS": 0, + "sentEmails": 0, + "subOrgs": 0, + "members": 0 + } } } ] @@ -481,6 +491,41 @@ If the user want to create a sub org, the address of the root organization must } ``` +* **Response** +```json +{ + "address": "0x23eE5d3ECE54a275FD75cF25E77C3bBeCe3CF3f7", + "website": "", + "createdAt": "2025-01-16T11:56:04Z", + "type": "community", + "size": "10", + "color": "#ff0000", + "subdomain": "mysubdomain", + "country": "Spain", + "timezone": "GMT+2", + "active": true, + "communications": false, + "parent": { + "...": {} + }, + "subscription": { + "planID": 2, + "startDate": "2025-01-16T11:56:04.079Z", + "renewalDate": "0001-01-01T00:00:00Z", + "lastPaymentDate": "0001-01-01T00:00:00Z", + "active": true, + "maxCensusSize": 50, + "email": "" + }, + "counters": { + "sentSMS": 0, + "sentEmails": 0, + "subOrgs": 0, + "members": 0 + } +} +``` + * **Errors** | HTTP Status | Error code | Message | @@ -536,23 +581,34 @@ Only the following parameters can be changed. Every parameter is optional. * **Response** ```json { - "address": "0x1234", - "name": "Test Organization", - "website": "https://[...].com", + "address": "0x23eE5d3ECE54a275FD75cF25E77C3bBeCe3CF3f7", + "website": "", + "createdAt": "2025-01-16T11:56:04Z", "type": "community", - "description": "My amazing testing organization", "size": "10", "color": "#ff0000", - "logo": "https://[...].png", - "header": "https://[...].png", "subdomain": "mysubdomain", - "country": "Germany", + "country": "Spain", "timezone": "GMT+2", - "Language": "EN", "active": true, - "communications": true, + "communications": false, "parent": { - "...": "..." + "...": {} + }, + "subscription": { + "planID": 2, + "startDate": "2025-01-16T11:56:04.079Z", + "renewalDate": "0001-01-01T00:00:00Z", + "lastPaymentDate": "0001-01-01T00:00:00Z", + "active": true, + "maxCensusSize": 50, + "email": "" + }, + "counters": { + "sentSMS": 0, + "sentEmails": 0, + "subOrgs": 0, + "members": 0 } } ``` diff --git a/api/organizations.go b/api/organizations.go index bfc89cc..7594521 100644 --- a/api/organizations.go +++ b/api/organizations.go @@ -41,8 +41,9 @@ func (a *API) createOrganizationHandler(w http.ResponseWriter, r *http.Request) return } parentOrg := "" + var dbParentOrg *db.Organization if orgInfo.Parent != nil { - dbParentOrg, _, err := a.db.Organization(orgInfo.Parent.Address, false) + dbParentOrg, _, err = a.db.Organization(orgInfo.Parent.Address, false) if err != nil { if err == db.ErrNotFound { ErrOrganizationNotFound.Withf("parent organization not found").Write(w) @@ -79,7 +80,7 @@ func (a *API) createOrganizationHandler(w http.ResponseWriter, r *http.Request) MaxCensusSize: defaultPlan.Organization.MaxCensus, } // create the organization - if err := a.db.SetOrganization(&db.Organization{ + dbOrg := &db.Organization{ Address: signer.AddressString(), Creator: user.Email, CreatedAt: time.Now(), @@ -96,7 +97,8 @@ func (a *API) createOrganizationHandler(w http.ResponseWriter, r *http.Request) TokensRemaining: 0, Parent: parentOrg, Subscription: *subscription, - }); err != nil { + } + if err := a.db.SetOrganization(dbOrg); err != nil { if err == db.ErrAlreadyExists { ErrInvalidOrganizationData.WithErr(err).Write(w) return @@ -105,7 +107,7 @@ func (a *API) createOrganizationHandler(w http.ResponseWriter, r *http.Request) return } // send the organization back to the user - httpWriteOK(w) + httpWriteJSON(w, organizationFromDB(dbOrg, dbParentOrg)) } // organizationInfoHandler handles the request to get the information of an