James Tombleson
8704680e82
* moved route context to the request and not passed down * dtoClient now returns a pointer to help on memory * moved funcs to use the dto pointer
45 lines
919 B
Go
45 lines
919 B
Go
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) {
|
|
// 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]
|
|
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
//var item model.Sources
|
|
id := chi.URLParam(r, "ID")
|
|
|
|
uuid, err := uuid.Parse(id)
|
|
if err != nil {
|
|
s.WriteError(w, err.Error(), http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
res, err := s.Db.GetSourceByID(r.Context(), uuid)
|
|
if err != nil {
|
|
s.WriteError(w, err.Error(), http.StatusNotFound)
|
|
return
|
|
}
|
|
|
|
bResult, err := json.Marshal(res)
|
|
if err != nil {
|
|
s.WriteError(w, err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Write(bResult)
|
|
}
|