Initial commit: gocarlog project — Milestones 1-10 completed
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"gocarlog/internal/middleware"
|
||||
"gocarlog/internal/model"
|
||||
)
|
||||
|
||||
// HandleListFuels handles GET /fuels
|
||||
func HandleListFuels(w http.ResponseWriter, r *http.Request) {
|
||||
db := r.Context().Value(middleware.DbKey).(*sql.DB)
|
||||
fuels, err := model.GetFuels(db)
|
||||
if err != nil {
|
||||
log.Printf("error listing fuels: %v", err)
|
||||
middleware.WriteError(w, http.StatusInternalServerError, "failed to list fuels")
|
||||
return
|
||||
}
|
||||
|
||||
if fuels == nil {
|
||||
fuels = []model.Fuel{}
|
||||
}
|
||||
|
||||
middleware.WriteJSON(w, http.StatusOK, map[string]interface{}{
|
||||
"success": true,
|
||||
"data": fuels,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user