Commit 0aff93cd authored by Narendar Vakiti's avatar Narendar Vakiti

added loggers

parent bd4a2236
......@@ -32,6 +32,19 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-log4j -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
......
package com.bookstore.bean;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
@Getter @Setter
@ToString
@AllArgsConstructor @NoArgsConstructor
public class Author {
private int authorId;
private String authorName;
private String address;
public Author() {
}
public Author(int authorId, String authorName, String address) {
super();
this.authorId = authorId;
this.authorName = authorName;
this.address = address;
}
public int getAuthorId() {
return authorId;
}
public void setAuthorId(int authorId) {
this.authorId = authorId;
}
public String getAuthorName() {
return authorName;
}
public void setAuthorName(String authorName) {
this.authorName = authorName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
package com.bookstore.bean;
import lombok.*;
import java.io.Serializable;
@Getter @Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class BookDetails implements Serializable{
/**
......@@ -16,84 +22,5 @@ public class BookDetails implements Serializable{
private int authorId;
private String authorName;
private String address;
public BookDetails() {
}
public BookDetails(int bookId, String bookName, double bookPrice, boolean active, int authorId, String authorName,
String address) {
super();
this.bookId = bookId;
this.bookName = bookName;
this.bookPrice = bookPrice;
this.active = active;
this.authorId = authorId;
this.authorName = authorName;
this.address = address;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public double getBookPrice() {
return bookPrice;
}
public void setBookPrice(double bookPrice) {
this.bookPrice = bookPrice;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public int getAuthorId() {
return authorId;
}
public void setAuthorId(int authorId) {
this.authorId = authorId;
}
public String getAuthorName() {
return authorName;
}
public void setAuthorName(String authorName) {
this.authorName = authorName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "[bookId=" + bookId + ", bookName=" + bookName + ", bookPrice=" + bookPrice + ", active="
+ active + ", authorId=" + authorId + ", authorName=" + authorName + ", address=" + address + "]";
}
}
package com.bookstore.bean;
import lombok.*;
@Getter @Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class BookStore {
private int bookId;
......@@ -7,60 +13,5 @@ public class BookStore {
private double bookPrice;
private boolean active;
private Author author;
public BookStore() {
}
public BookStore(int bookId, String bookName, double bookPrice, boolean active, Author author) {
super();
this.bookId = bookId;
this.bookName = bookName;
this.bookPrice = bookPrice;
this.active = active;
this.author = author;
}
public int getBookId() {
return bookId;
}
public void setBookId(int bookId) {
this.bookId = bookId;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public double getBookPrice() {
return bookPrice;
}
public void setBookPrice(double bookPrice) {
this.bookPrice = bookPrice;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public Author getAuthor() {
return author;
}
public void setAuthor(Author author) {
this.author = author;
}
}
......@@ -2,6 +2,8 @@ package com.bookstore.controller;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -13,26 +15,54 @@ import com.bookstore.bean.BookDetails;
import com.bookstore.bean.BookStore;
import com.bookstore.service.BookService;
/**
* @author nvakiti
*
*/
@RestController
public class BookController {
private static final Logger logger = LoggerFactory.getLogger(BookController.class);
@Autowired
private BookService bookService;
/**
* To get all book details
* @return books
*/
@GetMapping("/getbookdetails")
public List<BookStore> getBookDetails(){
return bookService.getBookDetails();
logger.info("Started getBookDetails()");
List<BookStore> books = bookService.getBookDetails();
logger.info("End getBookDetails()");
return books;
}
/**
* To get all book authors details
* @return authors
*/
@GetMapping("/getauthordetails")
public List<Author> getAuthorDetails(){
return bookService.getAuthorDetails();
logger.info("Started getAuthorDetails()");
List<Author> authors = bookService.getAuthorDetails();
logger.info("End getAuthorDetails()");
return authors;
}
/**
* Store book and author details
* @param bookDetails
* @return message
*/
@PostMapping("/addbookdetails")
public String addBookDetails(@RequestBody BookDetails bookDetails) {
String msg = bookService.saveBookDetails(bookDetails);
return msg;
logger.info("Started addBookDetails()");
String message = bookService.saveBookDetails(bookDetails);
logger.info("End addBookDetails()");
return message;
}
}
......@@ -4,17 +4,22 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.bookstore.bean.Author;
import com.bookstore.bean.BookDetails;
import com.bookstore.bean.BookStore;
import com.bookstore.bean.Status;
import com.bookstore.controller.BookController;
import com.google.gson.Gson;
@Service
public class BookServiceImpl implements BookService{
private static final Logger logger = LoggerFactory.getLogger(BookServiceImpl.class);
List<BookStore> books = new ArrayList<>();
List<Author> author = new ArrayList<>();
......@@ -23,8 +28,13 @@ public class BookServiceImpl implements BookService{
Author a3 = new Author(1013, "Jamie Chan", "Australia");
Author a4 = new Author(1014, "Joshua Bloch", "Japan");
/**
* To get all book details
* @return books
*/
@Override
public List<BookStore> getBookDetails() {
logger.info("Started getBookDetails()");
try {
books.add(new BookStore(101, "Head First Java", 500.00, true, a1));
books.add(new BookStore(102, "Java: A Beginner's Guide", 1000.00, true, a2));
......@@ -32,28 +42,41 @@ public class BookServiceImpl implements BookService{
books.add(new BookStore(104, "Effective Java", 500.00, true, a4));
books.add(new BookStore(105, "Head First Servlets and JSP", 480.00, true, a2));
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
}
logger.info("End getBookDetails()");
return books;
}
/**
* To get all book authors details
* @return authors
*/
@Override
public List<Author> getAuthorDetails() {
logger.info("Started getAuthorDetails()");
try {
author.add(a1);
author.add(a2);
author.add(a3);
author.add(a4);
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
}
logger.info("Started getAuthorDetails()");
return author;
}
/**
* Store book and author details
* @param bookDetails
* @return message
*/
@Override
public String saveBookDetails(BookDetails bookDetails) {
logger.info("Started saveBookDetails()");
String message = null;
Status status = new Status("Book Details Successfully Added", true);
Status status = new Status("Book details are not saved successfully", false);
try {
boolean bookFlag = Optional.ofNullable(bookDetails).isPresent();
if(bookFlag) {
......@@ -69,15 +92,16 @@ public class BookServiceImpl implements BookService{
author.add(a5);
books.add(new BookStore(bookId, bookName, price, flag, a5));
status = new Status("Book Details Successfully Added", true);
status = new Status("Book details are added successfully", true);
}
message = new Gson().toJson(status);
}
catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
}
logger.info("Started saveBookDetails()");
return message;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment