diff --git a/doc/api.oa3 b/doc/api.oa3 index 5c837a6b..35966a89 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -300,8 +300,6 @@ paths: - account description: Get profile of searchable accounts. Endpoint is publically accessible. operationId: get-account-listing - security: - - bearerAuth: [] parameters: - name: guid in: query @@ -351,7 +349,7 @@ paths: description: Get disabled status of account. Authorized to account username and password. operationId: get-account-status security: - - basicAuth: [] + - bearerAuth: [] responses: '200': description: successful operation @@ -371,7 +369,7 @@ paths: description: Set whether account is publicly listed. operationId: set-account-seachable security: - - basicAuth: [] + - bearerAuth: [] responses: '201': description: success diff --git a/net/server/internal/api_account.go b/net/server/internal/api_account.go index 217a0ab5..c392829f 100644 --- a/net/server/internal/api_account.go +++ b/net/server/internal/api_account.go @@ -58,9 +58,5 @@ func SetAccountNode(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) } -func GetAccountListing(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) -} diff --git a/net/server/internal/api_getAccountListing.go b/net/server/internal/api_getAccountListing.go new file mode 100644 index 00000000..bd7aa3c7 --- /dev/null +++ b/net/server/internal/api_getAccountListing.go @@ -0,0 +1,32 @@ +package databag + +import ( + "net/http" + "databag/internal/store" +) + +func GetAccountListing(w http.ResponseWriter, r *http.Request) { + + var accounts []store.Account + if err := store.DB.Preload("AccountDetail").Where("searchable = ? AND disabled = ?", true, false).Find(&accounts).Error; err != nil { + ErrResponse(w, http.StatusInternalServerError, err) + return + } + + profiles := []CardProfile{} + for _, account := range accounts { + profiles = append(profiles, CardProfile{ + Guid: account.Guid, + Handle: account.Username, + Name: account.AccountDetail.Name, + Description: account.AccountDetail.Description, + Location: account.AccountDetail.Location, + ImageSet: account.AccountDetail.Image != "", + Version: APP_VERSION, + Node: "https://" + getStrConfigValue(CONFIG_DOMAIN, "") + "/", + }) + } + + WriteResponse(w, &profiles) +} + diff --git a/net/server/internal/ucAccountConfig_test.go b/net/server/internal/ucAccountConfig_test.go index 4095a55a..46b82f11 100644 --- a/net/server/internal/ucAccountConfig_test.go +++ b/net/server/internal/ucAccountConfig_test.go @@ -111,6 +111,12 @@ func TestAccountConfig(t *testing.T) { "/content/channels/{channelId}/topics/{topicId}/assets?transforms=" + url.QueryEscape(string(transforms)), pathParams, img, APP_TOKENAPP, set.A.Token, assets, nil)) -PrintMsg(accountStatus) + // get list of accounts + profiles := []CardProfile{} + params = &TestApiParams{ query: "/account/listing" } + response = &TestApiResponse{ data: &profiles } + assert.NoError(t, TestApiRequest(GetAccountListing, params, response)) + assert.Equal(t, 1, len(profiles)) + assert.Equal(t, set.A.Guid, profiles[0].Guid); }