-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable filtering service offerings by name
Also accept the `fields` parameter but ignore it for now fixes #3270 #3272 Co-authored-by: Georgi Sabev <[email protected]>
- Loading branch information
1 parent
0547327
commit 0930ef1
Showing
8 changed files
with
156 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package payloads | ||
|
||
import ( | ||
"net/url" | ||
"regexp" | ||
|
||
"code.cloudfoundry.org/korifi/api/payloads/parse" | ||
"code.cloudfoundry.org/korifi/api/repositories" | ||
) | ||
|
||
type ServiceOfferingList struct { | ||
Names string | ||
} | ||
|
||
func (l *ServiceOfferingList) ToMessage() repositories.ListServiceOfferingMessage { | ||
return repositories.ListServiceOfferingMessage{ | ||
Names: parse.ArrayParam(l.Names), | ||
} | ||
} | ||
|
||
func (l *ServiceOfferingList) SupportedKeys() []string { | ||
return []string{"names", "page", "per_page"} | ||
} | ||
|
||
func (l *ServiceOfferingList) IgnoredKeys() []*regexp.Regexp { | ||
return []*regexp.Regexp{regexp.MustCompile(`fields\[.+\]`)} | ||
} | ||
|
||
func (l *ServiceOfferingList) DecodeFromURLValues(values url.Values) error { | ||
l.Names = values.Get("names") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package payloads_test | ||
|
||
import ( | ||
"code.cloudfoundry.org/korifi/api/payloads" | ||
"code.cloudfoundry.org/korifi/api/repositories" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("ServiceOffering", func() { | ||
DescribeTable("valid query", | ||
func(query string, expectedServiceOfferingList payloads.ServiceOfferingList) { | ||
actualServiceOfferingList, decodeErr := decodeQuery[payloads.ServiceOfferingList](query) | ||
|
||
Expect(decodeErr).NotTo(HaveOccurred()) | ||
Expect(*actualServiceOfferingList).To(Equal(expectedServiceOfferingList)) | ||
}, | ||
Entry("names", "names=b1,b2", payloads.ServiceOfferingList{Names: "b1,b2"}), | ||
) | ||
|
||
Describe("ToMessage", func() { | ||
It("converts payload to repository message", func() { | ||
payload := &payloads.ServiceOfferingList{Names: "b1,b2"} | ||
|
||
Expect(payload.ToMessage()).To(Equal(repositories.ListServiceOfferingMessage{ | ||
Names: []string{"b1", "b2"}, | ||
})) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters