-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented task #49
Closed
Closed
Implemented task #49
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ef4b559
added initial Ñstagemodel, controller andd service
OlegMR0 df10730
added few dto
OlegMR0 0851498
added repository
OlegMR0 19341ed
partly implemented service, added some improvements
OlegMR0 b8d4e51
added mapper
OlegMR0 d799aee
added swagger, fully implemented task
OlegMR0 e974f31
fixed incompatible dependencies
OlegMR0 3e6f470
added source directory to checkstyle build config
OlegMR0 7c9f811
added source directory to checkstyle build config
OlegMR0 00d39fb
fixed directory path
OlegMR0 2b4d664
added few fixes
OlegMR0 eddd62c
reworked getRandomCharacter method logic, changed return type
OlegMR0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,140 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.1.4</version> | ||
<relativePath/> | ||
</parent> | ||
<groupId>mate.academy</groupId> | ||
<artifactId>jv-rick-and-morty</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>jv-rick-and-morty</name> | ||
<description>jv-rick-and-morty</description> | ||
<properties> | ||
<java.version>17</java.version> | ||
<maven.checkstyle.plugin.version>3.1.1</maven.checkstyle.plugin.version> | ||
<maven.checkstyle.plugin.configLocation> | ||
https://raw.githubusercontent.com/mate-academy/style-guides/master/java/checkstyle.xml | ||
</maven.checkstyle.plugin.configLocation> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
<version>3.3.0</version> | ||
<executions> | ||
<execution> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<configLocation>${maven.checkstyle.plugin.configLocation}</configLocation> | ||
<consoleOutput>true</consoleOutput> | ||
<failsOnError>true</failsOnError> | ||
<linkXRef>false</linkXRef> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>3.1.4</version> | ||
<relativePath/> | ||
</parent> | ||
<groupId>mate.academy</groupId> | ||
<artifactId>jv-rick-and-morty</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>jv-rick-and-morty</name> | ||
<description>jv-rick-and-morty</description> | ||
<properties> | ||
|
||
<java.version>17</java.version> | ||
<maven.checkstyle.plugin.version>3.1.1</maven.checkstyle.plugin.version> | ||
<maven.checkstyle.plugin.configLocation> | ||
https://raw.githubusercontent.com/mate-academy/style-guides/master/java/checkstyle.xml | ||
</maven.checkstyle.plugin.configLocation> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
|
||
</properties> | ||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.springdoc</groupId> | ||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> | ||
<version>2.2.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>mapstruct</artifactId> | ||
<version>1.5.5.Final</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.28</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.mysql</groupId> | ||
<artifactId>mysql-connector-j</artifactId> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>3.1.3</version> | ||
</dependency> | ||
|
||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>2.15.2</version> | ||
</dependency> | ||
|
||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.28</version> | ||
</path> | ||
<path> | ||
<groupId>org.mapstruct</groupId> | ||
<artifactId>mapstruct-processor</artifactId> | ||
<version>1.5.5.Final</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
<version>3.3.0</version> | ||
<executions> | ||
<execution> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>check</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<configLocation>${maven.checkstyle.plugin.configLocation}</configLocation> | ||
<consoleOutput>true</consoleOutput> | ||
<failsOnError>true</failsOnError> | ||
<linkXRef>false</linkXRef> | ||
<sourceDirectories>src/main</sourceDirectories> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
39 changes: 39 additions & 0 deletions
39
src/main/java/mate/academy/rickandmorty/controller/CharacterController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package mate.academy.rickandmorty.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import mate.academy.rickandmorty.dto.internal.CharacterDto; | ||
import mate.academy.rickandmorty.service.CharacterService; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "Rick and Morty API") | ||
@RestController | ||
@RequestMapping("/api/characters") | ||
@AllArgsConstructor | ||
public class CharacterController { | ||
private CharacterService characterService; | ||
|
||
@Operation(summary = "Get all available characters.") | ||
@GetMapping | ||
public List<CharacterDto> getCharacters() { | ||
return characterService.getAll(); | ||
} | ||
|
||
@Operation(summary = "Find characters by specific name.") | ||
@GetMapping("/search") | ||
public List<CharacterDto> getCharactersByName(String name) { | ||
return characterService.getCharactersByName(name); | ||
} | ||
|
||
@Operation(summary = "Generate and save random existing character.") | ||
@GetMapping("/random") | ||
public CharacterDto getRandomCharacter() { | ||
CharacterDto character = characterService.getRandomCharacter(); | ||
return character; | ||
|
||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/mate/academy/rickandmorty/dto/external/CharacterResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package mate.academy.rickandmorty.dto.external; | ||
|
||
import java.util.List; | ||
import lombok.Data; | ||
import mate.academy.rickandmorty.model.Character; | ||
|
||
@Data | ||
public class CharacterResponseDto { | ||
private ResponseMetadataDto info; | ||
private List<Character> results; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/mate/academy/rickandmorty/dto/external/ResponseMetadataDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package mate.academy.rickandmorty.dto.external; | ||
|
||
import java.math.BigDecimal; | ||
import lombok.Data; | ||
|
||
@Data | ||
public class ResponseMetadataDto { | ||
private BigDecimal count; | ||
private BigDecimal pages; | ||
private String next; | ||
private String prev; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/mate/academy/rickandmorty/dto/internal/CharacterDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package mate.academy.rickandmorty.dto.internal; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class CharacterDto { | ||
private Long id; | ||
private String name; | ||
private String status; | ||
private String gender; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/mate/academy/rickandmorty/dto/mapper/CharacterMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package mate.academy.rickandmorty.dto.mapper; | ||
|
||
import java.util.List; | ||
import mate.academy.rickandmorty.dto.internal.CharacterDto; | ||
import mate.academy.rickandmorty.model.Character; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
|
||
@Mapper(componentModel = "spring") | ||
public interface CharacterMapper { | ||
|
||
@Mapping(target = "id", source = "externalId") | ||
CharacterDto characterToCharacterDto(Character character); | ||
|
||
List<CharacterDto> map(List<Character> characters); | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/mate/academy/rickandmorty/model/Character.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package mate.academy.rickandmorty.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonGetter; | ||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.Data; | ||
|
||
@Entity | ||
@Table(name = "characters") | ||
@Data | ||
public class Character { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long internalId; | ||
@JsonSetter("id") | ||
private Long externalId; | ||
private String name; | ||
private String status; | ||
private String gender; | ||
|
||
@JsonGetter("id") | ||
public Long getInternalId() { | ||
return internalId; | ||
} | ||
|
||
@JsonGetter("externalId") | ||
public Long getExternalId() { | ||
return externalId; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/mate/academy/rickandmorty/repository/CharacterRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package mate.academy.rickandmorty.repository; | ||
|
||
import java.util.List; | ||
import mate.academy.rickandmorty.model.Character; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CharacterRepository extends JpaRepository<Character, Long> { | ||
List<Character> findByNameContaining(String name); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/mate/academy/rickandmorty/service/CharacterClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package mate.academy.rickandmorty.service; | ||
|
||
import java.util.List; | ||
import mate.academy.rickandmorty.model.Character; | ||
|
||
public interface CharacterClient { | ||
List<Character> getCharacters(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you ever heard about YAGNI?