A website inspired by Last.fm that will keep track of your listening statistics
lastfm music statistics
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add empty handler structs for the pages of the application

oscar345 a505ce30 b0f0946f

+64 -32
+13
internal/web/handlers/friends.go
··· 1 + package handlers 2 + 3 + import "github.com/oscar345/keeptrack/internal/services" 4 + 5 + type FriendsHandler struct { 6 + userService services.UserService 7 + } 8 + 9 + func NewFriendsHandler(userService services.UserService) *FriendsHandler { 10 + return &FriendsHandler{ 11 + userService: userService, 12 + } 13 + }
+31 -32
internal/web/handlers/index.go
··· 1 1 package handlers 2 2 3 3 import ( 4 - "encoding/json" 5 4 "net/http" 6 - "strconv" 7 5 8 - "github.com/ggicci/httpin" 9 - "github.com/go-chi/chi/v5" 10 - "github.com/oscar345/keeptrack/internal/services" 11 - "github.com/oscar345/keeptrack/internal/web/requests" 12 - "github.com/oscar345/keeptrack/internal/web/responses" 13 - "github.com/oscar345/keeptrack/pkg/enum" 6 + "github.com/oscar345/keeptrack/pkg/inertia" 14 7 ) 15 8 16 9 type IndexHandler struct { 17 - artistService services.ArtistService 10 + inertia *inertia.Inertia 18 11 } 19 12 20 - func NewIndexHandler(artistService services.ArtistService) IndexHandler { 13 + func NewIndexHandler(inertia *inertia.Inertia) IndexHandler { 21 14 return IndexHandler{ 22 - artistService: artistService, 15 + inertia: inertia, 23 16 } 24 17 } 25 18 26 - func (handler *IndexHandler) Index(w http.ResponseWriter, r *http.Request) { 27 - id, err := strconv.Atoi(chi.URLParam(r, "id")) 28 - if err != nil { 29 - http.Error(w, err.Error(), http.StatusBadRequest) 30 - return 31 - } 19 + func (h *IndexHandler) Index(w http.ResponseWriter, r *http.Request) { 20 + h.inertia.Render(w, r, "Index", inertia.Props{ 21 + "title": inertia.Always("Welcome"), 22 + }) 23 + } 24 + 25 + // func (handler *IndexHandler) Index(w http.ResponseWriter, r *http.Request) { 26 + // id, err := strconv.Atoi(chi.URLParam(r, "id")) 27 + // if err != nil { 28 + // http.Error(w, err.Error(), http.StatusBadRequest) 29 + // return 30 + // } 32 31 33 - filter, err := r.Context().Value(httpin.Input).(*requests.Count).Filter() 34 - if err != nil { 35 - http.Error(w, err.Error(), http.StatusBadRequest) 36 - return 37 - } 38 - filter.UserID = id 32 + // filter, err := r.Context().Value(httpin.Input).(*requests.Count).Filter() 33 + // if err != nil { 34 + // http.Error(w, err.Error(), http.StatusBadRequest) 35 + // return 36 + // } 37 + // filter.UserID = id 39 38 40 - items, page, err := handler.artistService.ListArtistByCount(r.Context(), filter) 41 - if err != nil { 42 - http.Error(w, err.Error(), http.StatusInternalServerError) 43 - return 44 - } 39 + // items, page, err := handler.artistService.ListArtistByCount(r.Context(), filter) 40 + // if err != nil { 41 + // http.Error(w, err.Error(), http.StatusInternalServerError) 42 + // return 43 + // } 45 44 46 - artists := enum.Map(items, responses.NewArtistFromModel) 45 + // artists := enum.Map(items, responses.NewArtistFromModel) 47 46 48 - w.Header().Set("Content-Type", "application/json") 49 - json.NewEncoder(w).Encode(responses.Paginate(page, artists)) 50 - } 47 + // w.Header().Set("Content-Type", "application/json") 48 + // json.NewEncoder(w).Encode(responses.Paginate(page, artists)) 49 + // }
+13
internal/web/handlers/library.go
··· 1 + package handlers 2 + 3 + import "github.com/oscar345/keeptrack/internal/services" 4 + 5 + type LibraryHandler struct { 6 + artistService services.ArtistService 7 + } 8 + 9 + func NewLibraryHandler(artistService services.ArtistService) *LibraryHandler { 10 + return &LibraryHandler{ 11 + artistService: artistService, 12 + } 13 + }
+7
internal/web/handlers/mixtapes.go
··· 1 + package handlers 2 + 3 + type MixtapesHandler struct{} 4 + 5 + func NewMixtapesHandler() *MixtapesHandler { 6 + return &MixtapesHandler{} 7 + }