Skip to content

Commit

Permalink
Add params to ComponentFirmwareVersionListParams (#220)
Browse files Browse the repository at this point in the history
Allows requests /server-component-firmwares to filter on the filename and checksum
  • Loading branch information
diogomatsubara authored Jun 29, 2023
1 parent 812608f commit f991cfd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
26 changes: 23 additions & 3 deletions pkg/api/v1/firmware_list_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import (

// ComponentFirmwareVersionListParams allows you to filter the results
type ComponentFirmwareVersionListParams struct {
Vendor string `form:"vendor"`
Model []string `form:"model"`
Version string `form:"version"`
Vendor string `form:"vendor"`
Model []string `form:"model"`
Version string `form:"version"`
Filename string `form:"filename"`
Checksum string `form:"checksum"`
}

func (p *ComponentFirmwareVersionListParams) setQuery(q url.Values) {
Expand All @@ -34,6 +36,14 @@ func (p *ComponentFirmwareVersionListParams) setQuery(q url.Values) {
if p.Version != "" {
q.Set("version", p.Version)
}

if p.Filename != "" {
q.Set("filename", p.Filename)
}

if p.Checksum != "" {
q.Set("checksum", p.Checksum)
}
}

// queryMods converts the list params into sql conditions that can be added to sql queries
Expand All @@ -55,5 +65,15 @@ func (p *ComponentFirmwareVersionListParams) queryMods() []qm.QueryMod {
mods = append(mods, m)
}

if p.Filename != "" {
m := models.ComponentFirmwareVersionWhere.Filename.EQ(p.Filename)
mods = append(mods, m)
}

if p.Checksum != "" {
m := models.ComponentFirmwareVersionWhere.Checksum.EQ(p.Checksum)
mods = append(mods, m)
}

return mods
}
18 changes: 18 additions & 0 deletions pkg/api/v1/router_firmware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ func TestIntegrationFirmwareList(t *testing.T) {
false,
"",
},
{
"search by filename",
&serverservice.ComponentFirmwareVersionListParams{
Filename: "BIOS_C4FT0_WN64_2.6.6.EXE",
},
[]string{dbtools.FixtureDellR6515BIOS.ID},
false,
"",
},
{
"search by checksum",
&serverservice.ComponentFirmwareVersionListParams{
Checksum: "1ddcb3c3d0fc5925ef03a3dde768e9e245c579039dd958fc0f3a9c6368b6c5f4",
},
[]string{dbtools.FixtureDellR6515BIOS.ID},
false,
"",
},
}

for _, tt := range testCases {
Expand Down

0 comments on commit f991cfd

Please sign in to comment.