/Treasure-Hunt

Treasure Hunt

Primary LanguagePHP

Treasure-Hunt

Treasure Hunt Game for orientation day.

Technologies

Let's talk about the coarse architecture of this mono repo:

  • PHP: We use PHP to power our servers, and Vue to power our frontend.
  • Mysql : Data storage
  • Vue : Frontend
  • Laravel : Backend framework

Folder structure

TodoList
├── client     # Frontend
└── backend    # Backend ( laravel )

Backend

Database structure

users

Column Name Data Type Propeties Comment
id BIGINT PK AI
name VARCHAR
username VARCHAR UNIQUE Remove space and lowercase of group name Ex: Hello World -> helloworld
password VARCHAR
api_token VARCHAR(100)
remember_token VARCHAR(100)
created_at TIMESTAMP
updated_at TIMESTAMP

groups

Column Name Data Type Propeties Comment
id BIGINT PK AI
user_id BIGINT foreign key of id of users
group_name VARCHAR UNIQUE
created_at TIMESTAMP
updated_at TIMESTAMP

group_members

Column Name Data Type Propeties Comment
id BIGINT PK AI
group_id BIGINT foreign key of id of groups
name VARCHAR Ex: 26377
student_id VARCHAR(5) UNIQUE
created_at TIMESTAMP
updated_at TIMESTAMP

group_score

Column Name Data Type Propeties Comment
id BIGINT PK AI
group_id BIGINT foreign key of id of groups
score INTEGER
created_at TIMESTAMP
updated_at TIMESTAMP

group_questions

Column Name Data Type Propeties Comment
id BIGINT PK AI
group_id BIGINT foreign key of id of groups
question_id BIGINT foreign key of id of questions
answer VARCHAR
score INTEGER
created_at TIMESTAMP
updated_at TIMESTAMP

questions

Column Name Data Type Propeties Comment
id BIGINT PK AI
content VARCHAR
type TINYINTEGER
answer INTEGER
score INTEGER
created_at TIMESTAMP
updated_at TIMESTAMP

question_location

Column Name Data Type Propeties Comment
id BIGINT PK AI
question_id BIGINT PK AI foreign key of id of questions
place_id BIGINT foreign key of id of groups
created_at TIMESTAMP
updated_at TIMESTAMP

places

Column Name Data Type Propeties Comment
id BIGINT PK AI
name VARCHAR
created_at TIMESTAMP
updated_at TIMESTAMP

End-point API

Authorization

Login

POST /api/login

Request data

{
  username: "[string]",
  password: "[string]"
}

Response data

Code : 200

{
  result: "OK"
  data: {
    api_token: "[string]"
  }
}

Code : 403

{
  result: "FAIL"
  data: {
    error_message: "[string]"
  }
}
Register

POST /api/register

Request data

{
  group_name: "[string]",
  group_members: [
    { name: "[string]", student_id: "[integer]" },
    { name: "[string]", student_id: "[integer]" },
    { name: "[string]", student_id: "[integer]" },
    { name: "[string]", student_id: "[integer]" }
  ]
}

Response data

Code : 200

{
  result: "OK"
  data: {
    username: "[string]",
    password: "[string]",
    token: "[string]"
  }
}

Code : 403

{
  result: "FAIL"
  data: {
    error_message: "[string]"
  }
}
User

GET /api/user

Response data

Code : 200

{
  result: "OK",
  data: {
    group_name: "[string]",
    username: "[string]",
    ranking: "[string]",
    score: "[integer]",
  }
}

Code : 403

{
  result: "FAIL"
  data: {
    error_message: "user haven't login"
  }
}
Logout

GET /api/logout

Response data

Code : 200

{
  result: "OK"
}

Code : 403

{
  result: "FAIL"
  data: {
    error_message: "user haven't login"
  }
}

Questions

Get question

GET /api/game/questions

Response data

Code : 200

{
  result: "OK"
  data: [
    { id: "[integer]", content: "[string]", score: "[integer]"},
    { id: "[integer]", content: "[string]", score: "[integer]"},
    { id: "[integer]", content: "[string]", score: "[integer]"},
    { id: "[integer]", content: "[string]", score: "[integer]"}
  ]
}

Answer question

POST /api/game/question/answer

Request data

{
  id: "[integer]",
  answer: "[string]"
}

Response data

Code : 200

{
  result: "OK"
  data: {
    correct: "[boolean]"
  }
}

Scoreboard

Get scoreboard

GET /api/game/scoreboard

Response data

Code : 200

{
  result: "OK"
  data: [
    { group_name: "[string]", score: "[string]" },
    { group_name: "[string]", score: "[string]" },
    ...
  ]
}
Frontend
frontend/src
├── assets
├── layouts   
├── pages
├── components
├── router    # Vue Router
├── main.js
└── App.vue   # Frontend vue entry

About the server

We have not developed the server. Server is not avaliable.