Skip to content

Commit

Permalink
fix : issue with JOOQ mapping to field
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Oct 16, 2023
1 parent 76b34ee commit dcb0d45
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public class Inventory {
@Column(name = "quantity")
private Integer availableQuantity = 0;

@Column(name = "reserved_items")
private Integer reservedItems = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Licensed under MIT License Copyright (c) 2021-2022 Raja Kolli.
package com.example.inventoryservice.mapper;

import com.example.inventoryservice.entities.Inventory;
import com.example.inventoryservice.model.response.request.InventoryRequest;
import com.example.inventoryservice.model.request.InventoryRequest;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
Expand All @@ -18,9 +18,9 @@ public interface InventoryMapper {

@Mapping(target = "id", ignore = true)
@Mapping(target = "reservedItems", ignore = true)
Inventory toEntity(InventoryRequest inventoryDto);
Inventory toEntity(InventoryRequest inventoryRequest);

@InheritConfiguration
void updateInventoryFromRequest(
InventoryRequest inventoryDto, @MappingTarget Inventory inventory);
InventoryRequest inventoryRequest, @MappingTarget Inventory inventory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Licensed under MIT License Copyright (c) 2021-2022 Raja Kolli.
</p>
***/

package com.example.inventoryservice.model.response.request;
package com.example.inventoryservice.model.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.PositiveOrZero;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.
import com.example.inventoryservice.config.logging.Loggable;
import com.example.inventoryservice.entities.Inventory;
import com.example.inventoryservice.mapper.InventoryMapper;
import com.example.inventoryservice.model.request.InventoryRequest;
import com.example.inventoryservice.model.response.PagedResult;
import com.example.inventoryservice.model.response.request.InventoryRequest;
import com.example.inventoryservice.repositories.InventoryJOOQRepository;
import com.example.inventoryservice.repositories.InventoryRepository;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.
package com.example.inventoryservice.web.controllers;

import com.example.inventoryservice.entities.Inventory;
import com.example.inventoryservice.model.request.InventoryRequest;
import com.example.inventoryservice.model.response.PagedResult;
import com.example.inventoryservice.model.response.request.InventoryRequest;
import com.example.inventoryservice.services.InventoryService;
import com.example.inventoryservice.utils.AppConstants;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.

import com.example.inventoryservice.common.AbstractIntegrationTest;
import com.example.inventoryservice.entities.Inventory;
import com.example.inventoryservice.model.response.request.InventoryRequest;
import com.example.inventoryservice.model.request.InventoryRequest;
import com.example.inventoryservice.repositories.InventoryRepository;
import java.util.List;
import org.instancio.Instancio;
Expand Down Expand Up @@ -68,7 +68,9 @@ void shouldFindInventoryByProductCode() throws Exception {
this.mockMvc
.perform(get("/api/inventory/{productCode}", productCode))
.andExpect(status().isOk())
.andExpect(jsonPath("$.productCode", is(inventory.getProductCode())));
.andExpect(jsonPath("$.productCode", is(inventory.getProductCode())))
.andExpect(jsonPath("$.availableQuantity").value(inventory.getAvailableQuantity()))
.andExpect(jsonPath("$.reservedItems").value(inventory.getReservedItems()));
}

@Test
Expand Down Expand Up @@ -144,7 +146,8 @@ void shouldUpdateInventory() throws Exception {
.content(objectMapper.writeValueAsString(inventoryRequest)))
.andExpect(status().isOk())
.andExpect(jsonPath("$.productCode", is(inventory.getProductCode())))
.andExpect(jsonPath("$.availableQuantity", is(1000)));
.andExpect(jsonPath("$.availableQuantity", is(1000)))
.andExpect(jsonPath("$.reservedItems").value(inventory.getReservedItems()));
}

@Test
Expand All @@ -154,6 +157,8 @@ void shouldDeleteInventory() throws Exception {
this.mockMvc
.perform(delete("/api/inventory/{id}", inventory.getId()))
.andExpect(status().isOk())
.andExpect(jsonPath("$.productCode", is(inventory.getProductCode())));
.andExpect(jsonPath("$.productCode", is(inventory.getProductCode())))
.andExpect(jsonPath("$.availableQuantity", is(inventory.getAvailableQuantity())))
.andExpect(jsonPath("$.reservedItems").value(inventory.getReservedItems()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import com.example.inventoryservice.entities.Inventory;
import com.example.inventoryservice.model.request.InventoryRequest;
import com.example.inventoryservice.model.response.PagedResult;
import com.example.inventoryservice.model.response.request.InventoryRequest;
import com.example.inventoryservice.services.InventoryService;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.List;
Expand Down

0 comments on commit dcb0d45

Please sign in to comment.