Skip to content

Commit

Permalink
fix build after removing /supermarkets endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Nov 6, 2023
1 parent 60cf3cc commit 615d414
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import org.springframework.web.bind.annotation.RestController
@Tag(name = "Product", description = "All operations for supermarket products")
@RestController
@Log
class FlatProductController(
val alcoholController: AlcoholController,
val supermarketController: SupermarketController,
) {
class FlatProductController(val alcoholController: AlcoholController) {

private val acceptableDiscount = 75

Expand All @@ -38,17 +35,12 @@ class FlatProductController(
useCdn: Boolean,
): List<FlatProduct> {
val alcoholProductStore = alcoholController.alcohol(productCriteria, category, useCdn)
val supermarkets = supermarketController.supermarkets()

return alcoholProductStore.flatMap {
val supermarketStaticData =
supermarkets.firstOrNull { supermarket -> supermarket.name == it.supermarket }

it.products
?.map { product ->
FlatProduct(
supermarket = it.supermarket,
logo = supermarketStaticData?.logo,
name = product.name,
quantity = product.quantity,
price = product.price,
Expand Down Expand Up @@ -81,7 +73,6 @@ class FlatProductController(

data class FlatProduct(
val supermarket: String?,
val logo: String?,
val name: String,
val quantity: String?,
val price: Double?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.stefanbratanov.sofiasupermarketsapi.api
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import com.ninjasquad.springmockk.MockkBean
import com.stefanbratanov.sofiasupermarketsapi.model.Supermarket
import com.stefanbratanov.sofiasupermarketsapi.readResource
import io.mockk.every
import org.junit.jupiter.api.Test
Expand All @@ -27,28 +26,16 @@ internal class FlatProductControllerTest(@Autowired val mockMvc: MockMvc) {

@MockkBean private lateinit var alcoholController: AlcoholController

@MockkBean private lateinit var supermarketController: SupermarketController

@Test
fun `test getting alcohol products`() {
val alcohols = readResource("/api/alcohol/expected.json")
val beer = readResource("/api/alcohol/only-beer.json")
val expectedJson = readResource("/api/flat/expected.json")
val expectedBeer = readResource("/api/flat/expected-beer.json")

val supermarketStaticData =
Supermarket.values().map {
SupermarketController.SupermarketStaticData(
it.title,
"http://www.test.bg",
"http://${it.title.lowercase()}.bg",
)
}

every { alcoholController.alcohol(any(), null, true) } returns objectMapper.readValue(alcohols)
every { alcoholController.alcohol(any(), listOf("beer"), true) } returns
objectMapper.readValue(beer)
every { supermarketController.supermarkets() } returns supermarketStaticData

mockMvc
.perform(
Expand Down

This file was deleted.

22 changes: 0 additions & 22 deletions src/test/resources/api/expected-supermarkets.json

This file was deleted.

33 changes: 0 additions & 33 deletions src/test/resources/api/flat/expected-beer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[
{
"supermarket": "Billa",
"logo": "http://billa.bg",
"name": "Бира Загорка 0,5 л",
"quantity": null,
"price": 0.79,
Expand All @@ -12,7 +11,6 @@
},
{
"supermarket": "Billa",
"logo": "http://billa.bg",
"name": "Бира Budweiser 0,5 л",
"quantity": null,
"price": 1.69,
Expand All @@ -23,7 +21,6 @@
},
{
"supermarket": "Billa",
"logo": "http://billa.bg",
"name": "Бира Warsteiner 0,5 л",
"quantity": null,
"price": 1.79,
Expand All @@ -34,7 +31,6 @@
},
{
"supermarket": "Billa",
"logo": "http://billa.bg",
"name": "Бира Ариана 2 л Произход - България",
"quantity": null,
"price": 1.79,
Expand All @@ -45,7 +41,6 @@
},
{
"supermarket": "Kaufland",
"logo": "http://kaufland.bg",
"name": "Загорка ретро Светло пиво",
"quantity": "0,5 л",
"price": 0.89,
Expand All @@ -56,7 +51,6 @@
},
{
"supermarket": "Kaufland",
"logo": "http://kaufland.bg",
"name": "Каменица Светло пиво",
"quantity": "0,5 л кен",
"price": 0.79,
Expand All @@ -67,7 +61,6 @@
},
{
"supermarket": "Kaufland",
"logo": "http://kaufland.bg",
"name": "Бургаско Светло пиво",
"quantity": "2 л РЕТ",
"price": 1.79,
Expand All @@ -78,7 +71,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ПИРИНСКО буилка 500мл",
"quantity": null,
"price": 0.97,
Expand All @@ -89,7 +81,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ПИРИНСКО кен 500 мл",
"quantity": null,
"price": 1.01,
Expand All @@ -100,7 +91,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ПИРИНСКО АЙС кен 500мл",
"quantity": null,
"price": 1.09,
Expand All @@ -111,7 +101,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ПИРИНСКО кен безалкохолна 0.0% 500мл",
"quantity": null,
"price": 1.09,
Expand All @@ -122,7 +111,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира HEINEKEN кен 500 мл",
"quantity": null,
"price": 1.39,
Expand All @@ -133,7 +121,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира AMSTEL Premium 5% кен 500 мл",
"quantity": null,
"price": 1.52,
Expand All @@ -144,7 +131,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ПИРИНСКО 1.2л",
"quantity": null,
"price": 1.52,
Expand All @@ -155,7 +141,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира AMSTEL Premium 5% 1л",
"quantity": null,
"price": 1.77,
Expand All @@ -166,7 +151,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира АРИАНА 2л",
"quantity": null,
"price": 1.79,
Expand All @@ -177,7 +161,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира BARLEY",
"quantity": null,
"price": 0.75,
Expand All @@ -188,7 +171,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ШУМЕНСКО бутилка 330мл",
"quantity": null,
"price": 0.79,
Expand All @@ -199,7 +181,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ASTIKA кен 500мл",
"quantity": null,
"price": 1.05,
Expand All @@ -210,7 +191,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ARIANA Радлер Ягода, мента 0.0% 330мл",
"quantity": null,
"price": 1.05,
Expand All @@ -221,7 +201,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира АРИАНА Радлер Малина 0.0% 330мл",
"quantity": null,
"price": 1.09,
Expand All @@ -232,7 +211,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира АРИАНА Радлер Лимон 0.0% 330мл",
"quantity": null,
"price": 1.09,
Expand All @@ -243,7 +221,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира АРИАНА Радлер Портокал, Грейпфрут 0.0% 330мл",
"quantity": null,
"price": 1.09,
Expand All @@ -254,7 +231,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира БОЛЯРКА кен 500мл",
"quantity": null,
"price": 1.09,
Expand All @@ -265,7 +241,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ZAGORKA бутилка 500мл",
"quantity": null,
"price": 1.15,
Expand All @@ -276,7 +251,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ZAGORKA кен 500 мл",
"quantity": null,
"price": 1.19,
Expand All @@ -287,7 +261,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира АРИАНА кен 500 мл",
"quantity": null,
"price": 1.19,
Expand All @@ -298,7 +271,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ШУМЕНСКО 4.8% кен 500мл",
"quantity": null,
"price": 1.19,
Expand All @@ -309,7 +281,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира CESKA Koruna 4.1% кен 500мл",
"quantity": null,
"price": 1.19,
Expand All @@ -320,7 +291,6 @@
},
{
"supermarket": "T-Market",
"logo": "http://t-market.bg",
"name": "Бира ШУМЕНСКО бутилка 500мл",
"quantity": null,
"price": 1.19,
Expand All @@ -331,7 +301,6 @@
},
{
"supermarket": "Fantastico",
"logo": "http://fantastico.bg",
"name": "Бира SCHOFFERHOFER пшенична бутилка",
"quantity": "500 мл",
"price": 1.99,
Expand All @@ -342,7 +311,6 @@
},
{
"supermarket": "Fantastico",
"logo": "http://fantastico.bg",
"name": "Бира ЗАГОРКА кен",
"quantity": "500 мл",
"price": 0.79,
Expand All @@ -353,7 +321,6 @@
},
{
"supermarket": "Fantastico",
"logo": "http://fantastico.bg",
"name": "Бира ZATECKY HUS кен",
"quantity": "500 мл",
"price": 0.99,
Expand Down
Loading

0 comments on commit 615d414

Please sign in to comment.