mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-09 06:04:12 +00:00
Make repos and snapshots API return JSON objects for packages when asked
This commit is contained in:
+19
-11
@@ -178,6 +178,15 @@ func apiReposPackagesShow(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
list, err := deb.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), nil)
|
||||
if err != nil {
|
||||
c.Fail(500, err)
|
||||
return
|
||||
}
|
||||
|
||||
list.PrepareIndex()
|
||||
|
||||
result := []*deb.Package{}
|
||||
queryS := c.Request.URL.Query().Get("q")
|
||||
if queryS != "" {
|
||||
q, err := query.Parse(queryS)
|
||||
@@ -186,14 +195,6 @@ func apiReposPackagesShow(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
list, err := deb.NewPackageListFromRefList(repo.RefList(), context.CollectionFactory().PackageCollection(), nil)
|
||||
if err != nil {
|
||||
c.Fail(500, err)
|
||||
return
|
||||
}
|
||||
|
||||
list.PrepareIndex()
|
||||
|
||||
withDeps := c.Request.URL.Query().Get("withDeps") == "1"
|
||||
architecturesList := []string{}
|
||||
|
||||
@@ -212,16 +213,23 @@ func apiReposPackagesShow(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
result, err := list.Filter([]deb.PackageQuery{q}, withDeps,
|
||||
list, err = list.Filter([]deb.PackageQuery{q}, withDeps,
|
||||
nil, context.DependencyOptions(), architecturesList)
|
||||
if err != nil {
|
||||
c.Fail(500, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(200, result.Strings())
|
||||
if c.Request.URL.Query().Get("format") == "details" {
|
||||
list.ForEach(func(p *deb.Package) error {
|
||||
result = append(result, p)
|
||||
return nil
|
||||
})
|
||||
|
||||
c.JSON(200, result)
|
||||
} else {
|
||||
c.JSON(200, repo.RefList().Strings())
|
||||
c.JSON(200, list.Strings())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+15
-10
@@ -234,13 +234,19 @@ func apiSnapshotsShow(c *gin.Context) {
|
||||
collection.RLock()
|
||||
defer collection.RUnlock()
|
||||
|
||||
repo, err := collection.ByName(c.Params.ByName("name"))
|
||||
snapshot, err := collection.ByName(c.Params.ByName("name"))
|
||||
if err != nil {
|
||||
c.Fail(404, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, repo)
|
||||
err = collection.LoadComplete(snapshot)
|
||||
if err != nil {
|
||||
c.Fail(500, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, snapshot)
|
||||
}
|
||||
|
||||
// DELETE /api/snapshots/:name
|
||||
@@ -405,22 +411,21 @@ func apiSnapshotsSearchPackages(c *gin.Context) {
|
||||
|
||||
list.PrepareIndex()
|
||||
|
||||
packages, err := list.Filter([]deb.PackageQuery{q}, withDeps,
|
||||
list, err = list.Filter([]deb.PackageQuery{q}, withDeps,
|
||||
nil, context.DependencyOptions(), architecturesList)
|
||||
if err != nil {
|
||||
c.Fail(500, fmt.Errorf("unable to search: %s", err))
|
||||
}
|
||||
}
|
||||
|
||||
packages.ForEach(func(p *deb.Package) error {
|
||||
result = append(result, p)
|
||||
return nil
|
||||
})
|
||||
} else {
|
||||
if c.Request.URL.Query().Get("format") == "details" {
|
||||
list.ForEach(func(p *deb.Package) error {
|
||||
result = append(result, p)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
c.JSON(200, result)
|
||||
c.JSON(200, result)
|
||||
} else {
|
||||
c.JSON(200, list.Strings())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,10 @@ class SnapshotsAPITestCreateFromRepo(APITest):
|
||||
self.check_equal(self.get("/api/snapshots/" + snapshot_name).status_code, 200)
|
||||
|
||||
self.check_subset({u'Architecture': 'i386', u'Name': 'libboost-program-options-dev', u'Version': '1.49.0.1', 'FilesHash': '918d2f433384e378'},
|
||||
self.get("/api/snapshots/" + snapshot_name + "/packages").json()[0])
|
||||
self.get("/api/snapshots/" + snapshot_name + "/packages?format=details").json()[0])
|
||||
|
||||
self.check_subset({u'Architecture': 'i386', u'Name': 'libboost-program-options-dev', u'Version': '1.49.0.1', 'FilesHash': '918d2f433384e378'},
|
||||
self.get("/api/snapshots/" + snapshot_name + "/packages", params={"q": "Version (> 0.6.1-1.4)"}).json()[0])
|
||||
self.get("/api/snapshots/" + snapshot_name + "/packages?format=details", params={"q": "Version (> 0.6.1-1.4)"}).json()[0])
|
||||
|
||||
|
||||
class SnapshotsAPITestCreateUpdate(APITest):
|
||||
@@ -107,12 +107,18 @@ class SnapshotsAPITestSearch(APITest):
|
||||
resp = self.post("/api/repos/" + repo_name + '/snapshots', json={'Name': snapshot_name})
|
||||
self.check_equal(resp.status_code, 201)
|
||||
|
||||
resp = self.get("/api/snapshots/" + snapshot_name + "/packages?q=libboost-program-options-dev")
|
||||
resp = self.get("/api/snapshots/" + snapshot_name + "/packages?q=libboost-program-options-dev&format=details")
|
||||
self.check_equal(resp.status_code, 200)
|
||||
|
||||
self.check_equal(len(resp.json()), 1)
|
||||
self.check_equal(resp.json()[0]["Name"], "libboost-program-options-dev")
|
||||
|
||||
resp = self.get("/api/snapshots/" + snapshot_name + "/packages")
|
||||
self.check_equal(resp.status_code, 200)
|
||||
|
||||
self.check_equal(len(resp.json()), 1)
|
||||
self.check_equal(resp.json(), ["Pi386 libboost-program-options-dev 1.49.0.1 918d2f433384e378"])
|
||||
|
||||
|
||||
class SnapshotsAPITestDiff(APITest):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user