Skip to content

Commit 3d1d57c

Browse files
committed
admin: expose film data as JSON
1 parent 2e4b9e3 commit 3d1d57c

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

cmd/serve/admin/handlers/films.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,16 @@ func DeleteFilmHandler() func(http.ResponseWriter, *http.Request) {
355355
http.Redirect(w, r, "/films", http.StatusSeeOther)
356356
}
357357
}
358+
359+
func GetFilmsWithReviewsHandler() func(http.ResponseWriter, *http.Request) {
360+
return func(w http.ResponseWriter, r *http.Request) {
361+
films, err := db.GetAllFilmsWithReviews()
362+
if err != nil {
363+
http.Error(w, "Failed to retrieve films", http.StatusInternalServerError)
364+
return
365+
}
366+
367+
w.Header().Set("Content-Type", "application/json")
368+
json.NewEncoder(w).Encode(films)
369+
}
370+
}

cmd/serve/admin/tailscale.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ func Start() error {
104104
httpsMux.HandleFunc("POST /film-lists/{id}/entries", handlers.AddFilmToListHandler())
105105
httpsMux.HandleFunc("POST /film-lists/{id}/entries/remove/{entryId}", handlers.RemoveFilmFromListHandler())
106106
httpsMux.HandleFunc("POST /film-lists/{id}/entries/position/{entryId}", handlers.UpdateEntryPositionHandler())
107+
httpsMux.HandleFunc("GET /api/films/reviews/", handlers.GetFilmsWithReviewsHandler())
107108
httpsMux.HandleFunc("GET /videogames", handlers.ListVideoGamesHandler())
108109
httpsMux.HandleFunc("POST /videogames", handlers.CreateVideoGameHandler())
109110
httpsMux.HandleFunc("GET /videogames/edit/{id}", handlers.EditVideoGameHandler())

0 commit comments

Comments
 (0)