diff --git a/backend/src/main/java/bg/kidsground/domain/AgeGroup.java b/backend/src/main/java/bg/kidsground/domain/AgeGroup.java index 4b1d0a9..f1fcc16 100644 --- a/backend/src/main/java/bg/kidsground/domain/AgeGroup.java +++ b/backend/src/main/java/bg/kidsground/domain/AgeGroup.java @@ -1,5 +1,7 @@ package bg.kidsground.domain; +import com.fasterxml.jackson.annotation.JsonValue; + public enum AgeGroup { ZERO_TO_THREE("zero_to_three"), @@ -12,4 +14,9 @@ public enum AgeGroup { AgeGroup(String value) { this.value = value; } + + @JsonValue + public String getValue() { + return value; + } } diff --git a/backend/src/main/java/bg/kidsground/domain/Environment.java b/backend/src/main/java/bg/kidsground/domain/Environment.java index f914195..ad0433c 100644 --- a/backend/src/main/java/bg/kidsground/domain/Environment.java +++ b/backend/src/main/java/bg/kidsground/domain/Environment.java @@ -1,5 +1,7 @@ package bg.kidsground.domain; +import com.fasterxml.jackson.annotation.JsonValue; + public enum Environment { BOULEVARD("boulevard"), @@ -11,4 +13,9 @@ public enum Environment { Environment(final String value){ this.value = value; } + + @JsonValue + public String getValue() { + return value; + } } diff --git a/backend/src/main/java/bg/kidsground/domain/FloorType.java b/backend/src/main/java/bg/kidsground/domain/FloorType.java index 90c1faa..fb44406 100644 --- a/backend/src/main/java/bg/kidsground/domain/FloorType.java +++ b/backend/src/main/java/bg/kidsground/domain/FloorType.java @@ -1,5 +1,7 @@ package bg.kidsground.domain; +import com.fasterxml.jackson.annotation.JsonValue; + public enum FloorType { ASPHALT("asphalt"), GRASS("grass"), @@ -12,4 +14,9 @@ public enum FloorType { FloorType(String value) { this.value = value; } + + @JsonValue + public String getValue() { + return value; + } } diff --git a/backend/src/main/java/bg/kidsground/domain/Playground.java b/backend/src/main/java/bg/kidsground/domain/Playground.java index ec5d411..ad314ec 100644 --- a/backend/src/main/java/bg/kidsground/domain/Playground.java +++ b/backend/src/main/java/bg/kidsground/domain/Playground.java @@ -35,39 +35,30 @@ public class Playground { private FloorType floorType; @JsonProperty("shade_type") + @Enumerated(EnumType.STRING) private ShadeType shadeType; @JsonProperty("environment") - private String environment; + @Enumerated(EnumType.STRING) + private Environment environment; @JsonProperty("transport") + @ElementCollection private List transport; @JsonProperty("toys") + @ElementCollection private List toys; @JsonProperty("facilities") + @ElementCollection private List facilities; @JsonProperty("image_links") + @ElementCollection private List imageLinks; @JsonProperty("coordinates") private Coordinates coordinates; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } } diff --git a/backend/src/main/java/bg/kidsground/domain/ShadeType.java b/backend/src/main/java/bg/kidsground/domain/ShadeType.java index d41f027..5113ef1 100644 --- a/backend/src/main/java/bg/kidsground/domain/ShadeType.java +++ b/backend/src/main/java/bg/kidsground/domain/ShadeType.java @@ -1,5 +1,7 @@ package bg.kidsground.domain; +import com.fasterxml.jackson.annotation.JsonValue; + public enum ShadeType { TREES("trees"), @@ -11,4 +13,9 @@ public enum ShadeType { ShadeType(String value) { this.value = value; } + + @JsonValue + public String getValue() { + return value; + } } diff --git a/backend/src/test/java/bg/kidsground/controller/PlaygroundControllerTest.java b/backend/src/test/java/bg/kidsground/controller/PlaygroundControllerTest.java index 00a08d7..57d76ef 100644 --- a/backend/src/test/java/bg/kidsground/controller/PlaygroundControllerTest.java +++ b/backend/src/test/java/bg/kidsground/controller/PlaygroundControllerTest.java @@ -1,7 +1,12 @@ package bg.kidsground.controller; import bg.kidsground.constants.AppRestEndpoints; +import bg.kidsground.domain.AgeGroup; +import bg.kidsground.domain.Coordinates; +import bg.kidsground.domain.Environment; +import bg.kidsground.domain.FloorType; import bg.kidsground.domain.Playground; +import bg.kidsground.domain.ShadeType; import bg.kidsground.service.PlaygroundService; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; @@ -13,6 +18,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import java.util.List; import java.util.NoSuchElementException; import static org.mockito.ArgumentMatchers.any; @@ -39,8 +45,9 @@ void setUp() { @Test public void testSavePlayground() throws Exception { - Playground playground = new Playground(); // You need to create a Playground object here with appropriate data + Playground playground = new Playground(); playground.setName("Test Playground"); + playground.setAgeGroup(AgeGroup.THREE_TO_SIX); ObjectMapper objectMapper = new ObjectMapper(); String playgroundJson = objectMapper.writeValueAsString(playground); @@ -59,6 +66,15 @@ public void testGetPlaygroundById() throws Exception { Playground playground = new Playground(); // You need to create a Playground object here with appropriate data playground.setId(id); playground.setName(name); + playground.setAgeGroup(AgeGroup.THREE_TO_SIX); + playground.setCoordinates(Coordinates.builder().latitude(10.2).longitude(20.1).build()); + playground.setFacilities(List.of("пързалка", "люлка")); + playground.setFloorType(FloorType.RUBBER); + playground.setEnvironment(Environment.APARTMENTS); + playground.setHasFence(true); + playground.setToys(List.of("конче")); + playground.setImageLinks(List.of("https://example.com/image")); + playground.setShadeType(ShadeType.TREES); when(playgroundService.getById(id)).thenReturn(playground); @@ -66,7 +82,18 @@ public void testGetPlaygroundById() throws Exception { .andExpect(status().isOk()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.id").value(id)) - .andExpect(jsonPath("$.name").value(name)); + .andExpect(jsonPath("$.name").value(name)) + .andExpect(jsonPath("$.age_group").value("three_to_six")) + .andExpect(jsonPath("$.coordinates.lat").value(10.2)) + .andExpect(jsonPath("$.coordinates.lng").value(20.1)) + .andExpect(jsonPath("$.facilities[0]").value("пързалка")) + .andExpect(jsonPath("$.facilities[1]").value("люлка")) + .andExpect(jsonPath("$.toys[0]").value("конче")) + .andExpect(jsonPath("$.image_links").value("https://example.com/image")) + .andExpect(jsonPath("$.floor_type").value("rubber")) + .andExpect(jsonPath("$.shade_type").value("trees")) + .andExpect(jsonPath("$.has_fence").value(true)) + .andExpect(jsonPath("$.environment").value("apartments")); verify(playgroundService).getById(id); }