Compare commits

..

1 Commits

Author SHA1 Message Date
7a72287c00
implement searchtopics
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2021-07-05 20:39:49 +02:00
9 changed files with 3 additions and 94 deletions

View File

@ -66,7 +66,6 @@ def seed(dev: bool):
peters_profile = Profile(nickname="peternichtlustig", peters_profile = Profile(nickname="peternichtlustig",
pronouns="Herr Dr. Dr.", pronouns="Herr Dr. Dr.",
volunteerwork="Gartenverein", volunteerwork="Gartenverein",
availability="Immer",
freetext="Ich mag Kaffee", freetext="Ich mag Kaffee",
user=peter) user=peter)
db.session.add(peters_profile) db.session.add(peters_profile)

View File

@ -2,5 +2,4 @@
# #
# SPDX-License-Identifier: AGPL-3.0-or-later # SPDX-License-Identifier: AGPL-3.0-or-later
from ki.handlers.find_profiles import find_profiles # noqa
from ki.handlers.update_profile import update_profile # noqa from ki.handlers.update_profile import update_profile # noqa

View File

@ -1,32 +0,0 @@
# SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
from flask import make_response, request
from ki.models import Profile
def find_profiles():
page = int(request.args.get("page", 1))
if page < 1:
return make_response({"messages": {"page": "Die angefragte Seite muss mindestens 1 sein"}}, 400)
page_size = int(request.args.get("page_size", 20))
if page_size > 100:
return make_response({"messages": {"page_size": "Die maximale Anzahl Einträge pro Seite beträgt 100"}}, 400)
offset = (page - 1) * page_size
query = Profile.query.filter(Profile.visible is True)
count = query.count()
db_profiles = query.limit(page_size).offset(offset).all()
api_profiles = []
for db_profile in db_profiles:
api_profiles.append(db_profile.to_dict())
return make_response({"total": count, "profiles": api_profiles})

View File

@ -135,7 +135,6 @@ def update_profile(user_id: int):
profile.pronouns = request.json.get("pronouns", "") profile.pronouns = request.json.get("pronouns", "")
profile.volunteerwork = request.json.get("volunteerwork", "") profile.volunteerwork = request.json.get("volunteerwork", "")
profile.availability = request.json.get("availability", "")
profile.freetext = request.json.get("freetext", "") profile.freetext = request.json.get("freetext", "")
profile.visible = request.json.get("visible", False) profile.visible = request.json.get("visible", False)

View File

@ -32,7 +32,6 @@ class Profile(db.Model):
pronouns = Column(String(25), default="") pronouns = Column(String(25), default="")
volunteerwork = Column(String(4000), default="") volunteerwork = Column(String(4000), default="")
freetext = Column(String(4000), default="") freetext = Column(String(4000), default="")
availability = Column(String(4000), default="")
visible = Column(Boolean, nullable=False, default=False) visible = Column(Boolean, nullable=False, default=False)
created = Column(DateTime, nullable=False, default=datetime.now) created = Column(DateTime, nullable=False, default=datetime.now)
updated = Column(DateTime, onupdate=datetime.now, nullable=False, default=datetime.now) updated = Column(DateTime, onupdate=datetime.now, nullable=False, default=datetime.now)
@ -50,7 +49,6 @@ class Profile(db.Model):
"nickname": self.nickname, "nickname": self.nickname,
"pronouns": self.pronouns, "pronouns": self.pronouns,
"volunteerwork": self.volunteerwork, "volunteerwork": self.volunteerwork,
"availability": self.availability,
"freetext": self.freetext, "freetext": self.freetext,
"visible": self.visible, "visible": self.visible,
"address": self.address.to_dict(), "address": self.address.to_dict(),

View File

@ -7,7 +7,6 @@ from flask import g, make_response, request, send_file
from functools import wraps from functools import wraps
from ki.auth import auth from ki.auth import auth
from ki.handlers import find_profiles as find_profiles_handler
from ki.handlers import update_profile as update_profile_handler from ki.handlers import update_profile as update_profile_handler
from ki.models import ContactType, Language, Skill, Token, User from ki.models import ContactType, Language, Skill, Token, User
from app import app from app import app
@ -144,12 +143,6 @@ def get_contacttypes():
return handle_completion_request(ContactType, "contacttypes") return handle_completion_request(ContactType, "contacttypes")
@app.route("/users/profiles")
@token_auth
def find_profiles():
return find_profiles_handler()
@app.route("/skills") @app.route("/skills")
@token_auth @token_auth
def get_skills(): def get_skills():

View File

@ -1,43 +0,0 @@
# SPDX-FileCopyrightText: WTF Kooperative eG <https://wtf-eg.de/>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
import unittest
from ki.test.ApiTest import ApiTest
class TestSkillsEndpoint(ApiTest):
def test_skills_options(self):
response = self.client.options("/skills")
self.assertEqual(response.status_code, 200)
self.assertIn("Access-Control-Allow-Origin", response.headers)
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
def test_get_skills1(self):
token = self.login("peter", "geheim")["token"]
response = self.client.get("/skills?search=p", headers={"Authorization": "Bearer " + token})
self.assertEqual(response.status_code, 200)
self.assertEqual(
{
"skills": [{
"id": 1,
"name": "PHP",
"icon_url": "/skills/1/icon"
}, {
"id": 10,
"name": "PostgreSQL",
"icon_url": "/skills/10/icon"
}, {
"id": 3,
"name": "Python",
"icon_url": "/skills/3/icon"
}]
}, response.json)
self.assertIn("Access-Control-Allow-Origin", response.headers)
self.assertEqual(response.headers["Access-Control-Allow-Origin"], "*")
if __name__ == "main":
unittest.main()

View File

@ -33,7 +33,6 @@ class TestProfileEndpoint(ApiTest):
data = { data = {
"pronouns": "Monsieur", "pronouns": "Monsieur",
"volunteerwork": "ja", "volunteerwork": "ja",
"availability": "Nie",
"freetext": "Hallo", "freetext": "Hallo",
"visible": True, "visible": True,
"address": { "address": {
@ -110,7 +109,6 @@ class TestProfileEndpoint(ApiTest):
profile = user.profile profile = user.profile
self.assertEqual("Monsieur", profile.pronouns) self.assertEqual("Monsieur", profile.pronouns)
self.assertEqual("ja", profile.volunteerwork) self.assertEqual("ja", profile.volunteerwork)
self.assertEqual("Nie", profile.availability)
self.assertEqual("Hallo", profile.freetext) self.assertEqual("Hallo", profile.freetext)
self.assertTrue(profile.visible) self.assertTrue(profile.visible)
@ -191,7 +189,6 @@ class TestProfileEndpoint(ApiTest):
"user_id": 1, "user_id": 1,
"nickname": "peternichtlustig", "nickname": "peternichtlustig",
"pronouns": "Herr Dr. Dr.", "pronouns": "Herr Dr. Dr.",
"availability": "Immer",
"freetext": "Ich mag Kaffee", "freetext": "Ich mag Kaffee",
"volunteerwork": "Gartenverein", "volunteerwork": "Gartenverein",
"visible": False, "visible": False,

View File

@ -1,8 +1,8 @@
"""Initial migration. """Initial migration.
Revision ID: 44b45a772abd Revision ID: 1e1b2be49756
Revises: Revises:
Create Date: 2021-07-06 21:19:44.217722 Create Date: 2021-07-05 20:36:04.047270
""" """
from alembic import op from alembic import op
@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic. # revision identifiers, used by Alembic.
revision = '44b45a772abd' revision = '1e1b2be49756'
down_revision = None down_revision = None
branch_labels = None branch_labels = None
depends_on = None depends_on = None
@ -34,7 +34,6 @@ def upgrade():
sa.Column('pronouns', sa.String(length=25), nullable=True), sa.Column('pronouns', sa.String(length=25), nullable=True),
sa.Column('volunteerwork', sa.String(length=4000), nullable=True), sa.Column('volunteerwork', sa.String(length=4000), nullable=True),
sa.Column('freetext', sa.String(length=4000), nullable=True), sa.Column('freetext', sa.String(length=4000), nullable=True),
sa.Column('availability', sa.String(length=4000), nullable=True),
sa.Column('visible', sa.Boolean(), nullable=False), sa.Column('visible', sa.Boolean(), nullable=False),
sa.Column('created', sa.DateTime(), nullable=False), sa.Column('created', sa.DateTime(), nullable=False),
sa.Column('updated', sa.DateTime(), nullable=False), sa.Column('updated', sa.DateTime(), nullable=False),