making progress

This commit is contained in:
2026-05-07 02:06:54 +02:00
parent 7b7e2d399c
commit dea186c995
39 changed files with 2021 additions and 67 deletions
+60 -6
View File
@@ -51,13 +51,9 @@ func (h *RepoHandler) List(w http.ResponseWriter, r *http.Request) {
return
}
// Fetch owner username once (all repos belong to the same user in this query)
var owner models.User
h.db.ID(userID).Get(&owner)
result := make([]repoResponse, len(repos))
for i, repo := range repos {
result[i] = repoResponse{Repository: repo, OwnerName: owner.Username}
for i := range repos {
result[i] = h.withOwnerName(&repos[i])
}
jsonOK(w, result)
}
@@ -193,6 +189,64 @@ func (h *RepoHandler) Commits(w http.ResponseWriter, r *http.Request) {
jsonOK(w, commits)
}
func (h *RepoHandler) Update(w http.ResponseWriter, r *http.Request) {
repo, ok := h.lookupRepo(w, r)
if !ok {
return
}
var body struct {
Description *string `json:"description"`
IsPrivate *bool `json:"isPrivate"`
DefaultBranch *string `json:"defaultBranch"`
}
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
jsonError(w, "invalid request body", http.StatusBadRequest)
return
}
cols := []string{}
if body.Description != nil {
repo.Description = *body.Description
cols = append(cols, "description")
}
if body.IsPrivate != nil {
repo.IsPrivate = *body.IsPrivate
cols = append(cols, "is_private")
}
if body.DefaultBranch != nil {
repo.DefaultBranch = *body.DefaultBranch
cols = append(cols, "default_branch")
}
if len(cols) > 0 {
if _, err := h.db.ID(repo.ID).Cols(cols...).Update(repo); err != nil {
jsonError(w, "could not update repository", http.StatusInternalServerError)
return
}
}
jsonOK(w, h.withOwnerName(repo))
}
func (h *RepoHandler) Delete(w http.ResponseWriter, r *http.Request) {
repo, ok := h.lookupRepo(w, r)
if !ok {
return
}
callerID, _ := middleware.UserIDFromContext(r.Context())
if callerID != repo.OwnerID {
jsonError(w, "only the owner can delete a repository", http.StatusForbidden)
return
}
if _, err := h.db.ID(repo.ID).Delete(&models.Repository{}); err != nil {
jsonError(w, "could not delete repository", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusNoContent)
}
func (h *RepoHandler) Diff(w http.ResponseWriter, r *http.Request) {
repo, ok := h.lookupRepo(w, r)
if !ok {