1
0

Update databases coursework

This commit is contained in:
2025-12-05 15:46:49 +02:00
parent c96bc3728d
commit 3c5efb7886
7 changed files with 58 additions and 11 deletions

1
3/coursework/src/.envrc Normal file
View File

@@ -0,0 +1 @@
export DATABASE_URL="mysql://root:password@localhost:3306/repository"

View File

@@ -1,4 +1,45 @@
# Stuff that helped
# Information System "Package Repository"
## Setup
```bash
# Setup the database
docker compose up -d
# Get environment variables (optional)
source .envrc
# Compile and execute
cargo run
```
## Usage
A user `test` with the password `testtest` is available (or you can register your own).
To search all packages enter a `%` in the search bar. Try searching `lib` for example.
When no input field is focused, the app supports UI scaling with `Ctrl-` and `Ctrl+`.
## Cleanup
```bash
docker compose down -v
cargo clean
```
## Showcase
### Login page
![Login page of the application](../img/repo/login.png)
### Register page
![Register page of the application](../img/repo/register.png)
### Search page
![Search page of the application](../img/repo/search.png)
## Stuff that helped
* Architecture:
- [How to apply hexagonal architecture to Rust](https://www.barrage.net/blog/technology/how-to-apply-hexagonal-architecture-to-rust)

View File

@@ -5,7 +5,10 @@ services:
ports:
- "127.0.0.1:3306:3306"
volumes:
- ../../repo-database:/var/lib/mysql
- ./init:/docker-entrypoint-initdb.d/:ro
- repo-database:/var/lib/mysql
- ./sql:/docker-entrypoint-initdb.d/:ro
environment:
MYSQL_ROOT_PASSWORD: password # yes, I know
volumes:
repo-database:

View File

@@ -1,3 +1,5 @@
USE repository;
-- Insert Users
INSERT INTO Users (name, email, password, last_used) VALUES
('alice', 'alice@example.com', 'password123', NOW()),
@@ -14,7 +16,9 @@ INSERT INTO Users (name, email, password, last_used) VALUES
('oscar', 'oscar@example.com', 'oscarpass', NOW()),
('peggy', 'peggy@example.com', 'peggypwd', NOW()),
('trent', 'trent@example.com', 'trentpass', NOW()),
('victor', 'victor@example.com', 'victorpwd', NOW());
('victor', 'victor@example.com', 'victorpwd', NOW()),
('test', 'test@example.com', '$argon2id$v=19$m=19456,t=2,p=1$4POPE1A9A3evhePMYON7FQ$78A3OImH975IwugMikARwoEHkPixKJxJwPXgsCnQdY0', NOW());
-- Insert PackageBases
INSERT INTO PackageBases (name, description) VALUES

View File

@@ -58,13 +58,10 @@ impl Repository {
let (main_id, open_task) = window::open(window::Settings::default());
// let (main_window, main_window_task) = MainWindow::new();
let pool = MySqlPool::new(
SqlxPool::connect_lazy(
&std::env::var("DATABASE_URL")
.expect("environment variable `DATABASE_URL` should be set"),
)
.unwrap(),
);
let db_url = std::env::var("DATABASE_URL")
.unwrap_or_else(|_| "mysql://root:password@localhost:3306/repository".into());
let pool = MySqlPool::new(SqlxPool::connect_lazy(&db_url).unwrap());
let auth_service = Arc::new(Mutex::new(AuthenticationService::new(
AuthenticationAdapter::new(pool.clone()),

View File

@@ -35,6 +35,7 @@ npm run dev
- OpenAPI spec is at <http://localhost:3000/apidoc/openapi.json>
## Showcase
### Swagger UI
![Image of Swagger UI](img/swagger.png)