Skip to content

Commit

Permalink
correcao toString produtos, melhorias no menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ThauanAmorim committed Oct 7, 2021
1 parent f3ce556 commit 108838c
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 53 deletions.
113 changes: 64 additions & 49 deletions backend/src/main/java/com/bookstore/backend/BackendApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void run(String... args) throws Exception {
for(AdminModel admin: adminList) {
System.out.println(admin.toString());
}
System.out.println("enter the admin ID");
System.out.println("enter the admin ID (s to exit)");
String option = input.nextLine();
clearConsole();

Expand Down Expand Up @@ -292,12 +292,12 @@ public void run(String... args) throws Exception {

}
}else if(op.equals("3")){
List<AdminModel>admins = adminRepositoryService.getInstance().findAll();
for(AdminModel admin : admins) {
System.out.println(admin.toString());
}

while(true){
List<AdminModel>admins = adminRepositoryService.getInstance().findAll();
for(AdminModel admin : admins) {
System.out.println(admin.toString());
}

System.out.println("Type the ID admin(Type s for exit): ");
String id = input.nextLine();
if(id.equals("s")){
Expand Down Expand Up @@ -346,7 +346,7 @@ else if(op.equals("s")){
for(AuthorModel author : authors) {
System.out.println(author.toString());
}
System.out.println("enter the author ID");
System.out.println("enter the author ID (s to exit)");
String option = input.nextLine();
clearConsole();

Expand Down Expand Up @@ -416,13 +416,13 @@ else if(op.equals("s")){
clearConsole();

}else if(op.equals("3")){
System.out.println("List of Categories");
List<CategoryModel> categoryList = categoryRepositoryService.getInstance().findAll();
for(CategoryModel category : categoryList) {
System.out.println(category.toString());
}

while(true){
System.out.println("List of Categories");
List<CategoryModel> categoryList = categoryRepositoryService.getInstance().findAll();
for(CategoryModel category : categoryList) {
System.out.println(category.toString());
}

System.out.println("Type the ID Category(Type s for exit): ");
String id = input.nextLine();
clearConsole();
Expand All @@ -439,7 +439,7 @@ else if(op.equals("s")){
for(CategoryModel category : categorys) {
System.out.println(category.toString());
}
System.out.println("enter the category ID");
System.out.println("enter the category ID (s to exit)");
String option = input.nextLine();
clearConsole();

Expand Down Expand Up @@ -492,7 +492,7 @@ else if(op.equals("s")){
for(PublishingCompanyModel company : companys) {
System.out.println(company.toString());
}
System.out.println("enter the company ID");
System.out.println("enter the company ID (s to exit)");
String option = input.nextLine();
clearConsole();

Expand All @@ -512,12 +512,12 @@ else if(op.equals("s")){

}
}else if(op.equals("4")){
List<PublishingCompanyModel>companys = companyRepositoryService.getInstance().findAll();
for(PublishingCompanyModel company : companys) {
System.out.println(company.toString());
}

while(true){
List<PublishingCompanyModel>companys = companyRepositoryService.getInstance().findAll();
for(PublishingCompanyModel company : companys) {
System.out.println(company.toString());
}

System.out.println("Type the ID company(Type s for exit): ");
String id = input.nextLine();
clearConsole();
Expand All @@ -536,36 +536,48 @@ else if(op.equals("s")){
}
}else if(op.equals("6")){

shoppingCartModel shoppingCart = new shoppingCartModel(0l, null, userModel);
shoppingCartModel shoppingCart = userModel.getShoppingCart();

if(shoppingCart == null) {
shoppingCart = new shoppingCartModel(0l, null, userModel);
}

// Carrinho carrinho = ;
while(true){
System.out.println("ShoppingCart options:");

System.out.println("What option do you desire?");
System.out.println("1 - remove\n2 - add\n3 - exit: ");
System.out.println("1 - remove\n2 - add\ns - exit: ");
op = input.nextLine();
clearConsole();

//opção para remover livro do carrinho
if(op.equals("1")){
shoppingCart = shoppingCartRepositoryService.getInstance().findById(userModel.getShoppingCart().getId()).get();
while(true){
System.out.println("Items Oders:");
for(ItemOrderModel item: shoppingCart.getItemList()){
System.out.println(item.getProduct().toString() +
" Amount: " + item.getAmount()+
" Price: " + item.getTotalPrice());
}

System.out.print("Id Book for remove(Type s for exit): ");
String id = input.nextLine();
clearConsole();

if(id.equals("s")){
if(userModel.getShoppingCart() != null) {
shoppingCart = shoppingCartRepositoryService.getInstance().findById(userModel.getShoppingCart().getId()).get();
while(true){
System.out.println("Items Oders:");
for(ItemOrderModel item: shoppingCart.getItemList()){
System.out.println(item.getProduct().toString() +
" Amount: " + item.getAmount()+
" Price: " + item.getTotalPrice());
}

System.out.print("Id Book for remove(Type s for exit): ");
String id = input.nextLine();
clearConsole();
break;

if(id.equals("s")){
shoppingCartRepositoryService.getInstance().deleteById(shoppingCart.getId());
clearConsole();
break;
}
shoppingCart.removeItemOrderFromItemListByProductId(Long.parseLong(id));
}
shoppingCart.removeItemOrderFromItemListByProductId(Long.parseLong(id));
}else {
System.out.println("Carrinho vazio");
input.nextLine();
clearConsole();
}

//opção para adionar livro no carrinho
Expand Down Expand Up @@ -598,7 +610,9 @@ else if(op.equals("s")){
}
if(list.size() > 0) {
shoppingCart.setItemList(list);
shoppingCartRepositoryService.getInstance().save(shoppingCart);
shoppingCart = shoppingCartRepositoryService.getInstance().save(shoppingCart);
userModel.setShoppingCart(shoppingCart);
userRepositoryService.getInstance().save(userModel);
}
clearConsole();
break;
Expand Down Expand Up @@ -638,12 +652,12 @@ else if(op.equals("s")){
clearConsole();
System.out.println("Escolha o autor:");
// percorre a lista de autores.
List<AuthorModel> listAuthors = authorRepositoryService.getInstance().findAll();
for(AuthorModel author : listAuthors) {
System.out.println(author.toString());
}
List<AuthorModel> authorList = new ArrayList<>();
while(true){
List<AuthorModel> listAuthors = authorRepositoryService.getInstance().findAll();
for(AuthorModel author : listAuthors) {
System.out.println(author.toString());
}
System.out.println("Type the ID Author(Type s for exit): ");
String id = input.nextLine();
clearConsole();
Expand All @@ -662,12 +676,13 @@ else if(op.equals("s")){
System.out.println("pages: ");
int pages = Integer.parseInt(input.nextLine());
clearConsole();
List<CategoryModel> categoryList = categoryRepositoryService.getInstance().findAll();
for(CategoryModel category : categoryList) {
System.out.println(category.toString());
}
List<CategoryModel> cateList = new ArrayList<>();
while(true){
List<CategoryModel> categoryList = categoryRepositoryService.getInstance().findAll();
for(CategoryModel category : categoryList) {
System.out.println(category.toString());
}

System.out.println("Type the ID Category(Type s for exit): ");
String id = input.nextLine();
clearConsole();
Expand All @@ -691,7 +706,7 @@ else if(op.equals("s")){
PublishingCompanyModel companyModel = companyRepositoryService.getInstance().findById(companyId).get();
System.out.println("Inventory: ");
int qtd = Integer.parseInt(input.nextLine());
BookModel book = new BookModel(0l, title, description, yearLaunch, pages, price, null, null, categoryList, userModel, companyModel, authorList, null);
BookModel book = new BookModel(0l, title, description, yearLaunch, pages, price, null, null, cateList, userModel, companyModel, authorList, null);
book = bookRepositoryService.getInstance().save(book);
InventoryModel inventory = new InventoryModel(0l, qtd, book, null);
inventoryRepositoryService.getInstance().save(inventory);
Expand Down Expand Up @@ -974,7 +989,7 @@ public UserModel login() {
String password = input.nextLine();
clearConsole();

UserModel user = new UserModel(0l, username, email, password, null, null, null, null, null);
UserModel user = new UserModel(0l, username, email, password, null, null, null, new shoppingCartModel(), null);

userModel = userRepositoryService.getInstance().save(user);
clearConsole();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public BookModel() {

@Override
public String toString() {
return String.format("BOOK [ID: %s - TITLE: %s - DESCRIPTION: %s - YEAR LAUNCH: %s - PAGES: %s - PRICE: %s - COMPANY: %s - EVALUATE: %s]", getId(), getTitle(), getDescription(), getYearLaunch(), getPages(), getPrice().toString(), getCompany().getName(), String.valueOf(calculateStarAverage()));
return String.format("BOOK [ID: %s - TITLE: %s - DESCRIPTION: %s - YEAR LAUNCH: %s - PAGES: %s - PRICE: %s - COMPANY: %s - EVALUATE: [AVERAGE: %s - AVALUATE NUMBER: %s]]", getId(), getTitle(), getDescription(), getYearLaunch(), getPages(), getPrice().toString(), getCompany().getName(), String.valueOf(calculateStarAverage()), String.valueOf(getEvaluateList().size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public HqModel() {

@Override
public String toString() {
return String.format("HQ [ID: %s - TITLE: %s - DESCRIPTION: %s - YEAR LAUNCH: %s - PAGES: %s - PRICE: %s - COMPANY: %s - EVALUATE: %s]", getId(), getTitle(), getDescription(), getYearLaunch(), getPages(), getPrice().toString(), getCompany().getName(), String.valueOf(calculateStarAverage()));
return String.format("HQ [ID: %s - TITLE: %s - DESCRIPTION: %s - YEAR LAUNCH: %s - PAGES: %s - PRICE: %s - COMPANY: %s - EVALUATE: [AVERAGE: %s - AVALUATE NUMBER: %s]]", getId(), getTitle(), getDescription(), getYearLaunch(), getPages(), getPrice().toString(), getCompany().getName(), String.valueOf(calculateStarAverage()), String.valueOf(getEvaluateList().size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public MagazineModel() {

@Override
public String toString() {
return String.format("MAGAZINE [ID: %s - TITLE: %s - DESCRIPTION: %s - YEAR LAUNCH: %s - PAGES: %s - PRICE: %s - COMPANY: %s - EVALUATE: %s]", getId(), getTitle(), getDescription(), getYearLaunch(), getPages(), getPrice().toString(), getCompany().getName(), String.valueOf(calculateStarAverage()));
return String.format("MAGAZINE [ID: %s - TITLE: %s - DESCRIPTION: %s - YEAR LAUNCH: %s - PAGES: %s - PRICE: %s - COMPANY: %s - EVALUATE: [AVERAGE: %s - AVALUATE NUMBER: %s]]", getId(), getTitle(), getDescription(), getYearLaunch(), getPages(), getPrice().toString(), getCompany().getName(), String.valueOf(calculateStarAverage()), String.valueOf(getEvaluateList().size()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
Expand All @@ -15,6 +16,9 @@

import com.bookstore.backend.domain.model.user.UserModel;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -32,8 +36,9 @@ public class shoppingCartModel {
@Column(name = "ID")
private Long Id;

@OneToMany
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "ITEMLIST_FK")
@Fetch(FetchMode.SUBSELECT)
private List<ItemOrderModel> itemList;

@OneToOne
Expand Down

0 comments on commit 108838c

Please sign in to comment.