Skip to content

Commit

Permalink
✨ add pagination to list endpoints. (#296)
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Ortel <jortel@redhat.com>
  • Loading branch information
jortel committed Apr 13, 2023
1 parent 210c382 commit 11ec943
Show file tree
Hide file tree
Showing 20 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (h ApplicationHandler) Get(ctx *gin.Context) {
// @router /applications [get]
func (h ApplicationHandler) List(ctx *gin.Context) {
var list []model.Application
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down
2 changes: 1 addition & 1 deletion api/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (h BucketHandler) AddRoutes(e *gin.Engine) {
// @router /buckets [get]
func (h BucketHandler) List(ctx *gin.Context) {
var list []model.Bucket
result := h.DB(ctx).Find(&list)
result := h.Paginated(ctx).Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
return
Expand Down
2 changes: 1 addition & 1 deletion api/businessservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (h BusinessServiceHandler) Get(ctx *gin.Context) {
// @router /businessservices [get]
func (h BusinessServiceHandler) List(ctx *gin.Context) {
var list []model.BusinessService
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down
2 changes: 1 addition & 1 deletion api/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (h DependencyHandler) Get(ctx *gin.Context) {
func (h DependencyHandler) List(ctx *gin.Context) {
var list []model.Dependency

db := h.DB(ctx)
db := h.Paginated(ctx)
to := ctx.Query("to.id")
from := ctx.Query("from.id")
if to != "" {
Expand Down
2 changes: 1 addition & 1 deletion api/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (h FileHandler) AddRoutes(e *gin.Engine) {
// @router /files [get]
func (h FileHandler) List(ctx *gin.Context) {
var list []model.File
result := h.DB(ctx).Find(&list)
result := h.Paginated(ctx).Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
return
Expand Down
2 changes: 1 addition & 1 deletion api/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (h StakeholderGroupHandler) Get(ctx *gin.Context) {
// @router /stakeholdergroups [get]
func (h StakeholderGroupHandler) List(ctx *gin.Context) {
var list []model.StakeholderGroup
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down
2 changes: 1 addition & 1 deletion api/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (h IdentityHandler) List(ctx *gin.Context) {
var list []model.Identity
appId := ctx.Query(AppId)
kind := ctx.Query(Kind)
db := h.DB(ctx)
db := h.Paginated(ctx)
if appId != "" {
db = db.Where(
"id IN (SELECT identityID from ApplicationIdentity WHERE applicationID = ?)",
Expand Down
2 changes: 1 addition & 1 deletion api/jobfunction.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (h JobFunctionHandler) Get(ctx *gin.Context) {
// @router /jobfunctions [get]
func (h JobFunctionHandler) List(ctx *gin.Context) {
var list []model.JobFunction
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down
2 changes: 1 addition & 1 deletion api/migrationwave.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (h MigrationWaveHandler) Get(ctx *gin.Context) {
// @router /migrationwaves [get]
func (h MigrationWaveHandler) List(ctx *gin.Context) {
var list []model.MigrationWave
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down
2 changes: 1 addition & 1 deletion api/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (h ProxyHandler) Get(ctx *gin.Context) {
func (h ProxyHandler) List(ctx *gin.Context) {
var list []model.Proxy
kind := ctx.Query(Kind)
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
if kind != "" {
db = db.Where(Kind, kind)
}
Expand Down
2 changes: 1 addition & 1 deletion api/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (h ReviewHandler) Get(ctx *gin.Context) {
// @router /reviews [get]
func (h ReviewHandler) List(ctx *gin.Context) {
var list []model.Review
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down
2 changes: 1 addition & 1 deletion api/rulebundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (h RuleBundleHandler) Get(ctx *gin.Context) {
func (h RuleBundleHandler) List(ctx *gin.Context) {
var list []model.RuleBundle
db := h.preLoad(
h.DB(ctx),
h.Paginated(ctx),
clause.Associations,
"RuleSets.File")
result := db.Find(&list)
Expand Down
2 changes: 1 addition & 1 deletion api/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (h SettingHandler) Get(ctx *gin.Context) {
// @router /settings [get]
func (h SettingHandler) List(ctx *gin.Context) {
var list []model.Setting
result := h.DB(ctx).Find(&list)
result := h.Paginated(ctx).Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
return
Expand Down
2 changes: 1 addition & 1 deletion api/stakeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (h StakeholderHandler) Get(ctx *gin.Context) {
// @router /stakeholders [get]
func (h StakeholderHandler) List(ctx *gin.Context) {
var list []model.Stakeholder
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down
2 changes: 1 addition & 1 deletion api/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (h TagHandler) Get(ctx *gin.Context) {
// @router /tags [get]
func (h TagHandler) List(ctx *gin.Context) {
var list []model.Tag
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down
2 changes: 1 addition & 1 deletion api/tagcategory.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (h TagCategoryHandler) Get(ctx *gin.Context) {
// @param name query string false "Optional category name filter"
func (h TagCategoryHandler) List(ctx *gin.Context) {
var list []model.TagCategory
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
if name, found := ctx.GetQuery(Name); found {
db = db.Where("name = ?", name)
}
Expand Down
2 changes: 1 addition & 1 deletion api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (h TaskHandler) Get(ctx *gin.Context) {
// @router /tasks [get]
func (h TaskHandler) List(ctx *gin.Context) {
var list []model.Task
db := h.DB(ctx)
db := h.Paginated(ctx)
locator := ctx.Query(LocatorParam)
if locator != "" {
db = db.Where("locator", locator)
Expand Down
2 changes: 1 addition & 1 deletion api/taskgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (h TaskGroupHandler) Get(ctx *gin.Context) {
// @router /taskgroups [get]
func (h TaskGroupHandler) List(ctx *gin.Context) {
var list []model.TaskGroup
db := h.DB(ctx).Preload(clause.Associations)
db := h.Paginated(ctx).Preload(clause.Associations)
result := db.Find(&list)
if result.Error != nil {
_ = ctx.Error(result.Error)
Expand Down
2 changes: 1 addition & 1 deletion api/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (h TicketHandler) List(ctx *gin.Context) {
var list []model.Ticket
appId := ctx.Query(AppId)
trackerId := ctx.Query(TrackerId)
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
if appId != "" {
db = db.Where("ApplicationID = ?", appId)
}
Expand Down
2 changes: 1 addition & 1 deletion api/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (h TrackerHandler) Get(ctx *gin.Context) {
// @router /trackers [get]
func (h TrackerHandler) List(ctx *gin.Context) {
var list []model.Tracker
db := h.preLoad(h.DB(ctx), clause.Associations)
db := h.preLoad(h.Paginated(ctx), clause.Associations)
kind := ctx.Query(Kind)
if kind != "" {
db = db.Where(Kind, kind)
Expand Down

0 comments on commit 11ec943

Please sign in to comment.