Delcom Open API Logo

Delcom

Posts

Dokumentasi API

Posts

Posts Endpoint

info: Mengolah data postingan.


Base URL

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

Add New Post

Membuat dan mempublikasikan postingan baru.

  • URL
    • /posts
  • Method
    • POST
  • Headers
    • Content-Type: application/json
    • Authorization: Bearer <token>
  • Request Body
    • description as string
  • Contoh Request
    POST {{BaseURL}}/posts
    Accept: application/json
    Authorization: Bearer <token>
    Content-Type: application/json
    
    {
        "description": "Contoh deskripsi"
    }
    
  • Catatan: upload cover dilakukan terpisah lewat Change Cover Post.
  • Response Berhasil
    {
        "status": "success",
        "message": "Berhasil menambahkan data",
        "data": {
            "post_id": 6
        }
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Data tidak valid",
        "data": {
            "field": [
                "Pesan validasi"
            ]
        }
    }
    

Change Cover Post

Mengunggah atau memperbarui gambar sampul (cover) untuk postingan tertentu.

  • URL
    • /posts/:id/cover
  • Method
    • POST
  • Headers
    • Content-Type: multipart/form-data
    • Authorization: Bearer <token>
  • Request Body
    • cover as file
  • Contoh Request
    POST {{BaseURL}}/posts/1/cover
    Accept: application/json
    Authorization: Bearer <token>
    Content-Type: multipart/form-data; boundary=----DelcomFormBoundary
    
    ------DelcomFormBoundary
    Content-Disposition: form-data; name="cover"; filename="cover.jpg"
    Content-Type: image/jpeg
    
    < ./cover.jpg
    ------DelcomFormBoundary--
    
  • Response Berhasil
    {
        "status": "success",
        "message": "Berhasil mengubah cover"
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Data tidak valid",
        "data": {
            "field": [
                "Pesan validasi"
            ]
        }
    }
    

Update Post

Memperbarui isi deskripsi pada postingan yang telah dibuat.

  • URL
    • /posts/:id
  • Method
    • PUT
  • Headers
    • Content-Type: application/json
    • Authorization: Bearer <token>
  • Request Body
    • description as string
  • Contoh Request
    PUT {{BaseURL}}/posts/1
    Accept: application/json
    Authorization: Bearer <token>
    Content-Type: application/json
    
    {
        "description": "Contoh deskripsi"
    }
    
  • Response Berhasil
    {
        "status": "success",
        "message": "Berhasil mengubah data"
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Data tidak valid",
        "data": {
            "field": [
                "Pesan validasi"
            ]
        }
    }
    

Get All Posts

Mengambil seluruh daftar postingan publik atau postingan milik sendiri (is_me).

  • URL
    • /posts
  • Parameters
    • is_me as 1
      • Notes:
        • 1 as retrieve all data created
  • Method
    • GET
  • Headers
    • Authorization: Bearer <token>
  • Contoh Request
    GET {{BaseURL}}/posts
    Accept: application/json
    Authorization: Bearer <token>
    
  • Response Berhasil
    {
        "status": "success",
        "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]
                }
            ]
        }
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Data tidak valid",
        "data": {
            "field": [
                "Pesan validasi"
            ]
        }
    }
    

Detail Post

Melihat detail lengkap satu postingan beserta komentar dan interaksinya.

  • URL
    • /posts/:id
  • Method
    • GET
  • Headers
    • Authorization: Bearer <token>
  • Contoh Request
    GET {{BaseURL}}/posts/1
    Accept: application/json
    Authorization: Bearer <token>
    
  • Response Berhasil
    {
        "status": "success",
        "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"
                }
            }
        }
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Data tidak valid",
        "data": {
            "field": [
                "Pesan validasi"
            ]
        }
    }
    

Delete Post

Menghapus postingan tertentu dari sistem.

  • URL
    • /posts/:id
  • Method
    • DELETE
  • Headers
    • Authorization: Bearer <token>
  • Contoh Request
    DELETE {{BaseURL}}/posts/1
    Accept: application/json
    Authorization: Bearer <token>
    
  • Response Berhasil
    {
        "status": "success",
        "message": "Berhasil menghapus data"
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Data tidak valid",
        "data": {
            "field": [
                "Pesan validasi"
            ]
        }
    }
    

Add Like

Memberikan atau membatalkan status suka (like/unlike) pada suatu postingan.

  • URL
    • /posts/:id/likes
  • Method
    • POST
  • Headers
    • Content-Type: application/json
    • Authorization: Bearer <token>
  • Request Body
    • like as 1 | 0
      • Notes:
      • 1 as give like
      • 0 as delete like
  • Contoh Request
    POST {{BaseURL}}/posts/1/likes
    Accept: application/json
    Authorization: Bearer <token>
    Content-Type: application/json
    
    {
        "like": 1
    }
    
  • Response Berhasil
    {
        "status": "success",
        "message": "Berhasil mengubah status suka pada postingan"
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Data tidak valid",
        "data": {
            "field": [
                "Pesan validasi"
            ]
        }
    }
    

Add Comment

Menambahkan komentar baru ke dalam sebuah postingan.

  • URL
    • /posts/:id/comments
  • Method
    • POST
  • Headers
    • Content-Type: application/json
    • Authorization: Bearer <token>
  • Request Body
    • comment as string
  • Contoh Request
    POST {{BaseURL}}/posts/1/comments
    Accept: application/json
    Authorization: Bearer <token>
    Content-Type: application/json
    
    {
        "comment": "Komentar percobaan"
    }
    
  • Response Berhasil
    {
        "status": "success",
        "message": "Berhasil memberikan komentar pada postingan"
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Data tidak valid",
        "data": {
            "field": [
                "Pesan validasi"
            ]
        }
    }
    

Delete Comment

Menghapus komentar yang telah dikirim pada suatu postingan.

  • URL
    • /posts/:id/comments
  • Method
    • DELETE
  • Headers
    • Authorization: Bearer <token>
  • Contoh Request
    DELETE {{BaseURL}}/posts/1/comments
    Accept: application/json
    Authorization: Bearer <token>
    
  • Response Berhasil
    {
        "status": "success",
        "message": "Berhasil menghapus komentar pada postingan"
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Data tidak valid",
        "data": {
            "field": [
                "Pesan validasi"
            ]
        }
    }
    

Delete All Posts

Menghapus semua data postingan milik pengguna saat ini secara permanen beserta berkas cover, like, dan komentarnya.

  • URL
    • /posts
  • Method
    • DELETE
  • Headers
    • Authorization: Bearer <token>
  • Contoh Request
    DELETE {{BaseURL}}/posts
    Accept: application/json
    Authorization: Bearer <token>
    
  • Response Berhasil
    {
        "status": "success",
        "message": "Berhasil menghapus semua data postingan"
    }
    
  • Response Gagal
    {
        "status": "fail",
        "message": "Unauthenticated."
    }