Skip to content

WIP: feat: support liking any content represented by an LDP model

Ghost User requested to merge support-generic-likes into master

Depends on djangoldp!113 (closed)
Solves !1 (merged)

Likes are exposed on /likes/. Example:

{
  "@id": "http://localhost:8000/likes/",
  "@type": "ldp:Container",
  "ldp:contains": [
    {
      "sender": {
        "@id": "http://localhost:8000/users/chenry/"
      },
      "target": {
        "@id": "http://localhost:8000/circles/1/"
      },
      "timestamp": "2020-01-22T12:19:57Z",
      "@id": "http://localhost:8000/likes/1/",
      "@type": "coopstarter:like",
      "permissions": [
        {
          "mode": {
            "@type": "view"
          }
        }
      ]
    },
    {
      "sender": {
        "@id": "http://localhost:8000/users/user1/"
      },
      "target": {
        "@id": "http://localhost:8000/circles/1/"
      },
      "timestamp": "2020-01-22T12:19:57Z",
      "@id": "http://localhost:8000/likes/2/",
      "@type": "coopstarter:like",
      "permissions": [
        {
          "mode": {
            "@type": "view"
          }
        }
      ]
    },
    {
      "sender": {
        "@id": "http://localhost:8000/users/user2/"
      },
      "target": {
        "@id": "http://localhost:8000/circles/1/"
      },
      "timestamp": "2020-01-22T12:19:57Z",
      "@id": "http://localhost:8000/likes/3/",
      "@type": "coopstarter:like",
      "permissions": [
        {
          "mode": {
            "@type": "view"
          }
        }
      ]
    }
  ],
  "permissions": [
    {
      "mode": {
        "@type": "add"
      }
    },
    {
      "mode": {
        "@type": "view"
      }
    }
  ],
  "@context": "https://cdn.happy-dev.fr/owl/hdcontext.jsonld"
}

Can be tested with the following cURL command:

# Provided that server is exposed on localhost:8000, a user 'user2' and one circle exists:
curl -X POST -H 'Content-Type: application/ld+json' -i http://localhost:8000/likes/ --data '{"sender":{"@id":"http://localhost:8000/users/user2/"}, "timestamp":"2020-01-22T12:19:57Z","target":{"@id":"http://localhost:8000/circles/1/"},"@context":"https://cdn.happy-dev.fr/owl/hdcontext.jsonld"}'

Merge request reports