2020-12-02 12:32:47 -07:00
|
|
|
use diesel::{result::Error, *};
|
2020-12-18 11:38:32 -07:00
|
|
|
use lemmy_db_schema::{
|
2021-10-16 07:33:38 -06:00
|
|
|
aggregates::site_aggregates::SiteAggregates,
|
2022-01-26 10:57:16 -07:00
|
|
|
schema::{site, site_aggregates},
|
|
|
|
source::site::Site,
|
2020-12-02 12:32:47 -07:00
|
|
|
};
|
2021-10-19 10:37:01 -06:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-12-02 12:32:47 -07:00
|
|
|
|
2021-10-19 10:37:01 -06:00
|
|
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
2020-12-02 12:32:47 -07:00
|
|
|
pub struct SiteView {
|
|
|
|
pub site: Site,
|
2020-12-19 18:10:47 -07:00
|
|
|
pub counts: SiteAggregates,
|
2020-12-02 12:32:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SiteView {
|
2022-03-08 05:52:33 -07:00
|
|
|
pub fn read_local(conn: &PgConnection) -> Result<Self, Error> {
|
2022-02-07 12:23:12 -07:00
|
|
|
let (mut site, counts) = site::table
|
2020-12-19 18:10:47 -07:00
|
|
|
.inner_join(site_aggregates::table)
|
2022-01-26 10:57:16 -07:00
|
|
|
.select((site::all_columns, site_aggregates::all_columns))
|
2022-03-08 05:52:33 -07:00
|
|
|
.order_by(site::id)
|
2022-01-26 10:57:16 -07:00
|
|
|
.first::<(Site, SiteAggregates)>(conn)?;
|
2020-12-02 12:32:47 -07:00
|
|
|
|
2022-02-07 12:23:12 -07:00
|
|
|
site.private_key = None;
|
2022-01-26 10:57:16 -07:00
|
|
|
Ok(SiteView { site, counts })
|
2020-12-02 12:32:47 -07:00
|
|
|
}
|
|
|
|
}
|