Skip to content

Commit c7299f1

Browse files
committed
fix: Group search bug
1 parent 3aa1227 commit c7299f1

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

docker-compose.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
postgres:
33
image: postgres:latest
4-
ports:
4+
ports:
55
- "5434:5432"
66
volumes:
77
- db_data:/var/lib/postgresql/data
@@ -10,7 +10,7 @@ services:
1010
- POSTGRES_USER=admin
1111
mongodb:
1212
image: mongodb/mongodb-community-server:latest
13-
ports:
13+
ports:
1414
- "27017:27017"
1515
environment:
1616
- MONGO_INITDB_ROOT_USERNAME=admin
@@ -22,7 +22,7 @@ services:
2222
- "1025:1025"
2323
usernator:
2424
build: ./usernator
25-
ports:
25+
ports:
2626
- "3001:3000"
2727
- "3004:3001"
2828
environment:
@@ -45,7 +45,7 @@ services:
4545
context: ./authy
4646
args:
4747
- ARCH=aarch64
48-
ports:
48+
ports:
4949
- "3002:3000"
5050
environment:
5151
- JWT_SECRET=secret
@@ -59,7 +59,7 @@ services:
5959
context: ./tasky
6060
args:
6161
- ARCH=aarch64
62-
ports:
62+
ports:
6363
- "3005:3000"
6464
- "3006:3001"
6565
environment:
@@ -104,4 +104,4 @@ services:
104104
depends_on:
105105
- executor
106106
volumes:
107-
db_data:
107+
db_data:

tasky/src/models/group.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ use super::{PaginatedModel, DB};
44
use crate::schema::group_members;
55
use crate::schema::groups::dsl;
66
use chrono::NaiveDateTime;
7+
use diesel::debug_query;
78
use diesel::dsl::count_star;
9+
use diesel::pg::Pg;
810
use diesel::prelude::*;
911
use diesel::{associations::HasTable, dsl::not};
12+
use log::info;
1013
use serde::{Deserialize, Serialize};
1114

1215
#[derive(diesel_derive_enum::DbEnum, Debug, Clone, Deserialize, Serialize, PartialEq)]
@@ -127,7 +130,7 @@ impl GroupRepository {
127130
}
128131
}
129132

130-
/// Gets all groups a user is member or tutor of
133+
/// Gets all groups a user is no member or tutor of
131134
pub fn get_groups_for_not_member(
132135
member_id: i32,
133136
page: i64,
@@ -139,17 +142,21 @@ impl GroupRepository {
139142
.map(|x| x.group_id)
140143
.collect();
141144

142-
let base_predicate = not(dsl::tutor
143-
.eq(member_id)
144-
.or(dsl::id.eq_any(requested))
145-
.or(group_members::dsl::member_id.eq(member_id)));
145+
let base_predicate = not(dsl::tutor.eq(member_id).or(dsl::id.eq_any(requested)).or(
146+
group_members::dsl::member_id
147+
.eq(member_id)
148+
.and(group_members::dsl::group_id.is_not_null()),
149+
));
146150

147151
let total_base_query = dsl::groups
148152
.left_join(group_members::dsl::group_members)
149153
.select(count_star())
150154
.filter(base_predicate.clone())
151155
.into_boxed();
152156

157+
let sql_string = debug_query::<Pg, _>(&total_base_query).to_string();
158+
println!("{}", sql_string);
159+
153160
let total = match search.clone() {
154161
None => total_base_query
155162
.get_result::<i64>(conn)
@@ -177,7 +184,8 @@ impl GroupRepository {
177184
.load::<Group>(conn),
178185
};
179186

180-
if results.is_err() {
187+
if let Err(e) = results {
188+
info!("Error from database: {}", e);
181189
return PaginatedModel {
182190
total: 0,
183191
results: vec![],

0 commit comments

Comments
 (0)