This is a personal project that provides an API to keep track of how much screen time a child has earned by doing their chores. The available screen time can be adjusted upwards or downwards depending on whether they did their chores.
- MySQL or MariaDB
- Cargo
- Diesel CLI (
cargo install diesel_cli --no-default-features --features mysql
)
- Create an empty database and a database user that has all privileges on the database.
- Copy
.env.dist
to.env
and adapt it to include your database name and user credentials. - Create database tables:
$ diesel migration run
- Compile:
$ cargo build --release
- Symlink the binary somewhere in your
$PATH
, for example:$ ln -rs target/release/screentimeapi ~/.local/bin/
$ screentimeapi --help
See rest-api.http for examples of how to use the API.'
$ screentimeapi serve
Here is an example service file that you can adapt to your needs. It can be
placed in ~/.config/systemd/user/screentimeapi.service
:
[Unit]
Description=Screentime API
After=network.target
[Service]
Environment="DATABASE_URL=mysql://user:pass@localhost/screentimeapi"
Environment="SERVER_PORT=3000"
Environment="SERVER_ADDRESS=0.0.0.0"
ExecStart=/home/myuser/.local/bin/screentimeapi serve
Restart=always
RestartSec=5s
StartLimitBurst=5
[Install]
WantedBy=default.target
Once you've created this file, you can start the service with the following command:
$ systemctl --user enable screentimeapi
To enable the service to start automatically at boot:
$ systemctl --user start screentimeapi
To check the status of your service:
$ systemctl --user status screentimeapi
- Create an empty test database with corresponding user.
- Override the database URL with the test database while populating the tables
and running tests:
$ DATABASE_URL=mysql://screentimeapi:screentimeapi@localhost/screentimeapitest diesel migration run $ DATABASE_URL=mysql://screentimeapi:screentimeapi@localhost/screentimeapitest cargo test