Skip to content

API Documentation

Anugrah edited this page Apr 7, 2022 · 10 revisions

API Documentation

this section for explain API Go Postgres

  1. User
    • Register User
    • Login User
    • Update User
    • Delete User
  2. Photo
    • Upload Photo
    • Get Photo
    • Update Photo
    • Delete Photo
  3. Comment
    • Insert Comment
    • Get Comment
    • Update Comment
    • Delete Comment
  4. Social Media
    • Insert Social Media
    • Get Social Media
    • Update Social Media
    • Delete Social Media

User - User Register

This endpoint for register user, first hit API

Endpoint Register User

Command Method Routes Description
User Register POST /api/users/register this endpoint for user register

Authorization

this endpoint no auth

Request

{
	"email": "[email protected]",
	"username": "user",
	"age": 8,
	"password": "password"
}

Response

{
	"email": "[email protected]",
	"username": "user",
	"age": 8,
	"password": "password"
}

User - User Login

This endpoint for login user, first hit API, each endpoint must be use Token for authorization

Endpoint Login User

Command Method Routes Description
User Login POST /api/users/login this endpoint for get token and use each endpoint

Authorization

this endpoint no auth because for get token.

Request

{
	"email": "[email protected]",
	"password": "password"
}

Response

{
	"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVsCJ9.eyJlbWFpbCI6ImVtcGF0QGVtYWlsLmNvbSIsImlkIjo1fQ.VCD4Qkpez40hsuR-rYbJrwRN2eMQDg5FHvv8W_uJbrY"
}

User - User Update

This endpoint update detail user login use Token, will response data user email, id, age and username

Endpoint Update User

Command Method Routes Description
User Update PUT /api/users/:userId this endpoint for update user

Authorization

this endpoint using bearer auth, token will get if you login with endpoint Login User

Request

{
	"email": "[email protected]",
	"username": "userupdate",
        "age": 9
}

Response

{
	"age": 9,
	"email": "[email protected]",
	"id": 1,
	"update_at": "2022-04-05T11:49:05.608785+07:00",
	"username": "userupdate"
}

User - User Delete

This endpoint for delete user, this delete is softdelete

Endpoint Delete User

Command Method Routes Description
User Delete DELETE /api/users/:userId this endpoint for delete data user from table users

Authorization

this endpoint using bearer auth, token will get if you login with endpoint Login User

Request

none

Response

{
	"message": "your account has been successfully deleted"
}

Photo - Upload Photo

This endpoint for photo upload

Endpoint Upload Photo

Command Method Routes Description
Upload Photo POST /api/photos this endpoint for upload photo

Authorization

this endpoint using bearer auth, token will get if you login with endpoint Login User

Request

{
	"tittle": "Test Photo",
	"caption": "Upload",
	"photo_url": "https://www.facebook.com/pictures/test"
}

Response

{
	"caption": "Upload",
	"created_at": "2022-04-07T08:42:34.3307046+07:00",
	"id": 1,
	"photo_url": "https://www.facebook.com/pictures/test.jpg",
	"tittle": "Test Photo",
	"user_id": 1
}

Photo - Get Photo

This endpoint for get Photo

Endpoint Get Photo

Command Method Routes Description
Get Photo POST /api/photos this endpoint for get data from table photos

Authorization

this endpoint using bearer auth, token will get if you login with endpoint Login User

Request

none

Response

{
	"caption": "Upload",
	"created_at": "2022-04-06T08:19:36.502168+07:00",
	"id": 1,
	"photo_url": "https://www.facebook.com/pictures/test.jpg",
	"tittle": "Test Photo",
	"updated_at": "2022-04-06T08:19:36.502168+07:00",
	"user": {
		"username": "user",
		"email": "[email protected]"
	},
	"user_id": 1
}