Posts Endpoint

{info} Mengolah data postingan.


Base URL

https://public-api.delcom.org/api/v1

Add New Post

  • URL
    • /posts
  • Method
    • POST
  • Headers
    • Content-Type: multipart/form-data
    • Authorization: Bearer <token>
  • Request Body
    • cover as file
    • description as string
  • Response
{
    "success": true,
    "message": "Berhasil menambahkan data",
    "data": {
        "post_id": 6
    }
}

Change Cover Post

  • URL
    • /posts/:id/cover
  • Method
    • POST
  • Headers
    • Content-Type: multipart/form-data
    • Authorization: Bearer <token>
  • Request Body
    • cover as file
  • Response
{
    "success": true,
    "message": "Berhasil mengubah cover"
}

Update Post

  • URL
    • /posts/:id
  • Method
    • PUT
  • Headers
    • Content-Type: application/x-www-form-urlencoded
    • Authorization: Bearer <token>
  • Request Body
    • description as string
  • Response
{
    "success": true,
    "message": "Berhasil mengubah data"
}

Get All Posts

  • URL
    • /posts
  • Parameters
    • is_me as 1
      • Notes:
        • 1 as retrieve all data created
  • Method
    • GET
  • Headers
    • Authorization: Bearer <token>
  • Response
{
    "success": true,
    "message": "Berhasil mengambil data",
    "data": {
        "posts": [
            {
                "id": 4,
                "user_id": 1,
                "cover": "http://127.0.0.1:8000/img/posts/cover/1_1728097631.jpeg",
                "description": "Terus belajar apapun rintangannya!",
                "created_at": "2024-10-05T03:07:11.000000Z",
                "updated_at": "2024-10-05T03:07:11.000000Z",
                "author": {
                    "name": "Delcom Testing",
                    "photo": null
                },
                "likes": [],
                "comments": []
            },
            {
                "id": 5,
                "user_id": 1,
                "cover": "http://127.0.0.1:8000/img/posts/cover/1_1728097665.jpeg",
                "description": "Tolak ukur kemampuan adalah usaha...",
                "created_at": "2024-10-05T03:07:45.000000Z",
                "updated_at": "2024-10-05T03:07:45.000000Z",
                "author": {
                    "name": "Delcom Testing",
                    "photo": null
                },
                "likes": [2, 3],
                "comments": [3]
            },
            {
                "id": 6,
                "user_id": 3,
                "cover": "http://127.0.0.1:8000/img/posts/cover/3_1728101053.jpeg",
                "description": "Deskripsi telah berubah",
                "created_at": "2024-10-05T04:02:12.000000Z",
                "updated_at": "2024-10-05T04:05:05.000000Z",
                "author": {
                    "name": "Abdullah Ubaid",
                    "photo": null
                },
                "likes": [1],
                "comments": [1]
            }
        ]
    }
}

Detail Post

  • URL
    • /posts/:id
  • Method
    • GET
  • Headers
    • Authorization: Bearer <token>
  • Response
{
    "success": true,
    "message": "Berhasil mengambil data",
    "data": {
        "post": {
            "id": 5,
            "user_id": 1,
            "cover": "http://127.0.0.1:8000/img/posts/cover/1_1728097665.jpeg",
            "description": "Tolak ukur kemampuan adalah usaha...",
            "created_at": "2024-10-05T03:07:45.000000Z",
            "updated_at": "2024-10-05T03:07:45.000000Z",
            "author": {
                "name": "Delcom Testing",
                "photo": null
            },
            "likes": [2, 3],
            "comments": [
                {
                    "id": 2,
                    "comment": "Wah keren yah!",
                    "created_at": "2024-10-05T03:49:59.000000Z",
                    "updated_at": "2024-10-05T03:49:59.000000Z"
                }
            ],
            "my_comment": {
                "id": 2,
                "comment": "Wah keren yah!",
                "created_at": "2024-10-05T03:49:59.000000Z",
                "updated_at": "2024-10-05T03:49:59.000000Z"
            }
        }
    }
}

Delete Post

  • URL
    • /posts/:id
  • Method
    • DELETE
  • Headers
    • Authorization: Bearer <token>
  • Response
    {
        "success": true,
        "message": "Berhasil menghapus data"
    }

Add Like

  • URL
    • /posts/:id/likes
  • Method
    • POST
  • Headers
    • Content-Type: application/x-www-form-urlencoded
    • Authorization: Bearer <token>
  • Request Body
    • like as 1 | 0
      • Notes:
      • 1 as give like
      • 0 as delete like
  • Response
{
    "success": true,
    "message": "Berhasil mengubah status suka pada postingan"
}

Add Comment

  • URL
    • /posts/:id/comments
  • Method
    • POST
  • Headers
    • Content-Type: application/x-www-form-urlencoded
    • Authorization: Bearer <token>
  • Request Body
    • comment as string
  • Response
{
    "success": true,
    "message": "Berhasil memberikan komentar pada postingan"
}

Delete Comment

  • URL
    • /posts/:id/comments
  • Method
    • DELETE
  • Headers
    • Authorization: Bearer <token>
  • Response
{
    "success": true,
    "message": "Berhasil menghapus komentar pada postingan"
}