diff --git a/bookstore-api/.idea/workspace.xml b/bookstore-api/.idea/workspace.xml index 86b95d6..5df3313 100644 --- a/bookstore-api/.idea/workspace.xml +++ b/bookstore-api/.idea/workspace.xml @@ -26,7 +26,7 @@ - + @@ -110,11 +110,11 @@ - + - - + + @@ -176,7 +176,6 @@ @@ -982,12 +982,12 @@ - + - @@ -1010,7 +1010,7 @@ - + @@ -1328,14 +1328,6 @@ - - - - - - - - @@ -1396,5 +1388,13 @@ + + + + + + + + \ No newline at end of file diff --git a/bookstore-api/src/main/java/com/bookstore/resource/BookResource.java b/bookstore-api/src/main/java/com/bookstore/resource/BookResource.java index 15efbab..9f64443 100644 --- a/bookstore-api/src/main/java/com/bookstore/resource/BookResource.java +++ b/bookstore-api/src/main/java/com/bookstore/resource/BookResource.java @@ -1,7 +1,9 @@ package com.bookstore.resource; import com.bookstore.domain.Book; +import com.bookstore.domain.User; import com.bookstore.service.BookService; +import com.bookstore.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -12,12 +14,15 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.websocket.server.PathParam; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.security.Principal; +import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -33,6 +38,9 @@ public class BookResource { @Autowired private BookService bookService; + @Autowired + private UserService userService; + @RequestMapping(value = "/add/image", method = RequestMethod.POST) public ResponseEntity upload( @RequestParam("id") Long id, @@ -115,6 +123,18 @@ public class BookResource { return book; } + @RequestMapping("/{id}") + public ResponseEntity bookDetail(@PathVariable("id") Long id, Principal principal) { + if (principal != null) { + String username = principal.getName(); + User user = userService.findByUsername(username); + } + + Book book = bookService.findOne(id); + + return new ResponseEntity("Book Found!", HttpStatus.OK); + } + @RequestMapping(value = "/remove", method = RequestMethod.POST) public ResponseEntity remove( @RequestBody String id, Model model diff --git a/bookstore-api/src/main/resources/static/image/book/21.png b/bookstore-api/src/main/resources/static/image/book/21.png new file mode 100644 index 0000000..b3c7185 Binary files /dev/null and b/bookstore-api/src/main/resources/static/image/book/21.png differ diff --git a/bookstore-api/target/classes/static/image/book/21.png b/bookstore-api/target/classes/static/image/book/21.png new file mode 100644 index 0000000..b3c7185 Binary files /dev/null and b/bookstore-api/target/classes/static/image/book/21.png differ diff --git a/store-front/src/app/app.module.ts b/store-front/src/app/app.module.ts index 9f2dff3..0a13388 100644 --- a/store-front/src/app/app.module.ts +++ b/store-front/src/app/app.module.ts @@ -22,6 +22,7 @@ import { BookService } from './services/book.service'; import { MyAccountComponent } from './components/my-account/my-account.component'; import { MyProfileComponent } from './components/my-profile/my-profile.component'; import { BookListComponent } from './components/book-list/book-list.component'; +import { BookDetailComponent } from './components/book-detail/book-detail.component'; @NgModule({ declarations: [ @@ -31,7 +32,8 @@ import { BookListComponent } from './components/book-list/book-list.component'; NavBarComponent, MyAccountComponent, MyProfileComponent, - BookListComponent + BookListComponent, + BookDetailComponent ], imports: [ BrowserModule, diff --git a/store-front/src/app/app.routing.ts b/store-front/src/app/app.routing.ts index c161152..84dacef 100644 --- a/store-front/src/app/app.routing.ts +++ b/store-front/src/app/app.routing.ts @@ -8,7 +8,7 @@ import {HomeComponent} from './components/home/home.component'; import {MyAccountComponent} from './components/my-account/my-account.component'; import {MyProfileComponent} from './components/my-profile/my-profile.component'; import {BookListComponent} from './components/book-list/book-list.component'; - +import {BookDetailComponent} from './components/book-detail/book-detail.component'; const appRoutes: Routes = [ { @@ -31,6 +31,10 @@ const appRoutes: Routes = [ { path: 'bookList', component: BookListComponent + }, + { + path: 'bookDetail/:id', + component: BookDetailComponent } ]; diff --git a/store-front/src/app/components/book-detail/book-detail.component.css b/store-front/src/app/components/book-detail/book-detail.component.css new file mode 100644 index 0000000..e69de29 diff --git a/store-front/src/app/components/book-detail/book-detail.component.html b/store-front/src/app/components/book-detail/book-detail.component.html new file mode 100644 index 0000000..43e33df --- /dev/null +++ b/store-front/src/app/components/book-detail/book-detail.component.html @@ -0,0 +1,74 @@ +
+
+
+

All Books

+
+
+ +
+
+
+ + +
+
+ +
+

Added to cart.

+

Oops, only {{book.inStockNumber}} In Stock.

+

{{book.title}}

+
+
+
Author: {{book.author}}
+

Publisher: {{book.publisher}}

+

Publication Date: {{book.publicationDate}}

+

Language: {{book.language}}

+

Category: {{book.category}}

+

{{book.format}}: {{book.numberOfPages}} pages

+

ISBN: {{book.isbn}}

+

Shipping Weight: {{book.shippingWeight}} ounces

+ +
+
+
+
+
+
+

Our Price: ${{book.ourPrice | number : '1.2-2'}}

+

List Price: ${{book.listPrice | number : '1.2-2'}}

+

You Save: ${{book.listPrice-book.ourPrice | number : '1.2-2'}} +

+ Qty: + +
+
+

In Stock

+

Only {{book.inStockNumber}} In + Stock

+

Unavailable

+ +
+
+
+
+
+
+
+

{{book.description}}

+
+
+
+
\ No newline at end of file diff --git a/store-front/src/app/components/book-detail/book-detail.component.spec.ts b/store-front/src/app/components/book-detail/book-detail.component.spec.ts new file mode 100644 index 0000000..708e917 --- /dev/null +++ b/store-front/src/app/components/book-detail/book-detail.component.spec.ts @@ -0,0 +1,28 @@ +/* tslint:disable:no-unused-variable */ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +import { BookDetailComponent } from './book-detail.component'; + +describe('BookDetailComponent', () => { + let component: BookDetailComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ BookDetailComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(BookDetailComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/store-front/src/app/components/book-detail/book-detail.component.ts b/store-front/src/app/components/book-detail/book-detail.component.ts new file mode 100644 index 0000000..ee8d87f --- /dev/null +++ b/store-front/src/app/components/book-detail/book-detail.component.ts @@ -0,0 +1,40 @@ +import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'; +import {Book} from "../../models/book"; +import {BookService} from "../../services/book.service"; +import {Params, ActivatedRoute,Router} from "@angular/router"; +import {Http} from "@angular/http"; +import {AppConst} from '../../constants/app-const'; + +@Component({ + selector: 'app-book-detail', + templateUrl: './book-detail.component.html', + styleUrls: ['./book-detail.component.css'] +}) +export class BookDetailComponent implements OnInit { + + private bookId: number; + private book: Book = new Book(); + private serverPath = AppConst.serverPath; + private numberList: number[]=[1,2,3,4,5,6,7,8,9]; + private qty:number; + + private addBookSuccess:boolean = false; + private notEnoughStock:boolean = false; + + constructor(private bookService: BookService, private route: ActivatedRoute, private router:Router) { + this.route.params.forEach((params: Params) => { + this.bookId = Number.parseInt(params['id']); + }); + + this.bookService.getBook(this.bookId).subscribe( + res => { + this.book=res.json(); + }, + error => console.log(error) + ); + } + + ngOnInit() { + } + +} diff --git a/store-front/src/app/components/book-list/book-list.component.ts b/store-front/src/app/components/book-list/book-list.component.ts index 90d7187..9a6e518 100644 --- a/store-front/src/app/components/book-list/book-list.component.ts +++ b/store-front/src/app/components/book-list/book-list.component.ts @@ -12,8 +12,8 @@ import {AppConst} from '../../constants/app-const'; }) export class BookListComponent implements OnInit { - public filterQuery = ""; - public rowsOnPage = 10; + public filterQuery = ""; + public rowsOnPage = 10; private selectedBook : Book; private bookList: Book[]; diff --git a/store-front/src/app/services/book.service.ts b/store-front/src/app/services/book.service.ts index 3ccf567..afb2f6c 100644 --- a/store-front/src/app/services/book.service.ts +++ b/store-front/src/app/services/book.service.ts @@ -1,5 +1,7 @@ import { Injectable } from '@angular/core'; import {Headers, Http} from "@angular/http"; +import {AppConst} from '../constants/app-const'; + @Injectable() export class BookService { @@ -7,7 +9,15 @@ export class BookService { constructor(private http: Http) { } getBookList() { - let url = "http://localhost:8181/book/bookList"; + let url = AppConst.serverPath+"/book/bookList"; + let tokenHeader = new Headers ({ + 'x-auth-token' : localStorage.getItem("xAuthToken") + }); + return this.http.get(url, {headers : tokenHeader}); + } + + getBook(id:number) { + let url = AppConst.serverPath+"/book/"+id; let tokenHeader = new Headers ({ 'x-auth-token' : localStorage.getItem("xAuthToken") });