Skip to content

Commit

Permalink
Working code with commented feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-skill committed Jun 27, 2020
1 parent bc6967e commit 089e536
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 42 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ ext {
dependencies {
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-data-redis')
// implementation('org.springframework.boot:spring-boot-starter-data-redis')
implementation('org.springframework.boot:spring-boot-starter-data-rest')
implementation('org.springframework.boot:spring-boot-starter-hateoas')
implementation('org.springframework.boot:spring-boot-starter-quartz')
implementation('org.springframework.boot:spring-boot-starter-security')
implementation('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
// implementation('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')
implementation('org.springframework.cloud:spring-cloud-starter-netflix-hystrix')
implementation('org.springframework.cloud:spring-cloud-starter-netflix-ribbon')
implementation('org.springframework.cloud:spring-cloud-starter-sleuth')
implementation('org.springframework.cloud:spring-cloud-starter-zipkin')
// implementation('org.springframework.cloud:spring-cloud-starter-netflix-ribbon')
// implementation('org.springframework.cloud:spring-cloud-starter-sleuth')
// implementation('org.springframework.cloud:spring-cloud-starter-zipkin')
runtimeOnly('org.springframework.boot:spring-boot-devtools')
runtimeOnly('com.h2database:h2')
compileOnly('org.projectlombok:lombok')
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/pearl/controller/EmployeeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
Expand Down Expand Up @@ -58,4 +59,10 @@ public Employee deleteEmployee(@PathVariable Long id) {

}

@GetMapping(value = "/dump")
public List<Employee> addEmployee() {

return employeeService.createDump();
}

}
33 changes: 9 additions & 24 deletions src/main/java/com/pearl/model/Address.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.pearl.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

//@Embeddable
@Entity
@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Address {

@Id
Expand All @@ -15,28 +24,4 @@ public class Address {
private String street;
private String city;


public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getStreet() {
return street;
}

public void setStreet(String street) {
this.street = street;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/pearl/model/Employee.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Data
Expand All @@ -28,6 +29,6 @@ public class Employee {
private String mobile;

@OneToMany(cascade = CascadeType.ALL)
List<Address> addresses;
List<Address> addresses = new ArrayList<>();

}
1 change: 0 additions & 1 deletion src/main/java/com/pearl/repository/EmployeeRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
@Repository
public interface EmployeeRepository extends JpaRepository<Employee, Long> {


Iterable<Employee> findByFirstNameAndLastName(String firstName, String lastName);

Iterable<Employee> findByFirstName(String firstName);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/pearl/service/EmployeeService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.pearl.service;


import com.pearl.model.Address;
import com.pearl.model.Employee;
import com.pearl.repository.EmployeeRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
Expand All @@ -15,6 +20,7 @@ public class EmployeeService {

private EmployeeRepository employeeRepository;

Logger logger = LoggerFactory.getLogger(EmployeeService.class);
@Autowired
public EmployeeService(EmployeeRepository employeeRepository) {
this.employeeRepository = employeeRepository;
Expand Down Expand Up @@ -71,4 +77,31 @@ public Iterable<Employee> search(String firstName, String lastName) {
return null;
}

public List<Employee> createDump() {
int d = 99;
System.out.println("count"+ d);
for (int i = 9; i < d; i++) {
List<Address> addressList = new ArrayList<>();
for (int j = 1; j < 3; j++) {
Address address = Address.builder()
.city("city_" + j)
.street("street_" + j)
.build();
addressList.add(address);
}

Employee employee = Employee.builder()
.firstName("first_" + i)
.lastName("last_" + i)
.email("email_" + i)
.mobile("mobile_" + i)
.addresses(addressList)
.build();
logger.info("Employee :"+employee);
employeeRepository.save(employee);
logger.info("Employee saved successfully id: "+ employee.getId());
}

return employeeRepository.findAll();
}
}
Empty file.
28 changes: 17 additions & 11 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,34 @@ spring:
path: /h2
enabled: true
datasource:
url: jdbc:h2:mem:employee
url: jdbc:h2:mem:~/employee
# ;AUTO_SERVER=TRUE
driver-class-name: org.h2.Driver
platform: org.hibernate.dialect.H2Dialect
username: admin
password: admin
username: sa
password:

security:
basic:
enabled: false
user:
name: admin
password: admin

jpa:
show-sql: true
hibernate:
ddl-auto: update

eureka:
client:
service-url:
defaultZone: http://${eureka.instance.hostname}:${eureka.instance.port}/eureka/
instance:
hostname: localhost
port: 8761
banner:
image:
location: classpath:resources/bannername.txt
#eureka:
# client:
# service-url:
# defaultZone: http://${eureka.instance.hostname}:${eureka.instance.port}/eureka/
# instance:
# hostname: localhost
# port: 8761
server:
port: 8083

Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/bannername.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
88888b .88b d88. d8888b. db .d88b. db db d88888b d88888b .d8888. d88888b d8888b. db db d888888b .o88b. d88888b
88' 88'YbdP`88 88 `8D 88 .8P Y8. `8b d8' 88' 88' 88' YP 88' 88 `8D 88 88 `88' d8P Y8 88'
88ooooo 88 88 88 88oodD' 88 88 88 `8bd8' 88ooooo 88ooooo `8bo. 88ooooo 88oobY' Y8 8P 88 8P 88ooooo
88~~~~~ 88 88 88 88~~~ 88 88 88 88 88~~~~~ 88~~~~~ C8888D `Y8b. 88~~~~~ 88`8b `8b d8' 88 8b 88~~~~~
88. 88 88 88 88 88booo. `8b d8' 88 88. 88. db 8D 88. 88 `88. `8bd8' .88. Y8b d8 88.
Y88888P YP YP YP 88 Y88888P `Y88P' YP Y88888P Y88888P `8888Y' Y88888P 88 YD YP Y888888P `Y88P' Y88888P

0 comments on commit 089e536

Please sign in to comment.