Skip to content

linothomas14/exercise-course-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Course Exercise API

API ini ditujukan untuk memehuni Technical Test Backend Developer Intern

Table of Contents

Setup

Untuk menjalankan API ini diperlukan bahasa Go dan MySQL sebagai database

  • buat file .env, sesuai dengan .env-example
  • jalankan perintah go run main.go
  • creds akun admin :
{
  "name": "Admin",
  "email": "admin@gmail.com",
  "password": "admin123"
}

Routes

HTTP METHOD POST GET PUT DELETE
/users - List of User UpdateUser -
/users/<int:id> - Detail of User - DeleteUser
/users/profile - GetProfile - -
/user-courses EnrollCourse List of UserCourse - UnenrollCourse
/user-courses/<int:id> - Detail of UserCourse - -
/courses AddCourse List of Course - -
/courses/<int:id> - Detail of Course UpdateCourse DeleteCourse
/course-categories AddCategoryCourse List of CourseCategory - -
/course-categories/<int:id> - Detail of CourseCategory UpdateCourseCategory DeleteCourseCategory
/admins RegisterAdmin List of Admin - -
/admins/<int:id> - Detail of Admin UpdateAdmin DeleteAdmin
/login LoginUser - - -
/login-admin LoginAdmin - - -
/register RegisterUser - - -

API Documentation

List of Endpoints

Auth

Login

  • Method : POST
  • URL : /login
  • Token : -
  • Request body :
{
  "email": "string",
  "password": "string"
}
  • Response body :
{
  "message": "string",
  "data": {
    "token": "string"
  }
}

Login Admin

  • Method : POST
  • URL : /login-admin
  • Token : -
  • Request body :
{
  "email": "string",
  "password": "string"
}
  • Response body :
{
  "message": "string",
  "data": {
    "token": "string"
  }
}

Register

  • Method : POST
  • URL : /register
  • Token : -
  • Request body :
{
  "email": "string",
  "name": "string",
  "password": "string"
}
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "email": "string",
    "name": "string"
  }
}

User

Get All User

  • Method : GET
  • URL : /users
  • Token : adminToken
  • Request body : -
  • Response body :
{
  "message": "OK",
  "data": [
    {
      "id": "int",
      "email": "string",
      "name": "string"
    }
  ]
}

Get User Profile

  • Method : GET
  • URL : /users/profile
  • Token: token
  • Request body : -
  • Response body :
{
  "message": "OK",
  "data": {
    "id": "int",
    "email": "string",
    "name": "string"
  }
}

Get User by ID

  • Method : GET
  • URL : /users/<int:id>
  • Token: tokenAdmin
  • Request body : -
  • Response body :
{
  "message": "OK",
  "data": {
    "id": "int",
    "email": "string",
    "name": "string"
  }
}

Update User

  • Method : PUT
  • URL : /users
  • Token : tokenUser
  • Request body :
{
  "email": "string",
  "name": "string",
  "password": "string"
}
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "email": "string",
    "name": "string"
  }
}

Delete User

  • Method : DELETE
  • URL : /users/<id:int>
  • Token : tokenAdmin
  • Request body : -
  • Response body :
{
  "message": "User id `id` was deleted",
  "data": {}
}

Course

Get All Course

  • Method : GET
  • URL : /courses
  • Token : userToken / adminToken
  • Request body : -
  • Response body :
{
  "message": "OK",
  "data": [
    {
      "id": "int",
      "title": "string",
      "course_category_id": "int",
      "course_category": {
        "id": "int",
        "name": "string"
      }
    }
  ]
}

Get Course By ID

  • Method : GET
  • URL : /courses
  • Token : userToken / adminToken
  • Request body : -
  • Response body :
{
  "message": "OK",
  "data": {
    "id": "int",
    "title": "string",
    "course_category_id": "int",
    "course_category": {
      "id": "int",
      "name": "string"
    }
  }
}

Add Course

  • Method : POST
  • URL : /courses/<id:int>
  • Token : adminToken
  • Request body :
{
  "title": "string",
  "course_category_id": "int"
}
  • Response body :
{
  "message": "OK",
  "data": {
    "id": "int",
    "title": "string",
    "course_category_id": "int",
    "course_category": {
      "id": "int",
      "name": "string"
    }
  }
}

Update Course

  • Method : PUT
  • URL : /courses/<id:int>
  • Token : adminToken
  • Request body :
{
  "title": "string",
  "course_category_id": "int"
}
  • Response body :
{
  "message": "OK",
  "data": {
    "id": "int",
    "title": "string",
    "course_category_id": "int",
    "course_category": {
      "id": "int",
      "name": "string"
    }
  }
}

Delete Course

  • Method : DELETE

  • URL : /courses/<id:int>

  • Token : adminToken

  • Request body : -

  • Response body :

{
  "message": "Course id `id` was deleted",
  "data": {}
}

Course Category

Get All Course Category

  • Method : GET
  • URL : /course-categories
  • Token : userToken / adminToken
  • Request body : -
  • Response body :
{
  "message": "OK",
  "data": [
    {
      "id": "int",
      "name": "string"
    }
  ]
}

Get Course Category By ID

  • Method : GET
  • URL : /course-categories
  • Token : userToken / adminToken
  • Request body : -
  • Response body :
{
  "message": "OK",
  "data": [
    {
      "id": "int",
      "name": "string"
    }
  ]
}

Add Course Category

  • Method : POST
  • URL : /course-categories
  • Token : adminToken
  • Request body :
{
  "name": "string"
}
  • Response body :
{
  "message": "OK",
  "data": [
    {
      "id": "int",
      "name": "string"
    }
  ]
}

Update Course Category

  • Method : PUT
  • URL : /course-categories/<id:int>
  • Token : adminToken
  • Request body :
{
  "name": "string"
}
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "name": "string"
  }
}

Delete Course Category

  • Method : DELETE

  • URL : /course-categories/<id:int>

  • Token : adminToken

  • Request body : -

  • Response body :

{
  "message": "Data has been deleted",
  "data": {}
}

User Course

Get All User Course

  • Method : GET
  • URL : /user-courses
  • Token : adminToken
  • Request body : -
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "user_id": "int",
    "User": {
      "id": "int",
      "email": "string",
      "name": "string"
    },
    "course_id": "int",
    "Course": {
      "id": "int",
      "title": "string",
      "course_category_id": "int",
      "course_category": {
        "id": "int",
        "name": "string"
      }
    }
  }
}

Get User Course By ID

  • Method : GET
  • URL : /user-courses
  • Token : adminToken
  • Request body : -
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "user_id": "int",
    "User": {
      "id": "int",
      "email": "string",
      "name": "string"
    },
    "course_id": "int",
    "Course": {
      "id": "int",
      "title": "string",
      "course_category_id": "int",
      "course_category": {
        "id": "int",
        "name": "string"
      }
    }
  }
}

Enroll Course

  • Method : POST
  • URL : /user-courses
  • Token : token / adminToken
  • Request body :
{
  "user_id": 3,
  "course_id": 8
}
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "user_id": "int",
    "User": {
      "id": "int",
      "email": "string",
      "name": "string"
    },
    "course_id": "int",
    "Course": {
      "id": "int",
      "title": "string",
      "course_category_id": "int",
      "course_category": {
        "id": "int",
        "name": "string"
      }
    }
  }
}

UnEnroll Course

  • Method : DELETE
  • URL : /user-courses
  • Token : token / adminToken
  • Request body :
{
  "user_id": 3,
  "course_id": 8
}
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "user_id": "int",
    "User": {
      "id": "int",
      "email": "string",
      "name": "string"
    },
    "course_id": "int",
    "Course": {
      "id": "int",
      "title": "string",
      "course_category_id": "int",
      "course_category": {
        "id": "int",
        "name": "string"
      }
    }
  }
}

Admin

Get All Admin

  • Method : GET
  • URL : /admins
  • Token : adminToken
  • Request body : -
  • Response body :
{
  "message": "string",
  "data": [
    {
      "id": "int",
      "email": "string",
      "name": "string"
    }
  ]
}

Get Admin By ID

  • Method : GET
  • URL : /admins/<id:int>
  • Token : adminToken
  • Request body : -
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "email": "string",
    "name": "string"
  }
}

Add Admin

  • Method : POST
  • URL : /admins
  • Token : adminToken
  • Request body :
{
  "name": "string",
  "email": "string",
  "password": "string"
}
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "email": "string",
    "name": "string"
  }
}

Update Admin

  • Method : PUT
  • URL : /admins/<id:int>
  • Token : adminToken
  • Request body :
{
  "name": "string",
  "email": "string",
  "password": "string"
}
  • Response body :
{
  "message": "string",
  "data": {
    "id": "int",
    "email": "string",
    "name": "string"
  }
}

DELETE Admin

  • Method : DELETE

  • URL : /admins/<id:int>

  • Token : adminToken

  • Request body : -

  • Response body :

{
  "message": "Admin id `id` was deleted",
  "data": {}
}

Contributor

  • Yulyano Thomas Djaya - 56419764

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages