Skip to content

Commit

Permalink
Merge pull request stakwork#1951 from stakwork/feat/fix_feature_stories
Browse files Browse the repository at this point in the history
PR: Refactored feature stories webhook
  • Loading branch information
elraphty authored Nov 14, 2024
2 parents 3fbe8c5 + b3eba76 commit 8f04765
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
7 changes: 4 additions & 3 deletions db/structsv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 12 additions & 10 deletions handlers/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
12 changes: 7 additions & 5 deletions handlers/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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)
})
}

0 comments on commit 8f04765

Please sign in to comment.