Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
Expand Down Expand Up @@ -107,6 +108,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -118,6 +120,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
package com.example.restapidevelopment;

import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

import com.example.restapidevelopment.config.DummyData;
import com.example.restapidevelopment.repo.EmpRepository;
import com.example.restapidevelopment.entity.Car;
import com.example.restapidevelopment.entity.Emp;
import com.example.restapidevelopment.entity.Person;
import com.example.restapidevelopment.repo.CarRepository;
import com.example.restapidevelopment.repo.EmpRepository;
import com.example.restapidevelopment.repo.PersonRepository;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

import java.util.Arrays;
import java.util.List;

/**
* http://localhost:8384/swagger-ui.html <i>swagger home page</i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ public static List<Person> getPeople() throws IOException {
return personList;
}

public static List<Person> getPeoplev2() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
ClassLoader classLoader = DummyData.class.getClassLoader();
//using file
File file = new File(classLoader.getResource("peoplev2.json").getFile());
List<Person> personList = objectMapper.readValue(file, new TypeReference<List<Person>>(){});
return personList;
}

public static List<Car> getCars() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
ClassLoader classLoader = DummyData.class.getClassLoader();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.example.restapidevelopment.config;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
@RestController
@RequestMapping("/book")
public class BookController {
private static final List<Book> bookList = new ArrayList<>();
private static List<Book> bookList = new ArrayList<>();

static {
bookList.add(Book.builder().id(12345L).author("Rao").name("Black book").build());
bookList.add(Book.builder().id(12346L).author("Gosling").name("Java").build());
bookList.add(Book.builder().id(12345).author("Rao").name("Black book").build());
bookList.add(Book.builder().id(12346).author("Gosling").name("Java").build());

}

//localhost:8384/book/list
@GetMapping("/list")
public ResponseEntity<List<Book>> getBookList() {
ResponseEntity<List<Book>> responseEntity = new ResponseEntity<>(bookList, HttpStatus.OK);
ResponseEntity responseEntity = new ResponseEntity<>(bookList, HttpStatus.OK);
log.info(responseEntity);
return responseEntity;
}
Expand All @@ -38,11 +38,11 @@ public ResponseEntity<List<Book>> getBookList() {
public ResponseEntity<Book> getBookById(@PathVariable int id) {
Optional<Book> optionalBook = bookList.stream().filter(b -> b.getId() == id).findAny();
if (optionalBook.isPresent()) {
ResponseEntity<Book> responseEntity = new ResponseEntity<>(optionalBook.get(), HttpStatus.OK);
ResponseEntity responseEntity = new ResponseEntity<Book>(optionalBook.get(), HttpStatus.OK);
log.info(responseEntity);
return responseEntity;
}
ResponseEntity<Book> responseEntity1 = new ResponseEntity<>(Book.builder().build(), HttpStatus.NOT_FOUND);
ResponseEntity responseEntity1 = new ResponseEntity<>(Book.builder().build(), HttpStatus.NOT_FOUND);
log.info(responseEntity1);
return responseEntity1;
}
Expand All @@ -66,11 +66,12 @@ public ResponseEntity<Book> createBook(@Valid @RequestBody Book book) {
// localhost:8384/book/update
@PutMapping("/update")
public ResponseEntity<Book> updateBook(@RequestBody Book book) {
Book updatedUser = bookList.stream().filter(u-> u.getId().equals(book.getId())).peek(up->{
Book updatedUser = bookList.stream().filter(u->u.getId()==book.getId()).map(up->{
up.setAuthor(book.getAuthor());
up.setName(book.getName());
}).collect(Collectors.toList()).get(0);
return new ResponseEntity<>(updatedUser, HttpStatus.CREATED);
return up;
}).collect(Collectors.toList()).get(0);
return new ResponseEntity<Book>(updatedUser, HttpStatus.CREATED);
}


Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/restapidevelopment/dto/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class Book {
@NonNull
@Size(min = 4)
private Long id;
long id;
String name;
@Size(min = 3)
@ApiModelProperty("Author name should be 3 characters ")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.example.restapidevelopment.dto;

import com.example.restapidevelopment.entity.Emp;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Builder;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.experimental.Delegate;

import java.time.LocalDateTime;

@Builder
@Setter
@RequiredArgsConstructor
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/com/example/restapidevelopment/entity/Emp.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.example.restapidevelopment.entity;

import java.time.LocalDateTime;

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

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.time.LocalDateTime;

@Builder
@Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import java.time.LocalDateTime;

@RestControllerAdvice
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.example.restapidevelopment.exception;

import java.time.LocalDateTime;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDateTime;

@Data
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package com.example.restapidevelopment.exception;

public class UnAuthenticException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;

public UnAuthenticException(String error){
public UnAuthenticException(String error){
super(error);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
@ResponseStatus(HttpStatus.NOT_FOUND)
public class UserNotFoundException extends RuntimeException{

/**
*
*/
private static final long serialVersionUID = 1L;

public UserNotFoundException(String message){
public UserNotFoundException(String message){

super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.restapidevelopment.model;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Component
Expand Down
Loading