This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from PDOK/code-cleanup
Code cleanup
- Loading branch information
Showing
48 changed files
with
764 additions
and
1,195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package core | ||
|
||
import ( | ||
"net/http" | ||
"oaf-server/codegen" | ||
|
||
"github.com/getkin/kin-openapi/openapi3" | ||
) | ||
|
||
// GetApiProvider is returned by the NewGetApiProvider | ||
// containing the data and contenttype for the response | ||
type GetApiProvider struct { | ||
data *openapi3.T | ||
contenttype string | ||
} | ||
|
||
// NewGetApiProvider handles the request and return the GetApiProvider | ||
func NewGetApiProvider(api *openapi3.T) func(r *http.Request) (codegen.Provider, error) { | ||
|
||
return func(r *http.Request) (codegen.Provider, error) { | ||
p := &GetApiProvider{} | ||
|
||
ct, err := GetContentType(r, p.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
p.contenttype = ct | ||
p.data = api | ||
|
||
return p, nil | ||
} | ||
} | ||
|
||
// Provide provides the data | ||
func (gap *GetApiProvider) Provide() (interface{}, error) { | ||
return gap.data, nil | ||
} | ||
|
||
// ContentType returns the ContentType | ||
func (gap *GetApiProvider) ContentType() string { | ||
return gap.contenttype | ||
} | ||
|
||
// String returns the provider name | ||
func (gap *GetApiProvider) String() string { | ||
return "api" | ||
} | ||
|
||
// SrsId returns the srsid | ||
func (gap *GetApiProvider) SrsId() string { | ||
return "n.a" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"oaf-server/codegen" | ||
) | ||
|
||
// DescribeCollectionProvider is returned by the NewDescribeCollectionProvider | ||
// containing the data and contenttype for the response | ||
type DescribeCollectionProvider struct { | ||
data codegen.Collection | ||
contenttype string | ||
} | ||
|
||
// NewDescribeCollectionProvider handles the request and return the DescribeCollectionProvider | ||
func NewDescribeCollectionProvider(config Config) func(r *http.Request) (codegen.Provider, error) { | ||
|
||
return func(r *http.Request) (codegen.Provider, error) { | ||
path := r.URL.Path // collections/{{collectionId}} | ||
|
||
collectionId, _ := codegen.ParametersForDescribeCollection(r) | ||
|
||
p := &DescribeCollectionProvider{} | ||
|
||
ct, err := GetContentType(r, p.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
p.contenttype = ct | ||
|
||
for _, cn := range config.Datasource.Collections { | ||
// maybe convert to map, but not thread safe! | ||
if cn.Identifier != collectionId { | ||
continue | ||
} | ||
|
||
cInfo := codegen.Collection{ | ||
Id: cn.Identifier, | ||
Title: cn.Identifier, | ||
Description: cn.Description, | ||
Crs: []string{config.Crs[fmt.Sprintf("%d", cn.Srid)]}, | ||
Links: []codegen.Link{}, | ||
} | ||
|
||
// create links | ||
hrefBase := fmt.Sprintf("%s%s", config.Service.Url, path) // /collections | ||
links, _ := CreateLinks(collectionId, p.String(), hrefBase, "self", ct) | ||
|
||
cihrefBase := fmt.Sprintf("%s/items", hrefBase) | ||
ilinks, _ := CreateLinks("items of "+collectionId, p.String(), cihrefBase, "item", ct) | ||
cInfo.Links = append(links, ilinks...) | ||
|
||
for _, c := range config.Datasource.Collections { | ||
if c.Identifier == cn.Identifier { | ||
if len(c.Links) != 0 { | ||
cInfo.Links = append(cInfo.Links, c.Links...) | ||
} | ||
break | ||
} | ||
} | ||
|
||
p.data = cInfo | ||
break | ||
} | ||
|
||
return p, nil | ||
} | ||
|
||
} | ||
|
||
// Provide returns the srsid | ||
func (dcp *DescribeCollectionProvider) Provide() (interface{}, error) { | ||
return dcp.data, nil | ||
} | ||
|
||
// ContentType returns the srsid | ||
func (dcp *DescribeCollectionProvider) ContentType() string { | ||
return dcp.contenttype | ||
} | ||
|
||
// SrsStringId returns the provider name | ||
func (dcp *DescribeCollectionProvider) String() string { | ||
return "collection" | ||
} | ||
|
||
// SrsId returns the srsid | ||
func (dcp *DescribeCollectionProvider) SrsId() string { | ||
return "n.a." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package core | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"oaf-server/codegen" | ||
) | ||
|
||
// GetCollectionsProvider is returned by the NewGetCollectionsProvider | ||
// containing the data and contenttype for the response | ||
type GetCollectionsProvider struct { | ||
data codegen.Collections | ||
contenttype string | ||
} | ||
|
||
// NewGetCollectionsProvider handles the request and return the GetCollectionsProvider | ||
func NewGetCollectionsProvider(config Config) func(r *http.Request) (codegen.Provider, error) { | ||
|
||
return func(r *http.Request) (codegen.Provider, error) { | ||
path := r.URL.Path // collections | ||
|
||
p := &GetCollectionsProvider{} | ||
|
||
ct, err := GetContentType(r, p.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
p.contenttype = ct | ||
|
||
csInfo := codegen.Collections{Links: []codegen.Link{}, Collections: []codegen.Collection{}} | ||
// create Links | ||
hrefBase := fmt.Sprintf("%s%s", config.Service.Url, path) // /collections | ||
links, _ := CreateLinks("collections ", p.String(), hrefBase, "self", ct) | ||
csInfo.Links = append(csInfo.Links, links...) | ||
for _, cn := range config.Datasource.Collections { | ||
clinks, _ := CreateLinks("collection "+cn.Identifier, p.String(), fmt.Sprintf("%s/%s", hrefBase, cn.Identifier), "item", ct) | ||
csInfo.Links = append(csInfo.Links, clinks...) | ||
} | ||
|
||
for _, cn := range config.Datasource.Collections { | ||
|
||
cInfo := codegen.Collection{ | ||
Id: cn.Identifier, | ||
Title: cn.Identifier, | ||
Description: cn.Description, | ||
Crs: []string{config.Crs[fmt.Sprintf("%d", cn.Srid)]}, | ||
Links: []codegen.Link{}, | ||
} | ||
|
||
chrefBase := fmt.Sprintf("%s/%s", hrefBase, cn.Identifier) | ||
|
||
clinks, _ := CreateLinks("collection "+cn.Identifier, p.String(), chrefBase, "self", ct) | ||
cInfo.Links = append(cInfo.Links, clinks...) | ||
|
||
cihrefBase := fmt.Sprintf("%s/items", chrefBase) | ||
ilinks, _ := CreateLinks("items "+cn.Identifier, p.String(), cihrefBase, "item", ct) | ||
cInfo.Links = append(cInfo.Links, ilinks...) | ||
|
||
for _, c := range config.Datasource.Collections { | ||
if c.Identifier == cn.Identifier { | ||
if len(c.Links) != 0 { | ||
cInfo.Links = append(cInfo.Links, c.Links...) | ||
} | ||
break | ||
} | ||
} | ||
|
||
csInfo.Collections = append(csInfo.Collections, cInfo) | ||
} | ||
|
||
p.data = csInfo | ||
|
||
return p, nil | ||
} | ||
} | ||
|
||
// Provide provides the data | ||
func (gcp *GetCollectionsProvider) Provide() (interface{}, error) { | ||
return gcp.data, nil | ||
} | ||
|
||
// ContentType returns the ContentType | ||
func (gcp *GetCollectionsProvider) ContentType() string { | ||
return gcp.contenttype | ||
} | ||
|
||
// String returns the provider name | ||
func (gcp *GetCollectionsProvider) String() string { | ||
return "collections" | ||
} | ||
|
||
// SrsId returns the srsid | ||
func (gcp *GetCollectionsProvider) SrsId() string { | ||
return "n.a." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.