-
-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathactivity.v
More file actions
37 lines (30 loc) · 737 Bytes
/
activity.v
File metadata and controls
37 lines (30 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module main
import time
struct Activity {
mut:
id int @[primary; sql: serial]
user_id int
name string
created_at time.Time
}
fn (app App) add_activity(user_id int, name string) ! {
activity := Activity{
user_id: user_id
name: name
created_at: time.now()
}
sql app.db {
insert activity into Activity
}!
}
fn (mut app App) find_activities(user_id int) []Activity {
return sql app.db {
select from Activity where user_id == user_id order by created_at desc
} or { []Activity{} }
}
fn (mut app App) has_activity(user_id int, name string) bool {
activity_count := sql app.db {
select count from Activity where user_id == user_id && name == name
} or { 0 }
return activity_count > 0
}