Skip to content

Commit

Permalink
Fix method calls, add is null for globals
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-marschke committed Dec 2, 2023
1 parent b0baa71 commit 1f8dba2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 38 deletions.
1 change: 0 additions & 1 deletion api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ func Route() *mux.Router {
projectUserAPI.Path("/webhooks").HandlerFunc(projects.AddWebhook).Methods("POST")

projectWebhooksAPI := projectUserAPI.PathPrefix("/webhook").Subrouter()
projectWebhooksAPI.Use(projects.WebhookMiddleware, projects.MustBeAdmin)

projectWebhooksAPI.Path("/{webhook_id}").Methods("GET", "HEAD").HandlerFunc(projects.GetWebhook)
projectWebhooksAPI.Path("/{webhook_id}").Methods("PUT").HandlerFunc(projects.UpdateWebhook)
Expand Down
45 changes: 8 additions & 37 deletions db/sql/SqlDb.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

package sql

import (
Expand Down Expand Up @@ -207,53 +208,22 @@ func (d *SqlDb) getObjectsByReferrer(referrerID int, referringObjectProps db.Obj
var referringColumn = referringObjectProps.ReferringColumnSuffix

q := squirrel.Select("*").
From(props.TableName+" pe").
Where("pe." + referringColumn + "=?", referrerID)

orderDirection := "ASC"
if params.SortInverted {
orderDirection = "DESC"
}

orderColumn := props.DefaultSortingColumn
if containsStr(props.SortableColumns, params.SortBy) {
orderColumn = params.SortBy
}

if orderColumn != "" {
q = q.OrderBy("pe." + orderColumn + " " + orderDirection)
}

query, args, err := q.ToSql()

if err != nil {
return
}

_, err = d.selectAll(objects, query, args...)

return
}

func (d *SqlDb) getObjects(projectID int, props db.ObjectProps, params db.RetrieveQueryParams, objects interface{}) (err error) {
q := squirrel.Select("*").
From(props.TableName + " pe")
From(props.TableName+" pe")

if props.IsGlobal {
q = q.Where("pe.project_id is null")
q = q.Where("pe." + referringColumn + " is null")
} else {
q = q.Where("pe.project_id=?", projectID)
q = q.Where("pe." + referringColumn + "=?", referrerID)
}

orderDirection := "ASC"

orderDirection := "ASC"
if params.SortInverted {
orderDirection = "DESC"
orderDirection = "DESC"
}

orderColumn := props.DefaultSortingColumn
if containsStr(props.SortableColumns, params.SortBy) {
orderColumn = params.SortBy
orderColumn = params.SortBy
}

if orderColumn != "" {
Expand All @@ -274,6 +244,7 @@ func (d *SqlDb) getObjects(projectID int, props db.ObjectProps, params db.Retrie
func (d *SqlDb) getObject(projectID int, props db.ObjectProps, objectID int, objects interface{}) (err error) {
return d.getObjectByReferrer(projectID, db.ProjectProps, props, objectID, objects)
}

func (d *SqlDb) getObjects(projectID int, props db.ObjectProps, params db.RetrieveQueryParams, objects interface{}) (err error) {
return d.getObjectsByReferrer(projectID, db.ProjectProps, props, params, objects);
}
Expand Down

0 comments on commit 1f8dba2

Please sign in to comment.