From f3ce5561442f052715537b7f695143a0c309de05 Mon Sep 17 00:00:00 2001 From: Thauan Amorim Date: Thu, 7 Oct 2021 17:45:27 -0300 Subject: [PATCH] correcao dos update --- .../bookstore/backend/BackendApplication.java | 224 ++++++++++-------- 1 file changed, 131 insertions(+), 93 deletions(-) diff --git a/backend/src/main/java/com/bookstore/backend/BackendApplication.java b/backend/src/main/java/com/bookstore/backend/BackendApplication.java index 11b16f8f..dde31e4a 100644 --- a/backend/src/main/java/com/bookstore/backend/BackendApplication.java +++ b/backend/src/main/java/com/bookstore/backend/BackendApplication.java @@ -186,30 +186,37 @@ public void run(String... args) throws Exception { clearConsole(); } }else if(op.equals("4")){ - Listusers = userRepositoryService.getInstance().findAll(); - for(UserModel user : users ) { - System.out.println(user.toString()); - } - System.out.println("enter the user ID"); - Long option = Long.parseLong(input.nextLine()); - clearConsole(); - - System.out.println("Username: "); - String username = input.nextLine(); - clearConsole(); - if(username.equals("")) userModel = null; - System.out.println("Email: "); - String email = input.nextLine(); - clearConsole(); - if(email.equals("")) email = null; - System.out.println("Password: "); - String password = input.nextLine(); - clearConsole(); - if(password.equals("")) password = null; + while(true) { + Listusers = userRepositoryService.getInstance().findAll(); + for(UserModel user : users ) { + System.out.println(user.toString()); + } + System.out.println("enter the user ID (s to exit)"); + String option = input.nextLine(); + clearConsole(); + + if(option.equals("s")) { + clearConsole(); + break; + } + System.out.println("Username: "); + String username = input.nextLine(); + clearConsole(); + if(username.equals("")) userModel = null; + System.out.println("Email: "); + String email = input.nextLine(); + clearConsole(); + if(email.equals("")) email = null; + System.out.println("Password: "); + String password = input.nextLine(); + clearConsole(); + if(password.equals("")) password = null; + + UserModel userDataBase = new UserModel(Long.parseLong(option), username, email, password, null, null, null, null, null); + userRepositoryService.update(userDataBase); + clearConsole(); - UserModel userDataBase = new UserModel(option, username, email, password, null, null, null, null, null); - userRepositoryService.update(userDataBase); - clearConsole(); + } }else if(op.equals("5")){ Listusers = userRepositoryService.getInstance().findAll(); @@ -252,30 +259,38 @@ public void run(String... args) throws Exception { clearConsole(); }else if(op.equals("2")){ - ListadminList = adminRepositoryService.getInstance().findAll(); - for(AdminModel admin: adminList) { - System.out.println(admin.toString()); - } - System.out.println("enter the admin ID"); - Long option = Long.parseLong(input.nextLine()); - clearConsole(); + while(true) { + ListadminList = adminRepositoryService.getInstance().findAll(); + for(AdminModel admin: adminList) { + System.out.println(admin.toString()); + } + System.out.println("enter the admin ID"); + String option = input.nextLine(); + clearConsole(); - System.out.println("Username: "); - String username = input.nextLine(); - clearConsole(); - if(username.equals("")) username = null; - System.out.println("Email: "); - String email = input.nextLine(); - clearConsole(); - if(email.equals("")) email = null; - System.out.println("Password: "); - String password = input.nextLine(); - clearConsole(); - if(password.equals("")) password = null; + if(option.equals("s")){ + clearConsole(); + break; + } + + System.out.println("Username: "); + String username = input.nextLine(); + clearConsole(); + if(username.equals("")) username = null; + System.out.println("Email: "); + String email = input.nextLine(); + clearConsole(); + if(email.equals("")) email = null; + System.out.println("Password: "); + String password = input.nextLine(); + clearConsole(); + if(password.equals("")) password = null; + + AdminModel adminDataBase = new AdminModel(Long.parseLong(option), username, email, password, null, null, null); + adminRepositoryService.update(adminDataBase); + clearConsole(); - AdminModel adminDataBase = new AdminModel(option, username, email, password, null, null, null); - adminRepositoryService.update(adminDataBase); - clearConsole(); + } }else if(op.equals("3")){ Listadmins = adminRepositoryService.getInstance().findAll(); for(AdminModel admin : admins) { @@ -326,30 +341,38 @@ else if(op.equals("s")){ clearConsole(); }else if(op.equals("3")){ - Listauthors = authorRepositoryService.getInstance().findAll(); - for(AuthorModel author : authors) { - System.out.println(author.toString()); - } - System.out.println("enter the author ID"); - Long option = Long.parseLong(input.nextLine()); - clearConsole(); - - System.out.println("name: "); - String username = input.nextLine(); - clearConsole(); - if(username.equals("")) username = null; + while(true) { + Listauthors = authorRepositoryService.getInstance().findAll(); + for(AuthorModel author : authors) { + System.out.println(author.toString()); + } + System.out.println("enter the author ID"); + String option = input.nextLine(); + clearConsole(); - AuthorModel authorDataBase = new AuthorModel(option, username, null); - authorRepositoryService.update(authorDataBase); - clearConsole(); + if(option.equals("s")){ + clearConsole(); + break; + } + + System.out.println("name: "); + String username = input.nextLine(); + clearConsole(); + if(username.equals("")) username = null; + + AuthorModel authorDataBase = new AuthorModel(Long.parseLong(option), username, null); + authorRepositoryService.update(authorDataBase); + clearConsole(); - }else if(op.equals("4")){ - Listauthors = authorRepositoryService.getInstance().findAll(); - for(AuthorModel author : authors) { - System.out.println(author.toString()); } + }else if(op.equals("4")){ while(true){ + Listauthors = authorRepositoryService.getInstance().findAll(); + for(AuthorModel author : authors) { + System.out.println(author.toString()); + } + System.out.println("Type the ID author(Type s for exit): "); String id = input.nextLine(); clearConsole(); @@ -411,22 +434,30 @@ else if(op.equals("s")){ categoryRepositoryService.getInstance().deleteById(Long.parseLong(id)); } }else if (op.equals("4")){ - Listcategorys = categoryRepositoryService.getInstance().findAll(); - for(CategoryModel category : categorys) { - System.out.println(category.toString()); - } - System.out.println("enter the category ID"); - Long option = Long.parseLong(input.nextLine()); - clearConsole(); + while(true) { + Listcategorys = categoryRepositoryService.getInstance().findAll(); + for(CategoryModel category : categorys) { + System.out.println(category.toString()); + } + System.out.println("enter the category ID"); + String option = input.nextLine(); + clearConsole(); - System.out.println("name: "); - String name = input.nextLine(); - clearConsole(); - if(name.equals("")) name = null; + if(option.equals("s")){ + clearConsole(); + break; + } + + System.out.println("name: "); + String name = input.nextLine(); + clearConsole(); + if(name.equals("")) name = null; + + CategoryModel categoryDataBase = new CategoryModel(Long.parseLong(option), name, null); + categoryRepositoryService.update(categoryDataBase); + clearConsole(); - CategoryModel categoryDataBase = new CategoryModel(option, name, null); - categoryRepositoryService.update(categoryDataBase); - clearConsole(); + } }else if(op.equals("s")){ clearConsole(); @@ -456,23 +487,30 @@ else if(op.equals("s")){ input.nextLine(); clearConsole(); }else if(op.equals("3")){ + while(true) { + Listcompanys = companyRepositoryService.getInstance().findAll(); + for(PublishingCompanyModel company : companys) { + System.out.println(company.toString()); + } + System.out.println("enter the company ID"); + String option = input.nextLine(); + clearConsole(); + + if(option.equals("s")) { + clearConsole(); + break; + } - Listcompanys = companyRepositoryService.getInstance().findAll(); - for(PublishingCompanyModel company : companys) { - System.out.println(company.toString()); - } - System.out.println("enter the company ID"); - Long option = Long.parseLong(input.nextLine()); - clearConsole(); - - System.out.println("name: "); - String name = input.nextLine(); - clearConsole(); - if(name.equals("")) name = null; + System.out.println("name: "); + String name = input.nextLine(); + clearConsole(); + if(name.equals("")) name = null; + + PublishingCompanyModel companyDataBase = new PublishingCompanyModel(Long.parseLong(option), name, null); + companyRepositoryService.update(companyDataBase); + clearConsole(); - PublishingCompanyModel companyDataBase = new PublishingCompanyModel(option, name, null); - companyRepositoryService.update(companyDataBase); - clearConsole(); + } }else if(op.equals("4")){ Listcompanys = companyRepositoryService.getInstance().findAll(); for(PublishingCompanyModel company : companys) {