Skip to content
Merged
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: 0 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this version needed.

<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator -->
Expand Down Expand Up @@ -108,7 +107,6 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -120,7 +118,6 @@
<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,21 +1,23 @@
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;
import lombok.extern.log4j.Log4j2;

/**
* 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,6 +22,15 @@ 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,21 +1,20 @@
package com.example.restapidevelopment.config;

import com.google.common.base.Predicates;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

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 List<Book> bookList = new ArrayList<>();
private static final List<Book> bookList = new ArrayList<>();

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

}

//localhost:8384/book/list
@GetMapping("/list")
public ResponseEntity<List<Book>> getBookList() {
ResponseEntity responseEntity = new ResponseEntity<>(bookList, HttpStatus.OK);
ResponseEntity<List<Book>> responseEntity = new ResponseEntity<>(bookList, HttpStatus.OK);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this <>

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 responseEntity = new ResponseEntity<Book>(optionalBook.get(), HttpStatus.OK);
ResponseEntity<Book> responseEntity = new ResponseEntity<>(optionalBook.get(), HttpStatus.OK);
log.info(responseEntity);
return responseEntity;
}
ResponseEntity responseEntity1 = new ResponseEntity<>(Book.builder().build(), HttpStatus.NOT_FOUND);
ResponseEntity<Book> responseEntity1 = new ResponseEntity<>(Book.builder().build(), HttpStatus.NOT_FOUND);
log.info(responseEntity1);
return responseEntity1;
}
Expand All @@ -66,12 +66,11 @@ 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()==book.getId()).map(up->{
Book updatedUser = bookList.stream().filter(u-> u.getId().equals(book.getId())).peek(up->{
up.setAuthor(book.getAuthor());
up.setName(book.getName());
return up;
}).collect(Collectors.toList()).get(0);
return new ResponseEntity<Book>(updatedUser, HttpStatus.CREATED);
}).collect(Collectors.toList()).get(0);
return new ResponseEntity<>(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)
long id;
private 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,15 +1,13 @@
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: 11 additions & 9 deletions src/main/java/com/example/restapidevelopment/entity/Emp.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
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,11 +2,8 @@

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,11 +1,10 @@
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,7 +1,12 @@
package com.example.restapidevelopment.exception;

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

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

public UserNotFoundException(String message){
/**
*
*/
private static final long serialVersionUID = 1L;

public UserNotFoundException(String message){

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

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

@Component
Expand Down
Loading