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

templated links + plural endpoints #416

Merged
merged 5 commits into from
Apr 21, 2020

Conversation

pmattmann
Copy link
Member

router uses templated links
endpoints plural

router uses templated links
endpoints plural
@pmattmann pmattmann added this to the Core 21.04.2020 milestone Apr 7, 2020
@pmattmann pmattmann linked an issue Apr 7, 2020 that may be closed by this pull request
@@ -123,7 +123,7 @@ export default {
},
methods: {
invite (user, role) {
this.api.post('/camp-collaboration', {
this.api.post('/camp-collaborations', {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noch extremer ist es hier...
Beim erstellen neuer Objekte werden wir den Endpunkt immer angeben müssen...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aktuell könnte man das aber so lösen:

this.api.post(this.camp.camp_collaborations(), { ... })

Fast noch etwas schöner wäre es aber wenn wir den Store abändern, sodass folgendes möglich ist:

this.camp.camp_collaborations().post({ ... })

Dann wäre aber post ein reserviertes Wort, so dürfte dann keine Relation mehr heissen. Alternativ:

this.camp.camp_collaborations()._meta.post({ ... })

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gute Idee. Innerhalb von Vue ist das $ relativ weit verbreitet bzw. schon fast eine Konvention:
this.camp.camp_collaborations().$post({ ... })

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich verstehe die Idee nicht ganz.
CampCollaborations wird bereits als Embedded-Collection auf dem Camp mitgeliefert.
Wir kennen die Collection-URI somit nicht, sondern nur alle gelieferten CampCollaborations-Entity-URIs.

{
  "id": "9cd0d827",
  "name": "Camp 1",
  "title": "Sommerlager",
  "motto": "Camp 1 Motto",
  "_embedded": {
    "creator": { ... },
    "camp_type": { ... },
    "camp_collaborations": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8888/api/camp-collaborations/6a62ba05"
          }
        }
      },
      {
        "_links": {
          "self": {
            "href": "http://localhost:8888/api/camp-collaborations/6f7851cb"
          }
        }
      }
    ],
    "periods": [ ... ],
    "event_categories": [ ... ],
    "eventCategories": [ ... ]
  },
  "_links": {
    "self": {
      "href": "http://localhost:8888/api/camps/9cd0d827"
    },
    "events": {
      "href": "http://localhost:8888/api/events?camp_id=9cd0d827"
    }
  }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Das ist wahr, aber ich habe vor einigen Wochen im hal-json-normalizer für genau solche Fälle die Möglichkeit hinzugefügt, einen self link für eine embedded list anzugeben. Also wäre die Lösung hier, einfach noch zusätzlich in _links die URI für camp_collaborations anzugeben (plus beim Normalizer die Option embeddedStandaloneListKey: 'items' zu setzen). Dann wird die embedded List komplett standalone verwendbar, inklusive POST requests da rein.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool
Habe die API angepasst...
Resultat sieht jetzt so aus:

{
  "id": "1be066e5",
  "name": "Camp 2",
  "title": "Camp 2 Title",
  "motto": "Camp 2 Motto",
  "_embedded": {
    "creator": { ... },
    "camp_type": { ... },
    "camp_collaborations": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8888/api/camp-collaborations/d29e6221"
          }
        }
      }
    ],
    "periods": [ ... ],
    "event_categories": [ ... ],
    "eventCategories": [ ... ]
  },
  "_links": {
    "self": {
      "href": "http://localhost:8888/api/camps/1be066e5"
    },
    "camp_collaborations": {
      "href": "http://localhost:8888/api/camp-collaborations?camp_id=1be066e5"
    },
    "events": {
      "href": "http://localhost:8888/api/events?camp_id=1be066e5"
    }
  }
}

Ich habe die Client-Side jedoch nicht zum laufen gebracht... konnte den Link für die Camp-Collaboration-Collection nicht finden....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.camp.camp_collaborations._meta.self bzw. this.api.href(camp, 'camp_collaborations') müssten beide gehen, sonst funktioniert etwas noch nicht so wie ich es mir vorstelle

@carlobeltrame
Copy link
Member

@pmattmann Brauchst du hier nochmals ein Review oder gibts noch etwas von deiner Seite her zu tun?

@manuelmeister
Copy link
Member

manuelmeister commented Apr 21, 2020

Merged in Core Meeting

@manuelmeister manuelmeister reopened this Apr 21, 2020
@manuelmeister manuelmeister merged commit 812e36b into ecamp:devel Apr 21, 2020
@pmattmann pmattmann deleted the feature/templated-links branch October 4, 2020 12:51
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.

API endpoints in plural
4 participants