refactor: call database functions from app.Server.Database instead of directly from db

This commit is contained in:
2024-08-19 21:00:46 +07:00
parent 6a183f2c4e
commit fa2f4e8a87
18 changed files with 69 additions and 63 deletions

View File

@ -5,14 +5,13 @@ import (
"github.com/fossyy/filekeeper/view/client/download"
"net/http"
"github.com/fossyy/filekeeper/db"
"github.com/fossyy/filekeeper/types"
"github.com/fossyy/filekeeper/utils"
)
func GET(w http.ResponseWriter, r *http.Request) {
userSession := r.Context().Value("user").(types.User)
files, err := db.DB.GetFiles(userSession.UserID.String())
files, err := app.Server.Database.GetFiles(userSession.UserID.String())
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return

View File

@ -5,13 +5,11 @@ import (
"net/http"
"os"
"path/filepath"
"github.com/fossyy/filekeeper/db"
)
func GET(w http.ResponseWriter, r *http.Request) {
fileID := r.PathValue("id")
file, err := db.DB.GetFile(fileID)
file, err := app.Server.Database.GetFile(fileID)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
app.Server.Logger.Error(err.Error())