mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 23:44:22 +00:00
Implement auth handler integration test
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
// ListFiles returns a list of all files in the workspace
|
||||
func (h *Handler) ListFiles() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, ok := context.GetRequestContext(w, r)
|
||||
@@ -27,6 +28,7 @@ func (h *Handler) ListFiles() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// LookupFileByName returns the paths of files with the given name
|
||||
func (h *Handler) LookupFileByName() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, ok := context.GetRequestContext(w, r)
|
||||
@@ -50,6 +52,7 @@ func (h *Handler) LookupFileByName() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// GetFileContent returns the content of a file
|
||||
func (h *Handler) GetFileContent() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, ok := context.GetRequestContext(w, r)
|
||||
@@ -65,10 +68,15 @@ func (h *Handler) GetFileContent() http.HandlerFunc {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.Write(content)
|
||||
_, err = w.Write(content)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to write response", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SaveFile saves the content of a file
|
||||
func (h *Handler) SaveFile() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, ok := context.GetRequestContext(w, r)
|
||||
@@ -93,6 +101,7 @@ func (h *Handler) SaveFile() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// DeleteFile deletes a file
|
||||
func (h *Handler) DeleteFile() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, ok := context.GetRequestContext(w, r)
|
||||
@@ -108,10 +117,15 @@ func (h *Handler) DeleteFile() http.HandlerFunc {
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("File deleted successfully"))
|
||||
_, err = w.Write([]byte("File deleted successfully"))
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to write response", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetLastOpenedFile returns the last opened file in the workspace
|
||||
func (h *Handler) GetLastOpenedFile() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, ok := context.GetRequestContext(w, r)
|
||||
@@ -134,6 +148,7 @@ func (h *Handler) GetLastOpenedFile() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateLastOpenedFile updates the last opened file in the workspace
|
||||
func (h *Handler) UpdateLastOpenedFile() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, ok := context.GetRequestContext(w, r)
|
||||
|
||||
Reference in New Issue
Block a user