1
/*
2
 * This file is part of mailpot
3
 *
4
 * Copyright 2023 - Manos Pitsidianakis
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as
8
 * published by the Free Software Foundation, either version 3 of the
9
 * License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18
 */
19

            
20
//! Named templates, for generated e-mail like confirmations, alerts etc.
21
//!
22
//! Template database model: [`Template`](crate::Template).
23

            
24
use std::collections::HashMap;
25

            
26
use serde_json::Value;
27

            
28
use crate::{errors::*, Connection, DbVal};
29

            
30
impl Connection {
31
    /// Get json settings.
32
14
    pub fn get_settings(&self, list_pk: i64) -> Result<HashMap<String, DbVal<Value>>> {
33
14
        let mut stmt = self.connection.prepare(
34
            "SELECT pk, name, value FROM list_settings_json WHERE list = ? AND is_valid = 1;",
35
        )?;
36
15
        let iter = stmt.query_map(rusqlite::params![&list_pk], |row| {
37
1
            let pk: i64 = row.get("pk")?;
38
1
            let name: String = row.get("name")?;
39
1
            let value: Value = row.get("value")?;
40
1
            Ok((name, DbVal(value, pk)))
41
1
        })?;
42
14
        Ok(iter.collect::<std::result::Result<HashMap<String, DbVal<Value>>, rusqlite::Error>>()?)
43
14
    }
44
}