FIX: pagination
This commit is contained in:
parent
961fea97a0
commit
e8e20f57ae
|
@ -166,7 +166,7 @@ pub fn get_event(settings: &State<Settings>, event_id: uuid::Uuid) -> Result<Eve
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_event_count(settings: &State<Settings>, startdate: NaiveDateTime, enddate: NaiveDateTime, groups: Option<Vec<uuid::Uuid>>) -> Result<i64, diesel::result::Error>{
|
||||
pub fn get_event_count(settings: &State<Settings>, startdate: NaiveDateTime, enddate: NaiveDateTime, groups: Option<Vec<uuid::Uuid>>, states: Option<Vec<i16>>) -> Result<i64, diesel::result::Error>{
|
||||
use crate::schema::events::dsl::*;
|
||||
use diesel::dsl::count;
|
||||
|
||||
|
@ -174,11 +174,12 @@ pub fn get_event_count(settings: &State<Settings>, startdate: NaiveDateTime, end
|
|||
|
||||
let mut query = events.select(count(entity_id)).filter(start.ge(startdate)).filter(end.le(enddate)).into_boxed();
|
||||
|
||||
match groups{
|
||||
Some(groups) => {
|
||||
query = query.filter(related_group.eq(any(groups)))
|
||||
},
|
||||
None => {}
|
||||
if let Some(groups) = groups {
|
||||
query = query.filter(related_group.eq(any(groups)));
|
||||
};
|
||||
|
||||
if let Some(states) = states{
|
||||
query = query.filter(state.eq(any(states)));
|
||||
};
|
||||
|
||||
match query.get_result(&connection){
|
||||
|
|
|
@ -95,11 +95,11 @@ pub fn read_events(
|
|||
None => None,
|
||||
};
|
||||
|
||||
let events = match get_events(settings, start, end, limit, offset, groups.clone(), states){
|
||||
let events = match get_events(settings, start, end, limit, offset, groups.clone(), states.clone()){
|
||||
Ok(events) => events,
|
||||
Err(e) => return Err(translate_diesel(e)),
|
||||
};
|
||||
let total_event_count = match get_event_count(settings, start, end, groups){
|
||||
let total_event_count = match get_event_count(settings, start, end, groups, states){
|
||||
Ok(count) => count,
|
||||
Err(e) => return Err(translate_diesel(e)),
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue