|
- package controller
-
- import (
- "encoding/json"
- "net/http"
-
- "github.com/AFASystems/presence/internal/pkg/model"
- "github.com/gorilla/mux"
- "gorm.io/gorm"
- )
-
- func TracksListController(db *gorm.DB) http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- id := mux.Vars(r)["id"]
- var tracks []model.Tracks
- db.Where("uuid = ?", id).Order("timestamp DESC").Limit(100).Find(&tracks)
- res, err := json.Marshal(tracks)
- if err != nil {
- http.Error(w, err.Error(), 400)
- return
- }
-
- w.Write(res)
- }
- }
|