Skip to content

Commit

Permalink
global: use uow instead of explicit commit
Browse files Browse the repository at this point in the history
  • Loading branch information
utnapischtim committed Nov 3, 2024
1 parent 210c749 commit 97ba61c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
4 changes: 0 additions & 4 deletions invenio_banners/records/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ def update(cls, data, id):
# returned and this classmethod would be called
db.session.query(cls).filter_by(id=id).update(data)

db.session.commit()

@classmethod
def get(cls, id):
"""Get banner by its id."""
Expand Down Expand Up @@ -143,5 +141,3 @@ def disable_expired(cls):

for old in query.all():
old.active = False

db.session.commit()
15 changes: 10 additions & 5 deletions invenio_banners/services/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022-2023 CERN.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio-Banners is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -10,6 +11,7 @@
import distutils.util

import arrow
from invenio_db.uow import unit_of_work
from invenio_records_resources.services import RecordService
from invenio_records_resources.services.base import LinksTemplate
from invenio_records_resources.services.base.utils import map_search_params
Expand Down Expand Up @@ -81,7 +83,8 @@ def search(self, identity, params):
links_item_tpl=self.links_item_tpl,
)

def create(self, identity, data, raise_errors=True):
@unit_of_work()
def create(self, identity, data, raise_errors=True, uow=None):
"""Create a banner."""
self.require_permission(identity, "create")

Expand All @@ -99,17 +102,18 @@ def create(self, identity, data, raise_errors=True):
self, identity, banner, links_tpl=self.links_item_tpl, errors=errors
)

def delete(self, identity, id):
@unit_of_work()
def delete(self, identity, id, uow=None):
"""Delete a banner from database."""
self.require_permission(identity, "delete")

banner = self.record_cls.get(id)

self.record_cls.delete(banner)

return self.result_item(self, identity, banner, links_tpl=self.links_item_tpl)

def update(self, identity, id, data):
@unit_of_work()
def update(self, identity, id, data, uow=None):
"""Update a banner."""
self.require_permission(identity, "update")

Expand All @@ -131,7 +135,8 @@ def update(self, identity, id, data):
links_tpl=self.links_item_tpl,
)

def disable_expired(self, identity):
@unit_of_work()
def disable_expired(self, identity, uow=None):
"""Disable expired banners."""
self.require_permission(identity, "disable")
self.record_cls.disable_expired()
Expand Down

0 comments on commit 97ba61c

Please sign in to comment.