fix: resolve compilation errors in frontend and backend
This commit is contained in:
@@ -3,10 +3,10 @@ package admin
|
||||
import (
|
||||
"crussell/db"
|
||||
"crussell/internal/validators"
|
||||
"crussell/mw"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
@@ -117,38 +117,38 @@ func UpdatePatchTest(w http.ResponseWriter, r *http.Request) {
|
||||
i := 1
|
||||
|
||||
if req.Name != nil {
|
||||
query += "name = $" + string(rune('0'+i)) + ", "
|
||||
query += "name = $" + strconv.Itoa(i) + ", "
|
||||
args = append(args, *req.Name)
|
||||
i++
|
||||
}
|
||||
if req.Description != nil {
|
||||
query += "description = $" + string(rune('0'+i)) + ", "
|
||||
query += "description = $" + strconv.Itoa(i) + ", "
|
||||
args = append(args, *req.Description)
|
||||
i++
|
||||
}
|
||||
if req.NoticeDurationHours != nil {
|
||||
query += "notice_duration_hours = $" + string(rune('0'+i)) + ", "
|
||||
query += "notice_duration_hours = $" + strconv.Itoa(i) + ", "
|
||||
args = append(args, *req.NoticeDurationHours)
|
||||
i++
|
||||
}
|
||||
if req.ExpiryMonths != nil {
|
||||
query += "expiry_months = $" + string(rune('0'+i)) + ", "
|
||||
query += "expiry_months = $" + strconv.Itoa(i) + ", "
|
||||
args = append(args, *req.ExpiryMonths)
|
||||
i++
|
||||
}
|
||||
if req.ServiceIDs != nil {
|
||||
query += "service_ids = $" + string(rune('0'+i)) + ", "
|
||||
query += "service_ids = $" + strconv.Itoa(i) + ", "
|
||||
args = append(args, req.ServiceIDs)
|
||||
i++
|
||||
}
|
||||
|
||||
query = query[:len(query)-2]
|
||||
query += " WHERE id = $" + string(rune('0'+i))
|
||||
query += " WHERE id = $" + strconv.Itoa(i)
|
||||
args = append(args, id)
|
||||
|
||||
_, err := db.DB.Exec(r.Context(), query, args...)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to update patch test: "+err.Error(), http.StatusInternalServerError)
|
||||
http.Error(w, "Failed to update patch test: " + err.Error() + " Query: " + query, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
@@ -14,6 +11,7 @@ import (
|
||||
"crussell/testutils/fixtures"
|
||||
)
|
||||
|
||||
|
||||
func TestPatchTests_CRUD(t *testing.T) {
|
||||
resetTestData(t)
|
||||
|
||||
@@ -30,8 +28,7 @@ func TestPatchTests_CRUD(t *testing.T) {
|
||||
ExpiryMonths: 6,
|
||||
ServiceIDs: []string{serviceID},
|
||||
}
|
||||
body, _ := json.Marshal(req)
|
||||
w := makeAdminRequest(http.HandlerFunc(CreatePatchTest), "POST", "/api/admin/patch-tests", bytes.NewReader(body))
|
||||
w := makeAdminRequest(http.HandlerFunc(CreatePatchTest), "POST", "/api/admin/patch-tests", req)
|
||||
if w.Code != http.StatusCreated {
|
||||
t.Fatalf("expected 201, got %d", w.Code)
|
||||
}
|
||||
@@ -54,10 +51,9 @@ func TestPatchTests_CRUD(t *testing.T) {
|
||||
|
||||
newName := "Updated Name"
|
||||
updateReq := UpdatePatchTestRequest{Name: &newName}
|
||||
updateBody, _ := json.Marshal(updateReq)
|
||||
w = makeAdminRequest(http.HandlerFunc(UpdatePatchTest), "PUT", "/api/admin/patch-tests/"+created.ID, bytes.NewReader(updateBody))
|
||||
w = makeAdminRequest(http.HandlerFunc(UpdatePatchTest), "PUT", "/api/admin/patch-tests/"+created.ID, updateReq)
|
||||
if w.Code != http.StatusNoContent {
|
||||
t.Fatalf("expected 204, got %d", w.Code)
|
||||
t.Fatalf("expected 204, got %d, body: %s", w.Code, w.Body.String())
|
||||
}
|
||||
|
||||
w = makeAdminRequest(http.HandlerFunc(DeletePatchTest), "DELETE", "/api/admin/patch-tests/"+created.ID, nil)
|
||||
|
||||
Reference in New Issue
Block a user