Giter Club home page Giter Club logo

exercise-course-api's Introduction

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": "[email protected]",
  "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

exercise-course-api's People

Watchers

Yulyano Thomas Djaya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.