Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
updated router, refactored to use utils from sc
Browse files Browse the repository at this point in the history
  • Loading branch information
farshidtz committed Mar 2, 2020
1 parent eccf126 commit 6471fe5
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 1,008 deletions.
9 changes: 5 additions & 4 deletions catalog/catalogapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/linksmart/service-catalog/v3/utils"
)

type ThingsCollection struct {
Expand Down Expand Up @@ -180,8 +181,8 @@ func (a *HTTPAPI) List(w http.ResponseWriter, req *http.Request) {
ErrorResponse(w, http.StatusBadRequest, "Error parsing the query:", err.Error())
return
}
page, perPage, err := ParsePagingParams(
req.Form.Get(GetParamPage), req.Form.Get(GetParamPerPage), MaxPerPage)
page, perPage, err := utils.ParsePagingParams(
req.Form.Get(utils.GetParamPage), req.Form.Get(utils.GetParamPerPage), MaxPerPage)
if err != nil {
ErrorResponse(w, http.StatusBadRequest, "Error parsing query parameters:", err.Error())
return
Expand Down Expand Up @@ -224,8 +225,8 @@ func (a *HTTPAPI) Filter(w http.ResponseWriter, req *http.Request) {
ErrorResponse(w, http.StatusBadRequest, "Error parsing the query:", err.Error())
return
}
page, perPage, err := ParsePagingParams(
req.Form.Get(GetParamPage), req.Form.Get(GetParamPerPage), MaxPerPage)
page, perPage, err := utils.ParsePagingParams(
req.Form.Get(utils.GetParamPage), req.Form.Get(utils.GetParamPerPage), MaxPerPage)
if err != nil {
ErrorResponse(w, http.StatusBadRequest, "Error parsing query parameters:", err.Error())
return
Expand Down
31 changes: 0 additions & 31 deletions catalog/client.go

This file was deleted.

1 change: 0 additions & 1 deletion catalog/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ const (
ApiVersion = "1.0.0"
BackendMemory = "memory"
BackendLevelDB = "leveldb"
loggerPrefix = "[catalog] "
)
5 changes: 3 additions & 2 deletions catalog/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/linksmart/service-catalog/v3/utils"
uuid "github.com/satori/go.uuid"
)

Expand Down Expand Up @@ -98,7 +99,7 @@ func (c *Controller) filter(path, op, value string, page, perPage int) ([]ThingD
}

for i := range slice {
matched, err := MatchObject(slice[i], strings.Split(path, "."), op, value)
matched, err := utils.MatchObject(slice[i], strings.Split(path, "."), op, value)
if err != nil {
return nil, 0, err
}
Expand All @@ -112,7 +113,7 @@ func (c *Controller) filter(path, op, value string, page, perPage int) ([]ThingD
}
}
// Pagination
offset, limit, err := GetPagingAttr(len(matches), page, perPage, MaxPerPage)
offset, limit, err := utils.GetPagingAttr(len(matches), page, perPage, MaxPerPage)
if err != nil {
return nil, 0, &BadRequestError{fmt.Sprintf("Unable to paginate: %s", err)}
}
Expand Down
82 changes: 0 additions & 82 deletions catalog/http.go

This file was deleted.

3 changes: 2 additions & 1 deletion catalog/ldbstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"sync"

"github.com/linksmart/service-catalog/v3/utils"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
)
Expand Down Expand Up @@ -117,7 +118,7 @@ func (s *LevelDBStorage) list(page int, perPage int) ([]ThingDescription, int, e
if err != nil {
return nil, 0, err
}
offset, limit, err := GetPagingAttr(total, page, perPage, MaxPerPage)
offset, limit, err := utils.GetPagingAttr(total, page, perPage, MaxPerPage)
if err != nil {
return nil, 0, &BadRequestError{fmt.Sprintf("Unable to paginate: %s", err)}
}
Expand Down
50 changes: 0 additions & 50 deletions catalog/localclient.go

This file was deleted.

109 changes: 0 additions & 109 deletions catalog/pagination.go

This file was deleted.

Loading

0 comments on commit 6471fe5

Please sign in to comment.