zakariawahyu / go-fiber-gorm-basic

:zap: Basic REST API Post Tag User Locker with Fiber + GORM + MySQL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API Documentation

Users

Create User

POST /users
Body Request
{
  "name" : "Zakaria"
}

Response
{
  "message": "create data successfully",
  "user": {
    "id": 1,
    "name": "Zakaria"
  }
}

Get All User

GET /users
Response
[
  {
    "id": 1,
    "name": "Zakaria"
  }, 
  {
    "id": 2,
    "name": "Wahyu"
  }   
]

Get User By ID

GET /users/:id
Response
{
  "id": 1,
  "name": "Zakaria"
}

Update User By ID

PUT /users/:id

Delete User BY ID

DELETE /users/:id

Lockers

Create Locker

POST /lokers
Body Request
{
  "user_id" : 1,
  "code" : "123"
}

Response
{
  "message": "create data successfully",
  "locker": {
    "id": 2,
    "code": "123",
    "user_id": 1
  },
}

Get All Locker

GET /lockers
Response
[
  {
    "id": 1, 
    "code": "123",
    "user_id": 1,
    "user": {
      "id": 1,
      "name": "Zakaria"
    }
  }, 
  {
    "id": 2,
    "code": "456",
    "user_id": 2,
    "user": {
      "id": 2, 
      "name": "Wahyu"
    }
  }
]

Get Locker By ID

GET /lockers/:id
Response
{
  "id": 1,
  "code": "123",
  "user_id": 1,
  "user": {
    "id": 1,
    "name": "Zakaria"
  }
}

Update Locker By ID

PUT /lockers/:id

Delete Locker By ID

DELETE /lockers/:id

Tags

Create Tags

POST /tags
Body Request
{
  "name" : "Jakarta"
}

Response
{
  "message": "create data successfully",
  "tag": {
    "id": 1,
    "name": "Jakarta"
  }
}

Get All Tags

GET /tags
Response
[
  {
    "id": 1,
    "name": "Jakarta"
  },
  {
    "id": 2,
    "name": "Kota Kolaborasi"
  }
]

Get Tags By ID

GET /tags/:id
Response
{
  "id": 2,
  "name": "Kota Kolaborasi"
}

Update Tags By ID

PUT /tags/:id

Delete Tags By ID

DELETE /tags/:id

Post

Create Post

POST /posts
Body Request
{
  "title" : "Berita 1",
  "body" : "Isi berita 1",
  "user_id" : 1,
  "tags_id" : [
    1,
    2,
    3
  ]
}

Response
{
  "message": "create data successfully",
  "post": {
    "id": 1,
    "title": "Berita 1",
    "body": "Isi berita 1",
    "user_id": 1,
    "tags_id": [
      1,
      2,
      3
    ]
  }
}

Get All Posts

GET /posts
Response
[
  {
    "id": 1,
    "title": "Berita 2",
    "body": "Isi berita 2",
    "user_id": 1,
    "user": {
      "id": 1,
      "name": "Zakaria",
      "locker": {
        "id": 1,
        "code": "123",
        "user_id": 1
      }
    },
    "tags": [
      {
        "id": 1,
        "name": "Jakarta"
      },
      {
        "id": 2,
        "name": "Kota Kolaborasi"
      },
      {
        "id": 3,
        "name": "Metropolitan"
      }
    ]
  },
  {
    "id": 2,
    "title": "Berita Jakarta",
    "body": "Isi berita Jakarta",
    "user_id": 2,
    "user": {
      "id": 2,
      "name": "Wahyu",
      "locker": {
        "id": 2,
        "code": "456",
        "user_id": 2
      }
    },
    "tags": [
      {
        "id": 4,
        "name": "Banjir"
      },
      {
        "id": 5,
        "name": "BUMN"
      }
    ]
  }
]

Get Post By ID

GET /posts/:id
Response
{
  "id": 11,
  "title": "Berita Jakarta",
  "body": "Isi berita Jakarta",
  "user_id": 2,
  "user": {
    "id": 2,
    "name": "Wahyu",
    "locker": {
      "id": 2,
      "code": "456",
      "user_id": 2
    }
  },
  "tags": [
    {
      "id": 4,
      "name": "Banjir"
    },
    {
      "id": 5,
      "name": "BUMN"
    }
  ]
}

