2 newtypes::{DbUrl, SiteId},
3 source::{actor_language::SiteLanguage, site::*},
6 use diesel::{dsl::*, result::Error, *};
10 type InsertForm = SiteInsertForm;
11 type UpdateForm = SiteUpdateForm;
13 fn read(conn: &mut PgConnection, _site_id: SiteId) -> Result<Self, Error> {
14 use crate::schema::site::dsl::*;
15 site.first::<Self>(conn)
18 fn create(conn: &mut PgConnection, form: &Self::InsertForm) -> Result<Self, Error> {
19 use crate::schema::site::dsl::*;
21 let site_ = insert_into(site)
23 .on_conflict(actor_id)
26 .get_result::<Self>(conn)?;
28 // initialize with all languages
29 SiteLanguage::update(conn, vec![], &site_)?;
34 conn: &mut PgConnection,
36 new_site: &Self::UpdateForm,
37 ) -> Result<Self, Error> {
38 use crate::schema::site::dsl::*;
39 diesel::update(site.find(site_id))
41 .get_result::<Self>(conn)
44 fn delete(conn: &mut PgConnection, site_id: SiteId) -> Result<usize, Error> {
45 use crate::schema::site::dsl::*;
46 diesel::delete(site.find(site_id)).execute(conn)
51 pub fn read_from_apub_id(conn: &mut PgConnection, object_id: Url) -> Result<Option<Self>, Error> {
52 use crate::schema::site::dsl::*;
53 let object_id: DbUrl = object_id.into();
56 .filter(actor_id.eq(object_id))
63 // TODO this needs fixed
64 pub fn read_remote_sites(conn: &mut PgConnection) -> Result<Vec<Self>, Error> {
65 use crate::schema::site::dsl::*;
66 site.order_by(id).offset(1).get_results::<Self>(conn)