cleaned up get routes
This commit is contained in:
parent
ada453e08a
commit
6629a55157
@ -3,6 +3,7 @@ package routes
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -18,6 +19,7 @@ func (s *Server) GetArticleRouter() http.Handler {
|
|||||||
r.Get("/details", s.getArticleDetails)
|
r.Get("/details", s.getArticleDetails)
|
||||||
})
|
})
|
||||||
r.Get("/by/sourceid", s.GetArticlesBySourceId)
|
r.Get("/by/sourceid", s.GetArticlesBySourceId)
|
||||||
|
r.Get("/by/page", s.ListArticlesByPage)
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
@ -27,6 +29,16 @@ type ArticlesListResults struct {
|
|||||||
Payload []models.ArticleDto `json:"payload"`
|
Payload []models.ArticleDto `json:"payload"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ArticleGetResults struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload models.ArticleDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ArticleDetailsResult struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload models.ArticleDetailsDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
// ListArticles
|
// ListArticles
|
||||||
// @Summary Lists the top 50 records
|
// @Summary Lists the top 50 records
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
@ -41,27 +53,46 @@ func (s *Server) listArticles(w http.ResponseWriter, r *http.Request) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
|
|
||||||
res, err := s.dto.ListArticles(r.Context(), 50)
|
res, err := s.dto.ListArticles(r.Context(), 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
p.Payload = res
|
||||||
|
s.WriteJson(w, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListArticlesByPage
|
||||||
|
// @Summary List 50 items based on the requested page
|
||||||
|
// @Produce application/json
|
||||||
|
// @Param page query string true "page number"
|
||||||
|
// @Tags Articles
|
||||||
|
// @Router /articles/by/page [get]
|
||||||
|
// @Success 200 {object} ArticlesListResults "OK"
|
||||||
|
func (s *Server) ListArticlesByPage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
p := ArticlesListResults {
|
||||||
|
ApiStatusModel: ApiStatusModel{
|
||||||
|
Message: "OK",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
query := r.URL.Query()
|
||||||
|
page, err := strconv.Atoi(query["page"][0])
|
||||||
|
if err != nil {
|
||||||
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := s.dto.ListArticlesByPage(r.Context(), int32(page), 25)
|
||||||
|
if err != nil {
|
||||||
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
|
|
||||||
bres, err := json.Marshal(p)
|
s.WriteJson(w, p)
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ArticleGetResults struct {
|
|
||||||
ApiStatusModel
|
|
||||||
Payload models.ArticleDto `json:"payload"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetArticle
|
// GetArticle
|
||||||
@ -72,15 +103,13 @@ type ArticleGetResults struct {
|
|||||||
// @Router /articles/{ID} [get]
|
// @Router /articles/{ID} [get]
|
||||||
// @Success 200 {object} ArticleGetResults "OK"
|
// @Success 200 {object} ArticleGetResults "OK"
|
||||||
func (s *Server) getArticle(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) getArticle(w http.ResponseWriter, r *http.Request) {
|
||||||
p := ArticleGetResults {
|
p := ArticleGetResults{
|
||||||
ApiStatusModel: ApiStatusModel{
|
ApiStatusModel: ApiStatusModel{
|
||||||
Message: "OK",
|
Message: "OK",
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
|
|
||||||
id := chi.URLParam(r, "ID")
|
id := chi.URLParam(r, "ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -96,18 +125,7 @@ func (s *Server) getArticle(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
|
|
||||||
bres, err := json.Marshal(p)
|
s.WriteJson(w, p)
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ArticleDetailsResult struct {
|
|
||||||
ApiStatusModel
|
|
||||||
Payload models.ArticleDetailsDto `json:"payload"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetArticleDetails
|
// GetArticleDetails
|
||||||
@ -118,15 +136,13 @@ type ArticleDetailsResult struct {
|
|||||||
// @Router /articles/{ID}/details [get]
|
// @Router /articles/{ID}/details [get]
|
||||||
// @Success 200 {object} ArticleDetailsResult "OK"
|
// @Success 200 {object} ArticleDetailsResult "OK"
|
||||||
func (s *Server) getArticleDetails(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) getArticleDetails(w http.ResponseWriter, r *http.Request) {
|
||||||
p := ArticleDetailsResult {
|
p := ArticleDetailsResult{
|
||||||
ApiStatusModel: ApiStatusModel{
|
ApiStatusModel: ApiStatusModel{
|
||||||
Message: "OK",
|
Message: "OK",
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
|
|
||||||
id := chi.URLParam(r, "ID")
|
id := chi.URLParam(r, "ID")
|
||||||
uuid, err := uuid.Parse(id)
|
uuid, err := uuid.Parse(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -142,18 +158,7 @@ func (s *Server) getArticleDetails(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
|
|
||||||
bres, err := json.Marshal(p)
|
s.WriteJson(w, p)
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ArticlesBySourceIDResults struct {
|
|
||||||
ApiStatusModel
|
|
||||||
Payload []models.ArticleDto `json:"payload"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add page support
|
// TODO add page support
|
||||||
@ -165,7 +170,12 @@ type ArticlesBySourceIDResults struct {
|
|||||||
// @Router /articles/by/sourceid [get]
|
// @Router /articles/by/sourceid [get]
|
||||||
// @Success 200 {object} ArticlesListResults "OK"
|
// @Success 200 {object} ArticlesListResults "OK"
|
||||||
func (s *Server) GetArticlesBySourceId(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) GetArticlesBySourceId(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
p := ArticlesListResults{
|
||||||
|
ApiStatusModel: ApiStatusModel{
|
||||||
|
Message: "OK",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
r.URL.Query()
|
r.URL.Query()
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
@ -182,12 +192,7 @@ func (s *Server) GetArticlesBySourceId(w http.ResponseWriter, r *http.Request) {
|
|||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
p.Payload = res
|
||||||
|
|
||||||
bres, err := json.Marshal(res)
|
s.WriteJson(w, p)
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,16 @@ import (
|
|||||||
"github.com/jtom38/newsbot/collector/domain/models"
|
"github.com/jtom38/newsbot/collector/domain/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ListDiscordWebhooks struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload []models.DiscordWebHooksDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GetDiscordWebhook struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload models.DiscordWebHooksDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
func (s Server) DiscordWebHookRouter() http.Handler {
|
func (s Server) DiscordWebHookRouter() http.Handler {
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
||||||
@ -28,11 +38,6 @@ func (s Server) DiscordWebHookRouter() http.Handler {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListDiscordWebhooks struct {
|
|
||||||
ApiStatusModel
|
|
||||||
Payload []models.DiscordWebHooksDto `json:"payload"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ListDiscordWebhooks
|
// ListDiscordWebhooks
|
||||||
// @Summary Returns the top 100 entries from the queue to be processed.
|
// @Summary Returns the top 100 entries from the queue to be processed.
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
@ -46,27 +51,13 @@ func (s *Server) ListDiscordWebHooks(w http.ResponseWriter, r *http.Request) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
|
|
||||||
res, err := s.dto.ListDiscordWebHooks(r.Context(), 50)
|
res, err := s.dto.ListDiscordWebHooks(r.Context(), 50)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
|
s.WriteJson(w, p)
|
||||||
bres, err := json.Marshal(p)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
|
||||||
|
|
||||||
type GetDiscordWebhook struct {
|
|
||||||
ApiStatusModel
|
|
||||||
Payload models.DiscordWebHooksDto `json:"payload"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDiscordWebHook
|
// GetDiscordWebHook
|
||||||
@ -84,8 +75,6 @@ func (s *Server) GetDiscordWebHooksById(w http.ResponseWriter, r *http.Request)
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
|
|
||||||
_id := chi.URLParam(r, "ID")
|
_id := chi.URLParam(r, "ID")
|
||||||
if _id == "" {
|
if _id == "" {
|
||||||
s.WriteError(w, "id is missing", http.StatusBadRequest)
|
s.WriteError(w, "id is missing", http.StatusBadRequest)
|
||||||
@ -104,14 +93,7 @@ func (s *Server) GetDiscordWebHooksById(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
|
s.WriteJson(w, p)
|
||||||
bres, err := json.Marshal(p)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, "unable to convert to json", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDiscordWebHookByServerAndChannel
|
// GetDiscordWebHookByServerAndChannel
|
||||||
@ -130,8 +112,6 @@ func (s *Server) GetDiscordWebHooksByServerAndChannel(w http.ResponseWriter, r *
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
|
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
_server := query["server"][0]
|
_server := query["server"][0]
|
||||||
if _server == "" {
|
if _server == "" {
|
||||||
@ -152,14 +132,7 @@ func (s *Server) GetDiscordWebHooksByServerAndChannel(w http.ResponseWriter, r *
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
|
s.WriteJson(w, p)
|
||||||
bres, err := json.Marshal(p)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, "unable to convert to json", http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDiscordWebHook
|
// NewDiscordWebHook
|
||||||
|
@ -8,6 +8,11 @@ import (
|
|||||||
"github.com/jtom38/newsbot/collector/domain/models"
|
"github.com/jtom38/newsbot/collector/domain/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type ListDiscordWebHooksQueueResults struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload []models.DiscordQueueDetailsDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Server) GetQueueRouter() http.Handler {
|
func (s *Server) GetQueueRouter() http.Handler {
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
||||||
@ -16,11 +21,6 @@ func (s *Server) GetQueueRouter() http.Handler {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListDiscordWebHooksQueueResults struct {
|
|
||||||
ApiStatusModel
|
|
||||||
Payload []models.DiscordQueueDetailsDto `json:"payload"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetDiscordQueue
|
// GetDiscordQueue
|
||||||
// @Summary Returns the top 100 entries from the queue to be processed.
|
// @Summary Returns the top 100 entries from the queue to be processed.
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
@ -28,8 +28,6 @@ type ListDiscordWebHooksQueueResults struct {
|
|||||||
// @Router /queue/discord/webhooks [get]
|
// @Router /queue/discord/webhooks [get]
|
||||||
// @Success 200 {object} ListDiscordWebHooksQueueResults "ok"
|
// @Success 200 {object} ListDiscordWebHooksQueueResults "ok"
|
||||||
func (s *Server) ListDiscordWebhookQueue(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ListDiscordWebhookQueue(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
p := ListDiscordWebHooksQueueResults{
|
p := ListDiscordWebHooksQueueResults{
|
||||||
ApiStatusModel: ApiStatusModel{
|
ApiStatusModel: ApiStatusModel{
|
||||||
Message: "OK",
|
Message: "OK",
|
||||||
@ -45,13 +43,5 @@ func (s *Server) ListDiscordWebhookQueue(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
|
s.WriteJson(w, p)
|
||||||
// convert to json
|
|
||||||
b, err := json.Marshal(p)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(b)
|
|
||||||
}
|
}
|
||||||
|
@ -112,3 +112,15 @@ func (s *Server) WriteError(w http.ResponseWriter, errMessage string, HttpStatus
|
|||||||
|
|
||||||
w.Write(b)
|
w.Write(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Server) WriteJson(w http.ResponseWriter, model interface{}) {
|
||||||
|
w.Header().Set(HeaderContentType, ApplicationJson)
|
||||||
|
|
||||||
|
bres, err := json.Marshal(model)
|
||||||
|
if err != nil {
|
||||||
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Write(bres)
|
||||||
|
}
|
@ -61,8 +61,7 @@ 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))
|
||||||
*/
|
*/
|
||||||
|
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
p := ListSources{
|
||||||
result := ListSources{
|
|
||||||
ApiStatusModel: ApiStatusModel{
|
ApiStatusModel: ApiStatusModel{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Message: "OK",
|
Message: "OK",
|
||||||
@ -76,15 +75,8 @@ func (s *Server) listSources(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Payload = items
|
p.Payload = items
|
||||||
|
s.WriteJson(w, p)
|
||||||
bResult, err := json.Marshal(result)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bResult)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListSourcesBySource
|
// ListSourcesBySource
|
||||||
@ -106,9 +98,8 @@ func (s *Server) listSourcesBySource(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
res, err := s.Db.ListSources(*s.ctx, int32(topInt))
|
res, err := s.Db.ListSources(*s.ctx, int32(topInt))
|
||||||
*/
|
*/
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
|
|
||||||
result := ListSources{
|
p := ListSources{
|
||||||
ApiStatusModel: ApiStatusModel{
|
ApiStatusModel: ApiStatusModel{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
Message: "OK",
|
Message: "OK",
|
||||||
@ -116,24 +107,16 @@ func (s *Server) listSourcesBySource(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
_source := query["source"][0]
|
|
||||||
|
|
||||||
// Shows the list by Sources.source
|
// Shows the list by Sources.source
|
||||||
res, err := s.dto.ListSourcesBySource(r.Context(), _source)
|
res, err := s.dto.ListSourcesBySource(r.Context(), query["source"][0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Payload = res
|
p.Payload = res
|
||||||
|
s.WriteJson(w, p)
|
||||||
bResult, err := json.Marshal(result)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bResult)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSource
|
// GetSource
|
||||||
@ -154,10 +137,7 @@ func (s *Server) getSources(w http.ResponseWriter, r *http.Request) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
uuid, err := uuid.Parse(chi.URLParam(r, "ID"))
|
||||||
|
|
||||||
id := chi.URLParam(r, "ID")
|
|
||||||
uuid, err := uuid.Parse(id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@ -170,14 +150,7 @@ func (s *Server) getSources(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload.Payload = res
|
payload.Payload = res
|
||||||
|
s.WriteJson(w, payload)
|
||||||
bResult, err := json.Marshal(payload)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bResult)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSourceByNameAndSource
|
// GetSourceByNameAndSource
|
||||||
@ -219,15 +192,7 @@ func (s *Server) GetSourceBySourceAndName(w http.ResponseWriter, r *http.Request
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.Payload = item
|
p.Payload = item
|
||||||
|
s.WriteJson(w, p)
|
||||||
bResult, err := json.Marshal(item)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
w.Write(bResult)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRedditSource
|
// NewRedditSource
|
||||||
@ -242,8 +207,6 @@ func (s *Server) newRedditSource(w http.ResponseWriter, r *http.Request) {
|
|||||||
_url := query["url"][0]
|
_url := query["url"][0]
|
||||||
//_tags := query["tags"][0]
|
//_tags := query["tags"][0]
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
if _url == "" {
|
if _url == "" {
|
||||||
s.WriteError(w, "url is missing a value", http.StatusBadRequest)
|
s.WriteError(w, "url is missing a value", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@ -277,6 +240,7 @@ func (s *Server) newRedditSource(w http.ResponseWriter, r *http.Request) {
|
|||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
//s.WriteJson(w, ¶ms)
|
||||||
|
|
||||||
bJson, err := json.Marshal(¶ms)
|
bJson, err := json.Marshal(¶ms)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -34,6 +34,11 @@ type GetSubscription struct {
|
|||||||
Payload models.SubscriptionDto `json:"payload"`
|
Payload models.SubscriptionDto `json:"payload"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListSubscriptionDetails struct {
|
||||||
|
ApiStatusModel
|
||||||
|
Payload []models.SubscriptionDetailsDto `json:"payload"`
|
||||||
|
}
|
||||||
|
|
||||||
// GetSubscriptions
|
// GetSubscriptions
|
||||||
// @Summary Returns the top 100 entries from the queue to be processed.
|
// @Summary Returns the top 100 entries from the queue to be processed.
|
||||||
// @Produce application/json
|
// @Produce application/json
|
||||||
@ -43,8 +48,6 @@ type GetSubscription struct {
|
|||||||
// @Failure 400 {object} ApiError "Unable to reach SQL."
|
// @Failure 400 {object} ApiError "Unable to reach SQL."
|
||||||
// @Failure 500 {object} ApiError "Failed to process data from SQL."
|
// @Failure 500 {object} ApiError "Failed to process data from SQL."
|
||||||
func (s *Server) ListSubscriptions(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ListSubscriptions(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
payload := ListSubscriptions{
|
payload := ListSubscriptions{
|
||||||
ApiStatusModel: ApiStatusModel{
|
ApiStatusModel: ApiStatusModel{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
@ -59,19 +62,7 @@ func (s *Server) ListSubscriptions(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload.Payload = res
|
payload.Payload = res
|
||||||
|
s.WriteJson(w, payload)
|
||||||
bres, err := json.Marshal(payload)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ListSubscriptionDetails struct {
|
|
||||||
ApiStatusModel
|
|
||||||
Payload []models.SubscriptionDetailsDto `json:"payload"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListSubscriptionDetails
|
// ListSubscriptionDetails
|
||||||
@ -80,8 +71,7 @@ type ListSubscriptionDetails struct {
|
|||||||
// @Tags Subscription
|
// @Tags Subscription
|
||||||
// @Router /subscriptions/details [get]
|
// @Router /subscriptions/details [get]
|
||||||
// @Success 200 {object} ListSubscriptionDetails "ok"
|
// @Success 200 {object} ListSubscriptionDetails "ok"
|
||||||
func (s Server) ListSubscriptionDetails(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ListSubscriptionDetails(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
payload := ListSubscriptionDetails{
|
payload := ListSubscriptionDetails{
|
||||||
ApiStatusModel: ApiStatusModel{
|
ApiStatusModel: ApiStatusModel{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
@ -96,13 +86,7 @@ func (s Server) ListSubscriptionDetails(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
payload.Payload = res
|
payload.Payload = res
|
||||||
|
s.WriteJson(w, payload)
|
||||||
b, err := json.Marshal(payload)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(b)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSubscriptionsByDiscordId
|
// GetSubscriptionsByDiscordId
|
||||||
@ -115,8 +99,6 @@ func (s Server) ListSubscriptionDetails(w http.ResponseWriter, r *http.Request)
|
|||||||
// @Failure 400 {object} ApiError "Unable to reach SQL or Data problems"
|
// @Failure 400 {object} ApiError "Unable to reach SQL or Data problems"
|
||||||
// @Failure 500 {object} ApiError "Data problems"
|
// @Failure 500 {object} ApiError "Data problems"
|
||||||
func (s *Server) GetSubscriptionsByDiscordId(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) GetSubscriptionsByDiscordId(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set(HeaderContentType, ApplicationJson)
|
|
||||||
|
|
||||||
p := ListSubscriptions{
|
p := ListSubscriptions{
|
||||||
ApiStatusModel: ApiStatusModel{
|
ApiStatusModel: ApiStatusModel{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
@ -125,13 +107,12 @@ func (s *Server) GetSubscriptionsByDiscordId(w http.ResponseWriter, r *http.Requ
|
|||||||
}
|
}
|
||||||
|
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
_id := query["id"][0]
|
if query["id"][0] == "" {
|
||||||
if _id == "" {
|
|
||||||
s.WriteError(w, ErrIdValueMissing, http.StatusBadRequest)
|
s.WriteError(w, ErrIdValueMissing, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
uuid, err := uuid.Parse(_id)
|
uuid, err := uuid.Parse(query["id"][0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.WriteError(w, ErrValueNotUuid, http.StatusBadRequest)
|
s.WriteError(w, ErrValueNotUuid, http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@ -144,14 +125,7 @@ func (s *Server) GetSubscriptionsByDiscordId(w http.ResponseWriter, r *http.Requ
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
|
s.WriteJson(w, p)
|
||||||
bres, err := json.Marshal(p)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSubscriptionsBySourceId
|
// GetSubscriptionsBySourceId
|
||||||
@ -162,8 +136,6 @@ func (s *Server) GetSubscriptionsByDiscordId(w http.ResponseWriter, r *http.Requ
|
|||||||
// @Router /subscriptions/by/SourceId [get]
|
// @Router /subscriptions/by/SourceId [get]
|
||||||
// @Success 200 {object} ListSubscriptions "ok"
|
// @Success 200 {object} ListSubscriptions "ok"
|
||||||
func (s *Server) GetSubscriptionsBySourceId(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) GetSubscriptionsBySourceId(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
p := ListSubscriptions{
|
p := ListSubscriptions{
|
||||||
ApiStatusModel: ApiStatusModel{
|
ApiStatusModel: ApiStatusModel{
|
||||||
StatusCode: http.StatusOK,
|
StatusCode: http.StatusOK,
|
||||||
@ -191,14 +163,7 @@ func (s *Server) GetSubscriptionsBySourceId(w http.ResponseWriter, r *http.Reque
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.Payload = res
|
p.Payload = res
|
||||||
|
s.WriteJson(w, p)
|
||||||
bres, err := json.Marshal(p)
|
|
||||||
if err != nil {
|
|
||||||
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Write(bres)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDiscordWebHookSubscription
|
// NewDiscordWebHookSubscription
|
||||||
@ -208,8 +173,6 @@ func (s *Server) GetSubscriptionsBySourceId(w http.ResponseWriter, r *http.Reque
|
|||||||
// @Tags Subscription
|
// @Tags Subscription
|
||||||
// @Router /subscriptions/discord/webhook/new [post]
|
// @Router /subscriptions/discord/webhook/new [post]
|
||||||
func (s *Server) newDiscordWebHookSubscription(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) newDiscordWebHookSubscription(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
|
|
||||||
// Extract the values given
|
// Extract the values given
|
||||||
query := r.URL.Query()
|
query := r.URL.Query()
|
||||||
discordWebHookId := query["discordWebHookId"][0]
|
discordWebHookId := query["discordWebHookId"][0]
|
||||||
|
Loading…
Reference in New Issue
Block a user