Update Post By ID

PUT /posts/:id

Delete Post By ID

DELETE /posts/:id

Data Details

Get All Details Users

Detail with Lockers, Posts and Tags
GET /users-details
Response
[
  {
    "id": 1,
    "name": "Zakaria",
    "locker": {
      "id": 1,
      "code": "123",
      "user_id": 1
    },
    "post": [
      {
        "id": 1,
        "title": "Berita 2",
        "body": "Isi berita 2",
        "user_id": 1,
        "tags": [
          {
            "id": 1,
            "name": "Jakarta"
          },
          {
            "id": 2,
            "name": "Kota Kolaborasi"
          },
          {
            "id": 3,
            "name": "Metropolitan"
          }
        ]
      }
    ]
  },
  {
    "id": 2,
    "name": "Wahyu",
    "locker": {
      "id": 2,
      "code": "456",
      "user_id": 2
    },
    "post": [
      {
        "id": 11,
        "title": "Berita Jakarta",
        "body": "Isi berita Jakarta",
        "user_id": 2,
        "tags": [
          {
            "id": 4,
            "name": "Banjir"
          },
          {
            "id": 5,
            "name": "BUMN"
          }
        ]
      }
    ]
  }
]

Get Details Users By ID

GET /users-details/:id
Response
{
  "id": 1,
  "name": "Zakaria",
  "locker": {
    "id": 1,
    "code": "123",
    "user_id": 1
  },
  "post": [
    {
      "id": 1,
      "title": "Berita 2",
      "body": "Isi berita 2",
      "user_id": 1,
      "tags": [
        {
          "id": 1,
          "name": "Jakarta"
        },
        {
          "id": 2,
          "name": "Kota Kolaborasi"
        },
        {
          "id": 3,
          "name": "Metropolitan"
        }
      ]
    },
    {
      "id": 2,
      "title": "Berita Jakarta",
      "body": "Isi berita Jakarta",
      "user_id": 1,
      "tags": [
        {
          "id": 4,
          "name": "Banjir"
        },
        {
          "id": 5,
          "name": "BUMN"
        }
      ]
    }
  ]
}

Get All Details Tags

Detail with Posts

GET /tags-details
Response
[
  {
    "id": 1,
    "name": "Jakarta",
    "post": [
      {
        "id": 1,
        "title": "Berita 2",
        "body": "Isi berita 2"
      },
      {
        "id": 2,
        "title": "Berita 2",
        "body": "Isi berita 2"
      }
    ]
  },
  {
    "id": 2,
    "name": "Kota Kolaborasi",
    "post": [
      {
        "id": 1,
        "title": "Berita 2",
        "body": "Isi berita 2"
      },
      {
        "id": 2,
        "title": "Berita 2",
        "body": "Isi berita 2"
      }
    ]
  },
  {
    "id": 3,
    "name": "Metropolitan",
    "post": [
      {
        "id": 1,
        "title": "Berita 2",
        "body": "Isi berita 2"
      },
      {
        "id": 2,
        "title": "Berita 2",
        "body": "Isi berita 2"
      }
    ]
  },
  {
    "id": 4,
    "name": "Banjir",
    "post": [
      {
        "id": 10,
        "title": "Berita Jakarta",
        "body": "Isi berita Jakarta"
      },
      {
        "id": 11,
        "title": "Berita Jakarta",
        "body": "Isi berita Jakarta"
      }
    ]
  },
  {
    "id": 5,
    "name": "BUMN",
    "post": [
      {
        "id": 10,
        "title": "Berita Jakarta",
        "body": "Isi berita Jakarta"
      },
      {
        "id": 11,
        "title": "Berita Jakarta",
        "body": "Isi berita Jakarta"
      }
    ]
  }
]

Get Details Tags By ID

GET /tags-details/:id
Response
{
  "id": 4,
  "name": "Banjir",
  "post": [
    {
      "id": 10,
      "title": "Berita Jakarta",
      "body": "Isi berita Jakarta"
    },
    {
      "id": 11,
      "title": "Berita Jakarta",
      "body": "Isi berita Jakarta"
    }
  ]
}

About

:zap: Basic REST API Post Tag User Locker with Fiber + GORM + MySQL


Languages

Language:Go 100.0%