Skip to content

Commit

Permalink
removed the organisation endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
vsumit89 committed Sep 7, 2022
1 parent 4cf614c commit 778b88d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
80 changes: 40 additions & 40 deletions server/action/organisation/all.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package organisation

import (
"fmt"
"net/http"

"github.com/factly/kavach-server/model"
"github.com/factly/x/renderx"
)

type paging struct {
Nodes []model.Organisation `json:"nodes"`
Total int64 `json:"total"`
}

// all - Get all organisations
// @Summary Show all organisations
// @Description Get all organisations
// @Tags Organisation
// @ID get-all-organisations
// @Produce json
// @Param X-User header string true "User ID"
// @Param q query string false "Query"
// @Success 200 {array} model.Organisation
// @Router /organisations [get]
func all(w http.ResponseWriter, r *http.Request) {
result := paging{}
result.Nodes = make([]model.Organisation, 0)

searchQuery := r.URL.Query().Get("q")

tx := model.DB.Model(&model.Organisation{})

if searchQuery != "" {
query := fmt.Sprint("%", searchQuery, "%")
tx.Where("title ILIKE ?", query)
}

tx.Count(&result.Total).Preload("Medium").Find(&result.Nodes)

renderx.JSON(w, http.StatusOK, result)
}
// import (
// "fmt"
// "net/http"

// "github.com/factly/kavach-server/model"
// "github.com/factly/x/renderx"
// )

// type paging struct {
// Nodes []model.Organisation `json:"nodes"`
// Total int64 `json:"total"`
// }

// // all - Get all organisations
// // @Summary Show all organisations
// // @Description Get all organisations
// // @Tags Organisation
// // @ID get-all-organisations
// // @Produce json
// // @Param X-User header string true "User ID"
// // @Param q query string false "Query"
// // @Success 200 {array} model.Organisation
// // @Router /organisations [get]
// func all(w http.ResponseWriter, r *http.Request) {
// result := paging{}
// result.Nodes = make([]model.Organisation, 0)

// searchQuery := r.URL.Query().Get("q")

// tx := model.DB.Model(&model.Organisation{})

// if searchQuery != "" {
// query := fmt.Sprint("%", searchQuery, "%")
// tx.Where("title ILIKE ?", query)
// }

// tx.Count(&result.Total).Preload("Medium").Find(&result.Nodes)

// renderx.JSON(w, http.StatusOK, result)
// }
2 changes: 1 addition & 1 deletion server/action/organisation/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Router() chi.Router {

r.Get("/my", list)
r.Post("/", create)
r.Get("/", all)
// r.Get("/", all)
r.Route("/{organisation_id}", func(r chi.Router) {
r.Get("/", details)
r.Put("/", update)
Expand Down

0 comments on commit 778b88d

Please sign in to comment.