mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Update api docs
This commit is contained in:
@@ -7,6 +7,21 @@ import (
|
||||
"novamd/internal/context"
|
||||
)
|
||||
|
||||
// CommitRequest represents a request to commit changes
|
||||
type CommitRequest struct {
|
||||
Message string `json:"message" example:"Initial commit"`
|
||||
}
|
||||
|
||||
// CommitResponse represents a response to a commit request
|
||||
type CommitResponse struct {
|
||||
CommitHash string `json:"commitHash" example:"a1b2c3d4"`
|
||||
}
|
||||
|
||||
// PullResponse represents a response to a pull http request
|
||||
type PullResponse struct {
|
||||
Message string `json:"message" example:"Pulled changes from remote"`
|
||||
}
|
||||
|
||||
// StageCommitAndPush godoc
|
||||
// @Summary Stage, commit, and push changes
|
||||
// @Description Stages, commits, and pushes changes to the remote repository
|
||||
@@ -15,11 +30,11 @@ import (
|
||||
// @Security BearerAuth
|
||||
// @Produce json
|
||||
// @Param workspace_name path string true "Workspace name"
|
||||
// @Param body body string true "Commit message"
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Failure 400 {string} string "Invalid request body"
|
||||
// @Failure 400 {string} string "Commit message is required"
|
||||
// @Failure 500 {string} string "Failed to stage, commit, and push changes"
|
||||
// @Param body body CommitRequest true "Commit request"
|
||||
// @Success 200 {object} CommitResponse
|
||||
// @Failure 400 {object} ErrorResponse "Invalid request body"
|
||||
// @Failure 400 {object} ErrorResponse "Commit message is required"
|
||||
// @Failure 500 {object} ErrorResponse "Failed to stage, commit, and push changes"
|
||||
// @Router /workspaces/{workspace_name}/git/commit [post]
|
||||
func (h *Handler) StageCommitAndPush() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -28,27 +43,25 @@ func (h *Handler) StageCommitAndPush() http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
var requestBody struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
var requestBody CommitRequest
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&requestBody); err != nil {
|
||||
http.Error(w, "Invalid request body", http.StatusBadRequest)
|
||||
respondError(w, "Invalid request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if requestBody.Message == "" {
|
||||
http.Error(w, "Commit message is required", http.StatusBadRequest)
|
||||
respondError(w, "Commit message is required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
err := h.Storage.StageCommitAndPush(ctx.UserID, ctx.Workspace.ID, requestBody.Message)
|
||||
hash, err := h.Storage.StageCommitAndPush(ctx.UserID, ctx.Workspace.ID, requestBody.Message)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to stage, commit, and push changes: "+err.Error(), http.StatusInternalServerError)
|
||||
respondError(w, "Failed to stage, commit, and push changes: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
respondJSON(w, map[string]string{"message": "Changes staged, committed, and pushed successfully"})
|
||||
respondJSON(w, CommitResponse{CommitHash: hash.String()})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +73,8 @@ func (h *Handler) StageCommitAndPush() http.HandlerFunc {
|
||||
// @Security BearerAuth
|
||||
// @Produce json
|
||||
// @Param workspace_name path string true "Workspace name"
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Failure 500 {string} string "Failed to pull changes"
|
||||
// @Success 200 {object} PullResponse
|
||||
// @Failure 500 {object} ErrorResponse "Failed to pull changes"
|
||||
// @Router /workspaces/{workspace_name}/git/pull [post]
|
||||
func (h *Handler) PullChanges() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -72,10 +85,10 @@ func (h *Handler) PullChanges() http.HandlerFunc {
|
||||
|
||||
err := h.Storage.Pull(ctx.UserID, ctx.Workspace.ID)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to pull changes: "+err.Error(), http.StatusInternalServerError)
|
||||
respondError(w, "Failed to pull changes: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
respondJSON(w, map[string]string{"message": "Pulled changes from remote"})
|
||||
respondJSON(w, PullResponse{Message: "Successfully pulled changes from remote"})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user