Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrooshika-nomad committed Nov 13, 2017
0 parents commit 514402c
Show file tree
Hide file tree
Showing 21 changed files with 803 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .gitignore
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 added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions .mvn/wrapper/maven-wrapper.properties
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ifood-fullstack-test
12 changes: 12 additions & 0 deletions client-service/pom.xml
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 client-service/src/main/java/com/ifood/demo/ClientApplication.java
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 client-service/src/main/java/com/ifood/demo/client/Client.java
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);
}
}
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());
}
}
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);
}
2 changes: 2 additions & 0 deletions client-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server.port=8081
spring.data.rest.basePath=/v1
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());
}

}
}
Loading

0 comments on commit 514402c

Please sign in to comment.