2022-06-19 22:02:44 -07:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) getSettings(w http.ResponseWriter, r *http.Request) {
|
2023-01-21 18:24:04 -08:00
|
|
|
// GetSettings
|
|
|
|
// @Summary Returns a object based on the Key that was given.
|
|
|
|
// @Param key path string true "Settings Key value"
|
|
|
|
// @Produce application/json
|
|
|
|
// @Tags Settings
|
|
|
|
// @Router /settings/{key} [get]
|
|
|
|
|
|
|
|
|
2023-01-21 12:20:33 -08:00
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
|
2022-06-19 22:02:44 -07:00
|
|
|
//var item model.Sources
|
|
|
|
id := chi.URLParam(r, "ID")
|
|
|
|
|
|
|
|
uuid, err := uuid.Parse(id)
|
|
|
|
if err != nil {
|
2023-01-21 12:20:33 -08:00
|
|
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
2022-06-19 22:02:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
res, err := s.Db.GetSourceByID(*s.ctx, uuid)
|
|
|
|
if err != nil {
|
2023-01-21 12:20:33 -08:00
|
|
|
s.WriteError(w, err.Error(), http.StatusNotFound)
|
|
|
|
return
|
2022-06-19 22:02:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bResult, err := json.Marshal(res)
|
|
|
|
if err != nil {
|
2023-01-21 12:20:33 -08:00
|
|
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
2022-06-19 22:02:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
w.Write(bResult)
|
2022-12-04 08:49:17 -08:00
|
|
|
}
|