Re-struct pkg/api, pkg/database
This commit is contained in:
25
pkg/api/handle_get_random_files.go
Normal file
25
pkg/api/handle_get_random_files.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"msw-open-music/pkg/database"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type GetRandomFilesResponse struct {
|
||||
Files *[]database.File `json:"files"`
|
||||
}
|
||||
|
||||
func (api *API) HandleGetRandomFiles(w http.ResponseWriter, r *http.Request) {
|
||||
files, err := api.Db.GetRandomFiles(10)
|
||||
if err != nil {
|
||||
api.HandleError(w, r, err)
|
||||
return
|
||||
}
|
||||
getRandomFilesResponse := &GetRandomFilesResponse{
|
||||
Files: &files,
|
||||
}
|
||||
log.Println("[api] Get random files")
|
||||
json.NewEncoder(w).Encode(getRandomFilesResponse)
|
||||
}
|
||||
Reference in New Issue
Block a user