GithubHelp home page GithubHelp logo

hci-database's Introduction

HCI

apidoc for HCI database api

API

Server IP & Port 52.37.98.127:3000/v1/

ดู ตัวอย่างการใช้งาน api เพื่อต่อกับ db คลิก

วิธี deploy frontend ที่เป็น static file ขึ้น github page อยู่ข้างล่าง

ทำความเข้าใจเรื่องรูปแบบข้อมูลก่อน

  • ข้อมูลที่จัดเก็บจะเป็น Object 1 ก้อนเท่าัน้น
  • Properties ของ Object ที่ว่าจะมีกี่ตัวก็ได้ จะชื่ออะไรก็ได้ตั้งเอาเองได้
  • ข้างใน Properties จะเก็บข้อมูลเป็น Type อะไรก็ได้ arrya string int ...
  • ข้างใน Properties จะเก็บข้อมูลเท่าไรก็ได้ไม่มีจำกัด (จนกว่าจะ hdd เต็ม)

ตัวอย่างการเก็บข้อมูล ที่แนะนำ

{
	"5610546231": {
		"name": "Chin"
		"course": [courseID:int]
	},
	"5610546232": {
		"name": "ChinBi"
		"course": [courseID:int]
	},
	. 	.
	. 	.
	. 	.
}

หรือ (ไม่แนะนำเพราะใช้ยาก)

{
	"web_information": {
		"name": "HCI"
		"numOfStudent": int
	},
	"student_list": [
		{
			"StudentID": "561054631"
			"name": "Chin"
			. 	.
			. 	.
		},
		{
			"StudentID": "561054632"
			"name": "ChinBi"
			. 	.
			. 	.
		},
	],
	. 	.
	. 	.
	. 	.
}

ห้ามเก็บแบบนี้

[		<< ห้ามใช้ Array นะจ๊ะ ชั้นแรกต้องเป็น object เท่านั้น
	{....},
	{....}
]

แบบนี้ก็ไม่ได้นะ

{
	[		<< ใน object ต้องมี properties ก่อน จะยัด array ลงไปเลยไม่ได้
		{},
		{}
	]
}

APIdoc

1. Show All Data

ตอบกลับข้อมูลทั้งหมดของ Student ID นั้นๆในฐานข้อมูล

URL /:studentId?pin=:pin

Method GET

URL Params

  • Required
    • studentId : รหัสนิสิตของตัวเอง
    • pin : pin ตัวเลข 4 หลักที่เคยกรอกใน google form

Data Params

None

Success Response

  • Code 200

    Content: {userData}

Error Response

  • Code 404

    Student ID and PIN are incorrect.

Sample Code

$.ajax({
	url: "/5610546231?pin=1234",
    type : "GET",
    success : function(r) {
      console.log(r);
    }
  });

2. Update Data or Insert New Data

  • ในกรณีที่มี properties ชื่อนั้นๆอยู่แล้ว จะ อัพเดท properties ใน object
  • ในกรณีที่ยังไม่มี properties ชื่อนั้นใน object จะสร้าง properties ใหม่ให้ทันที

URL /:studentId?pin=:pin

Method POST

URL Params

  • Required
    • studentId : รหัสนิสิตของตัวเอง
    • pin : pin ตัวเลข 4 หลักที่เคยกรอกใน google form

Data Params

ข้อมูลที่ต้องส่งไปพร้อมกับการ POST

{
    "56105462xx": {
        . . .
    },
    "56105462xx": {
		. . .
	}
}

Success Response

  • Code 200

    Content: {userData}

Error Response

  • Code 404

    Student ID and PIN are incorrect.

Sample Code

$.ajax({
	url: "/5610546231?pin=1234",
    type : "POST",
    data : {ข้อมูลที่ต้องการจะบันทึกลง database},  	<< ห้ามส่งเป็น Array
    success : function(r) {
      console.log(r);
    }
  });

3. Get Properties Data

ตอบกลับค่าที่อยู่ใน property นั้นๆทั้งหมด

URL /:studentId/:property?pin=:pin

Method GET

URL Params

  • Required
    • studentId : รหัสนิสิตของตัวเอง
    • pin : pin ตัวเลข 4 หลักที่เคยกรอกใน google form
    • property : ชื่อ property ที่ต้องการ get ค่า

Data Params

None

Success Response

  • Code 200

URL /5610546231/5610546232?pin=1234

{
	stdId: 5610546232,
	name: String,
	courses: [courseID:Int]
}

Error Response

  • Code 404

    Student ID and PIN are incorrect.

Sample Code

$.ajax({
	url: "/5610546231/5610546232?pin=1234",
    type : "GET",
    success : function(r) {
      console.log(r);
    }
  });

4. Delete Properties

ลบ property

URL /:studentId/:property?pin=:pin

Method DELETE

URL Params

  • Required
    • studentId : รหัสนิสิตของตัวเอง
    • pin : pin ตัวเลข 4 หลักที่เคยกรอกใน google form
    • property : ชื่อ property ที่ต้องการลบ

Data Params

None

Success Response

  • Code 200

URL /5610546231/5610546232?pin=1234

{
	message: 'Property [5610546232] is deleted'
}

Error Response

  • Code 404

    Student ID and PIN are incorrect.

  • Code 401

    Property not found.

Sample Code

$.ajax({
	url: "/5610546231/5610546232?pin=1234",
    type : "DELETE",
    success : function(r) {
      console.log(r);
    }
  });

วิธี Deploy Frontend (github page)

ไม่จำเป็นต้องใช้ Angular React ก็ได้นะ ใช้แค่ jQuery หรือ javascript ล้วนๆก็ทำได้ js ไม่ต้อง compile

อ่านวิธี คลิก

ตัวอย่าง repository & url

hci-database's People

Contributors

0xchimz avatar

Watchers

 avatar  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.