wip: currently rewriting the project as a full stack application tangled.org/kacaii.dev/sigo
gleam

:recycle: add endpoint for occurrence data analysis

+544 -100
+1
README.md
··· 31 31 | /user/password | Update authenticated user password | PUT (JSON) | 32 32 | /brigade/{{id}}/members | List brigade members | GET | 33 33 | /dashboard/stats | Fetch stats for the dashboard page | GET | 34 + | /analysis/occurrence | Fetch data for analysis about occurrences | GET | 34 35 | /occurrence/new | Register a new occurrence | POST (Form) | 35 36 | /occurrence/resolve/{{id}} | Update an occurrence `resolved_at` field | POST / DELETE | 36 37
+9
dev/app_dev.gleam
··· 52 52 |> list.sized_chunk(n_occurences / n_brigades) 53 53 54 54 io.println(" 󱐁 Registrando ocorrências..") 55 + 55 56 let dummy_occurrences = 56 57 list.map(list.range(1, n_occurences), fn(_) { 57 58 let assert Ok(applicant_id) = list.first(list.sample(dummy_users, 1)) 58 59 let assert Ok(assign) = list.first(list.sample(assigned_brigades, 1)) 59 60 dummy.random_occurrence(conn: ctx.db, applicant_id:, assign:) 60 61 }) 62 + 63 + list.each(dummy_occurrences, fn(occ) { 64 + case int.random(2) { 65 + 0 -> dummy.update_occurrence_status(occ, ctx, False) 66 + 1 -> dummy.update_occurrence_status(occ, ctx, True) 67 + _ -> panic as "how?" 68 + } 69 + }) 61 70 62 71 // ALL DONE ------------------------------------------------------------------ 63 72 let n_created_brigades_str =
+4 -4
dev/app_dev/sql.gleam
··· 1 1 //// This module contains the code to run the sql queries defined in 2 2 //// `./dev/app_dev/sql`. 3 - //// > 🐿️ This module was generated automatically using v4.5.0 of 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 4 //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 5 //// 6 6 ··· 10 10 /// Runs the `soft_truncate_user_account` query 11 11 /// defined in `./dev/app_dev/sql/soft_truncate_user_account.sql`. 12 12 /// 13 - /// > 🐿️ This function was generated automatically using v4.5.0 of 13 + /// > 🐿️ This function was generated automatically using v4.6.0 of 14 14 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 15 15 /// 16 16 pub fn soft_truncate_user_account( ··· 29 29 /// Runs the `truncate_brigade` query 30 30 /// defined in `./dev/app_dev/sql/truncate_brigade.sql`. 31 31 /// 32 - /// > 🐿️ This function was generated automatically using v4.5.0 of 32 + /// > 🐿️ This function was generated automatically using v4.6.0 of 33 33 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 34 34 /// 35 35 pub fn truncate_brigade( ··· 47 47 /// Runs the `truncate_occurrence` query 48 48 /// defined in `./dev/app_dev/sql/truncate_occurrence.sql`. 49 49 /// 50 - /// > 🐿️ This function was generated automatically using v4.5.0 of 50 + /// > 🐿️ This function was generated automatically using v4.6.0 of 51 51 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 52 52 /// 53 53 pub fn truncate_occurrence(
+22
dev/dummy.gleam
··· 7 7 import app/domain/occurrence/subcategory 8 8 import app/domain/role 9 9 import app/domain/user/sql as u_sql 10 + import app/web/context 10 11 import gleam/float 11 12 import gleam/list 12 13 import gleam/set ··· 281 282 as "Some brigades were not assigned" 282 283 283 284 created_occurrence_row.id 285 + } 286 + 287 + pub fn update_occurrence_status( 288 + occ: uuid.Uuid, 289 + ctx: context.Context, 290 + is_active: Bool, 291 + ) { 292 + let updated = case is_active { 293 + False -> { 294 + let assert Ok(returned) = o_sql.reopen_occurrence(ctx.db, occ) 295 + let assert Ok(row) = list.first(returned.rows) 296 + row.id 297 + } 298 + True -> { 299 + let assert Ok(returned) = o_sql.resolve_occurrence(ctx.db, occ) 300 + let assert Ok(row) = list.first(returned.rows) 301 + row.id 302 + } 303 + } 304 + 305 + assert occ == updated as "Update the correct occurrence" 284 306 } 285 307 286 308 /// Panic on failure
+2 -2
manifest.toml
··· 44 44 { name = "non_empty_list", version = "2.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "non_empty_list", source = "hex", outer_checksum = "1CA43D18C07E98E9ED5A60D9CB2FFE0FF40DEFFA45D58A3FF589589F05658F7B" }, 45 45 { name = "opentelemetry_api", version = "1.5.0", build_tools = ["rebar3", "mix"], requirements = [], otp_app = "opentelemetry_api", source = "hex", outer_checksum = "F53EC8A1337AE4A487D43AC89DA4BD3A3C99DDF576655D071DEED8B56A2D5DDA" }, 46 46 { name = "pg_types", version = "0.6.0", build_tools = ["rebar3"], requirements = [], otp_app = "pg_types", source = "hex", outer_checksum = "9949A4849DD13408FA249AB7B745E0D2DFDB9532AEE2B9722326E33CD082A778" }, 47 - { name = "pgo", version = "0.17.0", build_tools = ["rebar3"], requirements = ["backoff", "opentelemetry_api", "pg_types"], otp_app = "pgo", source = "hex", outer_checksum = "06E46B53D3AD51F66C1A893849147976011750453727FBAB9332C92C4F9F4DF9" }, 47 + { name = "pgo", version = "0.20.0", build_tools = ["rebar3"], requirements = ["backoff", "opentelemetry_api", "pg_types"], otp_app = "pgo", source = "hex", outer_checksum = "2F11E6649CEB38E569EF56B16BE1D04874AE5B11A02867080A2817CE423C683B" }, 48 48 { name = "platform", version = "1.0.0", build_tools = ["gleam"], requirements = [], otp_app = "platform", source = "hex", outer_checksum = "8339420A95AD89AAC0F82F4C3DB8DD401041742D6C3F46132A8739F6AEB75391" }, 49 49 { name = "pog", version = "4.1.0", build_tools = ["gleam"], requirements = ["exception", "gleam_erlang", "gleam_otp", "gleam_stdlib", "gleam_time", "pgo"], otp_app = "pog", source = "hex", outer_checksum = "E4AFBA39A5FAA2E77291836C9683ADE882E65A06AB28CA7D61AE7A3AD61EBBD5" }, 50 50 { name = "ranger", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_yielder"], otp_app = "ranger", source = "hex", outer_checksum = "C8988E8F8CDBD3E7F4D8F2E663EF76490390899C2B2885A6432E942495B3E854" }, ··· 55 55 { name = "term_size", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "term_size", source = "hex", outer_checksum = "D00BD2BC8FB3EBB7E6AE076F3F1FF2AC9D5ED1805F004D0896C784D06C6645F1" }, 56 56 { name = "tom", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "gleam_time"], otp_app = "tom", source = "hex", outer_checksum = "74D0C5A3761F7A7D06994755D4D5AD854122EF8E9F9F76A3E7547606D8C77091" }, 57 57 { name = "tote", version = "1.0.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "tote", source = "hex", outer_checksum = "A249892E26A53C668897F8D47845B0007EEE07707A1A03437487F0CD5A452CA5" }, 58 - { name = "wisp", version = "2.1.0", build_tools = ["gleam"], requirements = ["directories", "exception", "filepath", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_json", "gleam_stdlib", "houdini", "logging", "marceau", "mist", "simplifile"], otp_app = "wisp", source = "hex", outer_checksum = "362BDDD11BF48EB38CDE51A73BC7D1B89581B395CA998E3F23F11EC026151C54" }, 58 + { name = "wisp", version = "2.1.1", build_tools = ["gleam"], requirements = ["directories", "exception", "filepath", "gleam_crypto", "gleam_erlang", "gleam_http", "gleam_json", "gleam_stdlib", "houdini", "logging", "marceau", "mist", "simplifile"], otp_app = "wisp", source = "hex", outer_checksum = "46E2E31DECD61A3748CF6CB317D9AC432BBC8D8A6E65655A9E787BDC69389DE0" }, 59 59 { name = "youid", version = "1.5.1", build_tools = ["gleam"], requirements = ["gleam_crypto", "gleam_stdlib", "gleam_time"], otp_app = "youid", source = "hex", outer_checksum = "580E909FD704DB16416D5CB080618EDC2DA0F1BE4D21B490C0683335E3FFC5AF" }, 60 60 ] 61 61
+6 -6
src/app/domain/admin/sql.gleam
··· 1 1 //// This module contains the code to run the sql queries defined in 2 2 //// `./src/app/domain/admin/sql`. 3 - //// > 🐿️ This module was generated automatically using v4.5.0 of 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 4 //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 5 //// 6 6 ··· 12 12 /// A row you get from running the `admin_update_user` query 13 13 /// defined in `./src/app/domain/admin/sql/admin_update_user.sql`. 14 14 /// 15 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 15 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 16 16 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 17 17 /// 18 18 pub type AdminUpdateUserRow { ··· 29 29 30 30 ///  Update an user's information as admin 31 31 /// 32 - /// > 🐿️ This function was generated automatically using v4.5.0 of 32 + /// > 🐿️ This function was generated automatically using v4.6.0 of 33 33 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 34 34 /// 35 35 pub fn admin_update_user( ··· 93 93 /// A row you get from running the `count_total_users` query 94 94 /// defined in `./src/app/domain/admin/sql/count_total_users.sql`. 95 95 /// 96 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 96 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 97 97 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 98 98 /// 99 99 pub type CountTotalUsersRow { ··· 102 102 103 103 /// 󰆙 Count the total number of users in our system 104 104 /// 105 - /// > 🐿️ This function was generated automatically using v4.5.0 of 105 + /// > 🐿️ This function was generated automatically using v4.6.0 of 106 106 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 107 107 /// 108 108 pub fn count_total_users( ··· 126 126 127 127 /// Corresponds to the Postgres `user_role_enum` enum. 128 128 /// 129 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 129 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 130 130 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 131 131 /// 132 132 pub type UserRoleEnum {
+20 -20
src/app/domain/brigade/sql.gleam
··· 1 1 //// This module contains the code to run the sql queries defined in 2 2 //// `./src/app/domain/brigade/sql`. 3 - //// > 🐿️ This module was generated automatically using v4.5.0 of 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 4 //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 5 //// 6 6 ··· 13 13 /// A row you get from running the `assign_brigade_members` query 14 14 /// defined in `./src/app/domain/brigade/sql/assign_brigade_members.sql`. 15 15 /// 16 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 16 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 17 17 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 18 18 /// 19 19 pub type AssignBrigadeMembersRow { ··· 22 22 23 23 ///  Assign a list of members to a brigade 24 24 /// 25 - /// > 🐿️ This function was generated automatically using v4.5.0 of 25 + /// > 🐿️ This function was generated automatically using v4.6.0 of 26 26 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 27 27 /// 28 28 pub fn assign_brigade_members( ··· 51 51 /// A row you get from running the `delete_brigade_by_id` query 52 52 /// defined in `./src/app/domain/brigade/sql/delete_brigade_by_id.sql`. 53 53 /// 54 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 54 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 55 55 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 56 56 /// 57 57 pub type DeleteBrigadeByIdRow { ··· 60 60 61 61 ///  Remove a brigade from the DataBase 62 62 /// 63 - /// > 🐿️ This function was generated automatically using v4.5.0 of 63 + /// > 🐿️ This function was generated automatically using v4.6.0 of 64 64 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 65 65 /// 66 66 pub fn delete_brigade_by_id( ··· 89 89 /// A row you get from running the `insert_new_brigade` query 90 90 /// defined in `./src/app/domain/brigade/sql/insert_new_brigade.sql`. 91 91 /// 92 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 92 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 93 93 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 94 94 /// 95 95 pub type InsertNewBrigadeRow { ··· 98 98 99 99 ///  Register a new brigade into the database 100 100 /// 101 - /// > 🐿️ This function was generated automatically using v4.5.0 of 101 + /// > 🐿️ This function was generated automatically using v4.6.0 of 102 102 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 103 103 /// 104 104 pub fn insert_new_brigade( ··· 141 141 /// A row you get from running the `query_all_brigades` query 142 142 /// defined in `./src/app/domain/brigade/sql/query_all_brigades.sql`. 143 143 /// 144 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 144 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 145 145 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 146 146 /// 147 147 pub type QueryAllBrigadesRow { ··· 155 155 156 156 /// 󱉯 Find all registered brigades 157 157 /// 158 - /// > 🐿️ This function was generated automatically using v4.5.0 of 158 + /// > 🐿️ This function was generated automatically using v4.6.0 of 159 159 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 160 160 /// 161 161 pub fn query_all_brigades( ··· 192 192 /// A row you get from running the `query_brigade_info` query 193 193 /// defined in `./src/app/domain/brigade/sql/query_brigade_info.sql`. 194 194 /// 195 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 195 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 196 196 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 197 197 /// 198 198 pub type QueryBrigadeInfoRow { ··· 206 206 207 207 /// 󰡦 Find details about a specific brigade 208 208 /// 209 - /// > 🐿️ This function was generated automatically using v4.5.0 of 209 + /// > 🐿️ This function was generated automatically using v4.6.0 of 210 210 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 211 211 /// 212 212 pub fn query_brigade_info( ··· 246 246 /// A row you get from running the `query_members_id` query 247 247 /// defined in `./src/app/domain/brigade/sql/query_members_id.sql`. 248 248 /// 249 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 249 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 250 250 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 251 251 /// 252 252 pub type QueryMembersIdRow { ··· 255 255 256 256 ///  Find the id of all members assigned a specific brigade 257 257 /// 258 - /// > 🐿️ This function was generated automatically using v4.5.0 of 258 + /// > 🐿️ This function was generated automatically using v4.6.0 of 259 259 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 260 260 /// 261 261 pub fn query_members_id( ··· 283 283 /// A row you get from running the `query_members_info` query 284 284 /// defined in `./src/app/domain/brigade/sql/query_members_info.sql`. 285 285 /// 286 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 286 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 287 287 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 288 288 /// 289 289 pub type QueryMembersInfoRow { ··· 292 292 293 293 ///  Find all members of a brigade 294 294 /// 295 - /// > 🐿️ This function was generated automatically using v4.5.0 of 295 + /// > 🐿️ This function was generated automatically using v4.6.0 of 296 296 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 297 297 /// 298 298 pub fn query_members_info( ··· 325 325 /// A row you get from running the `replace_brigade_members` query 326 326 /// defined in `./src/app/domain/brigade/sql/replace_brigade_members.sql`. 327 327 /// 328 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 328 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 329 329 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 330 330 /// 331 331 pub type ReplaceBrigadeMembersRow { ··· 334 334 335 335 ///  Replace all brigade members 336 336 /// 337 - /// > 🐿️ This function was generated automatically using v4.5.0 of 337 + /// > 🐿️ This function was generated automatically using v4.6.0 of 338 338 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 339 339 /// 340 340 pub fn replace_brigade_members( ··· 363 363 /// A row you get from running the `update_brigade_status` query 364 364 /// defined in `./src/app/domain/brigade/sql/update_brigade_status.sql`. 365 365 /// 366 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 366 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 367 367 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 368 368 /// 369 369 pub type UpdateBrigadeStatusRow { ··· 372 372 373 373 ///  Set the brigade is_active status to ON or OFF 374 374 /// 375 - /// > 🐿️ This function was generated automatically using v4.5.0 of 375 + /// > 🐿️ This function was generated automatically using v4.6.0 of 376 376 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 377 377 /// 378 378 pub fn update_brigade_status( ··· 409 409 410 410 /// Corresponds to the Postgres `user_role_enum` enum. 411 411 /// 412 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 412 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 413 413 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 414 414 /// 415 415 pub type UserRoleEnum {
+3 -3
src/app/domain/dashboard/sql.gleam
··· 1 1 //// This module contains the code to run the sql queries defined in 2 2 //// `./src/app/domain/dashboard/sql`. 3 - //// > 🐿️ This module was generated automatically using v4.5.0 of 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 4 //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 5 //// 6 6 ··· 10 10 /// A row you get from running the `query_dashboard_stats` query 11 11 /// defined in `./src/app/domain/dashboard/sql/query_dashboard_stats.sql`. 12 12 /// 13 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 13 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 14 14 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 15 15 /// 16 16 pub type QueryDashboardStatsRow { ··· 24 24 25 25 /// 󱘟 Retrieve stats for the Dashboard page 26 26 /// 27 - /// > 🐿️ This function was generated automatically using v4.5.0 of 27 + /// > 🐿️ This function was generated automatically using v4.6.0 of 28 28 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 29 29 /// 30 30 pub fn query_dashboard_stats(
+152
src/app/domain/data_analysis/analysis_occurrence_volume.gleam
··· 1 + import app/domain/data_analysis/sql 2 + import app/domain/occurrence/category 3 + import app/domain/occurrence/priority 4 + import app/domain/occurrence/subcategory 5 + import app/domain/role 6 + import app/domain/user 7 + import app/web 8 + import app/web/context.{type Context} 9 + import gleam/http 10 + import gleam/json 11 + import gleam/option 12 + import gleam/result 13 + import gleam/time/timestamp 14 + import pog 15 + import wisp 16 + import youid/uuid 17 + 18 + type AnalysisError { 19 + Database(pog.QueryError) 20 + AccessControl(user.AccessControlError) 21 + } 22 + 23 + pub fn handle_request( 24 + request req: wisp.Request, 25 + ctx ctx: Context, 26 + ) -> wisp.Response { 27 + use <- wisp.require_method(req, http.Get) 28 + 29 + case query_database(req, ctx) { 30 + Error(err) -> handle_error(err, req) 31 + Ok(body) -> wisp.json_response(body, 200) 32 + } 33 + } 34 + 35 + fn handle_error(err: AnalysisError, req: wisp.Request) -> wisp.Response { 36 + case err { 37 + Database(err) -> web.handle_database_error(err) 38 + AccessControl(err) -> user.handle_access_control_error(req, err) 39 + } 40 + } 41 + 42 + fn query_database(req: wisp.Request, ctx: Context) { 43 + use _ <- result.try( 44 + user.check_role_authorization( 45 + request: req, 46 + ctx:, 47 + cookie_name: user.uuid_cookie_name, 48 + authorized_roles: [role.Admin, role.Developer, role.Analyst], 49 + ) 50 + |> result.map_error(AccessControl), 51 + ) 52 + 53 + use returned <- result.map( 54 + sql.occurrence_volume(ctx.db) 55 + |> result.map_error(Database), 56 + ) 57 + 58 + returned.rows 59 + |> json.array(of: row_to_json) 60 + |> json.to_string 61 + } 62 + 63 + fn row_to_json(row: sql.OccurrenceVolumeRow) -> json.Json { 64 + let timestamp_to_json = fn(t: timestamp.Timestamp) { 65 + timestamp.to_unix_seconds(t) |> json.float 66 + } 67 + 68 + let maybe_timestamp_to_json = fn(t: option.Option(timestamp.Timestamp)) { 69 + case t { 70 + option.None -> json.null() 71 + option.Some(t) -> timestamp_to_json(t) 72 + } 73 + } 74 + 75 + let cat_to_json = fn(c: sql.OccurrenceCategoryEnum) { 76 + case c { 77 + sql.Fire -> category.Fire 78 + sql.MedicEmergency -> category.MedicEmergency 79 + sql.Other -> category.Other 80 + sql.TrafficAccident -> category.TrafficAccident 81 + } 82 + |> category.to_string 83 + |> json.string 84 + } 85 + 86 + let subcat_to_json = fn(s: option.Option(sql.OccurrenceSubcategoryEnum)) -> json.Json { 87 + case s { 88 + option.None -> json.null() 89 + option.Some(value) -> 90 + case value { 91 + sql.Collision -> subcategory.Collision 92 + sql.Comercial -> subcategory.Comercial 93 + sql.Flood -> subcategory.Flood 94 + sql.HeartStop -> subcategory.HeartStop 95 + sql.InjuredAnimal -> subcategory.InjuredAnimal 96 + sql.Intoxication -> subcategory.Intoxication 97 + sql.MotorcycleCrash -> subcategory.MotorcycleCrash 98 + sql.PreHospitalCare -> subcategory.PreHospitalCare 99 + sql.Residential -> subcategory.Residential 100 + sql.Rollover -> subcategory.Rollover 101 + sql.RunOver -> subcategory.RunOver 102 + sql.Seizure -> subcategory.Seizure 103 + sql.SeriousInjury -> subcategory.SeriousInjury 104 + sql.TreeCrash -> subcategory.TreeCrash 105 + sql.Vegetation -> subcategory.Vegetation 106 + sql.Vehicle -> subcategory.Vehicle 107 + } 108 + |> subcategory.to_string 109 + |> json.string 110 + } 111 + } 112 + 113 + let maybe_role_to_json = fn(r: option.Option(sql.UserRoleEnum)) -> json.Json { 114 + case r { 115 + option.None -> json.null() 116 + option.Some(value) -> 117 + case value { 118 + sql.Admin -> role.Admin 119 + sql.Analyst -> role.Analyst 120 + sql.Captain -> role.Captain 121 + sql.Developer -> role.Developer 122 + sql.Firefighter -> role.Firefighter 123 + sql.Sargeant -> role.Sargeant 124 + } 125 + |> role.to_json 126 + } 127 + } 128 + 129 + let priority_to_json = fn(p: sql.OccurrencePriorityEnum) -> json.Json { 130 + case p { 131 + sql.High -> priority.High 132 + sql.Low -> priority.Low 133 + sql.Medium -> priority.Medium 134 + } 135 + |> priority.to_string 136 + |> json.string 137 + } 138 + 139 + json.object([ 140 + #("occurrence_id", json.string(row.occurrence_id |> uuid.to_string)), 141 + #("reported_timestamp", timestamp_to_json(row.reported_timestamp)), 142 + #("arrival_timestamp", maybe_timestamp_to_json(row.arrival_timestamp)), 143 + #("resolved_timestamp", maybe_timestamp_to_json(row.resolved_timestamp)), 144 + #("occurrence_category", cat_to_json(row.occurrence_category)), 145 + #("occurrence_subcategory", subcat_to_json(row.occurrence_subcategory)), 146 + #("priority", priority_to_json(row.priority)), 147 + #("applicant_name", json.nullable(row.applicant_name, json.string)), 148 + #("applicant_role", maybe_role_to_json(row.applicant_role)), 149 + #("latitude", json.float(row.latitude)), 150 + #("longitude", json.float(row.longitude)), 151 + ]) 152 + }
+235
src/app/domain/data_analysis/sql.gleam
··· 1 + //// This module contains the code to run the sql queries defined in 2 + //// `./src/app/domain/data_analysis/sql`. 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 + //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 + //// 6 + 7 + import gleam/dynamic/decode 8 + import gleam/option.{type Option} 9 + import gleam/time/timestamp.{type Timestamp} 10 + import pog 11 + import youid/uuid.{type Uuid} 12 + 13 + /// A row you get from running the `occurrence_volume` query 14 + /// defined in `./src/app/domain/data_analysis/sql/occurrence_volume.sql`. 15 + /// 16 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 17 + /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 18 + /// 19 + pub type OccurrenceVolumeRow { 20 + OccurrenceVolumeRow( 21 + occurrence_id: Uuid, 22 + reported_timestamp: Timestamp, 23 + arrival_timestamp: Option(Timestamp), 24 + resolved_timestamp: Option(Timestamp), 25 + occurrence_category: OccurrenceCategoryEnum, 26 + occurrence_subcategory: Option(OccurrenceSubcategoryEnum), 27 + priority: OccurrencePriorityEnum, 28 + applicant_name: Option(String), 29 + applicant_role: Option(UserRoleEnum), 30 + latitude: Float, 31 + longitude: Float, 32 + ) 33 + } 34 + 35 + /// 󰕮 Occurrence reports 36 + /// 37 + /// > 🐿️ This function was generated automatically using v4.6.0 of 38 + /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 39 + /// 40 + pub fn occurrence_volume( 41 + db: pog.Connection, 42 + ) -> Result(pog.Returned(OccurrenceVolumeRow), pog.QueryError) { 43 + let decoder = { 44 + use occurrence_id <- decode.field(0, uuid_decoder()) 45 + use reported_timestamp <- decode.field(1, pog.timestamp_decoder()) 46 + use arrival_timestamp <- decode.field( 47 + 2, 48 + decode.optional(pog.timestamp_decoder()), 49 + ) 50 + use resolved_timestamp <- decode.field( 51 + 3, 52 + decode.optional(pog.timestamp_decoder()), 53 + ) 54 + use occurrence_category <- decode.field( 55 + 4, 56 + occurrence_category_enum_decoder(), 57 + ) 58 + use occurrence_subcategory <- decode.field( 59 + 5, 60 + decode.optional(occurrence_subcategory_enum_decoder()), 61 + ) 62 + use priority <- decode.field(6, occurrence_priority_enum_decoder()) 63 + use applicant_name <- decode.field(7, decode.optional(decode.string)) 64 + use applicant_role <- decode.field( 65 + 8, 66 + decode.optional(user_role_enum_decoder()), 67 + ) 68 + use latitude <- decode.field(9, decode.float) 69 + use longitude <- decode.field(10, decode.float) 70 + decode.success(OccurrenceVolumeRow( 71 + occurrence_id:, 72 + reported_timestamp:, 73 + arrival_timestamp:, 74 + resolved_timestamp:, 75 + occurrence_category:, 76 + occurrence_subcategory:, 77 + priority:, 78 + applicant_name:, 79 + applicant_role:, 80 + latitude:, 81 + longitude:, 82 + )) 83 + } 84 + 85 + "-- 󰕮 Occurrence reports 86 + select 87 + o.id as occurrence_id, 88 + o.created_at as reported_timestamp, 89 + o.arrived_at as arrival_timestamp, 90 + o.resolved_at as resolved_timestamp, 91 + o.occurrence_category, 92 + o.occurrence_subcategory, 93 + o.priority, 94 + u_applicant.full_name as applicant_name, 95 + u_applicant.user_role as applicant_role, 96 + o.occurrence_location[1] as latitude, 97 + o.occurrence_location[2] as longitude 98 + from 99 + public.occurrence as o 100 + left join 101 + public.user_account as u_applicant 102 + on o.applicant_id = u_applicant.id 103 + order by 104 + o.created_at desc; 105 + " 106 + |> pog.query 107 + |> pog.returning(decoder) 108 + |> pog.execute(db) 109 + } 110 + 111 + // --- Enums ------------------------------------------------------------------- 112 + 113 + /// Corresponds to the Postgres `occurrence_category_enum` enum. 114 + /// 115 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 116 + /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 117 + /// 118 + pub type OccurrenceCategoryEnum { 119 + Other 120 + TrafficAccident 121 + Fire 122 + MedicEmergency 123 + } 124 + 125 + fn occurrence_category_enum_decoder() -> decode.Decoder(OccurrenceCategoryEnum) { 126 + use occurrence_category_enum <- decode.then(decode.string) 127 + case occurrence_category_enum { 128 + "other" -> decode.success(Other) 129 + "traffic_accident" -> decode.success(TrafficAccident) 130 + "fire" -> decode.success(Fire) 131 + "medic_emergency" -> decode.success(MedicEmergency) 132 + _ -> decode.failure(Other, "OccurrenceCategoryEnum") 133 + } 134 + }/// Corresponds to the Postgres `occurrence_priority_enum` enum. 135 + /// 136 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 137 + /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 138 + /// 139 + pub type OccurrencePriorityEnum { 140 + High 141 + Medium 142 + Low 143 + } 144 + 145 + fn occurrence_priority_enum_decoder() -> decode.Decoder(OccurrencePriorityEnum) { 146 + use occurrence_priority_enum <- decode.then(decode.string) 147 + case occurrence_priority_enum { 148 + "high" -> decode.success(High) 149 + "medium" -> decode.success(Medium) 150 + "low" -> decode.success(Low) 151 + _ -> decode.failure(High, "OccurrencePriorityEnum") 152 + } 153 + }/// Corresponds to the Postgres `occurrence_subcategory_enum` enum. 154 + /// 155 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 156 + /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 157 + /// 158 + pub type OccurrenceSubcategoryEnum { 159 + InjuredAnimal 160 + Flood 161 + TreeCrash 162 + MotorcycleCrash 163 + Rollover 164 + RunOver 165 + Collision 166 + Vehicle 167 + Vegetation 168 + Comercial 169 + Residential 170 + Intoxication 171 + SeriousInjury 172 + Seizure 173 + PreHospitalCare 174 + HeartStop 175 + } 176 + 177 + fn occurrence_subcategory_enum_decoder() -> decode.Decoder(OccurrenceSubcategoryEnum) { 178 + use occurrence_subcategory_enum <- decode.then(decode.string) 179 + case occurrence_subcategory_enum { 180 + "injured_animal" -> decode.success(InjuredAnimal) 181 + "flood" -> decode.success(Flood) 182 + "tree_crash" -> decode.success(TreeCrash) 183 + "motorcycle_crash" -> decode.success(MotorcycleCrash) 184 + "rollover" -> decode.success(Rollover) 185 + "run_over" -> decode.success(RunOver) 186 + "collision" -> decode.success(Collision) 187 + "vehicle" -> decode.success(Vehicle) 188 + "vegetation" -> decode.success(Vegetation) 189 + "comercial" -> decode.success(Comercial) 190 + "residential" -> decode.success(Residential) 191 + "intoxication" -> decode.success(Intoxication) 192 + "serious_injury" -> decode.success(SeriousInjury) 193 + "seizure" -> decode.success(Seizure) 194 + "pre_hospital_care" -> decode.success(PreHospitalCare) 195 + "heart_stop" -> decode.success(HeartStop) 196 + _ -> decode.failure(InjuredAnimal, "OccurrenceSubcategoryEnum") 197 + } 198 + }/// Corresponds to the Postgres `user_role_enum` enum. 199 + /// 200 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 201 + /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 202 + /// 203 + pub type UserRoleEnum { 204 + Sargeant 205 + Developer 206 + Captain 207 + Firefighter 208 + Analyst 209 + Admin 210 + } 211 + 212 + fn user_role_enum_decoder() -> decode.Decoder(UserRoleEnum) { 213 + use user_role_enum <- decode.then(decode.string) 214 + case user_role_enum { 215 + "sargeant" -> decode.success(Sargeant) 216 + "developer" -> decode.success(Developer) 217 + "captain" -> decode.success(Captain) 218 + "firefighter" -> decode.success(Firefighter) 219 + "analyst" -> decode.success(Analyst) 220 + "admin" -> decode.success(Admin) 221 + _ -> decode.failure(Sargeant, "UserRoleEnum") 222 + } 223 + } 224 + 225 + // --- Encoding/decoding utils ------------------------------------------------- 226 + 227 + /// A decoder to decode `Uuid`s coming from a Postgres query. 228 + /// 229 + fn uuid_decoder() { 230 + use bit_array <- decode.then(decode.bit_array) 231 + case uuid.from_bit_array(bit_array) { 232 + Ok(uuid) -> decode.success(uuid) 233 + Error(_) -> decode.failure(uuid.v7(), "Uuid") 234 + } 235 + }
+20
src/app/domain/data_analysis/sql/occurrence_volume.sql
··· 1 + -- 󰕮 Occurrence reports 2 + select 3 + o.id as occurrence_id, 4 + o.created_at as reported_timestamp, 5 + o.arrived_at as arrival_timestamp, 6 + o.resolved_at as resolved_timestamp, 7 + o.occurrence_category, 8 + o.occurrence_subcategory, 9 + o.priority, 10 + u_applicant.full_name as applicant_name, 11 + u_applicant.user_role as applicant_role, 12 + o.occurrence_location[1] as latitude, 13 + o.occurrence_location[2] as longitude 14 + from 15 + public.occurrence as o 16 + left join 17 + public.user_account as u_applicant 18 + on o.applicant_id = u_applicant.id 19 + order by 20 + o.created_at desc;
+8 -8
src/app/domain/notification/sql.gleam
··· 1 1 //// This module contains the code to run the sql queries defined in 2 2 //// `./src/app/domain/notification/sql`. 3 - //// > 🐿️ This module was generated automatically using v4.5.0 of 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 4 //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 5 //// 6 6 ··· 11 11 /// A row you get from running the `query_active_notifications` query 12 12 /// defined in `./src/app/domain/notification/sql/query_active_notifications.sql`. 13 13 /// 14 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 14 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 15 15 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 16 16 /// 17 17 pub type QueryActiveNotificationsRow { ··· 20 20 21 21 ///  Find the active notifications from an user 22 22 /// 23 - /// > 🐿️ This function was generated automatically using v4.5.0 of 23 + /// > 🐿️ This function was generated automatically using v4.6.0 of 24 24 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 25 25 /// 26 26 pub fn query_active_notifications( ··· 48 48 /// A row you get from running the `query_notification_preferences` query 49 49 /// defined in `./src/app/domain/notification/sql/query_notification_preferences.sql`. 50 50 /// 51 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 51 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 52 52 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 53 53 /// 54 54 pub type QueryNotificationPreferencesRow { ··· 60 60 61 61 ///  Find the notification preferences for an user 62 62 /// 63 - /// > 🐿️ This function was generated automatically using v4.5.0 of 63 + /// > 🐿️ This function was generated automatically using v4.6.0 of 64 64 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 65 65 /// 66 66 pub fn query_notification_preferences( ··· 89 89 /// A row you get from running the `update_notification_preferences` query 90 90 /// defined in `./src/app/domain/notification/sql/update_notification_preferences.sql`. 91 91 /// 92 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 92 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 93 93 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 94 94 /// 95 95 pub type UpdateNotificationPreferencesRow { ··· 101 101 102 102 ///  Update user notification preference 103 103 /// 104 - /// > 🐿️ This function was generated automatically using v4.5.0 of 104 + /// > 🐿️ This function was generated automatically using v4.6.0 of 105 105 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 106 106 /// 107 107 pub fn update_notification_preferences( ··· 143 143 144 144 /// Corresponds to the Postgres `notification_type_enum` enum. 145 145 /// 146 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 146 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 147 147 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 148 148 /// 149 149 pub type NotificationTypeEnum {
+22 -22
src/app/domain/occurrence/sql.gleam
··· 1 1 //// This module contains the code to run the sql queries defined in 2 2 //// `./src/app/domain/occurrence/sql`. 3 - //// > 🐿️ This module was generated automatically using v4.5.0 of 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 4 //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 5 //// 6 6 ··· 13 13 /// A row you get from running the `assign_brigades_to_occurrence` query 14 14 /// defined in `./src/app/domain/occurrence/sql/assign_brigades_to_occurrence.sql`. 15 15 /// 16 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 16 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 17 17 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 18 18 /// 19 19 pub type AssignBrigadesToOccurrenceRow { ··· 22 22 23 23 ///  Assign as list of brigades as participants of a occurrence 24 24 /// 25 - /// > 🐿️ This function was generated automatically using v4.5.0 of 25 + /// > 🐿️ This function was generated automatically using v4.6.0 of 26 26 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 27 27 /// 28 28 pub fn assign_brigades_to_occurrence( ··· 51 51 /// A row you get from running the `delete_occurrence_by_id` query 52 52 /// defined in `./src/app/domain/occurrence/sql/delete_occurrence_by_id.sql`. 53 53 /// 54 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 54 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 55 55 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 56 56 /// 57 57 pub type DeleteOccurrenceByIdRow { ··· 60 60 61 61 ///  Remove an occurrence from the database 62 62 /// 63 - /// > 🐿️ This function was generated automatically using v4.5.0 of 63 + /// > 🐿️ This function was generated automatically using v4.6.0 of 64 64 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 65 65 /// 66 66 pub fn delete_occurrence_by_id( ··· 86 86 /// A row you get from running the `insert_new_occurence` query 87 87 /// defined in `./src/app/domain/occurrence/sql/insert_new_occurence.sql`. 88 88 /// 89 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 89 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 90 90 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 91 91 /// 92 92 pub type InsertNewOccurenceRow { ··· 101 101 102 102 ///  Inserts a new occurrence into the database 103 103 /// 104 - /// > 🐿️ This function was generated automatically using v4.5.0 of 104 + /// > 🐿️ This function was generated automatically using v4.6.0 of 105 105 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 106 106 /// 107 107 pub fn insert_new_occurence( ··· 172 172 /// A row you get from running the `query_occurences_by_applicant` query 173 173 /// defined in `./src/app/domain/occurrence/sql/query_occurences_by_applicant.sql`. 174 174 /// 175 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 175 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 176 176 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 177 177 /// 178 178 pub type QueryOccurencesByApplicantRow { ··· 195 195 ///  Retrieves all occurrences associated with a user, 196 196 /// including detailed category information and resolution status. 197 197 /// 198 - /// > 🐿️ This function was generated automatically using v4.5.0 of 198 + /// > 🐿️ This function was generated automatically using v4.6.0 of 199 199 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 200 200 /// 201 201 pub fn query_occurences_by_applicant( ··· 280 280 /// A row you get from running the `query_participants` query 281 281 /// defined in `./src/app/domain/occurrence/sql/query_participants.sql`. 282 282 /// 283 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 283 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 284 284 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 285 285 /// 286 286 pub type QueryParticipantsRow { ··· 289 289 290 290 /// 󰀖 Find all users that participated in a occurrence 291 291 /// 292 - /// > 🐿️ This function was generated automatically using v4.5.0 of 292 + /// > 🐿️ This function was generated automatically using v4.6.0 of 293 293 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 294 294 /// 295 295 pub fn query_participants( ··· 318 318 /// A row you get from running the `query_recent_occurrences` query 319 319 /// defined in `./src/app/domain/occurrence/sql/query_recent_occurrences.sql`. 320 320 /// 321 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 321 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 322 322 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 323 323 /// 324 324 pub type QueryRecentOccurrencesRow { ··· 335 335 336 336 ///  Find all occurrences from the last 24 hours 337 337 /// 338 - /// > 🐿️ This function was generated automatically using v4.5.0 of 338 + /// > 🐿️ This function was generated automatically using v4.6.0 of 339 339 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 340 340 /// 341 341 pub fn query_recent_occurrences( ··· 389 389 /// A row you get from running the `reopen_occurrence` query 390 390 /// defined in `./src/app/domain/occurrence/sql/reopen_occurrence.sql`. 391 391 /// 392 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 392 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 393 393 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 394 394 /// 395 395 pub type ReopenOccurrenceRow { ··· 402 402 403 403 /// 󰚰 Mark a occurrence as unresolved 404 404 /// 405 - /// > 🐿️ This function was generated automatically using v4.5.0 of 405 + /// > 🐿️ This function was generated automatically using v4.6.0 of 406 406 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 407 407 /// 408 408 pub fn reopen_occurrence( ··· 436 436 /// A row you get from running the `replace_occurrence_brigades` query 437 437 /// defined in `./src/app/domain/occurrence/sql/replace_occurrence_brigades.sql`. 438 438 /// 439 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 439 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 440 440 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 441 441 /// 442 442 pub type ReplaceOccurrenceBrigadesRow { ··· 445 445 446 446 ///  Replace all assigned brigades 447 447 /// 448 - /// > 🐿️ This function was generated automatically using v4.5.0 of 448 + /// > 🐿️ This function was generated automatically using v4.6.0 of 449 449 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 450 450 /// 451 451 pub fn replace_occurrence_brigades( ··· 474 474 /// A row you get from running the `resolve_occurrence` query 475 475 /// defined in `./src/app/domain/occurrence/sql/resolve_occurrence.sql`. 476 476 /// 477 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 477 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 478 478 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 479 479 /// 480 480 pub type ResolveOccurrenceRow { ··· 487 487 488 488 /// 󰚰 Mark a occurrence as resolved 489 489 /// 490 - /// > 🐿️ This function was generated automatically using v4.5.0 of 490 + /// > 🐿️ This function was generated automatically using v4.6.0 of 491 491 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 492 492 /// 493 493 pub fn resolve_occurrence( ··· 522 522 523 523 /// Corresponds to the Postgres `occurrence_category_enum` enum. 524 524 /// 525 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 525 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 526 526 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 527 527 /// 528 528 pub type OccurrenceCategoryEnum { ··· 553 553 |> pog.text 554 554 }/// Corresponds to the Postgres `occurrence_priority_enum` enum. 555 555 /// 556 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 556 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 557 557 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 558 558 /// 559 559 pub type OccurrencePriorityEnum { ··· 581 581 |> pog.text 582 582 }/// Corresponds to the Postgres `occurrence_subcategory_enum` enum. 583 583 /// 584 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 584 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 585 585 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 586 586 /// 587 587 pub type OccurrenceSubcategoryEnum {
+4 -4
src/app/domain/role/sql.gleam
··· 1 1 //// This module contains the code to run the sql queries defined in 2 2 //// `./src/app/domain/role/sql`. 3 - //// > 🐿️ This module was generated automatically using v4.5.0 of 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 4 //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 5 //// 6 6 ··· 10 10 /// A row you get from running the `query_available_user_roles` query 11 11 /// defined in `./src/app/domain/role/sql/query_available_user_roles.sql`. 12 12 /// 13 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 13 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 14 14 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 15 15 /// 16 16 pub type QueryAvailableUserRolesRow { ··· 19 19 20 20 ///  Find all available user roles 21 21 /// 22 - /// > 🐿️ This function was generated automatically using v4.5.0 of 22 + /// > 🐿️ This function was generated automatically using v4.6.0 of 23 23 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 24 24 /// 25 25 pub fn query_available_user_roles( ··· 42 42 43 43 /// Corresponds to the Postgres `user_role_enum` enum. 44 44 /// 45 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 45 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 46 46 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 47 47 /// 48 48 pub type UserRoleEnum {
+31 -31
src/app/domain/user/sql.gleam
··· 1 1 //// This module contains the code to run the sql queries defined in 2 2 //// `./src/app/domain/user/sql`. 3 - //// > 🐿️ This module was generated automatically using v4.5.0 of 3 + //// > 🐿️ This module was generated automatically using v4.6.0 of 4 4 //// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 5 5 //// 6 6 ··· 12 12 /// A row you get from running the `delete_user_by_id` query 13 13 /// defined in `./src/app/domain/user/sql/delete_user_by_id.sql`. 14 14 /// 15 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 15 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 16 16 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 17 17 /// 18 18 pub type DeleteUserByIdRow { ··· 21 21 22 22 ///  Remove and user from the database 23 23 /// 24 - /// > 🐿️ This function was generated automatically using v4.5.0 of 24 + /// > 🐿️ This function was generated automatically using v4.6.0 of 25 25 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 26 26 /// 27 27 pub fn delete_user_by_id( ··· 48 48 /// A row you get from running the `get_complete_user_profiles` query 49 49 /// defined in `./src/app/domain/user/sql/get_complete_user_profiles.sql`. 50 50 /// 51 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 51 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 52 52 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 53 53 /// 54 54 pub type GetCompleteUserProfilesRow { ··· 64 64 65 65 /// 󰀖 Find all users on the database 66 66 /// 67 - /// > 🐿️ This function was generated automatically using v4.5.0 of 67 + /// > 🐿️ This function was generated automatically using v4.6.0 of 68 68 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 69 69 /// 70 70 pub fn get_complete_user_profiles( ··· 105 105 /// A row you get from running the `insert_new_user` query 106 106 /// defined in `./src/app/domain/user/sql/insert_new_user.sql`. 107 107 /// 108 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 108 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 109 109 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 110 110 /// 111 111 pub type InsertNewUserRow { ··· 114 114 115 115 ///  Inserts a new user into the database 116 116 /// 117 - /// > 🐿️ This function was generated automatically using v4.5.0 of 117 + /// > 🐿️ This function was generated automatically using v4.6.0 of 118 118 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 119 119 /// 120 120 pub fn insert_new_user( ··· 158 158 /// A row you get from running the `query_crew_members` query 159 159 /// defined in `./src/app/domain/user/sql/query_crew_members.sql`. 160 160 /// 161 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 161 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 162 162 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 163 163 /// 164 164 pub type QueryCrewMembersRow { ··· 173 173 /// 󰢫 Retrieves detailed information about fellow brigade members 174 174 /// for a given user, including their names and role details. 175 175 /// 176 - /// > 🐿️ This function was generated automatically using v4.5.0 of 176 + /// > 🐿️ This function was generated automatically using v4.6.0 of 177 177 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 178 178 /// 179 179 pub fn query_crew_members( ··· 208 208 /// A row you get from running the `query_login_token` query 209 209 /// defined in `./src/app/domain/user/sql/query_login_token.sql`. 210 210 /// 211 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 211 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 212 212 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 213 213 /// 214 214 pub type QueryLoginTokenRow { ··· 218 218 ///  Retrieves a user's ID and password hash from their registration 219 219 /// number for authentication purposes. 220 220 /// 221 - /// > 🐿️ This function was generated automatically using v4.5.0 of 221 + /// > 🐿️ This function was generated automatically using v4.6.0 of 222 222 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 223 223 /// 224 224 pub fn query_login_token( ··· 250 250 /// A row you get from running the `query_occurrences_by_participant` query 251 251 /// defined in `./src/app/domain/user/sql/query_occurrences_by_participant.sql`. 252 252 /// 253 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 253 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 254 254 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 255 255 /// 256 256 pub type QueryOccurrencesByParticipantRow { ··· 259 259 260 260 /// 󰡦 Find all occurrences a user participated in 261 261 /// 262 - /// > 🐿️ This function was generated automatically using v4.5.0 of 262 + /// > 🐿️ This function was generated automatically using v4.6.0 of 263 263 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 264 264 /// 265 265 pub fn query_occurrences_by_participant( ··· 289 289 /// A row you get from running the `query_user_brigades` query 290 290 /// defined in `./src/app/domain/user/sql/query_user_brigades.sql`. 291 291 /// 292 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 292 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 293 293 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 294 294 /// 295 295 pub type QueryUserBrigadesRow { ··· 298 298 299 299 ///  Find all brigades an user is assigned to 300 300 /// 301 - /// > 🐿️ This function was generated automatically using v4.5.0 of 301 + /// > 🐿️ This function was generated automatically using v4.6.0 of 302 302 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 303 303 /// 304 304 pub fn query_user_brigades( ··· 324 324 /// A row you get from running the `query_user_id_by_registration` query 325 325 /// defined in `./src/app/domain/user/sql/query_user_id_by_registration.sql`. 326 326 /// 327 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 327 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 328 328 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 329 329 /// 330 330 pub type QueryUserIdByRegistrationRow { ··· 333 333 334 334 ///  Retrieves a user's ID from their registration number. 335 335 /// 336 - /// > 🐿️ This function was generated automatically using v4.5.0 of 336 + /// > 🐿️ This function was generated automatically using v4.6.0 of 337 337 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 338 338 /// 339 339 pub fn query_user_id_by_registration( ··· 359 359 /// A row you get from running the `query_user_name` query 360 360 /// defined in `./src/app/domain/user/sql/query_user_name.sql`. 361 361 /// 362 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 362 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 363 363 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 364 364 /// 365 365 pub type QueryUserNameRow { ··· 368 368 369 369 ///  Retrieves a user's full name by their user ID. 370 370 /// 371 - /// > 🐿️ This function was generated automatically using v4.5.0 of 371 + /// > 🐿️ This function was generated automatically using v4.6.0 of 372 372 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 373 373 /// 374 374 pub fn query_user_name( ··· 394 394 /// A row you get from running the `query_user_password` query 395 395 /// defined in `./src/app/domain/user/sql/query_user_password.sql`. 396 396 /// 397 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 397 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 398 398 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 399 399 /// 400 400 pub type QueryUserPasswordRow { ··· 403 403 404 404 ///  Find the password hash from an user 405 405 /// 406 - /// > 🐿️ This function was generated automatically using v4.5.0 of 406 + /// > 🐿️ This function was generated automatically using v4.6.0 of 407 407 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 408 408 /// 409 409 pub fn query_user_password( ··· 429 429 /// A row you get from running the `query_user_profile` query 430 430 /// defined in `./src/app/domain/user/sql/query_user_profile.sql`. 431 431 /// 432 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 432 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 433 433 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 434 434 /// 435 435 pub type QueryUserProfileRow { ··· 445 445 446 446 /// 󰀖 Find basic information about an user account 447 447 /// 448 - /// > 🐿️ This function was generated automatically using v4.5.0 of 448 + /// > 🐿️ This function was generated automatically using v4.6.0 of 449 449 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 450 450 /// 451 451 pub fn query_user_profile( ··· 489 489 /// A row you get from running the `query_user_role` query 490 490 /// defined in `./src/app/domain/user/sql/query_user_role.sql`. 491 491 /// 492 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 492 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 493 493 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 494 494 /// 495 495 pub type QueryUserRoleRow { ··· 498 498 499 499 /// 󰀖 Find user access level 500 500 /// 501 - /// > 🐿️ This function was generated automatically using v4.5.0 of 501 + /// > 🐿️ This function was generated automatically using v4.6.0 of 502 502 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 503 503 /// 504 504 pub fn query_user_role( ··· 524 524 525 525 ///  Set an new value to the password of an user 526 526 /// 527 - /// > 🐿️ This function was generated automatically using v4.5.0 of 527 + /// > 🐿️ This function was generated automatically using v4.6.0 of 528 528 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 529 529 /// 530 530 pub fn update_user_password( ··· 551 551 /// A row you get from running the `update_user_profile` query 552 552 /// defined in `./src/app/domain/user/sql/update_user_profile.sql`. 553 553 /// 554 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 554 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 555 555 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 556 556 /// 557 557 pub type UpdateUserProfileRow { ··· 560 560 561 561 ///  Update an authenticated user profile 562 562 /// 563 - /// > 🐿️ This function was generated automatically using v4.5.0 of 563 + /// > 🐿️ This function was generated automatically using v4.6.0 of 564 564 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 565 565 /// 566 566 pub fn update_user_profile( ··· 600 600 /// A row you get from running the `update_user_status` query 601 601 /// defined in `./src/app/domain/user/sql/update_user_status.sql`. 602 602 /// 603 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 603 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 604 604 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 605 605 /// 606 606 pub type UpdateUserStatusRow { ··· 609 609 610 610 /// 󰚰 Update an user `is_active` field 611 611 /// 612 - /// > 🐿️ This function was generated automatically using v4.5.0 of 612 + /// > 🐿️ This function was generated automatically using v4.6.0 of 613 613 /// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). 614 614 /// 615 615 pub fn update_user_status( ··· 642 642 643 643 /// Corresponds to the Postgres `user_role_enum` enum. 644 644 /// 645 - /// > 🐿️ This type definition was generated automatically using v4.5.0 of the 645 + /// > 🐿️ This type definition was generated automatically using v4.6.0 of the 646 646 /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). 647 647 /// 648 648 pub type UserRoleEnum {
+5
src/app/http_router.gleam
··· 15 15 import app/domain/brigade/register_new_brigade 16 16 import app/domain/brigade/update_brigade_status 17 17 import app/domain/dashboard 18 + import app/domain/data_analysis/analysis_occurrence_volume 18 19 import app/domain/notification/get_notification_preferences 19 20 import app/domain/notification/update_notification_preferences 20 21 import app/domain/occurrence/delete_occurrence ··· 82 83 83 84 // 󰨇 Dashboard stats ------------------------------------------------------ 84 85 http.Get, ["dashboard", "stats"] -> dashboard.handle_request(request:, ctx:) 86 + 87 + // 󰕮 Data analysis routes 88 + http.Get, ["analysis", "occurrence"] -> 89 + analysis_occurrence_volume.handle_request(request:, ctx:) 85 90 86 91 //  User data routes ----------------------------------------------------- 87 92 http.Get, ["user", id, "occurrences"] ->