-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
162 additions
and
0 deletions.
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
25 changes: 25 additions & 0 deletions
25
src/main/java/mate/academy/rickandmorty/controller/RickAndMortyController.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,25 @@ | ||
package mate.academy.rickandmorty.controller; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import mate.academy.rickandmorty.model.Personage; | ||
import mate.academy.rickandmorty.repository.PersonageRepository; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController("/rick-and-morty") | ||
@RequiredArgsConstructor | ||
public class RickAndMortyController { | ||
private final PersonageRepository characterRepository; | ||
|
||
@GetMapping("/random-personage") | ||
public Object getRandomPersonage() { | ||
return characterRepository; | ||
} | ||
|
||
@GetMapping("/search") | ||
public List<Personage> getPersonageByName(@RequestParam String name) { | ||
return characterRepository.findAllByNameLike(name); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/mate/academy/rickandmorty/model/Personage.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,29 @@ | ||
package mate.academy.rickandmorty.model; | ||
|
||
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 | ||
@Data | ||
@Table(name = "personages") | ||
public class Personage { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "external_id", nullable = false) | ||
private Long externalId; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
|
||
@Column(nullable = false) | ||
private String status; | ||
|
||
private String gender; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/mate/academy/rickandmorty/repository/PersonageRepository.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.Personage; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PersonageRepository extends JpaRepository<Personage, Long> { | ||
List<Personage> findAllByNameLike(String name); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/mate/academy/rickandmorty/service/RickAndMortyApiService.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 org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class RickAndMortyApiService { | ||
|
||
} |
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 +1,9 @@ | ||
spring.datasource.url=jdbc:mysql://localhost/rick_and_morty?serverTimezone=UTC | ||
spring.datasource.username=root | ||
spring.datasource.password=1234 | ||
spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver | ||
|
||
spring.jpa.hibernate.ddl-auto=validate | ||
spring.jpa.show-sql=true | ||
|
||
spring.jpa.open-in-view=false |
33 changes: 33 additions & 0 deletions
33
src/main/resources/db/changelog/changes/01-create-characters-table.yaml
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,33 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: create-characters-table | ||
author: teract10s | ||
changes: | ||
- createTable: | ||
tableName: characters | ||
columns: | ||
- column: | ||
name: id | ||
type: bigint | ||
autoIncrement: true | ||
constraints: | ||
primaryKey: true | ||
nullable: false | ||
- column: | ||
name: external_id | ||
type: bigint | ||
constraints: | ||
nullable: false | ||
- column: | ||
name: name | ||
type: varchar(255) | ||
constraints: | ||
nullable: false | ||
- column: | ||
name: status | ||
type: varchar(255) | ||
constraints: | ||
nullable: false | ||
- column: | ||
name: gender | ||
type: varchar(255) |
8 changes: 8 additions & 0 deletions
8
src/main/resources/db/changelog/changes/02-rename-characters-to-personages.yaml
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 @@ | ||
databaseChangeLog: | ||
- changeSet: | ||
id: rename-characters-to-personages | ||
author: teract10s | ||
changes: | ||
- renameTable: | ||
oldTableName: characters | ||
newTableName: personages |
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,5 @@ | ||
databaseChangeLog: | ||
- include: | ||
file: db/changelog/changes/01-create-characters-table.yaml | ||
- include: | ||
file: db/changelog/changes/02-rename-characters-to-personages.yaml |
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,5 @@ | ||
url=jdbc:mysql://localhost/rick_and_morty?serverTimezone=UTC | ||
username=root | ||
password=1234 | ||
changeLogFile=db/changelog/db.changelog-master.yaml | ||
driver=com.mysql.cj.jdbc.Driver |