Skip to content

Midterm Interview Exam - Case 2: Employee Clock-In

TL;DR: Read the Specifications and start working on the Programming Tasks. To understand the background, read the problem description from the beginning.

Some workplaces use an attendance monitoring system to track the punctuality and presence of their employees. One of the core features is keeping track of employee attendance during workdays. The company would like to know when they start working in a day.

For the interview exam, the scope of the requirements is simplified. The project only requires a single Web service that lets the user clock in their presence by sending an HTTP POST message and store the attendance. In addition, there is no authentication required in the Web service.

For example, suppose that an employee would like to clock in their presence. He or she can use the terminal and use curl to send an HTTP POST to the Web service:

1
2
3
4
5
$ curl -X POST \
    -d 'date=2021-04-01' \
    -d 'time=14:20' \
    -d 'name=Employee A' \
    https://example.com/clock-in

Or if the employee prefer to use Python script instead of curl:

1
2
3
4
# Note: Using `requests` module. Install: pip install requests
import requests
response = requests.post('https://example.com/clock-in',
    data={'date': '2021-04-01', 'time': '14:20', 'name': 'Employee A'})

Both script examples send a form data containing three fields (date, time, name) to the /clock-in endpoint served at https://example.com. You are allowed to deploy and run the Web service locally, i.e., on localhost.

Specifications

Estimated reading time: 5 minutes

Develop a Web service with a single endpoint named /clock-in that handles an HTTP POST message containing form data with the following fields:

  • date : Date of the clock-in, written in yyyy-mm-dd format. E.g., 2021-03-20
  • time : Clock-in time, written in hh:mm format. E.g, 16:20
  • name : Employee name

If all fields are present and contain valid values, store them as an object in data storage. Then, return an HTTP 200 response if the clock-in time is successfully stored. Otherwise, implement basic error handling. For example, return an HTTP 400 response if some of the fields are missing.

Programming Tasks

Estimated working time: 10 - 15 minutes

Turn on your camera and share your desktop screen. Ensure that the proctor (in most cases, the lecturer and sometimes the TAs) can monitor your activities during the interview exam. Imagine you are conducting a remote pair programming where the partner needs to observe your work.

Do the tasks in the Mandatory subsection. If there is some time left after you completed the Mandatory subsection, you can do the tasks in the Optional subsection.

Mandatory

We recommend you to do the tasks according to the given order. The tasks are sorted based on the required effort and logical order to complete them.

  1. Create a new project under your own GitLab subgroup in KKI 2021 group.
  2. Initialise the Git repository to track your progress.

    You can commit and push the initial commit that only contains the starter code at this point.

  3. Prepare the starter code for building the project. The starter code may be written in Java (Spring Boot) or any programming language/framework that you are familiar with.

    If you choose to use another programming language/framework, make sure it has support for developing a Web service, writing unit test and can be deployed on Heroku.

  4. Design a test case that verifies only one of the following: (1) Checks whether valid clock-in data is successfully stored in the data storage; or (2) Ensures a valid HTTP POST request to /clock-in endpoint will return a HTTP 200 response; or (3) Ensures an invalid HTTP request to /clock-in endpoint will return a HTTP 400 response.
  5. Work on the problem set. Write the code to implement the required feature. Do not forget to commit and push your work-in-progress frequently.
  6. Write a test program using the testing framework provided by the programming language/framework and implements the test case you have designed in the previous problem.

Optional

Feel free to do the tasks in any order. It is alright if some of the tasks are not completed. The discussion session may ask you to complete the unfinished tasks.

  • Implement a basic authentication mechanism by checking whether the HTTP request contains a header named X-AdvProg-Auth with the value 2021. If the request is valid, then proceed to store the new clock-in data. Otherwise, reject the input and return a HTTP 403 response.
  • Design and implement the test case for verifying the basic authentication mechanism.
  • Create a new Heroku app and deploy the local version of the project to Heroku using Heroku CLI.
  • Create a new project on SonarQube AdvProg and run SonarScanner that sends the scan result to SonarQube AdvProg.
  • Set up a GitLab CI/CD pipeline that automatically runs the test suite each time a new commit has been pushed to master branch.

Discussion

Estimated discussion time: 5 - 10 minutes

The list of possible topics during the discussion is as follows:

  • Development workflow (Git, IDE)

    Examples: How do you use Git when working on your course work?; How to merge a branch into another branch?; How do you resolve a merge conflict?

  • Writing and running test

    Examples: How do you design the test cases to test a piece of code?; How to measure line coverage?

  • Concurrency

    Examples: How to prevent a race condition in implementation level or architectural level?; Describe one example of serialisation technique employed in a programming language/framework of your choice

  • Deployment workflow (GitLab CI/CD, Heroku)

    Examples: Describe one or more elements commonly found in a .gitlab-ci.yml file; Show how to deploy a codebase to Heroku using Heroku CLI

  • Code quality (SonarQube, SonarScanner)

    Examples: Mention some code smells that you have encountered throughout this course; What is the responsibility of SonarQube and SonarScanner?

It is also possible that the proctor will ask questions that are not listed above.

Hints

  • As mentioned in the requirements, you do not have to set up a database. The most straightforward approach is to use the collection library provided by the standard library of programming language/framework of your choice.
  • If you are using Spring Boot, you only need Spring Web in the project dependencies. Do not make the project more complex by adding other dependencies such as Spring Data REST or database connection drivers.
  • You already have a collection of code examples that you can adapt to solve this problem. Hence, we do not recommend you to search for tutorials or code snippets through a search engine. You may do so, but we think it is better to spend your time in coding and reuse the available resources.

Last update: 2022-03-24 15:13:08
Created: 2022-03-24 15:13:08
Back to top