forge
Explore
Log in

Don't you dare go Hollow

hezarfen_backend

Clone
★ 0

0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits

work_entry.rs52 lines, 1.8 KiBHistoryRawDownload
1//! Work-log surfacing: the check-in/check-out pair, the staff log, and the
2//! manager corrections. The queries live in [`crate::db::work_entry`] — both
3//! transitions are single atomic writes the database itself arbitrates (the
4//! `work_entry_open` partial unique index refuses a second check-in; the
5//! check-out's conditional `UPDATE` takes the one open row), so this domain
6//! has no workflow of its own.
7
8use crate::database::Database;
9use crate::db::work_entry;
10use crate::domain::timestamp::Timestamp;
11use crate::domain::user::UserId;
12use crate::domain::work_entry::WorkEntry;
13use crate::domain::work_entry::WorkEntryId;
14use crate::error::AppError;
15
16/// Check in (`409` while already checked in).
17pub async fn check_in(db: &Database, user: &UserId) -> Result<WorkEntry, AppError> {
18 work_entry::check_in(db, user).await
19}
20
21/// Check out (`409` when not checked in).
22pub async fn check_out(db: &Database, user: &UserId) -> Result<WorkEntry, AppError> {
23 work_entry::check_out(db, user).await
24}
25
26pub async fn read(db: &Database, id: &WorkEntryId) -> Result<Option<WorkEntry>, AppError> {
27 work_entry::read(db, id).await
28}
29
30/// Every stint of `user`, newest first — the open one included.
31pub async fn list_for_user(
32 db: &Database,
33 user: &UserId,
34 limit: Option<i64>,
35 offset: i64,
36) -> Result<(Vec<WorkEntry>, i64), AppError> {
37 work_entry::list_for_user(db, user, limit, offset).await
38}
39
40/// Persist corrected instants on a closed entry; `None` keeps the field.
41pub async fn update(
42 db: &Database,
43 entry: WorkEntry,
44 check_in: Option<Timestamp>,
45 check_out: Option<Timestamp>,
46) -> Result<WorkEntry, AppError> {
47 work_entry::update(db, entry, check_in, check_out).await
48}
49
50pub async fn remove(db: &Database, id: &WorkEntryId) -> Result<Option<WorkEntry>, AppError> {
51 work_entry::remove(db, id).await
52}