Attendance API is a REST API to provide a way to manage employee's attendance, shifts and more. It is intended to be a coding challenge test. This project is built using:
- Go (v1.22.2)
- PostgreSQL
First of all, make sure you have a PostgreSQL database server running. And make sure that you have installed Go (v1.22.2) or higher on your local machine to build this project. Once you're ready, clone this repository and then run:
go build -o bin/attendanceThen lookup into the folder bin/ of your current directory, there will be an executable file called attendance. Depending on your operating system but if you're on windows it will output an attendance.exe file which you can run directly.
The binary provides you some ability which is:
- To provision your database & run your migrations
- To start the API server
There is a config.example.yml file in this repository which you can copy and paste on your local machine as the main configuration of the API. Before you move further, please adjust the configuration based on your local machine especially the database (PostgreSQl).
Important
The binary default configuration will be at your $HOME/.attendance-api/confg.yml. Although you can customize it by providing a --config flag every time you run the binary
which point to an absolute path to where you put the configuration file.
Before you can run the migrations, please setup your configuration first. To run the migration use this command:
./bin/attendance migration upAfter all of the above steps successfully finished, you can run the API server to start using the API by running this command on your terminal:
./bin/attendanceYou can test the API by using the postman collection that i've provided here.
Another option to run this project is by using docker. Please make sure you have this docker requirements on your local machine:
- Docker Client & Server (v26.0.2 or higher)
- Docker Compose (v2.26.1)
Like the other steps above, the first thing you want to do is to configure the config.yml file. You can refer to this file for all available configurations.
After you clone this repository, just run:
docker compose up --build -dAfter you've successfully run the containers. To run the migrations (if you're using docker) you can use this command:
docker exec {container_name} sh -c "attendance --config /home/server/config.yml migration up"Make sure you replace the {container_name with your own container name.
Note
If you have a problem running this project on your local machine, feel free to contact me at: dewaadiperdana@gmail.com.