Skip to content

Commit

Permalink
fix problems and add Swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
silchenko-arsen committed Oct 20, 2023
1 parent 692b371 commit 42be6d6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mate.academy.rickandmorty.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import mate.academy.rickandmorty.dto.CharacterDto;
import mate.academy.rickandmorty.service.CharacterService;
Expand All @@ -10,18 +12,23 @@

import java.util.List;

@Tag(name = "Character management", description = "Endpoints for getting characters from db")
@RequiredArgsConstructor
@RestController
@RequestMapping("/api")
public class CharacterController {
private final CharacterService characterService;

@GetMapping("/randomCharacter")
@Operation(summary = "Get random character",
description = "Get a random characters from Rick and Morty world")
@GetMapping("/random")
public CharacterDto getRandomCharacter() {
return characterService.getRandomCharacter();
}

@GetMapping("/searchCharacter")
@GetMapping("/search")
@Operation(summary = "Search characters by name's part",
description = "Search characters by name's part")
public List<CharacterDto> searchCharacter(@RequestParam String name) {
return characterService.findByName(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
public class ListCharacterDto {
private List<CharacterResponseDto> characterResponseDto;
private List<CharacterResponseDto> results;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public List<CharacterResponseDto> getCharacters() {
.send(request, HttpResponse.BodyHandlers.ofString());
ListCharacterDto listCharacterDto = objectMapper
.readValue(response.body(), ListCharacterDto.class);
return listCharacterDto.getCharacterResponseDto();
return listCharacterDto.getResults();
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 42be6d6

Please sign in to comment.