Advertisement
Guest User

aSD

a guest
Dec 7th, 2019
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.08 KB | None | 0 0
  1. JS Applications Exam - The Trekking Zone SPA
  2. You are assigned to implement a Web application (SPA) using HTML5, JavaScript, AJAX, REST and JSON with cloud-based backend (Kinvey). Using libraries like jQuery, Handlebars and Sammy is allowed but is not obligatory. The app keeps users and treks. Guests should be able to register and login. Logged-in users should be able to view all treks, create treks, like treks, see details about a trek and logout. Logged-in users should also be able to edit or delete the treks they have created. There should also be a section where users can see only the treks they have created.
  3. 1. Create a Kinvey REST Service
  4. Register at Kinvey.com and create application to keep your data in the cloud.
  5. Create a collection called treks. Each trek has a location, date, description, organizer and likes (starting from 0).
  6.  
  7.  
  8. In order to be able to keep track of the likes of the trek, you need to give all users permission to edit this collection. So, go to the properties of the collection.
  9.  
  10. Then go to the permissions and edit them to look like this:
  11.  
  12. 2. Test the Kinvey REST Services
  13. Using Postman or other HTTP client tool (you can use Kinvey's built-in API Console), test the REST service end points:
  14. User Registration (Sign Up)
  15. POST https://baas.kinvey.com/user/app_id/
  16.  
  17. Request headers Authorization: Basic base64(app_id:app_secret)
  18. Content-Type: application/json
  19. Request body {
  20. "username": "testuser",
  21. "password": "testuserpass890"
  22. }
  23. Response
  24. 201 Created {
  25. "_id": "59930c78a743e20c7d3fca77",
  26. "username": "testuser",
  27. "password": "testuserpass890"
  28. }
  29. Error response
  30. 409 Conflict { "error": "UserAlreadyExists", "description": "This username is already taken. Please retry your request with a different username", "debug": "" }
  31. Error response
  32. 401 Unauthorized { "error": "InvalidCredentials", "description": "Invalid credentials. Please retry your request with correct credentials", "debug": "" }
  33.  
  34. The request needs "Basic" authentication. Use the Kinvey App Key and App Secret as credentials.
  35.  
  36. User Login
  37. POST https://baas.kinvey.com/user/app_id/login
  38.  
  39. Request headers Authorization: Basic base64(app_id:app_secret)
  40. Content-Type: application/json
  41. Request body {
  42. "username": "testuser",
  43. "password": "testuserpass890"
  44. }
  45. Response
  46. 200 OK {
  47. "_id": "59930c78a743e20c7d3fca77",
  48. "username": "testuser"
  49. "_kmd": {
  50. "authtoken":"8e6471bc-3712-4cfb-b92e-50e62a0c80….Duj5fHdM /7XHIe6KdY="
  51. },
  52. }
  53. Error response
  54. 401 Unauthorized { "error": "InvalidCredentials", "description": "Invalid credentials. Please retry your request with correct credentials", "debug": "" }
  55. Successful login returns an authtoken which is later used to authenticate the CRUD operations.
  56. User Logout
  57. POST https://baas.kinvey.com/user/app_id/_logout
  58.  
  59. Request headers Authorization: Kinvey authtoken
  60. Response
  61. 204 No Content
  62. Error response
  63. 401 Unauthorized { "error": "InvalidCredentials", "description": "Invalid credentials. Please retry your request with correct credentials", "debug": "" }
  64. To logout, you need to provide the authtoken given by login/register as "Kinvey" authorization header.
  65. List All Treks
  66. GET https://baas.kinvey.com/appdata/app_id/treks
  67.  
  68. Request headers Authorization: Kinvey authtoken
  69. Response
  70. 200 OK [{
  71. "name":"Everest Base Camp",
  72. "dateTime":"28.08.2020",
  73. "description":"Experience beautiful...",
  74. "imageURL":"https://....",
  75. "likes":"0",
  76. "organizer": "peter.georgiev"
  77. "_acl":
  78. {
  79. "creator":"5bfd4674682ae23931b4f91c"
  80. },
  81. "_kmd":
  82. {
  83. "lmt":"2018-11-28T15:25:24.521Z",
  84. "ect":"2018-11-28T14:55:00.958Z"
  85. }
  86. }, …]
  87. Error response
  88. 401 Unauthorized { "error": "InvalidCredentials", "description": "Invalid credentials. Please retry your request with correct credentials", "debug": "" }
  89.  
  90. Create Trek
  91. POST https://baas.kinvey.com/appdata/app_id/treks
  92.  
  93. Request headers Authorization: Kinvey authtoken
  94. Content-Type: application/json
  95. Request body {
  96. "name": "Everest Base Camp",
  97. "dateTime": "28.08.2020",
  98. "description": "Experience beautiful...",
  99. "imageURL": "https://...",
  100. "likes":0,
  101. "organizer": "peter.georgiev"
  102. }
  103. Response
  104. 201 Created {
  105. "name": "Everest Base Camp",
  106. "dateTime": "28.08.2020",
  107. "description": "Experience beautiful...",
  108. "imageURL": "https://...",
  109. "likes":0,
  110. "organizer": "peter.georgiev"
  111. "_acl": {
  112. "creator": "5bfd4674682ae23931b4f91c"
  113. },
  114. "_kmd": {
  115. "lmt": "2018-11-28T15:39:58.801Z",
  116. "ect": "2018-11-28T15:39:58.801Z"
  117. },
  118. "_id": "5bfeb6ce682ae23931bf7d26"
  119. }
  120. Error response
  121. 401 Unauthorized { "error": "InvalidCredentials", "description": "Invalid credentials. Please retry your request with correct credentials", "debug": "" }
  122.  
  123. Edit Trek
  124. PUT https://baas.kinvey.com/appdata/app_id/treks/trek_id
  125.  
  126. Request headers Authorization: Kinvey authtoken
  127. Content-Type: application/json
  128. Request body {
  129. "name": "Everest Base Camp",
  130. "dateTime": "28.08.2020",
  131. "description": "Experience beautiful...",
  132. "imageURL": "https://...",
  133. "likes":0,
  134. "organizer": "peter.georgiev"
  135. }
  136. Response
  137. 200 Ok {
  138. "_id": "59931398996ab5127d2a84d1",
  139. "name": "Everest Base Camp",
  140. "dateTime": "28.08.2020",
  141. "description": "Experience beautiful...",
  142. "imageURL": "https://...",
  143. "likes":0,
  144. "organizer": "peter.georgiev"
  145. }
  146. Error response
  147. 401 Unauthorized { "error": "InvalidCredentials", "description": "Invalid credentials. Please retry your request with correct credentials", "debug": "" }
  148.  
  149. Delete Trek
  150. DELETE https://baas.kinvey.com/appdata/app_id/treks/trek_id
  151.  
  152. Request headers Authorization: Kinvey authtoken
  153. Response
  154. 200 OK {
  155. "count": 1
  156. }
  157. Error response
  158. 404 Not Found { "error": "EntityNotFound", "description": "This entity not found in the collection", "debug": "" }
  159. Error response
  160. 401 Unauthorized { "error": "InvalidCredentials", "description": "Invalid credentials. Please retry your request with correct credentials", "debug": "" }
  161.  
  162. Like Trek
  163. PUT https://baas.kinvey.com/appdata/app_id/treks/trek_id
  164.  
  165. Request headers Authorization: Kinvey authtoken
  166. Content-Type: application/json
  167. Request body {
  168. "name": "Everest Base Camp",
  169. "dateTime": "28.08.2020",
  170. "description": "Experience beautiful...",
  171. "imageURL": "https://...",
  172. "likes":0,
  173. "organizer": "peter.georgiev"
  174. }
  175. Response
  176. 200 Ok {
  177. "name": "Everest Base Camp",
  178. "dateTime": "28.08.2020",
  179. "description": "Experience beautiful...",
  180. "imageURL": "https://...",
  181. "likes":0,
  182. "organizer": "peter.georgiev"
  183. "_id": "5bfeb6ce682ae23931bf7d26",
  184. "_acl": {
  185. "creator": "5bfd4674682ae23931b4f91c"
  186. },
  187. "_kmd": {
  188. "lmt": "2018-11-28T15:45:13.760Z",
  189. "ect": "2018-11-28T15:39:58.801Z"
  190. }
  191. }
  192. Error response
  193. 401 Unauthorized { "error": "InvalidCredentials", "description": "Invalid credentials. Please retry your request with correct credentials", "debug": "" }
  194.  
  195. My Treks
  196. GET https://baas.kinvey.com/appdata/app_id/treks?query={"_acl.creator":"${user_id}"}
  197.  
  198. Request headers Authorization: Kinvey authtoken
  199. Response
  200. 200 OK [{
  201. "name": "Everest Base Camp",
  202. "dateTime": "28.08.2020",
  203. "description": "Experience beautiful...",
  204. "imageURL": "https://...",
  205. "likes":0,
  206. "organizer": "peter.georgiev"
  207. "_acl":
  208. {
  209. "creator":"5bfd4674682ae23931b4f91c"
  210. },
  211. "_kmd":
  212. {
  213. "lmt":"2018-11-28T15:25:24.521Z",
  214. "ect":"2018-11-28T14:55:00.958Z"
  215. }
  216. }, …]
  217. Error response
  218. 401 Unauthorized { "error": "InvalidCredentials", "description": "Invalid credentials. Please retry your request with correct credentials", "debug": "" }
  219.  
  220. 3. The Trekking Zone - HTML and CSS
  221. You have been given the web design of the application as HTML + CSS files.
  222. • Initially all views and forms are shown by the HTML. Your application may hide/show elements by CSS (display: none) or delete/reattach from and to the DOM all unneeded elements, or just display the views it needs to display.
  223. • You may render the views/forms/components with jQuery or Handlebars.
  224. Important: Don’t change the elements’ class names and ids. Don’t rename form fields/link names/ids. You are allowed to add data attributes to any elements. You may modify href attributes of links and add action/method attributes to forms, to allow the use of a routing library.
  225. 4. The Trekking Zone - Client-Side Web Application
  226. Design and implement a client-side front-end app (SPA) for managing treks. Implement the functionality described below.
  227. Navigation Bar (5 pts)
  228. Navigation links should correctly change the current page (view).
  229. • Clicking on the links in the NavBar should display the view behind the link (views are represented as sections in the HTML code).
  230. • Your application may hide/show elements by CSS (display: none) or delete/reattach from and to the DOM all unneeded elements, or just display the views it needs to display.
  231. • The Logged-in user navbar should contain the following elements: Icon (icon.jpg) which is a link to the Home page, [Request Trek], the user caption ("{username}"), [Logout].
  232. o The user caption should be a link that navigates to the currently logged in user’s profile.
  233.  
  234. • The guest users navbar should contain the following elements: : Icon (icon.jpg) which is a link to the Home page and [Login].
  235.  
  236.  
  237.  
  238. Home Page (Guest) (5 pts)
  239. The initial page (view) should display the guest navigation bar ("Home" (icon) and "Login") + Guest Home Page + Footer.
  240.  
  241.  
  242. Register User (5 pts)
  243. By given username and password, the app should register a new user in the system.
  244. • (Bonus) The following validations should be made:
  245. o The username should be at least 3 characters long
  246. o The password should be at least 6 characters long
  247. o The repeat password should be equal to the password
  248. • (Bonus) After a successful registration, a notification message "Successfully registered user." should be displayed and the app should redirect to the home page with the right navbar.
  249. • In case of error (eg. invalid username/password), an appropriate error message should be displayed, and the user should be able to try to register again.
  250. • Keep the user local data in the browser's local storage.
  251. Register once and create/like awesome treks!
  252.  
  253.  
  254.  
  255.  
  256. Login User (5 pts)
  257. By given username and password, the app should login an existing user.
  258. • (Bonus) After a successful login, a notification message "Successfully logged user." should be shown and the user home screen should be displayed.
  259. • In case of error, an appropriate error message should be displayed and the user should be able to fill in the login form again.
  260. • Keep the user local data in the browser's local storage.
  261. • Clear all input fields after a successful login.
  262. You are one step away from awesome treks!
  263.  
  264.  
  265.  
  266. Logout (5 pts)
  267. Successfully logged in users should be able to logout from the app.
  268. • (Bonus) After a successful logout, a notification message "Logout successful." should be displayed and the anonymous screen should be shown
  269. • The "logout" REST service at the back-end must be called at logout
  270. • All local information in the browser (user local data) about the current user should be deleted
  271.  
  272.  
  273.  
  274.  
  275. Home Page (30 pts)
  276. Successfully logged-in users should be welcomed by the Home page. They should be able to see all created (organized) treks.
  277. If there are NO such treks, the following view should be displayed:
  278.  
  279.  
  280. [Create the first trek?] button should refer to the request trek form
  281. Request Trek (10 pts)
  282. Logged-in users should be able to Create (organize) treks.
  283. Clicking the [Request Trek] link in the NavBar should display the Request Trek page.
  284. • (Bonus) The form should contain the following validations:
  285. o The trek name should be at least 6 characters long.
  286. o The description should be at least 10 characters long.
  287. o After a successful trek creation, a notification message "Trek created successfully." should be displayed and the Home page should be shown.
  288. • By default, every newly created trek must have additional information:
  289. o Organizer: string representing the current trek creator;
  290. o Likes: number starting from 0;
  291. • The inputs fields in the form should be cleared.
  292. • The newly organizer trek should be stored in the Kinvey collection "treks".
  293.  
  294.  
  295.  
  296. Details Trek (10 pts)
  297. Logged-in users should be able to view details about treks.
  298. Clicking the [More] link in of a particular trek should display the Trek Details page.
  299. • If the currently logged-in user is the organizer of the trek, the [Edit] and [Close] buttons should be set to visible, otherwise there should be only 1 button [Like].
  300.  
  301.  
  302. Edit Trek (10 pts)
  303. Logged-in users should be able to edit their own treks.
  304. Clicking the [Edit the trek] link of a particular trek on the Trek Details page should display the Edit Trek page:
  305.  
  306. • (Bonus) After a successful edit, a notification message "Trek edited successfully." should be displayed, and the user should be redirected to the Home page.
  307.  
  308. Like Trek (10 pts)
  309. Logged-in users should be able to Like treks, organized by other users.
  310. NOTE: A user should NOT be able to like a trek, organized by himself.
  311. Clicking the [Like the trek] link of an trek (on the Trek Details page) should increase the property for the likes the corresponding trek.
  312. Users can like treks multiple times.
  313. • (Bonus) After successfully liking a trek, a notification message "You liked the trek successfully." should be displayed.
  314.  
  315. Delete Trek (5 pts)
  316. Logged-in users should be able to delete their treks.
  317. Clicking the [Close the trek] link of an trek (on the Trek Details page) should delete the trek.
  318. • (Bonus) After successful trek delete a notification message "You closed the trek successfully." should be displayed
  319. • After successful trek delete you should show the Home page
  320.  
  321. (BONUS) Notifications (5 pts)
  322. The application should notify the users about the result of their actions.
  323. • In case of a successful action, a notification message (green) should be shown, which disappears automatically after 5 seconds or manually when the user clicks it.
  324.  
  325. • In case of error, an error notification message (red) should be shown, which disappears on user click.
  326.  
  327. • During the AJAX calls a loading notification message (blue) should be shown. It should disappear automatically as soon as the AJAX call is completed.
  328.  
  329. • NOTE: You get all the points if all the notifications have the exact content as described in each section above.
  330.  
  331. (BONUS) User Profile (5 pts)
  332. Logged-in users should be able to view their profile.
  333. Clicking the user caption ({USERNAME}) link on the navigation bar should display the
  334. User Profile page:
  335. • Each user profile should display user info - profile picture, username and organization information
  336. o "Wished {count} treks =)"
  337. o The names of all treks which the user has organized.
  338.  
  339. • In case of no treks, display "No treks".
  340.  
  341. (BONUS) Sorting: (5 pts)
  342. The treks in the home page (for registered users), should be sorted in descending order by likes.
  343. (BONUS) Validations: (5 pts)
  344. 5. Submitting Your Solution
  345. Exclude the node_modules folder and ZIP your project. Upload the archive to Judge system.
  346. https://judge.softuni.bg/Contests/Compete/Index/1645#0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement