Skip to content

Commit

Permalink
feat: update slot operator controller (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras authored Apr 22, 2024
1 parent 93ef114 commit cf09d80
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ public PageResult<Slot> findByCriteria(SlotSearchCriteria criteria) {
}
}

public Slot findByProductNameAppId(String productName, String appId) {
public Slot findByProductNameAppId(String productName, String appId, String name) {
try {
var cb = this.getEntityManager().getCriteriaBuilder();
var cq = cb.createQuery(Slot.class);
var root = cq.from(Slot.class);
cq.where(cb.and(
cb.equal(root.get(Slot_.APP_ID), appId),
cb.equal(root.get(Slot_.NAME), name),
cb.equal(root.get(Slot_.PRODUCT_NAME), productName)));
return this.getEntityManager().createQuery(cq).getSingleResult();
} catch (NoResultException nre) {
return null;
} catch (Exception ex) {
throw new DAOException(ErrorKeys.ERROR_FIND_SLOT_PRODUCT_NAME_APP_ID, ex, appId);
throw new DAOException(ErrorKeys.ERROR_FIND_SLOT_PRODUCT_NAME_APP_ID_NAME, ex, appId);
}
}

Expand Down Expand Up @@ -98,7 +99,7 @@ public void deleteByProductName(String productName) {
public enum ErrorKeys {
ERROR_UPDATE_BY_PRODUCT_NAME,
ERROR_DELETE_BY_PRODUCT_NAME,
ERROR_FIND_SLOT_PRODUCT_NAME_APP_ID,
ERROR_FIND_SLOT_PRODUCT_NAME_APP_ID_NAME,
ERROR_FIND_SLOTS_BY_CRITERIA,

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class OperatorSlotRestControllerV1 implements OperatorSlotApi {
@Override
public Response createOrUpdateSlot(String productName, String appId,
UpdateSlotRequestSlotDTOv1 updateSlotRequestSlotDTOv1) {
var ms = dao.findByProductNameAppId(productName, appId);
var ms = dao.findByProductNameAppId(productName, appId, updateSlotRequestSlotDTOv1.getName());
if (ms == null) {
ms = mapper.create(updateSlotRequestSlotDTOv1);
ms.setAppId(appId);
Expand Down
2 changes: 2 additions & 0 deletions src/main/openapi/onecx-product-store-operator-slot-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ components:
type: string
UpdateSlotRequest:
type: object
required:
- name
properties:
description:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ void beforeAll() {

@Test
void methodExceptionTests() {
methodExceptionTests(() -> dao.findByProductNameAppId("test", "test"),
SlotDAO.ErrorKeys.ERROR_FIND_SLOT_PRODUCT_NAME_APP_ID);
methodExceptionTests(() -> dao.findByProductNameAppId("test", "test", "test"),
SlotDAO.ErrorKeys.ERROR_FIND_SLOT_PRODUCT_NAME_APP_ID_NAME);
methodExceptionTests(() -> dao.findByCriteria(null),
SlotDAO.ErrorKeys.ERROR_FIND_SLOTS_BY_CRITERIA);
methodExceptionTests(() -> dao.deleteByProductName(null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class OperatorSlotRestControllerV1ExceptionTest extends AbstractTest {

@BeforeEach
void beforeAll() {
Mockito.when(dao.findByProductNameAppId(any(), any()))
Mockito.when(dao.findByProductNameAppId(any(), any(), any()))
.thenThrow(new RuntimeException("Test technical error exception"))
.thenThrow(new DAOException(SlotDAO.ErrorKeys.ERROR_FIND_SLOT_PRODUCT_NAME_APP_ID,
.thenThrow(new DAOException(SlotDAO.ErrorKeys.ERROR_FIND_SLOT_PRODUCT_NAME_APP_ID_NAME,
new RuntimeException("Test")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void createSlotTest() {
@Test
void updateSlotTest() {
var dto = new UpdateSlotRequestSlotDTOv1();
dto.name("display-name");
dto.name("slot1");
dto.description("description");

given()
Expand Down

0 comments on commit cf09d80

Please sign in to comment.