Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
bookstore-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Narendar Vakiti
bookstore-api
Commits
0aff93cd
Commit
0aff93cd
authored
Mar 10, 2020
by
Narendar Vakiti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added loggers
parent
bd4a2236
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
97 additions
and
181 deletions
+97
-181
pom.xml
pom.xml
+13
-0
Author.java
src/main/java/com/bookstore/bean/Author.java
+9
-38
BookDetails.java
src/main/java/com/bookstore/bean/BookDetails.java
+6
-79
BookStore.java
src/main/java/com/bookstore/bean/BookStore.java
+6
-55
BookController.java
src/main/java/com/bookstore/controller/BookController.java
+34
-4
BookServiceImpl.java
src/main/java/com/bookstore/service/BookServiceImpl.java
+29
-5
No files found.
pom.xml
View file @
0aff93cd
...
...
@@ -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>
...
...
src/main/java/com/bookstore/bean/Author.java
View file @
0aff93cd
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
;
}
}
src/main/java/com/bookstore/bean/BookDetails.java
View file @
0aff93cd
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
+
"]"
;
}
}
src/main/java/com/bookstore/bean/BookStore.java
View file @
0aff93cd
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
;
}
}
src/main/java/com/bookstore/controller/BookController.java
View file @
0aff93cd
...
...
@@ -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
;
}
}
src/main/java/com/bookstore/service/BookServiceImpl.java
View file @
0aff93cd
...
...
@@ -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"
,
tru
e
);
Status
status
=
new
Status
(
"Book
details are not saved successfully"
,
fals
e
);
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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment