Skip to content

rama4zis/go-mygram-aplication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang MyGram

Aplikasi API sederhana menggunakan Golang

Database Configuration

  1. PostgreSQL
  2. Database Name: mygram
  3. Database User: postgres
  4. Database Password: root
  5. Database Port: 5432

[!] You can change the database configuration in the file models/setup.go

How to run

go mod tidy
go run main.go

This will runing on default localhost port 8080

Postman Collection

You can import this postman collection to test the API

[!] Collection file in folder test

[!] Remember after login, you need to copy the token and paste it in the header Authorization with Bearer Token manually

Fitur

  • Register User

  • Login User

  • Update User

  • Delete User

  • Create Photo Post

  • Update Photo Post

  • Delete Photo Post

  • Create Comment

  • Update Comment

  • Delete Comment

  • Create User Social Media

  • Update User Social Media

  • Delete User Social Media

Get data API

User

Register User

*Note : username and email is unique

curl --location --request POST 'http://localhost:8080/users/register' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Username=example' \
--data-urlencode 'Email=yourmail' \
--data-urlencode 'Password=yourpassword' \
--data-urlencode 'Age=yourage'

Login User

curl --location --request POST 'http://localhost:8080/users/login' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Email=yourMail' \
--data-urlencode 'Password=yourPassword'

This will return token, save it for next request

Update User

curl --location --request PUT 'http://localhost:8080/users/update' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "updateyourmail@test.com",
    "username": "updateyourname"
}'

Delete User

curl --location --request DELETE 'http://localhost:8080/users/' \
--header 'Authorization: Bearer {YOURTOKEN}'

Token is required

Photo Post

Get All Your Photo Post

curl --location --request GET 'http://localhost:8080/posts/' \
--header 'Authorization: Bearer {YOURTOKEN}'

Create Photo Post

curl --location --request POST 'http://localhost:8080/photos' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "title": "your title",
    "caption": "your caption",
    "photo_url": "your photo url"
}'

Update Photo Post

curl --location --request PUT 'http://localhost:8080/photos/{PHOTOID}' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "title": "update your title",
    "caption": "update your caption",
    "photo_url": "update your photo url"
}'

Delete Photo Post

curl --location --request DELETE 'http://localhost:8080/photos/{PHOTOID}' \
--header 'Authorization: Bearer {YOURTOKEN}'

Comment

Get All Your Comment

curl --location --request GET 'http://localhost:8080/comments/' \
--header 'Authorization: Bearer {YOURTOKEN}'

Post Comment

curl --location --request POST 'http://localhost:8080/comments' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": "your message",
    "photo_id": {PHOTOID}
}'

Update Comment

curl --location --request PUT 'http://localhost:8080/comments/{COMMENTID}' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "message": "update your message"
}'

Delete Comment

curl --location --request DELETE 'http://localhost:8080/comments/{COMMENTID}' \
--header 'Authorization: Bearer {YOURTOKEN}'

User Social Media

Get All Your User Social Media

curl --location --request GET 'http://localhost:8080/socialmedias' \
--header 'Authorization: Bearer {YOURTOKEN}'

Create User Social Media

curl --location --request POST 'http://localhost:8080/socialmedias' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "your social media name",
    "social_media_url": "your social media url"
}'

Update User Social Media

curl --location --request PUT 'http://localhost:8080/socialmedias/{SOCIALMEDIAID}' \
--header 'Authorization: Bearer {YOURTOKEN}' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "update your social media name",
    "social_media_url": "update your social media url"
}'

Delete User Social Media

curl --location --request DELETE 'http://localhost:8080/socialmedias/{SOCIALMEDIAID}' \
--header 'Authorization: Bearer {YOURTOKEN}'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages