forked from kompetenzinventar/ki-backend
fix find profile query #51
This commit is contained in:
parent
0fa5612dce
commit
8bdc1564be
@ -139,12 +139,15 @@ def seed(dev: bool):
|
||||
freetext="1001010010111!!!",
|
||||
skills=[(Skill.skill_id_php, 5)])
|
||||
|
||||
seed_user("jutta",
|
||||
visible=True,
|
||||
languages=[("fr", 5)],
|
||||
skills=[(Skill.skill_id_php, 3), (Skill.skill_id_mysql, 4)])
|
||||
all_skills = Skill.query.all()
|
||||
all_profile_skills = []
|
||||
for skill in all_skills:
|
||||
all_profile_skills.append((skill.id, 3))
|
||||
|
||||
seed_user("jutta", visible=True, languages=[("fr", 5)], skills=all_profile_skills)
|
||||
seed_user("giesela", visible=True, skills=[(Skill.skill_id_mysql, 3), (Skill.skill_id_postgresql, 5)])
|
||||
seed_user("bertha", visible=False, skills=[(Skill.skill_id_sqlite, 3), (Skill.skill_id_postgresql, 5)])
|
||||
|
||||
seed_user("monique", visible=True, languages=[("fr", 4)])
|
||||
|
||||
db.session.commit()
|
||||
|
@ -18,7 +18,8 @@ def find_profiles():
|
||||
if page_size > 100:
|
||||
return make_response({"messages": {"page_size": "Die maximale Anzahl Einträge pro Seite beträgt 100"}}, 400)
|
||||
|
||||
query = Profile.query.filter(Profile.visible.is_(True)) \
|
||||
query = Profile.query.distinct(Profile.id) \
|
||||
.filter(Profile.visible.is_(True)) \
|
||||
.join(Profile.skills, isouter=True).join(ProfileSkill.skill, isouter=True) \
|
||||
.join(Profile.languages, isouter=True).join(ProfileLanguage.language, isouter=True)
|
||||
|
||||
@ -32,7 +33,7 @@ def find_profiles():
|
||||
nickname = request.args.get("nickname")
|
||||
query = query.filter(Profile.nickname.like(f"%{nickname}%"))
|
||||
|
||||
count = query.distinct(Profile.id).count()
|
||||
count = query.count()
|
||||
|
||||
offset = (page - 1) * page_size
|
||||
db_profiles = query.limit(page_size).offset(offset).all()
|
||||
|
@ -36,6 +36,9 @@ class TestFindProfilesEndpoint(ApiTest):
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertDictContainsSubset({"total": 4}, response.json)
|
||||
self.assertDictContainsSubset({"nickname": "dirtydieter"}, response.json["profiles"][0])
|
||||
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][1])
|
||||
self.assertDictContainsSubset({"nickname": "giesela"}, response.json["profiles"][2])
|
||||
self.assertDictContainsSubset({"nickname": "monique"}, response.json["profiles"][3])
|
||||
|
||||
def test_find_dieter(self):
|
||||
token = self.login("peter", "geheim")["token"]
|
||||
@ -67,8 +70,9 @@ class TestFindProfilesEndpoint(ApiTest):
|
||||
|
||||
response = self.client.get("/users/profiles?search=post", headers={"Authorization": "Bearer " + token})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertDictContainsSubset({"total": 1}, response.json)
|
||||
self.assertDictContainsSubset({"nickname": "giesela"}, response.json["profiles"][0])
|
||||
self.assertDictContainsSubset({"total": 2}, response.json)
|
||||
self.assertDictContainsSubset({"nickname": "jutta"}, response.json["profiles"][0])
|
||||
self.assertDictContainsSubset({"nickname": "giesela"}, response.json["profiles"][1])
|
||||
|
||||
def test_find_php_franzosen(self):
|
||||
token = self.login("peter", "geheim")["token"]
|
||||
|
Loading…
Reference in New Issue
Block a user