Fix some bullshit
This commit is contained in:
@@ -14,9 +14,9 @@ func setupCollections(app core.App) error {
|
|||||||
// Create events collection if it doesn't exist
|
// Create events collection if it doesn't exist
|
||||||
if _, err := app.FindCollectionByNameOrId("events"); err != nil {
|
if _, err := app.FindCollectionByNameOrId("events"); err != nil {
|
||||||
fmt.Println("Creating events collection...")
|
fmt.Println("Creating events collection...")
|
||||||
|
|
||||||
eventsCollection := core.NewBaseCollection("events")
|
eventsCollection := core.NewBaseCollection("events")
|
||||||
|
|
||||||
// Admin only access for events
|
// Admin only access for events
|
||||||
eventsCollection.ListRule = nil
|
eventsCollection.ListRule = nil
|
||||||
eventsCollection.ViewRule = nil
|
eventsCollection.ViewRule = nil
|
||||||
@@ -80,9 +80,9 @@ func setupCollections(app core.App) error {
|
|||||||
// Create shopping_items collection if it doesn't exist
|
// Create shopping_items collection if it doesn't exist
|
||||||
if _, err := app.FindCollectionByNameOrId("shopping_items"); err != nil {
|
if _, err := app.FindCollectionByNameOrId("shopping_items"); err != nil {
|
||||||
fmt.Println("Creating shopping_items collection...")
|
fmt.Println("Creating shopping_items collection...")
|
||||||
|
|
||||||
itemsCollection := core.NewBaseCollection("shopping_items")
|
itemsCollection := core.NewBaseCollection("shopping_items")
|
||||||
|
|
||||||
// Public access rules
|
// Public access rules
|
||||||
itemsCollection.ListRule = types.Pointer("")
|
itemsCollection.ListRule = types.Pointer("")
|
||||||
itemsCollection.ViewRule = types.Pointer("")
|
itemsCollection.ViewRule = types.Pointer("")
|
||||||
@@ -90,17 +90,21 @@ func setupCollections(app core.App) error {
|
|||||||
itemsCollection.UpdateRule = types.Pointer("")
|
itemsCollection.UpdateRule = types.Pointer("")
|
||||||
itemsCollection.DeleteRule = types.Pointer("")
|
itemsCollection.DeleteRule = types.Pointer("")
|
||||||
|
|
||||||
// Add fields
|
// Add static fields only - no arbitrary fields allowed
|
||||||
itemsCollection.Fields.Add(&core.TextField{
|
itemsCollection.Fields.Add(&core.TextField{
|
||||||
Name: "content",
|
Name: "content",
|
||||||
Required: false,
|
Required: false,
|
||||||
})
|
})
|
||||||
|
itemsCollection.Fields.Add(&core.TextField{
|
||||||
|
Name: "priority",
|
||||||
|
Required: false,
|
||||||
|
})
|
||||||
itemsCollection.Fields.Add(&core.DateField{
|
itemsCollection.Fields.Add(&core.DateField{
|
||||||
Name: "created_at",
|
Name: "created_at",
|
||||||
Required: false,
|
Required: false,
|
||||||
})
|
})
|
||||||
itemsCollection.Fields.Add(&core.DateField{
|
itemsCollection.Fields.Add(&core.DateField{
|
||||||
Name: "updated_at",
|
Name: "updated_at",
|
||||||
Required: false,
|
Required: false,
|
||||||
})
|
})
|
||||||
itemsCollection.Fields.Add(&core.DateField{
|
itemsCollection.Fields.Add(&core.DateField{
|
||||||
|
10
test_api.sh
10
test_api.sh
@@ -16,13 +16,13 @@ echo
|
|||||||
echo "3. Create an item - single operation"
|
echo "3. Create an item - single operation"
|
||||||
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"op": "add", "path": "/content", "value": "My test item"}'
|
-d "{\"op\": \"add\", \"path\": \"/content\", \"value\": \"My test item\"}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "4. Update the item - single operation"
|
echo "4. Update the item - single operation"
|
||||||
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"op": "replace", "path": "/content", "value": "Updated test item"}'
|
-d "{\"op\": \"replace\", \"path\": \"/content\", \"value\": \"Updated test item\"}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "5. Get all items"
|
echo "5. Get all items"
|
||||||
@@ -32,19 +32,19 @@ echo
|
|||||||
echo "6. Add another field - single operation"
|
echo "6. Add another field - single operation"
|
||||||
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"op": "add", "path": "/priority", "value": "high"}'
|
-d "{\"op\": \"add\", \"path\": \"/priority\", \"value\": \"high\"}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "7. Remove a field - single operation"
|
echo "7. Remove a field - single operation"
|
||||||
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"op": "remove", "path": "/priority"}'
|
-d "{\"op\": \"remove\", \"path\": \"/priority\"}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "8. Soft delete - single operation"
|
echo "8. Soft delete - single operation"
|
||||||
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
curl -X PATCH "$BASE_URL/api/collections/shopping_items/items/test12345678901" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{"op": "add", "path": "/deleted_at", "value": "2025-09-29T10:00:00Z"}'
|
-d "{\"op\": \"add\", \"path\": \"/deleted_at\", \"value\": \"2025-09-29T10:00:00Z\"}"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
echo "9. Final state"
|
echo "9. Final state"
|
||||||
|
Reference in New Issue
Block a user