added a new endpoint to get a list of sources by the source value (#18)
This commit is contained in:
parent
66c74802d9
commit
206251a3d1
22
docs/docs.go
22
docs/docs.go
@ -104,6 +104,28 @@ const docTemplate = `{
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/config/sources/by/source": {
|
||||||
|
"get": {
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Config",
|
||||||
|
"Source"
|
||||||
|
],
|
||||||
|
"summary": "Lists the top 50 records based on the name given. Example: reddit",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Source Name",
|
||||||
|
"name": "source",
|
||||||
|
"in": "query",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/config/sources/new/reddit": {
|
"/config/sources/new/reddit": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": [
|
"tags": [
|
||||||
|
@ -95,6 +95,28 @@
|
|||||||
"responses": {}
|
"responses": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/config/sources/by/source": {
|
||||||
|
"get": {
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Config",
|
||||||
|
"Source"
|
||||||
|
],
|
||||||
|
"summary": "Lists the top 50 records based on the name given. Example: reddit",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Source Name",
|
||||||
|
"name": "source",
|
||||||
|
"in": "query",
|
||||||
|
"required": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/config/sources/new/reddit": {
|
"/config/sources/new/reddit": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": [
|
"tags": [
|
||||||
|
@ -118,6 +118,21 @@ paths:
|
|||||||
tags:
|
tags:
|
||||||
- Config
|
- Config
|
||||||
- Source
|
- Source
|
||||||
|
/config/sources/by/source:
|
||||||
|
get:
|
||||||
|
parameters:
|
||||||
|
- description: Source Name
|
||||||
|
in: query
|
||||||
|
name: source
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses: {}
|
||||||
|
summary: 'Lists the top 50 records based on the name given. Example: reddit'
|
||||||
|
tags:
|
||||||
|
- Config
|
||||||
|
- Source
|
||||||
/config/sources/new/reddit:
|
/config/sources/new/reddit:
|
||||||
post:
|
post:
|
||||||
parameters:
|
parameters:
|
||||||
|
@ -93,6 +93,7 @@ func (s *Server) MountRoutes() {
|
|||||||
|
|
||||||
/* Source Routes */
|
/* Source Routes */
|
||||||
s.Router.Get("/api/config/sources", s.listSources)
|
s.Router.Get("/api/config/sources", s.listSources)
|
||||||
|
s.Router.Get("/api/config/sources/by/source", s.listSourcesBySource)
|
||||||
|
|
||||||
/* Reddit Source Routes */
|
/* Reddit Source Routes */
|
||||||
|
|
||||||
|
@ -28,12 +28,49 @@ func (s *Server) listSources(w http.ResponseWriter, r *http.Request) {
|
|||||||
res, err := s.Db.ListSources(*s.ctx, int32(topInt))
|
res, err := s.Db.ListSources(*s.ctx, int32(topInt))
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Default way of showing all sources
|
||||||
res, err := s.Db.ListSources(*s.ctx, 50)
|
res, err := s.Db.ListSources(*s.ctx, 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "url is missing a value", http.StatusBadRequest)
|
http.Error(w, "url is missing a value", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
bResult, err := json.Marshal(res)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "unable to convert to json", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Write(bResult)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListSourcesBySource
|
||||||
|
// @Summary Lists the top 50 records based on the name given. Example: reddit
|
||||||
|
// @Param source query string true "Source Name"
|
||||||
|
// @Produce application/json
|
||||||
|
// @Tags Config, Source
|
||||||
|
// @Router /config/sources/by/source [get]
|
||||||
|
func (s *Server) listSourcesBySource(w http.ResponseWriter, r *http.Request) {
|
||||||
|
//TODO Add top?
|
||||||
|
/*
|
||||||
|
top := chi.URLParam(r, "top")
|
||||||
|
topInt, err := strconv.ParseInt(top, 0, 32)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
res, err := s.Db.ListSources(*s.ctx, int32(topInt))
|
||||||
|
*/
|
||||||
|
|
||||||
|
query := r.URL.Query()
|
||||||
|
_source := query["source"][0]
|
||||||
|
|
||||||
|
// Shows the list by Sources.source
|
||||||
|
res, err := s.Db.ListSourcesBySource(*s.ctx, strings.ToLower(_source))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "invalid source is missing a value", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
bResult, err := json.Marshal(res)
|
bResult, err := json.Marshal(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "unable to convert to json", http.StatusBadRequest)
|
http.Error(w, "unable to convert to json", http.StatusBadRequest)
|
||||||
@ -116,10 +153,6 @@ func (s *Server) newRedditSource(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.Write(bJson)
|
w.Write(bJson)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) getSourceByType(w http.ResponseWriter, r *http.Request) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewYoutubeSource
|
// NewYoutubeSource
|
||||||
// @Summary Creates a new youtube source to monitor.
|
// @Summary Creates a new youtube source to monitor.
|
||||||
// @Param name query string true "name"
|
// @Param name query string true "name"
|
||||||
|
Loading…
Reference in New Issue
Block a user