From 4da4416cd90b1888de135cf506dc803a09ed5cc8 Mon Sep 17 00:00:00 2001 From: pluja Date: Tue, 7 May 2024 23:12:15 +0200 Subject: [PATCH] optimize api response --- src/database/models.go | 10 +++++----- src/server/api_v1.go | 9 +++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/database/models.go b/src/database/models.go index 8340767..9ed6b48 100644 --- a/src/database/models.go +++ b/src/database/models.go @@ -4,11 +4,11 @@ type Service struct { Category string `json:"category"` CollectionID string `json:"collectionId"` CollectionName string `json:"collectionName"` - Comments []string `json:"comments"` + Comments []string `json:"comments,omitempty"` Created string `json:"created"` Description string `json:"description"` - Expand map[string][]Attribute `json:"expand"` - Attributes []string `json:"attributes"` + Expand map[string][]Attribute `json:"expand,omitempty"` + Attributes []string `json:"attributes,omitempty"` ID string `json:"id"` KycLevel int `json:"kyc_level"` Listed bool `json:"listed"` @@ -18,7 +18,7 @@ type Service struct { Pending bool `json:"pending"` Score int `json:"score"` Tags []string `json:"tags"` - TosReviews []TosReview `json:"tos_reviews"` + TosReviews []TosReview `json:"tos_reviews,omitempty"` LastTosReview string `json:"last_tos_review"` TosUrls []string `json:"tos_urls"` Type string `json:"type"` @@ -31,7 +31,7 @@ type Service struct { Fiat bool `json:"fiat"` Cash bool `json:"cash"` Lightning bool `json:"lightning"` - Notes []string `json:"notes"` + Notes []string `json:"notes,omitempty"` } type TosReview struct { diff --git a/src/server/api_v1.go b/src/server/api_v1.go index 582bf4c..68aba40 100644 --- a/src/server/api_v1.go +++ b/src/server/api_v1.go @@ -18,6 +18,15 @@ func (s *Server) handleApiService(c iris.Context) { return } + // Remove 'tosReviews' service field to make a shorter answer + service.TosReviews = nil + service.Notes = nil + service.Comments = nil + service.Expand = nil + service.Attributes = nil + + // Ensure to remove any other additional unnecessary fields to ensure code efficiency and better clarity. + // Return the service as JSON c.JSON(service) }