Skip to content

Commit 4243a40

Browse files
author
Ferenc Hammerl
committed
Update readme
1 parent 93bfc1c commit 4243a40

File tree

2 files changed

+68
-11
lines changed

2 files changed

+68
-11
lines changed

README.md

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,51 @@
11
# Backend Engineer hiring challenge - Ferenc Hammerl
2+
3+
## How do I use it?
4+
If you can't wait to try this api, you're at the right place.
5+
Run:
6+
```
7+
docker-compose up
8+
```
9+
in the polls folder, wait for Docker and Maven to do their thing, then fire away.
10+
### 1. List all polls created by a user
11+
`http://localhost:8080/api/v1/polls/createdBy?userId=4`
12+
13+
_Challenge: make it return a 500 (one answer in the controller)_
14+
### 2. Search polls by its title
15+
`http://localhost:8080/api/v1/polls/search`
16+
17+
RequestBody:
18+
```
19+
{
20+
"title":"谁是最坏蛋奇迹超级英雄?"
21+
}
22+
```
23+
### 3. List all polls created after a certain date
24+
`http://localhost:8080/api/v1/polls/listFrom?fromDate=2019-06-01` - all 3 polls
25+
`http://localhost:8080/api/v1/polls/listFrom?fromDate=2020-05-15` - only 2
26+
`http://localhost:8080/api/v1/polls/listFrom?fromDate=2020-06-15` - none
27+
***
228
## Getting started
29+
330
### Discovery
431
I started by registering an account on Doodle and playing around a bit with my dashboard. Creating polls, participating in them as different users, checking out the request to `https://api.doodle.com/v2.2/users/me/polls` and its response.
32+
533
### Analysys
6-
After analyzing polls.json, I came up with a rough relational DB schema and some ideas about the tech stack.
34+
After analyzing polls.json, I came up with the two tables I need to create to complete the tasks.
35+
36+
### User stories
37+
38+
39+
### 1. List all polls created by a user
40+
Create an endpoint that takes an integer `userId` param and returns with an empty list or a list of polls that the user created
41+
42+
### 2. Search polls by its title
43+
Create an endpoint that takes a string `title` param and returns with an empty list or a list of polls with the exact title
44+
45+
### 3. List all polls created after a certain date
46+
Create an endpoint that takes an ISO date `date` in param and returns with an empty list or a list of polls with `initiated` post the date param.
47+
As a timestamp, the date 2020-01-01 is 2020-01-01 00:00, so an initiated timestamp of 2020-01-01 01:00 is 'after' 2020-01-01
48+
749
## Technology choices
850
### Visual Studio Code + Remote Development / Dev Containers
951
With VS Code Remote Development, you can use a Docker container as a full-featured development environment. VS Code is going to work **as if it was running locally on the Linux container** I chose to develop on. Other tools offer similar solutions of course (mounting the workspace, hot-reload), but I find the extreme approach of hooking the entire "IDE" into a container quite inspiring.
@@ -18,12 +60,24 @@ Nothing really comes close.
1860

1961
### PostgreSQL
2062
Easy integration with Java, UUID as primary key natively, can index JSON objects.
63+
***
64+
## If I had more time...
65+
I would
66+
- Test more!
67+
- *Observability*: request tracing and logging for both the DB and the service
68+
- Performance:
69+
- Add an index for the `title` and `initiated` column (if we want it them be really fast)
70+
- Consider replacing Tomcat with Undertow (slightly better throughput afaik)
71+
- Based on polls.json, the database has a lot more tables than what I modeled. We could consider preloading some sort of cache storage (probably NoSQL) as the poll is created
72+
- Read heavy system calls for read replicas
73+
- Refactorings:
74+
- Find a better home for `SearchQuery.java`
75+
- Add some sort of linting / auto formatter
76+
- If only I could find some automapping from Postres snake_case to camelCase...
77+
- Nicer `docker-compose`: Work on making it a bit more configurable production ready, like using the devcontainer image for building and a jre image for running
78+
79+
## What I'd do differently
2180

22-
## User stories
23-
### 1. List all polls created by a user
24-
Create an endpoint that takes an integer `userId` param and returns with an empty list or a list of polls that the user created
25-
### 2. Search polls by its title
26-
Create an endpoint that takes a string `title` param and returns with an empty list or a list of polls with the exact title
27-
### 3. List all polls created after a certain date
28-
Create an endpoint that takes an ISO date `date` in param and returns with an empty list or a list of polls with `initiated` post the date param.
29-
As a timestamp, the date 2020-01-01 is 2020-01-01 00:00, so an initiated timestamp of 2020-01-01 01:00 is 'after' 2020-01-01
81+
- Consider dropping the ORM in favour of DTOs: While I had fun with the ORM, some queries into POJOs would have done the job much faster.
82+
- Have much less trouble using dev containers (First time using them for Java!)
83+
- Not forget about adding the user_id to the

src/main/java/com/fhammerl/polls/controllers/PollsController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public List<Poll> list() {
2525
}
2626

2727

28-
// Test: http://localhost:8080/api/v1/polls/createdBy?userId=4
28+
// To Test: http://localhost:8080/api/v1/polls/createdBy?userId=4
29+
// To get a 500: http://localhost:8080/api/v1/polls/createdBy?userId=
2930
@GetMapping
3031
@RequestMapping("createdBy")
3132
public List<Poll> createdBy(int userId) {
@@ -40,7 +41,9 @@ public List<Poll> search(@RequestBody SearchQuery query) {
4041
return pollRepository.findByTitle(query.getTitle());
4142
}
4243

43-
// Test: http://localhost:8080/api/v1/polls/list?fromDate=2020-06-01
44+
// Test: http://localhost:8080/api/v1/polls/listFrom?fromDate=2019-06-01 - all 3 polls
45+
// Test: http://localhost:8080/api/v1/polls/listFrom?fromDate=2020-05-15 - only 2
46+
// Test: http://localhost:8080/api/v1/polls/listFrom?fromDate=2020-06-15 - none
4447
@GetMapping
4548
@RequestMapping("listFrom")
4649
public List<Poll> listFrom(@DateTimeFormat(pattern="yyyy-MM-dd") Date fromDate) {

0 commit comments

Comments
 (0)