forked from douglasofreitas/ifood-fullstack-test
-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 514402c
Showing
21 changed files
with
803 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### NetBeans ### | ||
nbproject/private/ | ||
build/ | ||
nbbuild/ | ||
dist/ | ||
nbdist/ | ||
.nb-gradle/ |
Binary file not shown.
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 @@ | ||
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip |
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 @@ | ||
ifood-fullstack-test |
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 @@ | ||
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.ifood</groupId> | ||
<artifactId>fullstack-demo</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>fullstack-demo-client-service</artifactId> | ||
|
||
</project> |
22 changes: 22 additions & 0 deletions
22
client-service/src/main/java/com/ifood/demo/ClientApplication.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,22 @@ | ||
package com.ifood.demo; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
import com.ifood.demo.client.ClientEventHandler; | ||
|
||
@SpringBootApplication | ||
@EnableJpaRepositories("com.ifood.demo") | ||
public class ClientApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(ClientApplication.class, args); | ||
} | ||
|
||
@Bean | ||
ClientEventHandler clientEventHandler() { | ||
return new ClientEventHandler(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
client-service/src/main/java/com/ifood/demo/client/Client.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 com.ifood.demo.client; | ||
|
||
import java.util.UUID; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import lombok.Data; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Entity | ||
@Data | ||
@RequiredArgsConstructor | ||
public class Client { | ||
|
||
private @Id @GeneratedValue UUID id; | ||
private final String name; | ||
private final String email; | ||
private final String phone; | ||
|
||
protected Client() { | ||
this(null, null, null); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
client-service/src/main/java/com/ifood/demo/client/ClientEventHandler.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,28 @@ | ||
package com.ifood.demo.client; | ||
|
||
import org.springframework.data.rest.core.annotation.HandleAfterCreate; | ||
import org.springframework.data.rest.core.annotation.HandleAfterDelete; | ||
import org.springframework.data.rest.core.annotation.HandleAfterSave; | ||
import org.springframework.data.rest.core.annotation.RepositoryEventHandler; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RepositoryEventHandler(Client.class) | ||
public class ClientEventHandler { | ||
|
||
@HandleAfterCreate | ||
public void handleClientCreate(Client c) { | ||
log.info("handleClientCreate: {}", c.getId()); | ||
} | ||
|
||
@HandleAfterSave | ||
public void handleClientSave(Client c) { | ||
log.info("handleClientSave: {}", c.getId()); | ||
} | ||
|
||
@HandleAfterDelete | ||
public void handleClientDelete(Client c) { | ||
log.info("handleClientDelete: {}", c.getId()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
client-service/src/main/java/com/ifood/demo/client/ClientRepository.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,21 @@ | ||
package com.ifood.demo.client; | ||
|
||
import java.util.Collection; | ||
import java.util.UUID; | ||
|
||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.data.rest.core.annotation.RestResource; | ||
|
||
|
||
public interface ClientRepository extends CrudRepository<Client, UUID> { | ||
|
||
@RestResource(path = "byName") | ||
Collection<Client> findByNameIgnoreCaseContaining(@Param("name") String name); | ||
|
||
@RestResource(path = "byPhone") | ||
Collection<Client> findByPhoneIgnoreCaseContaining(@Param("phone") String phone); | ||
|
||
@RestResource(path = "byEmail") | ||
Collection<Client> findByEmailIgnoreCaseContaining(@Param("email") String email); | ||
} |
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,2 @@ | ||
server.port=8081 | ||
spring.data.rest.basePath=/v1 |
38 changes: 38 additions & 0 deletions
38
client-service/src/test/java/com/ifood/demo/ClientApplicationTests.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,38 @@ | ||
package com.ifood.demo; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import com.ifood.demo.client.Client; | ||
import com.ifood.demo.client.ClientRepository; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class ClientApplicationTests { | ||
|
||
@Autowired | ||
ClientRepository clientRepository; | ||
|
||
@Test | ||
public void clientTest() { | ||
|
||
clientRepository.save(new Client("John Doe", "[email protected]", "12345678")); | ||
clientRepository.save(new Client("Mary Doe", "[email protected]", "12348765")); | ||
clientRepository.save(new Client("Billy Bob", "[email protected]", "11112345")); | ||
|
||
for (Client client : clientRepository.findAll()) { | ||
log.info("Hello {}", client.toString()); | ||
} | ||
|
||
for (Client client : clientRepository.findByNameIgnoreCaseContaining("doe")) { | ||
log.info("Hello 'Doe' {}", client.toString()); | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.