mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Rename fs variable
This commit is contained in:
@@ -12,11 +12,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// SetupRoutes configures the API routes
|
// SetupRoutes configures the API routes
|
||||||
func SetupRoutes(r chi.Router, db *db.DB, fs *filesystem.Storage, authMiddleware *auth.Middleware, sessionService *auth.SessionService) {
|
func SetupRoutes(r chi.Router, db *db.DB, s *filesystem.Storage, authMiddleware *auth.Middleware, sessionService *auth.SessionService) {
|
||||||
|
|
||||||
handler := &handlers.Handler{
|
handler := &handlers.Handler{
|
||||||
DB: db,
|
DB: db,
|
||||||
FS: fs,
|
S: s,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public routes (no authentication required)
|
// Public routes (no authentication required)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func (h *Handler) AdminCreateUser() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize user workspace
|
// Initialize user workspace
|
||||||
if err := h.FS.InitializeUserWorkspace(insertedUser.ID, insertedUser.LastWorkspaceID); err != nil {
|
if err := h.S.InitializeUserWorkspace(insertedUser.ID, insertedUser.LastWorkspaceID); err != nil {
|
||||||
http.Error(w, "Failed to initialize user workspace", http.StatusInternalServerError)
|
http.Error(w, "Failed to initialize user workspace", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ func (h *Handler) AdminListWorkspaces() http.HandlerFunc {
|
|||||||
workspaceData.WorkspaceName = ws.Name
|
workspaceData.WorkspaceName = ws.Name
|
||||||
workspaceData.WorkspaceCreatedAt = ws.CreatedAt
|
workspaceData.WorkspaceCreatedAt = ws.CreatedAt
|
||||||
|
|
||||||
fileStats, err := h.FS.GetFileStats(ws.UserID, ws.ID)
|
fileStats, err := h.S.GetFileStats(ws.UserID, ws.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to get file stats", http.StatusInternalServerError)
|
http.Error(w, "Failed to get file stats", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -278,7 +278,7 @@ func (h *Handler) AdminGetSystemStats() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fileStats, err := h.FS.GetTotalFileStats()
|
fileStats, err := h.S.GetTotalFileStats()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to get file stats", http.StatusInternalServerError)
|
http.Error(w, "Failed to get file stats", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ func (h *Handler) ListFiles() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
files, err := h.FS.ListFilesRecursively(ctx.UserID, ctx.Workspace.ID)
|
files, err := h.S.ListFilesRecursively(ctx.UserID, ctx.Workspace.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to list files", http.StatusInternalServerError)
|
http.Error(w, "Failed to list files", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -40,7 +40,7 @@ func (h *Handler) LookupFileByName() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
filePaths, err := h.FS.FindFileByName(ctx.UserID, ctx.Workspace.ID, filename)
|
filePaths, err := h.S.FindFileByName(ctx.UserID, ctx.Workspace.ID, filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "File not found", http.StatusNotFound)
|
http.Error(w, "File not found", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
@@ -58,7 +58,7 @@ func (h *Handler) GetFileContent() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filePath := chi.URLParam(r, "*")
|
filePath := chi.URLParam(r, "*")
|
||||||
content, err := h.FS.GetFileContent(ctx.UserID, ctx.Workspace.ID, filePath)
|
content, err := h.S.GetFileContent(ctx.UserID, ctx.Workspace.ID, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to read file", http.StatusNotFound)
|
http.Error(w, "Failed to read file", http.StatusNotFound)
|
||||||
return
|
return
|
||||||
@@ -83,7 +83,7 @@ func (h *Handler) SaveFile() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.FS.SaveFile(ctx.UserID, ctx.Workspace.ID, filePath, content)
|
err = h.S.SaveFile(ctx.UserID, ctx.Workspace.ID, filePath, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to save file", http.StatusInternalServerError)
|
http.Error(w, "Failed to save file", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -101,7 +101,7 @@ func (h *Handler) DeleteFile() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filePath := chi.URLParam(r, "*")
|
filePath := chi.URLParam(r, "*")
|
||||||
err := h.FS.DeleteFile(ctx.UserID, ctx.Workspace.ID, filePath)
|
err := h.S.DeleteFile(ctx.UserID, ctx.Workspace.ID, filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to delete file", http.StatusInternalServerError)
|
http.Error(w, "Failed to delete file", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -125,7 +125,7 @@ func (h *Handler) GetLastOpenedFile() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := h.FS.ValidatePath(ctx.UserID, ctx.Workspace.ID, filePath); err != nil {
|
if _, err := h.S.ValidatePath(ctx.UserID, ctx.Workspace.ID, filePath); err != nil {
|
||||||
http.Error(w, "Invalid file path", http.StatusBadRequest)
|
http.Error(w, "Invalid file path", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -152,7 +152,7 @@ func (h *Handler) UpdateLastOpenedFile() http.HandlerFunc {
|
|||||||
|
|
||||||
// Validate the file path exists in the workspace
|
// Validate the file path exists in the workspace
|
||||||
if requestBody.FilePath != "" {
|
if requestBody.FilePath != "" {
|
||||||
if _, err := h.FS.ValidatePath(ctx.UserID, ctx.Workspace.ID, requestBody.FilePath); err != nil {
|
if _, err := h.S.ValidatePath(ctx.UserID, ctx.Workspace.ID, requestBody.FilePath); err != nil {
|
||||||
http.Error(w, "Invalid file path", http.StatusBadRequest)
|
http.Error(w, "Invalid file path", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func (h *Handler) StageCommitAndPush() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := h.FS.StageCommitAndPush(ctx.UserID, ctx.Workspace.ID, requestBody.Message)
|
err := h.S.StageCommitAndPush(ctx.UserID, ctx.Workspace.ID, requestBody.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to stage, commit, and push changes: "+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "Failed to stage, commit, and push changes: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
@@ -45,7 +45,7 @@ func (h *Handler) PullChanges() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err := h.FS.Pull(ctx.UserID, ctx.Workspace.ID)
|
err := h.S.Pull(ctx.UserID, ctx.Workspace.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Failed to pull changes: "+err.Error(), http.StatusInternalServerError)
|
http.Error(w, "Failed to pull changes: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ import (
|
|||||||
// Handler provides common functionality for all handlers
|
// Handler provides common functionality for all handlers
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
DB *db.DB
|
DB *db.DB
|
||||||
FS *filesystem.Storage
|
S *filesystem.Storage
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHandler creates a new handler with the given dependencies
|
// NewHandler creates a new handler with the given dependencies
|
||||||
func NewHandler(db *db.DB, fs *filesystem.Storage) *Handler {
|
func NewHandler(db *db.DB, fs *filesystem.Storage) *Handler {
|
||||||
return &Handler{
|
return &Handler{
|
||||||
DB: db,
|
DB: db,
|
||||||
FS: fs,
|
S: fs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ func (h *Handler) DeleteAccount() http.HandlerFunc {
|
|||||||
|
|
||||||
// Delete workspace directories
|
// Delete workspace directories
|
||||||
for _, workspace := range workspaces {
|
for _, workspace := range workspaces {
|
||||||
if err := h.FS.DeleteUserWorkspace(ctx.UserID, workspace.ID); err != nil {
|
if err := h.S.DeleteUserWorkspace(ctx.UserID, workspace.ID); err != nil {
|
||||||
http.Error(w, "Failed to delete workspace files", http.StatusInternalServerError)
|
http.Error(w, "Failed to delete workspace files", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ func (h *Handler) CreateWorkspace() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := h.FS.InitializeUserWorkspace(workspace.UserID, workspace.ID); err != nil {
|
if err := h.S.InitializeUserWorkspace(workspace.UserID, workspace.ID); err != nil {
|
||||||
http.Error(w, "Failed to initialize workspace directory", http.StatusInternalServerError)
|
http.Error(w, "Failed to initialize workspace directory", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ func (h *Handler) UpdateWorkspace() http.HandlerFunc {
|
|||||||
// Handle Git repository setup/teardown if Git settings changed
|
// Handle Git repository setup/teardown if Git settings changed
|
||||||
if gitSettingsChanged(&workspace, ctx.Workspace) {
|
if gitSettingsChanged(&workspace, ctx.Workspace) {
|
||||||
if workspace.GitEnabled {
|
if workspace.GitEnabled {
|
||||||
if err := h.FS.SetupGitRepo(
|
if err := h.S.SetupGitRepo(
|
||||||
ctx.UserID,
|
ctx.UserID,
|
||||||
ctx.Workspace.ID,
|
ctx.Workspace.ID,
|
||||||
workspace.GitURL,
|
workspace.GitURL,
|
||||||
@@ -119,7 +119,7 @@ func (h *Handler) UpdateWorkspace() http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
h.FS.DisableGitRepo(ctx.UserID, ctx.Workspace.ID)
|
h.S.DisableGitRepo(ctx.UserID, ctx.Workspace.ID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user