Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clangs #11

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Clangs #11

wants to merge 8 commits into from

Conversation

skerbis
Copy link
Member

@skerbis skerbis commented Feb 26, 2025

New System Clangs API Endpoints

This PR adds a new API package for managing REDAXO languages (clangs) through the REST API. The implementation follows the established pattern of other API packages, while ensuring proper integration with REDAXO's internal language management system.

New Endpoints

Endpoint Method Description
/api/system/clangs GET Retrieve a list of all languages with filtering options
/api/system/clangs/{id} GET Get details for a specific language
/api/system/clangs POST Create a new language
/api/system/clangs/{id} PUT/PATCH Update an existing language
/api/system/clangs/{id} DELETE Delete a language

Beispiele

1. Sprachen abrufen

  • GET /api/system/clangs
    • Beschreibung: Ruft eine Liste aller Sprachen ab.

    • Parameter:

      • filter[status]: Filtert nach Status (z.B. 1 für aktiv).
      • filter[code]: Filtert nach Sprachcode (z.B. de).
      • filter[priority]: Filtert nach Priorität.
      • page: Seitenzahl für Paginierung (optional).
      • per_page: Anzahl der Einträge pro Seite für Paginierung (optional).
    • Beispiele:

      • Alle Sprachen abrufen:
        curl -X GET 'https://example.com/api/system/clangs' \
        -H 'Authorization: Bearer YOUR_API_TOKEN'
      • Sprachen mit Status "aktiv" abrufen:
        curl -X GET 'https://example.com/api/system/clangs?filter%5Bstatus%5D=1' \
        -H 'Authorization: Bearer YOUR_API_TOKEN'
      • Paginierung (Seite 2, 5 Einträge pro Seite):
        curl -X GET 'https://example.com/api/system/clangs?page=2&per_page=5' \
        -H 'Authorization: Bearer YOUR_API_TOKEN'
      • Komplexe Filterung (Status aktiv, Code 'de', Priorität 1):
        curl -X GET 'https://example.com/api/system/clangs?filter%5Bstatus%5D=1&filter%5Bcode%5D=de&filter%5Bpriority%5D=1' \
        -H 'Authorization: Bearer YOUR_API_TOKEN'

2. Eine spezifische Sprache abrufen

  • GET /api/system/clangs/{id}
    • Beschreibung: Ruft eine spezifische Sprache anhand ihrer ID ab.

    • Parameter:

      • id: Die ID der Sprache.
    • Beispiel:

      curl -X GET 'https://example.com/api/system/clangs/2' \
      -H 'Authorization: Bearer YOUR_API_TOKEN'

3. Eine neue Sprache hinzufügen

  • POST /api/system/clangs
    • Beschreibung: Erstellt eine neue Sprache.

    • Anfrage-Body (JSON):

      • code (String, required): Der Sprachcode (z.B. "fr", "en", "de").
      • name (String, required): Der Name der Sprache.
      • priority (Integer, optional): Die Priorität der Sprache (z.B. 1, 2, 3).
      • status (Integer, optional): Der Status der Sprache (z.B. 1 für aktiv, 0 für inaktiv).
    • Beispiel:

      curl -X POST 'https://example.com/api/system/clangs' \
      -H 'Authorization: Bearer YOUR_API_TOKEN' \
      -H 'Content-Type: application/json' \
      -d '{
        "code": "fr",
        "name": "Français",
        "priority": 2,
        "status": 1
      }'

4. Eine Sprache aktualisieren

  • PATCH /api/system/clangs/{id}
    • Beschreibung: Aktualisiert eine bestehende Sprache.

    • Parameter:

      • id: Die ID der Sprache, die aktualisiert werden soll.
    • Anfrage-Body (JSON): Nur die Felder, die aktualisiert werden sollen (optional).

      • name (String, optional): Der neue Name der Sprache.
      • priority (Integer, optional): Die neue Priorität der Sprache.
      • status (Integer, optional): Der neue Status der Sprache.
    • Beispiel:

      curl -X PATCH 'https://example.com/api/system/clangs/2' \
      -H 'Authorization: Bearer YOUR_API_TOKEN' \
      -H 'Content-Type: application/json' \
      -d '{
        "name": "Deutsch",
        "status": 1
      }'

5. Eine Sprache löschen

  • DELETE /api/system/clangs/{id}
    • Beschreibung: Löscht eine Sprache.

    • Parameter:

      • id: Die ID der Sprache, die gelöscht werden soll.
    • Beispiel:

      curl -X DELETE 'https://example.com/api/system/clangs/2' \
      -H 'Authorization: Bearer YOUR_API_TOKEN'

6. Eine Sprache löschen (z.B. ID = 2)

curl -X DELETE 'https://example.com/api/system/clangs/2'
-H 'Authorization: Bearer YOUR_API_TOKEN'

7. Pagination anwenden (z.B. Seite 2 mit 5 Einträgen pro Seite)

curl -X GET 'https://example.com/api/system/clangs?page=2&per_page=5'
-H 'Authorization: Bearer YOUR_API_TOKEN'

8. Komplexere Filterung (mehrere Parameter)

curl -X GET 'https://example.com/api/system/clangs?filter%5Bstatus%5D=1&filter%5Bcode%5D=de&filter%5Bpriority%5D=1'
-H 'Authorization: Bearer YOUR_API_TOKEN'

Key Features

  • Full integration with REDAXO's language management system
  • Support for all standard language properties (code, name, priority, status)
  • Respects existing extension points (CLANG_ADDED, CLANG_UPDATED, CLANG_DELETED)
  • Validation to prevent common errors (duplicate codes, deleting the last language)
  • Proper cache management and priority organization
  • Consistent error responses and status codes

Usage Examples

List all languages

GET /api/system/clangs

Get a specific language

GET /api/system/clangs/2

Create a new language

POST /api/system/clangs
{
  "code": "es",
  "name": "Spanish",
  "priority": 3,
  "status": 1
}

Update a language

PATCH /api/system/clangs/2
{
  "name": "Español",
  "status": 0
}

Delete a language

DELETE /api/system/clangs/2

Implementation Notes

  • Added new Clangs.php file with all endpoint handlers
  • Updated boot.php to register the new route package
  • Aligned with existing API code style and patterns
  • Completes the planned endpoints from the README.md roadmap

@skerbis skerbis marked this pull request as draft February 26, 2025 19:37
@skerbis skerbis requested a review from dergel February 26, 2025 21:54
@skerbis skerbis marked this pull request as ready for review February 26, 2025 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant