Skip to content

Commit

Permalink
remove prints
Browse files Browse the repository at this point in the history
  • Loading branch information
legatusL committed Nov 21, 2023
1 parent 20fd068 commit 32f94e3
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 5 deletions.
6 changes: 5 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
A_KEY = "5a5eee010163426c5475191847949825467de6ecb148e44763661c9cc62e35b7"

op = OpenProject(url="https://192.168.102.178:8080", api_key=A_KEY)
user = op.get_notification_service().find_all()
#user = op.get_notification_service().find_all(filters=[{ "readIAN": { "operator": "=", "values": ["f"] } }])
#user = op.get_notification_service().find('189')
#user = op.get_notification_service().read_all(filters=[{ "reason": { "operator": "=", "values": ["mentioned"] } }])
#user = op.get_notification_service().unread_all()

print(user)
23 changes: 23 additions & 0 deletions pyopenproject/business/services/command/notification/find.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from pyopenproject.api_connection.exceptions.request_exception import RequestError
from pyopenproject.api_connection.requests.get_request import GetRequest
from pyopenproject.business.exception.business_error import BusinessError
from pyopenproject.business.services.command.find_list_command import FindListCommand
from pyopenproject.business.services.command.notification.notification_command import NotificationCommand
from pyopenproject.model.notification import Notification


class Find(NotificationCommand):

def __init__(self, connection, notification_id):
super().__init__(connection)
self.notification_id = notification_id

def execute(self):
try:
json_obj = GetRequest(
self.connection, f"{self.CONTEXT}/{self.notification_id}",).execute()
return Notification(json_obj)

except RequestError as re:
raise BusinessError(
f"Error finding notifications:{re.args}")
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def execute(self):
"pageSize", self.page_size),
])
))
print(request)
return FindListCommand(self.connection, request, Notification).execute()

except RequestError as re:
Expand Down
26 changes: 26 additions & 0 deletions pyopenproject/business/services/command/notification/read.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pyopenproject.api_connection.exceptions.request_exception import RequestError
from pyopenproject.api_connection.requests.post_request import PostRequest
from pyopenproject.business.exception.business_error import BusinessError
from pyopenproject.business.services.command.notification.notification_command import NotificationCommand
from pyopenproject.model.notification import Notification
import json


class Read(NotificationCommand):

def __init__(self, connection, notification_id, filters):
super().__init__(connection)
self.filters = json.dumps({'filters': filters})
self.notification_id = notification_id

def execute(self):
try:
response = PostRequest(connection=self.connection,
headers={
"Content-Type": "application/json"},
context=f"{self.CONTEXT}/{self.notification_id}/read_ian",
json=self.filters).execute()
return response
except RequestError as re:
raise BusinessError(
f"Error creating project form: {self.form.name}") from re
26 changes: 26 additions & 0 deletions pyopenproject/business/services/command/notification/read_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pyopenproject.api_connection.exceptions.request_exception import RequestError
from pyopenproject.api_connection.requests.post_request import PostRequest
from pyopenproject.business.exception.business_error import BusinessError
from pyopenproject.business.services.command.find_list_command import FindListCommand
from pyopenproject.business.services.command.notification.notification_command import NotificationCommand
from pyopenproject.model.notification import Notification
import json


class ReadAll(NotificationCommand):

def __init__(self, connection, filters):
super().__init__(connection)
self.filters = json.dumps([{'filters':filters}])

def execute(self):
try:
response = PostRequest(connection=self.connection,
headers={
"Content-Type": "application/json"},
context=f"{self.CONTEXT}/read_ian",
json=self.filters).execute()
return response
except RequestError as re:
raise BusinessError(
f"Error creating project form: {self.form.name}") from re
26 changes: 26 additions & 0 deletions pyopenproject/business/services/command/notification/unread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from pyopenproject.api_connection.exceptions.request_exception import RequestError
from pyopenproject.api_connection.requests.post_request import PostRequest
from pyopenproject.business.exception.business_error import BusinessError
from pyopenproject.business.services.command.notification.notification_command import NotificationCommand
from pyopenproject.model.notification import Notification
import json


class UnRead(NotificationCommand):

def __init__(self, connection, notification_id, filters):
super().__init__(connection)
self.filters = json.dumps({'filters': filters})
self.notification_id = notification_id

def execute(self):
try:
response = PostRequest(connection=self.connection,
headers={
"Content-Type": "application/json"},
context=f"{self.CONTEXT}/{self.notification_id}/unread_ian",
json=self.filters).execute()
return response
except RequestError as re:
raise BusinessError(
f"Error creating project form: {self.form.name}") from re
25 changes: 25 additions & 0 deletions pyopenproject/business/services/command/notification/unread_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pyopenproject.api_connection.exceptions.request_exception import RequestError
from pyopenproject.api_connection.requests.post_request import PostRequest
from pyopenproject.business.exception.business_error import BusinessError
from pyopenproject.business.services.command.notification.notification_command import NotificationCommand
from pyopenproject.model.notification import Notification
import json


class UnReadAll(NotificationCommand):

def __init__(self, connection, filters):
super().__init__(connection)
self.filters = json.dumps({'filters':filters})

def execute(self):
try:
response = PostRequest(connection=self.connection,
headers={
"Content-Type": "application/json"},
context=f"{self.CONTEXT}/unread_ian",
json=self.filters).execute()
return response
except RequestError as re:
raise BusinessError(
f"Error creating project form: {self.form.name}") from re
8 changes: 5 additions & 3 deletions pyopenproject/business/util/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pyopenproject.business.util.url_parameter import URLParameter
import urllib
import json


class Filters(URLParameter):

def __init__(self, value):
Expand Down Expand Up @@ -28,6 +30,6 @@ def __str__(self) -> str:
# output += "]}}"
# output += "," if len(self.value) != 1 and i != len(self.value)-1 else ""
# output += "]"
params = urllib.parse.quote_plus(json.dumps(self.value,separators=(',', ':')))
return f"filters={params}"

params = urllib.parse.quote_plus(
json.dumps(self.value, separators=(',', ':')))
return f"{self.name}={params}"

0 comments on commit 32f94e3

Please sign in to comment.