From b3eba760507ce337b944ffcdeaa9aca8f826d94f Mon Sep 17 00:00:00 2001 From: elraphty Date: Thu, 14 Nov 2024 14:20:01 +0100 Subject: [PATCH] updated feature stories --- db/structsv2.go | 7 ++++--- handlers/features.go | 22 ++++++++++++---------- handlers/features_test.go | 12 +++++++----- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/db/structsv2.go b/db/structsv2.go index 299ddbbd7..2e68ca46f 100644 --- a/db/structsv2.go +++ b/db/structsv2.go @@ -66,12 +66,13 @@ type FeatureStories struct { } type FeatureOutput struct { - FeatureUuid string `json:"featureUuid"` - Stories []FeatureStories `json:"stories"` + FeatureContext string `json:"featureContext"` + FeatureUuid string `json:"featureUuid"` + Stories []FeatureStories `json:"stories"` } type FeatureStoriesReponse struct { - Output FeatureOutput `json:"feature_output"` + Output FeatureOutput `json:"output"` } type InviteReponse struct { diff --git a/handlers/features.go b/handlers/features.go index 558d74f21..aab547ea8 100644 --- a/handlers/features.go +++ b/handlers/features.go @@ -429,26 +429,28 @@ func (oh *featureHandler) GetFeatureStories(w http.ResponseWriter, r *http.Reque featureUuid := featureStories.Output.FeatureUuid - log.Println("Webhook Feature Uuid", featureUuid) - if err != nil { w.WriteHeader(http.StatusNotAcceptable) log.Printf("Error decoding request body: %v", err) return } - log.Println("Webhook Feature Output", featureStories.Output) + log.Println("Webhook Feature Uuid", featureUuid) log.Println("Webhook Feature Stories === ", featureStories.Output.Stories) - for _, story := range featureStories.Output.Stories { - // check if feature story exists - feature := oh.db.GetFeatureByUuid(featureUuid) + // check if feature story exists + feature := oh.db.GetFeatureByUuid(featureUuid) - if feature.ID == 0 { - log.Println("Feature ID does not exists", featureUuid) - continue - } + if feature.ID == 0 { + msg := "Feature ID does not exists" + log.Println(msg, featureUuid) + w.WriteHeader(http.StatusNotAcceptable) + json.NewEncoder(w).Encode(msg) + return + } + + for _, story := range featureStories.Output.Stories { now := time.Now() diff --git a/handlers/features_test.go b/handlers/features_test.go index 30ead4149..2e2118f99 100644 --- a/handlers/features_test.go +++ b/handlers/features_test.go @@ -1577,15 +1577,17 @@ func TestGetFeatureStories(t *testing.T) { featureStories := db.FeatureStoriesReponse{ Output: db.FeatureOutput{ - FeatureUuid: feature.Uuid, - Stories: stories, + FeatureUuid: feature.Uuid, + FeatureContext: "Feature Context", + Stories: stories, }, } featureStories2 := db.FeatureStoriesReponse{ Output: db.FeatureOutput{ - FeatureUuid: "Fake-feature-uuid", - Stories: stories2, + FeatureUuid: "Fake-feature-uuid", + FeatureContext: "Feature Context", + Stories: stories2, }, } @@ -1631,6 +1633,6 @@ func TestGetFeatureStories(t *testing.T) { featureStoriesCount := len(featureStories) assert.Equal(t, int64(featureStoriesCount), int64(0)) - assert.Equal(t, http.StatusOK, rr.Code) + assert.Equal(t, http.StatusNotAcceptable, rr.Code) }) }