From ac2fe8cf274c16068f7c38b1877dc9cfe5faefcd Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 19 Mar 2022 16:15:46 -0400 Subject: [PATCH 01/69] wip: email working --- pom.xml | 10 ++++-- .../demo/appuser/AppUserRepository.java | 6 ++-- .../com/example/demo/appuser/AppUserRole.java | 6 ---- .../example/demo/appuser/AppUserService.java | 2 +- .../{AppUser.java => UserCredentials.java} | 25 ++++---------- .../com/example/demo/appuser/UserRole.java | 7 ++++ .../com/example/demo/email/EmailService.java | 2 +- .../registration/RegistrationService.java | 12 +++---- .../registration/token/ConfirmationToken.java | 8 ++--- src/main/resources/application.yml | 34 ++++++++++++++----- 10 files changed, 61 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/com/example/demo/appuser/AppUserRole.java rename src/main/java/com/example/demo/appuser/{AppUser.java => UserCredentials.java} (77%) create mode 100644 src/main/java/com/example/demo/appuser/UserRole.java diff --git a/pom.xml b/pom.xml index 167df52..c7c7712 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,11 @@ + + mysql + mysql-connector-java + runtime + org.springframework.boot spring-boot-starter-data-jpa @@ -36,14 +41,15 @@ spring-boot-starter-web - + org.projectlombok lombok + 1.18.22 true diff --git a/src/main/java/com/example/demo/appuser/AppUserRepository.java b/src/main/java/com/example/demo/appuser/AppUserRepository.java index d8eaa8f..551a4e8 100644 --- a/src/main/java/com/example/demo/appuser/AppUserRepository.java +++ b/src/main/java/com/example/demo/appuser/AppUserRepository.java @@ -11,13 +11,13 @@ @Repository @Transactional(readOnly = true) public interface AppUserRepository - extends JpaRepository { + extends JpaRepository { - Optional findByEmail(String email); + Optional findByEmail(String email); @Transactional @Modifying - @Query("UPDATE AppUser a " + + @Query("UPDATE UserCredentials a " + "SET a.enabled = TRUE WHERE a.email = ?1") int enableAppUser(String email); diff --git a/src/main/java/com/example/demo/appuser/AppUserRole.java b/src/main/java/com/example/demo/appuser/AppUserRole.java deleted file mode 100644 index b05de93..0000000 --- a/src/main/java/com/example/demo/appuser/AppUserRole.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.example.demo.appuser; - -public enum AppUserRole { - USER, - ADMIN -} diff --git a/src/main/java/com/example/demo/appuser/AppUserService.java b/src/main/java/com/example/demo/appuser/AppUserService.java index aa23eb5..2411cce 100644 --- a/src/main/java/com/example/demo/appuser/AppUserService.java +++ b/src/main/java/com/example/demo/appuser/AppUserService.java @@ -32,7 +32,7 @@ public UserDetails loadUserByUsername(String email) String.format(USER_NOT_FOUND_MSG, email))); } - public String signUpUser(AppUser appUser) { + public String signUpUser(UserCredentials appUser) { boolean userExists = appUserRepository .findByEmail(appUser.getEmail()) .isPresent(); diff --git a/src/main/java/com/example/demo/appuser/AppUser.java b/src/main/java/com/example/demo/appuser/UserCredentials.java similarity index 77% rename from src/main/java/com/example/demo/appuser/AppUser.java rename to src/main/java/com/example/demo/appuser/UserCredentials.java index 793a3ef..e8fc06b 100644 --- a/src/main/java/com/example/demo/appuser/AppUser.java +++ b/src/main/java/com/example/demo/appuser/UserCredentials.java @@ -17,7 +17,7 @@ @EqualsAndHashCode @NoArgsConstructor @Entity -public class AppUser implements UserDetails { +public class UserCredentials implements UserDetails { @SequenceGenerator( @@ -31,22 +31,18 @@ public class AppUser implements UserDetails { generator = "student_sequence" ) private Long id; - private String firstName; - private String lastName; private String email; private String password; @Enumerated(EnumType.STRING) - private AppUserRole appUserRole; + private UserRole appUserRole; private Boolean locked = false; private Boolean enabled = false; - public AppUser(String firstName, - String lastName, - String email, - String password, - AppUserRole appUserRole) { - this.firstName = firstName; - this.lastName = lastName; + public UserCredentials( + String email, + String password, + UserRole appUserRole) { + this.email = email; this.password = password; this.appUserRole = appUserRole; @@ -69,13 +65,6 @@ public String getUsername() { return email; } - public String getFirstName() { - return firstName; - } - - public String getLastName() { - return lastName; - } @Override public boolean isAccountNonExpired() { diff --git a/src/main/java/com/example/demo/appuser/UserRole.java b/src/main/java/com/example/demo/appuser/UserRole.java new file mode 100644 index 0000000..d8411f9 --- /dev/null +++ b/src/main/java/com/example/demo/appuser/UserRole.java @@ -0,0 +1,7 @@ +package com.example.demo.appuser; + +public enum UserRole { + PERSONAL, + ADMIN, + BUSINESS +} diff --git a/src/main/java/com/example/demo/email/EmailService.java b/src/main/java/com/example/demo/email/EmailService.java index 975c44f..2c5f106 100644 --- a/src/main/java/com/example/demo/email/EmailService.java +++ b/src/main/java/com/example/demo/email/EmailService.java @@ -30,7 +30,7 @@ public void send(String to, String email) { helper.setText(email, true); helper.setTo(to); helper.setSubject("Confirm your email"); - helper.setFrom("hello@amigoscode.com"); + helper.setFrom("ethniconnect@gmail.com"); mailSender.send(mimeMessage); } catch (MessagingException e) { LOGGER.error("failed to send email", e); diff --git a/src/main/java/com/example/demo/registration/RegistrationService.java b/src/main/java/com/example/demo/registration/RegistrationService.java index f505b11..32d18dc 100644 --- a/src/main/java/com/example/demo/registration/RegistrationService.java +++ b/src/main/java/com/example/demo/registration/RegistrationService.java @@ -1,7 +1,7 @@ package com.example.demo.registration; -import com.example.demo.appuser.AppUser; -import com.example.demo.appuser.AppUserRole; +import com.example.demo.appuser.UserCredentials; +import com.example.demo.appuser.UserRole; import com.example.demo.appuser.AppUserService; import com.example.demo.email.EmailSender; import com.example.demo.registration.token.ConfirmationToken; @@ -30,17 +30,15 @@ public String register(RegistrationRequest request) { } String token = appUserService.signUpUser( - new AppUser( - request.getFirstName(), - request.getLastName(), + new UserCredentials( request.getEmail(), request.getPassword(), - AppUserRole.USER + UserRole.BUSINESS ) ); - String link = "http://localhost:8080/api/v1/registration/confirm?token=" + token; + String link = "www.google.com"; emailSender.send( request.getEmail(), buildEmail(request.getFirstName(), link)); diff --git a/src/main/java/com/example/demo/registration/token/ConfirmationToken.java b/src/main/java/com/example/demo/registration/token/ConfirmationToken.java index fa90b09..8a4dec5 100644 --- a/src/main/java/com/example/demo/registration/token/ConfirmationToken.java +++ b/src/main/java/com/example/demo/registration/token/ConfirmationToken.java @@ -1,6 +1,6 @@ package com.example.demo.registration.token; -import com.example.demo.appuser.AppUser; +import com.example.demo.appuser.UserCredentials; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -42,15 +42,15 @@ public class ConfirmationToken { nullable = false, name = "app_user_id" ) - private AppUser appUser; + private UserCredentials appUser; public ConfirmationToken(String token, LocalDateTime createdAt, LocalDateTime expiresAt, - AppUser appUser) { + UserCredentials userCredentials) { this.token = token; this.createdAt = createdAt; this.expiresAt = expiresAt; - this.appUser = appUser; + this.appUser = userCredentials; } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c270e3e..c5f2cdd 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,27 +1,44 @@ server: + port: 9191 error: include-message: always include-binding-errors: always + + + spring: datasource: - password: - url: jdbc:postgresql://localhost:5432/registration - username: + driver-class-name: com.mysql.cj.jdbc.Driver + password: bharani16 + url: jdbc:mysql://localhost:3306/registration?serverTimezone=UTC + username: root jpa: hibernate: ddl-auto: create-drop properties: hibernate: - dialect: org.hibernate.dialect.PostgreSQLDialect + dialect: org.hibernate.dialect.MySQL5Dialect format_sql: true show-sql: true + # mail: + # host: smtp.gmail.com + # port: 587 + #username: sravan.mummadi06@gmail.com + #password: Ishikammulu1! + #properties: + #mail: + #smtp: + #auth: true + #starttls: + #enable: true mail: - host: localhost - port: 1025 - username: hello - password: hello + host: smtp.gmail.com + port: 587 + username: ethniconnect@gmail.com + password: nftvtqgflwntjipb + properties: mail: @@ -34,4 +51,3 @@ spring: connectiontimeout: 5000 timeout: 3000 writetimeout: 5000 - From 1467a539f6b85905bfd9a9a4ad226756f3ae17aa Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 19 Mar 2022 17:13:12 -0400 Subject: [PATCH 02/69] working with AWS rds --- src/main/resources/application.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c5f2cdd..7036b1e 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -11,14 +11,16 @@ spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver password: bharani16 - url: jdbc:mysql://localhost:3306/registration?serverTimezone=UTC + initialization-mode: ALWAYS + #url: jdbc:mysql://localhost:3306/registration?serverTimezone=UTC + url: jdbc:mysql://ethniconnect.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect username: root jpa: hibernate: ddl-auto: create-drop properties: hibernate: - dialect: org.hibernate.dialect.MySQL5Dialect + dialect: org.hibernate.dialect.MySQL8Dialect format_sql: true show-sql: true From 3544e39c485ff975760730ef7c8b0cc750e7d808 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 19 Mar 2022 17:26:18 -0400 Subject: [PATCH 03/69] Update pom.xml update pom --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index c7c7712..a667ad7 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,12 @@ spring-security-test test + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + From 8e7614e3202a66f1fcf0cce28d992bfbbbd60936 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 19 Mar 2022 17:37:18 -0400 Subject: [PATCH 04/69] Update pom.xml add plugin --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index a667ad7..554ebc3 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + org.springframework.boot spring-boot-maven-plugin From 13080519d745763ec47c026a81f02e4eb7c4f87c Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 20 Mar 2022 18:53:42 -0400 Subject: [PATCH 05/69] working working add and update chef --- .DS_Store | Bin 0 -> 6148 bytes .../com/example/demo/Chefprofile/Chef.java | 37 ++++++++++ .../Chefprofile/ChefProfileController.java | 36 ++++++++++ .../Chefprofile/ChefProfileRepository.java | 12 ++++ .../demo/Chefprofile/ChefProfileService.java | 66 ++++++++++++++++++ .../registration/RegistrationRequest.java | 2 +- .../registration/RegistrationService.java | 5 +- .../security/config/WebSecurityConfig.java | 2 +- src/main/resources/application.yml | 6 +- 9 files changed, 159 insertions(+), 7 deletions(-) create mode 100644 .DS_Store create mode 100644 src/main/java/com/example/demo/Chefprofile/Chef.java create mode 100644 src/main/java/com/example/demo/Chefprofile/ChefProfileController.java create mode 100644 src/main/java/com/example/demo/Chefprofile/ChefProfileRepository.java create mode 100644 src/main/java/com/example/demo/Chefprofile/ChefProfileService.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ea7febd2e65262fee36b8037c1a892c8bea09758 GIT binary patch literal 6148 zcmeHKL5tHs6n@jzZNeh-pyEXccrCT-3a)s`*6zWBmyPH_r6x^TgV{`J(v46GIV%1b zZ~hejizofw%tT14;z`7v2Q%Nyo9|8fzNDEvA`+8zd_XiHA_tAJlhC& z3f|*!D(6uuBg}b2YyZ9ieD8X6P8XC>*}8wnSQ~v)rV?>#9*t;@aopm6YVrHDBnjS# z-l0#MY;mi_cIlK(=$NMT1UTB=UwmvubSbA5&0G6^ZL#*Kpb)$>T2RsCcFumsjmms! zp61WdGEMSgJpLj&-QJbGzSDR1omasdSq4Q|tn*2@dcm`&Ql?Qo4x?wuqMQw`J(5`w zCfQ=80+M(E%FE|T7Rz!X*IAsa*g!8huH()IH#VE`(7ShkJM=aOhYt>i-qGEo?bda! z-@fzkboMqq&*XdjdYHg}PuW$2HGIIJk^M!m%2Jte)^$wHwP+Qv3S2G)%sar@zg%hC zY^?%Tfj>}y-wz%dqi?X%s9qiDR0#m=!L1Bq_301v*a7qnRvO`f2^|X5p~93H!c-1I zhhyD0{7Rz^C!wy4eaw}GsZfL|JcOs{Bz%pww+dJVnhJFFbin8T$*=4GW{{m(1*`)9 zl>(wS4W<*MWX{%| JR)N2&z;_m(lx6?` literal 0 HcmV?d00001 diff --git a/src/main/java/com/example/demo/Chefprofile/Chef.java b/src/main/java/com/example/demo/Chefprofile/Chef.java new file mode 100644 index 0000000..4214d99 --- /dev/null +++ b/src/main/java/com/example/demo/Chefprofile/Chef.java @@ -0,0 +1,37 @@ +package com.example.demo.Chefprofile; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Table(name = "chef") +public class Chef { + @Id + @GeneratedValue + private int chef_id; + private long login_id; + private String chef_fname; + private String chef_lname; + private String chef_emailid; + private String chef_phone; + private String chef_street; + private String chef_city; + private String chef_state; + private String chef_zip; + private String chef_paymode; + private String chef_description; + private int chef_experience; + private String chef_fblink; + private String chef_linkdin; + private String chef_image; + +} diff --git a/src/main/java/com/example/demo/Chefprofile/ChefProfileController.java b/src/main/java/com/example/demo/Chefprofile/ChefProfileController.java new file mode 100644 index 0000000..09b1cff --- /dev/null +++ b/src/main/java/com/example/demo/Chefprofile/ChefProfileController.java @@ -0,0 +1,36 @@ +package com.example.demo.Chefprofile; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +public class ChefProfileController { + @Autowired + private ChefProfileService chefProfileService; + + @PostMapping("/chef") + public Chef addChef(@RequestBody Chef chef) throws Exception + { + + return chefProfileService.saveChef(chef); + } + /* @PostMapping("/chefs") + public List addChefs(@RequestBody List chefs) + { + return chefProfileService.saveChefs(chefs); + }*/ + + @GetMapping({"/chefById/{id}"}) + public Chef findChefById(@PathVariable int id) + { + return chefProfileService.getChefById(id); + } + + @PutMapping("/updatechef") + public Chef updateChef(@RequestBody Chef chef) + { + return chefProfileService.updateChef(chef); + } +} diff --git a/src/main/java/com/example/demo/Chefprofile/ChefProfileRepository.java b/src/main/java/com/example/demo/Chefprofile/ChefProfileRepository.java new file mode 100644 index 0000000..af51dc7 --- /dev/null +++ b/src/main/java/com/example/demo/Chefprofile/ChefProfileRepository.java @@ -0,0 +1,12 @@ +package com.example.demo.Chefprofile; + +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface ChefProfileRepository extends JpaRepository { + + + + /*Chef findByEmailId(String chef_emailid);*/ +} diff --git a/src/main/java/com/example/demo/Chefprofile/ChefProfileService.java b/src/main/java/com/example/demo/Chefprofile/ChefProfileService.java new file mode 100644 index 0000000..0bdae5c --- /dev/null +++ b/src/main/java/com/example/demo/Chefprofile/ChefProfileService.java @@ -0,0 +1,66 @@ +package com.example.demo.Chefprofile; + +import com.example.demo.appuser.AppUserRepository; +import com.example.demo.appuser.UserCredentials; +import org.springframework.beans.factory.annotation.Autowired; + +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +public class ChefProfileService { + @Autowired + private ChefProfileRepository chefProfileRepository; + @Autowired + private AppUserRepository appUserRepository; + + public Chef saveChef(Chef chef) throws Exception{ + Optional userData =appUserRepository.findByEmail(chef.getChef_emailid()); + if(!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + Long loginId = userData.get().getId(); + + chef.setLogin_id(loginId); + return chefProfileRepository.save(chef); + } + public List saveChefs(List chefs){ + return chefProfileRepository.saveAll(chefs); + } + + public List getChefs(){ + return chefProfileRepository.findAll(); + } + public Chef getChefById(int chef_id){ + return chefProfileRepository.findById(chef_id).orElse(null); + } + /*public Chef getChefByEmailId(String chef_emailid){ + return chefProfileRepository.findByEmailId(chef_emailid); + }*/ + public String deleteChef(int chef_id) + { + chefProfileRepository.deleteById(chef_id); + return "chef removed !!" + chef_id; + } + public Chef updateChef(Chef chef) + { + Chef existingChef=chefProfileRepository.findById(chef.getChef_id()).orElse(null); + existingChef.setChef_fname(chef.getChef_fname()); + existingChef.setChef_lname(chef.getChef_lname()); + existingChef.setChef_phone(chef.getChef_phone()); + existingChef.setChef_city(chef.getChef_city()); + existingChef.setChef_description(chef.getChef_description()); + existingChef.setChef_fblink(chef.getChef_fblink()); + existingChef.setChef_linkdin(chef.getChef_linkdin()); + existingChef.setChef_image(chef.getChef_image()); + existingChef.setChef_paymode(chef.getChef_paymode()); + existingChef.setChef_state(chef.getChef_state()); + existingChef.setChef_street(chef.getChef_street()); + existingChef.setChef_zip(chef.getChef_zip()); + existingChef.setChef_city(chef.getChef_city()); + existingChef.setChef_experience(chef.getChef_experience()); + return chefProfileRepository.save(existingChef); + + } +} diff --git a/src/main/java/com/example/demo/registration/RegistrationRequest.java b/src/main/java/com/example/demo/registration/RegistrationRequest.java index 2dd483a..64f0907 100644 --- a/src/main/java/com/example/demo/registration/RegistrationRequest.java +++ b/src/main/java/com/example/demo/registration/RegistrationRequest.java @@ -11,7 +11,7 @@ @ToString public class RegistrationRequest { private final String firstName; - private final String lastName; + /* private final String lastName;*/ private final String email; private final String password; } diff --git a/src/main/java/com/example/demo/registration/RegistrationService.java b/src/main/java/com/example/demo/registration/RegistrationService.java index 32d18dc..9fc4685 100644 --- a/src/main/java/com/example/demo/registration/RegistrationService.java +++ b/src/main/java/com/example/demo/registration/RegistrationService.java @@ -38,7 +38,8 @@ public String register(RegistrationRequest request) { ) ); - String link = "www.google.com"; + /*String link = "www.google.com";*/ + String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; emailSender.send( request.getEmail(), buildEmail(request.getFirstName(), link)); @@ -125,7 +126,7 @@ private String buildEmail(String name, String link) { "
\n" + " \n" + " \n" + - "

Hi " + name + ",

Thank you for registering. Please click on the below link to activate your account:

Activate Now

\n Link will expire in 15 minutes.

See you soon

" + + "

Hi " + name + ",

Thank you for registering to Ethniconnect. Please click on the below link to activate your account:

Activate Now

\n Link will expire in 15 minutes.

See you soon

" + " \n" + " \n" + "
\n" + diff --git a/src/main/java/com/example/demo/security/config/WebSecurityConfig.java b/src/main/java/com/example/demo/security/config/WebSecurityConfig.java index 72b110d..a431645 100644 --- a/src/main/java/com/example/demo/security/config/WebSecurityConfig.java +++ b/src/main/java/com/example/demo/security/config/WebSecurityConfig.java @@ -24,7 +24,7 @@ protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .authorizeRequests() - .antMatchers("/api/v*/registration/**") + .antMatchers("/**") .permitAll() .anyRequest() .authenticated().and() diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 7036b1e..3732653 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 9191 + port: 5000 error: include-message: always include-binding-errors: always @@ -12,8 +12,8 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver password: bharani16 initialization-mode: ALWAYS - #url: jdbc:mysql://localhost:3306/registration?serverTimezone=UTC - url: jdbc:mysql://ethniconnect.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect + url: jdbc:mysql://localhost:3306/registration?serverTimezone=UTC + #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect username: root jpa: hibernate: From a9090aebc2ef1a34d7cb243b1a14a67211aaa363 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 20 Mar 2022 23:40:15 -0400 Subject: [PATCH 06/69] resetpassword working --- .../com/example/demo/email/EmailService.java | 40 -------- .../Chefprofile/Chef.java | 2 +- .../Chefprofile/ChefProfileController.java | 4 +- .../Chefprofile/ChefProfileRepository.java | 4 +- .../Chefprofile/ChefProfileService.java | 9 +- .../ContactPage/Contact.java | 24 +++++ .../ContactPage/ContactController.java | 34 +++++++ .../ContactPage/ContactRepository.java | 7 ++ .../ContactPage/ContactService.java | 27 ++++++ .../DemoApplication.java | 2 +- .../appuser/AppUserRepository.java | 5 +- .../appuser/AppUserService.java | 29 ++++-- .../appuser/UserCredentials.java | 3 +- .../appuser/UserRole.java | 2 +- .../email/EmailSender.java | 2 +- .../email/EmailService.java} | 95 +++++++------------ .../registration/EmailValidator.java | 2 +- .../registration/RegistrationController.java | 6 +- .../registration/RegistrationRequest.java | 2 +- .../registration/RegistrationService.java | 80 ++++++++++++++++ .../registration/token/ConfirmationToken.java | 4 +- .../token/ConfirmationTokenRepository.java | 2 +- .../token/ConfirmationTokenService.java | 2 +- .../ResetPasswordController.java | 33 +++++++ .../resetpassword/ResetPasswordRequest.java | 20 ++++ .../resetpassword/ResetPasswordService.java | 65 +++++++++++++ .../security/PasswordEncoder.java | 2 +- .../security/config/WebSecurityConfig.java | 4 +- .../DemoApplicationTests.java | 2 +- 29 files changed, 375 insertions(+), 138 deletions(-) delete mode 100644 src/main/java/com/example/demo/email/EmailService.java rename src/main/java/{com/example/demo => ethniconnect_backend}/Chefprofile/Chef.java (95%) rename src/main/java/{com/example/demo => ethniconnect_backend}/Chefprofile/ChefProfileController.java (93%) rename src/main/java/{com/example/demo => ethniconnect_backend}/Chefprofile/ChefProfileRepository.java (74%) rename src/main/java/{com/example/demo => ethniconnect_backend}/Chefprofile/ChefProfileService.java (92%) create mode 100644 src/main/java/ethniconnect_backend/ContactPage/Contact.java create mode 100644 src/main/java/ethniconnect_backend/ContactPage/ContactController.java create mode 100644 src/main/java/ethniconnect_backend/ContactPage/ContactRepository.java create mode 100644 src/main/java/ethniconnect_backend/ContactPage/ContactService.java rename src/main/java/{com/example/demo => ethniconnect_backend}/DemoApplication.java (90%) rename src/main/java/{com/example/demo => ethniconnect_backend}/appuser/AppUserRepository.java (86%) rename src/main/java/{com/example/demo => ethniconnect_backend}/appuser/AppUserService.java (80%) rename src/main/java/{com/example/demo => ethniconnect_backend}/appuser/UserCredentials.java (96%) rename src/main/java/{com/example/demo => ethniconnect_backend}/appuser/UserRole.java (62%) rename src/main/java/{com/example/demo => ethniconnect_backend}/email/EmailSender.java (67%) rename src/main/java/{com/example/demo/registration/RegistrationService.java => ethniconnect_backend/email/EmailService.java} (68%) rename src/main/java/{com/example/demo => ethniconnect_backend}/registration/EmailValidator.java (86%) rename src/main/java/{com/example/demo => ethniconnect_backend}/registration/RegistrationController.java (83%) rename src/main/java/{com/example/demo => ethniconnect_backend}/registration/RegistrationRequest.java (89%) create mode 100644 src/main/java/ethniconnect_backend/registration/RegistrationService.java rename src/main/java/{com/example/demo => ethniconnect_backend}/registration/token/ConfirmationToken.java (92%) rename src/main/java/{com/example/demo => ethniconnect_backend}/registration/token/ConfirmationTokenRepository.java (94%) rename src/main/java/{com/example/demo => ethniconnect_backend}/registration/token/ConfirmationTokenService.java (93%) create mode 100644 src/main/java/ethniconnect_backend/resetpassword/ResetPasswordController.java create mode 100644 src/main/java/ethniconnect_backend/resetpassword/ResetPasswordRequest.java create mode 100644 src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java rename src/main/java/{com/example/demo => ethniconnect_backend}/security/PasswordEncoder.java (90%) rename src/main/java/{com/example/demo => ethniconnect_backend}/security/config/WebSecurityConfig.java (94%) rename src/test/java/{com/example/demo => ethniconnect_backend}/DemoApplicationTests.java (85%) diff --git a/src/main/java/com/example/demo/email/EmailService.java b/src/main/java/com/example/demo/email/EmailService.java deleted file mode 100644 index 2c5f106..0000000 --- a/src/main/java/com/example/demo/email/EmailService.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.example.demo.email; - -import lombok.AllArgsConstructor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.mail.javamail.JavaMailSender; -import org.springframework.mail.javamail.MimeMessageHelper; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Service; - -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; - -@Service -@AllArgsConstructor -public class EmailService implements EmailSender{ - - private final static Logger LOGGER = LoggerFactory - .getLogger(EmailService.class); - - private final JavaMailSender mailSender; - - @Override - @Async - public void send(String to, String email) { - try { - MimeMessage mimeMessage = mailSender.createMimeMessage(); - MimeMessageHelper helper = - new MimeMessageHelper(mimeMessage, "utf-8"); - helper.setText(email, true); - helper.setTo(to); - helper.setSubject("Confirm your email"); - helper.setFrom("ethniconnect@gmail.com"); - mailSender.send(mimeMessage); - } catch (MessagingException e) { - LOGGER.error("failed to send email", e); - throw new IllegalStateException("failed to send email"); - } - } -} diff --git a/src/main/java/com/example/demo/Chefprofile/Chef.java b/src/main/java/ethniconnect_backend/Chefprofile/Chef.java similarity index 95% rename from src/main/java/com/example/demo/Chefprofile/Chef.java rename to src/main/java/ethniconnect_backend/Chefprofile/Chef.java index 4214d99..3c2dda3 100644 --- a/src/main/java/com/example/demo/Chefprofile/Chef.java +++ b/src/main/java/ethniconnect_backend/Chefprofile/Chef.java @@ -1,4 +1,4 @@ -package com.example.demo.Chefprofile; +package ethniconnect_backend.Chefprofile; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/example/demo/Chefprofile/ChefProfileController.java b/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileController.java similarity index 93% rename from src/main/java/com/example/demo/Chefprofile/ChefProfileController.java rename to src/main/java/ethniconnect_backend/Chefprofile/ChefProfileController.java index 09b1cff..f45aaf1 100644 --- a/src/main/java/com/example/demo/Chefprofile/ChefProfileController.java +++ b/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileController.java @@ -1,10 +1,8 @@ -package com.example.demo.Chefprofile; +package ethniconnect_backend.Chefprofile; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.List; - @RestController public class ChefProfileController { @Autowired diff --git a/src/main/java/com/example/demo/Chefprofile/ChefProfileRepository.java b/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileRepository.java similarity index 74% rename from src/main/java/com/example/demo/Chefprofile/ChefProfileRepository.java rename to src/main/java/ethniconnect_backend/Chefprofile/ChefProfileRepository.java index af51dc7..fe66531 100644 --- a/src/main/java/com/example/demo/Chefprofile/ChefProfileRepository.java +++ b/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileRepository.java @@ -1,9 +1,7 @@ -package com.example.demo.Chefprofile; +package ethniconnect_backend.Chefprofile; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; - public interface ChefProfileRepository extends JpaRepository { diff --git a/src/main/java/com/example/demo/Chefprofile/ChefProfileService.java b/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileService.java similarity index 92% rename from src/main/java/com/example/demo/Chefprofile/ChefProfileService.java rename to src/main/java/ethniconnect_backend/Chefprofile/ChefProfileService.java index 0bdae5c..04fbfc3 100644 --- a/src/main/java/com/example/demo/Chefprofile/ChefProfileService.java +++ b/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileService.java @@ -1,7 +1,7 @@ -package com.example.demo.Chefprofile; +package ethniconnect_backend.Chefprofile; -import com.example.demo.appuser.AppUserRepository; -import com.example.demo.appuser.UserCredentials; +import ethniconnect_backend.appuser.AppUserRepository; +import ethniconnect_backend.appuser.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,7 +29,8 @@ public List saveChefs(List chefs){ return chefProfileRepository.saveAll(chefs); } - public List getChefs(){ + public List getChefs() + { return chefProfileRepository.findAll(); } public Chef getChefById(int chef_id){ diff --git a/src/main/java/ethniconnect_backend/ContactPage/Contact.java b/src/main/java/ethniconnect_backend/ContactPage/Contact.java new file mode 100644 index 0000000..392dfad --- /dev/null +++ b/src/main/java/ethniconnect_backend/ContactPage/Contact.java @@ -0,0 +1,24 @@ +package ethniconnect_backend.ContactPage; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Table(name = "contact") +public class Contact { + @Id + @GeneratedValue + private int id; + private String name; + private String message; + +} diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java new file mode 100644 index 0000000..aac0b52 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java @@ -0,0 +1,34 @@ +package ethniconnect_backend.ContactPage; + +import ethniconnect_backend.Chefprofile.Chef; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +public class ContactController { + @Autowired + private ContactService contactService; + + @PostMapping("/ContactRequest") + public Contact addcontactrequest(@RequestBody Contact contact) + { + + return contactService.saveContact(contact); + } + + @GetMapping({"/ContactRequests"}) + public List findcontactrequests() + + { + return contactService.getContactRequets(); + } + + @GetMapping({"/ContactRequestById/{id}"}) + public Contact findcontactrequestbyId(@PathVariable int id) + { + return contactService.getContactRequestById(id); + } + +} diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactRepository.java b/src/main/java/ethniconnect_backend/ContactPage/ContactRepository.java new file mode 100644 index 0000000..324f2e4 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactRepository.java @@ -0,0 +1,7 @@ +package ethniconnect_backend.ContactPage; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ContactRepository extends JpaRepository +{ +} diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java new file mode 100644 index 0000000..9063575 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java @@ -0,0 +1,27 @@ +package ethniconnect_backend.ContactPage; + +import ethniconnect_backend.Chefprofile.Chef; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class ContactService { + @Autowired + public ContactRepository contactRepository; + public Contact saveContact(Contact contact) + { + return contactRepository.save(contact); + } + + public List getContactRequets() + { + return contactRepository.findAll(); + } + public Contact getContactRequestById(int id) + { + return contactRepository.findById(id).orElse(null); + } + +} diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/ethniconnect_backend/DemoApplication.java similarity index 90% rename from src/main/java/com/example/demo/DemoApplication.java rename to src/main/java/ethniconnect_backend/DemoApplication.java index 64b538a..3d1086b 100644 --- a/src/main/java/com/example/demo/DemoApplication.java +++ b/src/main/java/ethniconnect_backend/DemoApplication.java @@ -1,4 +1,4 @@ -package com.example.demo; +package ethniconnect_backend; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/src/main/java/com/example/demo/appuser/AppUserRepository.java b/src/main/java/ethniconnect_backend/appuser/AppUserRepository.java similarity index 86% rename from src/main/java/com/example/demo/appuser/AppUserRepository.java rename to src/main/java/ethniconnect_backend/appuser/AppUserRepository.java index 551a4e8..0142814 100644 --- a/src/main/java/com/example/demo/appuser/AppUserRepository.java +++ b/src/main/java/ethniconnect_backend/appuser/AppUserRepository.java @@ -1,4 +1,4 @@ -package com.example.demo.appuser; +package ethniconnect_backend.appuser; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; @@ -14,6 +14,7 @@ public interface AppUserRepository extends JpaRepository { Optional findByEmail(String email); + public UserCredentials findByResetpasswordtoken(String token); @Transactional @Modifying @@ -21,4 +22,6 @@ public interface AppUserRepository "SET a.enabled = TRUE WHERE a.email = ?1") int enableAppUser(String email); + + } diff --git a/src/main/java/com/example/demo/appuser/AppUserService.java b/src/main/java/ethniconnect_backend/appuser/AppUserService.java similarity index 80% rename from src/main/java/com/example/demo/appuser/AppUserService.java rename to src/main/java/ethniconnect_backend/appuser/AppUserService.java index 2411cce..ff5ef25 100644 --- a/src/main/java/com/example/demo/appuser/AppUserService.java +++ b/src/main/java/ethniconnect_backend/appuser/AppUserService.java @@ -1,17 +1,18 @@ -package com.example.demo.appuser; +package ethniconnect_backend.appuser; -import com.example.demo.registration.token.ConfirmationToken; -import com.example.demo.registration.token.ConfirmationTokenService; +import ethniconnect_backend.registration.token.ConfirmationToken; +import ethniconnect_backend.registration.token.ConfirmationTokenService; import lombok.AllArgsConstructor; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; import java.util.UUID; - +@Transactional @Service @AllArgsConstructor public class AppUserService implements UserDetailsService { @@ -23,6 +24,13 @@ public class AppUserService implements UserDetailsService { private final BCryptPasswordEncoder bCryptPasswordEncoder; private final ConfirmationTokenService confirmationTokenService; + public boolean isEmailIdExist(String emailId) + { + if(appUserRepository.findByEmail(emailId).isPresent()) + return true; + return false; + } + @Override public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { @@ -51,6 +59,14 @@ public String signUpUser(UserCredentials appUser) { appUserRepository.save(appUser); + String token = getToken(appUser); + +// TODO: SEND EMAIL + + return token; + } + + public String getToken(UserCredentials appUser) { String token = UUID.randomUUID().toString(); ConfirmationToken confirmationToken = new ConfirmationToken( @@ -62,13 +78,12 @@ public String signUpUser(UserCredentials appUser) { confirmationTokenService.saveConfirmationToken( confirmationToken); - -// TODO: SEND EMAIL - return token; } public int enableAppUser(String email) { return appUserRepository.enableAppUser(email); } + + } diff --git a/src/main/java/com/example/demo/appuser/UserCredentials.java b/src/main/java/ethniconnect_backend/appuser/UserCredentials.java similarity index 96% rename from src/main/java/com/example/demo/appuser/UserCredentials.java rename to src/main/java/ethniconnect_backend/appuser/UserCredentials.java index e8fc06b..07087ea 100644 --- a/src/main/java/com/example/demo/appuser/UserCredentials.java +++ b/src/main/java/ethniconnect_backend/appuser/UserCredentials.java @@ -1,4 +1,4 @@ -package com.example.demo.appuser; +package ethniconnect_backend.appuser; import lombok.EqualsAndHashCode; import lombok.Getter; @@ -35,6 +35,7 @@ public class UserCredentials implements UserDetails { private String password; @Enumerated(EnumType.STRING) private UserRole appUserRole; + private String resetpasswordtoken; private Boolean locked = false; private Boolean enabled = false; diff --git a/src/main/java/com/example/demo/appuser/UserRole.java b/src/main/java/ethniconnect_backend/appuser/UserRole.java similarity index 62% rename from src/main/java/com/example/demo/appuser/UserRole.java rename to src/main/java/ethniconnect_backend/appuser/UserRole.java index d8411f9..0d7dc04 100644 --- a/src/main/java/com/example/demo/appuser/UserRole.java +++ b/src/main/java/ethniconnect_backend/appuser/UserRole.java @@ -1,4 +1,4 @@ -package com.example.demo.appuser; +package ethniconnect_backend.appuser; public enum UserRole { PERSONAL, diff --git a/src/main/java/com/example/demo/email/EmailSender.java b/src/main/java/ethniconnect_backend/email/EmailSender.java similarity index 67% rename from src/main/java/com/example/demo/email/EmailSender.java rename to src/main/java/ethniconnect_backend/email/EmailSender.java index 3b2c58b..a57c2d0 100644 --- a/src/main/java/com/example/demo/email/EmailSender.java +++ b/src/main/java/ethniconnect_backend/email/EmailSender.java @@ -1,4 +1,4 @@ -package com.example.demo.email; +package ethniconnect_backend.email; public interface EmailSender { void send(String to, String email); diff --git a/src/main/java/com/example/demo/registration/RegistrationService.java b/src/main/java/ethniconnect_backend/email/EmailService.java similarity index 68% rename from src/main/java/com/example/demo/registration/RegistrationService.java rename to src/main/java/ethniconnect_backend/email/EmailService.java index 9fc4685..a3b85b3 100644 --- a/src/main/java/com/example/demo/registration/RegistrationService.java +++ b/src/main/java/ethniconnect_backend/email/EmailService.java @@ -1,76 +1,26 @@ -package com.example.demo.registration; +package ethniconnect_backend.email; -import com.example.demo.appuser.UserCredentials; -import com.example.demo.appuser.UserRole; -import com.example.demo.appuser.AppUserService; -import com.example.demo.email.EmailSender; -import com.example.demo.registration.token.ConfirmationToken; -import com.example.demo.registration.token.ConfirmationTokenService; import lombok.AllArgsConstructor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDateTime; +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; @Service @AllArgsConstructor -public class RegistrationService { +public class EmailService implements EmailSender{ - private final AppUserService appUserService; - private final EmailValidator emailValidator; - private final ConfirmationTokenService confirmationTokenService; - private final EmailSender emailSender; + private final static Logger LOGGER = LoggerFactory + .getLogger(EmailService.class); - public String register(RegistrationRequest request) { - boolean isValidEmail = emailValidator. - test(request.getEmail()); + private final JavaMailSender mailSender; - if (!isValidEmail) { - throw new IllegalStateException("email not valid"); - } - - String token = appUserService.signUpUser( - new UserCredentials( - request.getEmail(), - request.getPassword(), - UserRole.BUSINESS - - ) - ); - - /*String link = "www.google.com";*/ - String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; - emailSender.send( - request.getEmail(), - buildEmail(request.getFirstName(), link)); - - return token; - } - - @Transactional - public String confirmToken(String token) { - ConfirmationToken confirmationToken = confirmationTokenService - .getToken(token) - .orElseThrow(() -> - new IllegalStateException("token not found")); - - if (confirmationToken.getConfirmedAt() != null) { - throw new IllegalStateException("email already confirmed"); - } - - LocalDateTime expiredAt = confirmationToken.getExpiresAt(); - - if (expiredAt.isBefore(LocalDateTime.now())) { - throw new IllegalStateException("token expired"); - } - - confirmationTokenService.setConfirmedAt(token); - appUserService.enableAppUser( - confirmationToken.getAppUser().getEmail()); - return "confirmed"; - } - - private String buildEmail(String name, String link) { + public String buildEmail(String name, String link) { return "
\n" + "\n" + "\n" + @@ -138,4 +88,23 @@ private String buildEmail(String name, String link) { "\n" + "
"; } + + + @Override + @Async + public void send(String to, String email) { + try { + MimeMessage mimeMessage = mailSender.createMimeMessage(); + MimeMessageHelper helper = + new MimeMessageHelper(mimeMessage, "utf-8"); + helper.setText(email, true); + helper.setTo(to); + helper.setSubject("Confirm your email"); + helper.setFrom("ethniconnect@gmail.com"); + mailSender.send(mimeMessage); + } catch (MessagingException e) { + LOGGER.error("failed to send email", e); + throw new IllegalStateException("failed to send email"); + } + } } diff --git a/src/main/java/com/example/demo/registration/EmailValidator.java b/src/main/java/ethniconnect_backend/registration/EmailValidator.java similarity index 86% rename from src/main/java/com/example/demo/registration/EmailValidator.java rename to src/main/java/ethniconnect_backend/registration/EmailValidator.java index 085cbe0..7b673a2 100644 --- a/src/main/java/com/example/demo/registration/EmailValidator.java +++ b/src/main/java/ethniconnect_backend/registration/EmailValidator.java @@ -1,4 +1,4 @@ -package com.example.demo.registration; +package ethniconnect_backend.registration; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/example/demo/registration/RegistrationController.java b/src/main/java/ethniconnect_backend/registration/RegistrationController.java similarity index 83% rename from src/main/java/com/example/demo/registration/RegistrationController.java rename to src/main/java/ethniconnect_backend/registration/RegistrationController.java index c8b12b8..5efe567 100644 --- a/src/main/java/com/example/demo/registration/RegistrationController.java +++ b/src/main/java/ethniconnect_backend/registration/RegistrationController.java @@ -1,5 +1,6 @@ -package com.example.demo.registration; +package ethniconnect_backend.registration; +import ethniconnect_backend.resetpassword.ResetPasswordRequest; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -20,4 +21,5 @@ public String confirm(@RequestParam("token") String token) { return registrationService.confirmToken(token); } -} + + } diff --git a/src/main/java/com/example/demo/registration/RegistrationRequest.java b/src/main/java/ethniconnect_backend/registration/RegistrationRequest.java similarity index 89% rename from src/main/java/com/example/demo/registration/RegistrationRequest.java rename to src/main/java/ethniconnect_backend/registration/RegistrationRequest.java index 64f0907..fdfa5b6 100644 --- a/src/main/java/com/example/demo/registration/RegistrationRequest.java +++ b/src/main/java/ethniconnect_backend/registration/RegistrationRequest.java @@ -1,4 +1,4 @@ -package com.example.demo.registration; +package ethniconnect_backend.registration; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; diff --git a/src/main/java/ethniconnect_backend/registration/RegistrationService.java b/src/main/java/ethniconnect_backend/registration/RegistrationService.java new file mode 100644 index 0000000..1a0fba9 --- /dev/null +++ b/src/main/java/ethniconnect_backend/registration/RegistrationService.java @@ -0,0 +1,80 @@ +package ethniconnect_backend.registration; + +import ethniconnect_backend.appuser.UserCredentials; +import ethniconnect_backend.appuser.UserRole; +import ethniconnect_backend.appuser.AppUserService; +import ethniconnect_backend.email.EmailSender; +import ethniconnect_backend.email.EmailService; +import ethniconnect_backend.registration.token.ConfirmationToken; +import ethniconnect_backend.registration.token.ConfirmationTokenService; +import ethniconnect_backend.resetpassword.ResetPasswordRequest; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; + +@Service +@AllArgsConstructor +public class RegistrationService { + + private final AppUserService appUserService; + private final EmailValidator emailValidator; + private final ConfirmationTokenService confirmationTokenService; + private final EmailSender emailSender; + private EmailService emailService; + + public String register(RegistrationRequest request) { + boolean isValidEmail = emailValidator. + test(request.getEmail()); + + if (!isValidEmail) { + throw new IllegalStateException("email not valid"); + } + + String token = appUserService.signUpUser( + new UserCredentials( + request.getEmail(), + request.getPassword(), + UserRole.BUSINESS + + ) + ); + + /*String link = "www.google.com";*/ + String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; + emailSender.send( + request.getEmail(), + emailService.buildEmail(request.getFirstName(), link)); + + return token; + } + + @Transactional + public String confirmToken(String token) { + ConfirmationToken confirmationToken = confirmationTokenService + .getToken(token) + .orElseThrow(() -> + new IllegalStateException("token not found")); + + if (confirmationToken.getConfirmedAt() != null) { + throw new IllegalStateException("email already confirmed"); + } + + LocalDateTime expiredAt = confirmationToken.getExpiresAt(); + + if (expiredAt.isBefore(LocalDateTime.now())) { + throw new IllegalStateException("token expired"); + } + + confirmationTokenService.setConfirmedAt(token); + appUserService.enableAppUser( + confirmationToken.getAppUser().getEmail()); + return "confirmed"; + } + + + + + +} diff --git a/src/main/java/com/example/demo/registration/token/ConfirmationToken.java b/src/main/java/ethniconnect_backend/registration/token/ConfirmationToken.java similarity index 92% rename from src/main/java/com/example/demo/registration/token/ConfirmationToken.java rename to src/main/java/ethniconnect_backend/registration/token/ConfirmationToken.java index 8a4dec5..5f10a8e 100644 --- a/src/main/java/com/example/demo/registration/token/ConfirmationToken.java +++ b/src/main/java/ethniconnect_backend/registration/token/ConfirmationToken.java @@ -1,6 +1,6 @@ -package com.example.demo.registration.token; +package ethniconnect_backend.registration.token; -import com.example.demo.appuser.UserCredentials; +import ethniconnect_backend.appuser.UserCredentials; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/src/main/java/com/example/demo/registration/token/ConfirmationTokenRepository.java b/src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenRepository.java similarity index 94% rename from src/main/java/com/example/demo/registration/token/ConfirmationTokenRepository.java rename to src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenRepository.java index a9c7b0d..968338f 100644 --- a/src/main/java/com/example/demo/registration/token/ConfirmationTokenRepository.java +++ b/src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenRepository.java @@ -1,4 +1,4 @@ -package com.example.demo.registration.token; +package ethniconnect_backend.registration.token; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; diff --git a/src/main/java/com/example/demo/registration/token/ConfirmationTokenService.java b/src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenService.java similarity index 93% rename from src/main/java/com/example/demo/registration/token/ConfirmationTokenService.java rename to src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenService.java index 8d268a0..5311841 100644 --- a/src/main/java/com/example/demo/registration/token/ConfirmationTokenService.java +++ b/src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenService.java @@ -1,4 +1,4 @@ -package com.example.demo.registration.token; +package ethniconnect_backend.registration.token; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordController.java b/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordController.java new file mode 100644 index 0000000..c09b84e --- /dev/null +++ b/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordController.java @@ -0,0 +1,33 @@ +package ethniconnect_backend.resetpassword; + +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.servlet.view.RedirectView; + +@RestController +@RequestMapping(path = "api/v1") +@AllArgsConstructor +public class ResetPasswordController { + + @Autowired + ResetPasswordService resetPasswordService; + + @PostMapping(path="resetpassword") + public void restpassword(@RequestBody ResetPasswordRequest resetPasswordRequest) + { + resetPasswordService.resetPassword(resetPasswordRequest); + } + + @GetMapping(path = "/resetpassword/confirm") + public RedirectView confirm(@RequestParam("token") String token) { + String email=resetPasswordService.confirmToken(token); + RedirectView redirectView = new RedirectView(); + String redirectUrl = "https://fullstackdeveloper.guru?email="+email; + redirectView.setUrl(redirectUrl); + + return redirectView; + } + + +} diff --git a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordRequest.java b/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordRequest.java new file mode 100644 index 0000000..4887179 --- /dev/null +++ b/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordRequest.java @@ -0,0 +1,20 @@ +package ethniconnect_backend.resetpassword; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.*; + +@Getter +@EqualsAndHashCode +@ToString +@Setter +public class ResetPasswordRequest { + + private String emailId; + @JsonCreator + ResetPasswordRequest(@JsonProperty("emailId") String emailId) { + this.emailId = emailId; + } + + +} diff --git a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java b/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java new file mode 100644 index 0000000..59a02f3 --- /dev/null +++ b/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java @@ -0,0 +1,65 @@ +package ethniconnect_backend.resetpassword; + +import ethniconnect_backend.appuser.AppUserRepository; +import ethniconnect_backend.appuser.AppUserService; +import ethniconnect_backend.appuser.UserCredentials; +import ethniconnect_backend.email.EmailSender; +import ethniconnect_backend.email.EmailService; +import ethniconnect_backend.registration.token.ConfirmationToken; +import ethniconnect_backend.registration.token.ConfirmationTokenService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; + +@Service +public class ResetPasswordService { + + @Autowired + AppUserService appUserService; + @Autowired + AppUserRepository appUserRepository; + @Autowired + EmailSender emailSender; + @Autowired + EmailService emailService; + @Autowired + ConfirmationTokenService confirmationTokenService; + + public void resetPassword(ResetPasswordRequest resetPasswordRequest) { + UserCredentials userCredentials = appUserRepository.findByEmail(resetPasswordRequest.getEmailId()).get(); + + if(appUserService.isEmailIdExist(resetPasswordRequest.getEmailId())) + { + String token =appUserService.getToken(userCredentials); + String link = "http://localhost:5000/api/v1/resetpassword/confirm?token=" + token; + emailSender.send( + resetPasswordRequest.getEmailId(), + emailService.buildEmail("User", link)); + } + + } + + @Transactional + public String confirmToken(String token) { + ConfirmationToken confirmationToken = confirmationTokenService + .getToken(token) + .orElseThrow(() -> + new IllegalStateException("token not found")); + + if (confirmationToken.getConfirmedAt() != null) { + throw new IllegalStateException("email already confirmed"); + } + + LocalDateTime expiredAt = confirmationToken.getExpiresAt(); + + if (expiredAt.isBefore(LocalDateTime.now())) { + throw new IllegalStateException("token expired"); + } + + confirmationTokenService.setConfirmedAt(token); + + return confirmationToken.getAppUser().getEmail(); + } +} diff --git a/src/main/java/com/example/demo/security/PasswordEncoder.java b/src/main/java/ethniconnect_backend/security/PasswordEncoder.java similarity index 90% rename from src/main/java/com/example/demo/security/PasswordEncoder.java rename to src/main/java/ethniconnect_backend/security/PasswordEncoder.java index b4f4291..dfb329b 100644 --- a/src/main/java/com/example/demo/security/PasswordEncoder.java +++ b/src/main/java/ethniconnect_backend/security/PasswordEncoder.java @@ -1,4 +1,4 @@ -package com.example.demo.security; +package ethniconnect_backend.security; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/main/java/com/example/demo/security/config/WebSecurityConfig.java b/src/main/java/ethniconnect_backend/security/config/WebSecurityConfig.java similarity index 94% rename from src/main/java/com/example/demo/security/config/WebSecurityConfig.java rename to src/main/java/ethniconnect_backend/security/config/WebSecurityConfig.java index a431645..e595c26 100644 --- a/src/main/java/com/example/demo/security/config/WebSecurityConfig.java +++ b/src/main/java/ethniconnect_backend/security/config/WebSecurityConfig.java @@ -1,6 +1,6 @@ -package com.example.demo.security.config; +package ethniconnect_backend.security.config; -import com.example.demo.appuser.AppUserService; +import ethniconnect_backend.appuser.AppUserService; import lombok.AllArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/src/test/java/com/example/demo/DemoApplicationTests.java b/src/test/java/ethniconnect_backend/DemoApplicationTests.java similarity index 85% rename from src/test/java/com/example/demo/DemoApplicationTests.java rename to src/test/java/ethniconnect_backend/DemoApplicationTests.java index 2778a6a..fa62e2c 100644 --- a/src/test/java/com/example/demo/DemoApplicationTests.java +++ b/src/test/java/ethniconnect_backend/DemoApplicationTests.java @@ -1,4 +1,4 @@ -package com.example.demo; +package ethniconnect_backend; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; From af072211b3f0d82b3ce6f0c451d645967ddad0ae Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Tue, 22 Mar 2022 15:05:31 -0400 Subject: [PATCH 07/69] working code --- .../{Chefprofile => Chef}/Chef.java | 2 +- .../ChefController.java} | 6 +- .../Chef/ChefRepository.java | 10 +++ .../ChefService.java} | 12 +-- .../ChefCreateMenu/ChefMenu.java | 23 ++++++ .../ChefCreateMenu/ChefMenuController.java | 4 + .../ChefCreateMenu/ChefMenuRepository.java | 6 ++ .../ChefCreateMenu/ChefMenuService.java | 4 + .../ChefCreateMenu/MenuCategories.java | 10 +++ .../ChefCreateMenu/Week.java | 11 +++ .../ChefSignupController.java} | 9 +-- .../ChefSignupRequest.java} | 4 +- .../ChefSignupService.java} | 19 +++-- .../EmailValidator.java | 2 +- .../token/ConfirmationToken.java | 4 +- .../token/ConfirmationTokenRepository.java | 2 +- .../token/ConfirmationTokenService.java | 2 +- .../Chefprofile/ChefProfileRepository.java | 10 --- .../ContactPage/ContactController.java | 1 - .../ContactPage/ContactService.java | 1 - .../Customer/Customer.java | 33 ++++++++ .../Customer/CustomerController.java | 31 +++++++ .../Customer/CustomerRepository.java | 6 ++ .../Customer/CustomerService.java | 61 ++++++++++++++ .../CustomerSignup/CustSignupController.java | 29 +++++++ .../CustomerSignup/CustSignupRequest.java | 19 +++++ .../CustomerSignup/CustSignupService.java | 80 +++++++++++++++++++ .../UserCredentials.java | 2 +- .../UserCredentialsRepository.java} | 4 +- .../UserCredentialsService.java} | 10 +-- .../UserRole.java | 2 +- .../email/EmailService.java | 69 ++++++++++++++++ .../resetpassword/ResetPasswordService.java | 16 ++-- .../security/config/WebSecurityConfig.java | 4 +- 34 files changed, 445 insertions(+), 63 deletions(-) rename src/main/java/ethniconnect_backend/{Chefprofile => Chef}/Chef.java (95%) rename src/main/java/ethniconnect_backend/{Chefprofile/ChefProfileController.java => Chef/ChefController.java} (85%) create mode 100644 src/main/java/ethniconnect_backend/Chef/ChefRepository.java rename src/main/java/ethniconnect_backend/{Chefprofile/ChefProfileService.java => Chef/ChefService.java} (88%) create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/MenuCategories.java create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/Week.java rename src/main/java/ethniconnect_backend/{registration/RegistrationController.java => ChefSignup/ChefSignupController.java} (65%) rename src/main/java/ethniconnect_backend/{registration/RegistrationRequest.java => ChefSignup/ChefSignupRequest.java} (80%) rename src/main/java/ethniconnect_backend/{registration/RegistrationService.java => ChefSignup/ChefSignupService.java} (79%) rename src/main/java/ethniconnect_backend/{registration => ChefSignup}/EmailValidator.java (86%) rename src/main/java/ethniconnect_backend/{registration => ChefSignup}/token/ConfirmationToken.java (92%) rename src/main/java/ethniconnect_backend/{registration => ChefSignup}/token/ConfirmationTokenRepository.java (94%) rename src/main/java/ethniconnect_backend/{registration => ChefSignup}/token/ConfirmationTokenService.java (93%) delete mode 100644 src/main/java/ethniconnect_backend/Chefprofile/ChefProfileRepository.java create mode 100644 src/main/java/ethniconnect_backend/Customer/Customer.java create mode 100644 src/main/java/ethniconnect_backend/Customer/CustomerController.java create mode 100644 src/main/java/ethniconnect_backend/Customer/CustomerRepository.java create mode 100644 src/main/java/ethniconnect_backend/Customer/CustomerService.java create mode 100644 src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java create mode 100644 src/main/java/ethniconnect_backend/CustomerSignup/CustSignupRequest.java create mode 100644 src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java rename src/main/java/ethniconnect_backend/{appuser => UserCredentials}/UserCredentials.java (97%) rename src/main/java/ethniconnect_backend/{appuser/AppUserRepository.java => UserCredentials/UserCredentialsRepository.java} (88%) rename src/main/java/ethniconnect_backend/{appuser/AppUserService.java => UserCredentials/UserCredentialsService.java} (89%) rename src/main/java/ethniconnect_backend/{appuser => UserCredentials}/UserRole.java (58%) diff --git a/src/main/java/ethniconnect_backend/Chefprofile/Chef.java b/src/main/java/ethniconnect_backend/Chef/Chef.java similarity index 95% rename from src/main/java/ethniconnect_backend/Chefprofile/Chef.java rename to src/main/java/ethniconnect_backend/Chef/Chef.java index 3c2dda3..8c27684 100644 --- a/src/main/java/ethniconnect_backend/Chefprofile/Chef.java +++ b/src/main/java/ethniconnect_backend/Chef/Chef.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.Chefprofile; +package ethniconnect_backend.Chef; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileController.java b/src/main/java/ethniconnect_backend/Chef/ChefController.java similarity index 85% rename from src/main/java/ethniconnect_backend/Chefprofile/ChefProfileController.java rename to src/main/java/ethniconnect_backend/Chef/ChefController.java index f45aaf1..5562293 100644 --- a/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileController.java +++ b/src/main/java/ethniconnect_backend/Chef/ChefController.java @@ -1,12 +1,12 @@ -package ethniconnect_backend.Chefprofile; +package ethniconnect_backend.Chef; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @RestController -public class ChefProfileController { +public class ChefController { @Autowired - private ChefProfileService chefProfileService; + private ChefService chefProfileService; @PostMapping("/chef") public Chef addChef(@RequestBody Chef chef) throws Exception diff --git a/src/main/java/ethniconnect_backend/Chef/ChefRepository.java b/src/main/java/ethniconnect_backend/Chef/ChefRepository.java new file mode 100644 index 0000000..d41fad1 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Chef/ChefRepository.java @@ -0,0 +1,10 @@ +package ethniconnect_backend.Chef; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ChefRepository extends JpaRepository { + + + + /*Chef findByEmailId(String chef_emailid);*/ +} diff --git a/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileService.java b/src/main/java/ethniconnect_backend/Chef/ChefService.java similarity index 88% rename from src/main/java/ethniconnect_backend/Chefprofile/ChefProfileService.java rename to src/main/java/ethniconnect_backend/Chef/ChefService.java index 04fbfc3..d0afe09 100644 --- a/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileService.java +++ b/src/main/java/ethniconnect_backend/Chef/ChefService.java @@ -1,7 +1,7 @@ -package ethniconnect_backend.Chefprofile; +package ethniconnect_backend.Chef; -import ethniconnect_backend.appuser.AppUserRepository; -import ethniconnect_backend.appuser.UserCredentials; +import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import ethniconnect_backend.UserCredentials.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -10,11 +10,11 @@ import java.util.Optional; @Service -public class ChefProfileService { +public class ChefService { @Autowired - private ChefProfileRepository chefProfileRepository; + private ChefRepository chefProfileRepository; @Autowired - private AppUserRepository appUserRepository; + private UserCredentialsRepository appUserRepository; public Chef saveChef(Chef chef) throws Exception{ Optional userData =appUserRepository.findByEmail(chef.getChef_emailid()); diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java new file mode 100644 index 0000000..773f947 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java @@ -0,0 +1,23 @@ +package ethniconnect_backend.ChefCreateMenu; + +import ethniconnect_backend.UserCredentials.UserRole; + +import javax.persistence.*; + +@Entity +@Table(name = "menu_items") +public class ChefMenu { + @Id + @GeneratedValue + private int menu_item_id; + @Enumerated(EnumType.STRING) + private MenuCategories menuCategories; + private int chef_cuisine_id; + private String menu_item_image; + private int menu_item_price; + private String item_ingredients; + private String item_intresting_facts; + @Enumerated(EnumType.STRING) + private Week week; + +} diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java new file mode 100644 index 0000000..0bd3bb7 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java @@ -0,0 +1,4 @@ +package ethniconnect_backend.ChefCreateMenu; + +public class ChefMenuController { +} diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java new file mode 100644 index 0000000..5d884a6 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java @@ -0,0 +1,6 @@ +package ethniconnect_backend.ChefCreateMenu; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ChefMenuRepository extends JpaRepository { +} diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java new file mode 100644 index 0000000..8e99af4 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -0,0 +1,4 @@ +package ethniconnect_backend.ChefCreateMenu; + +public class ChefMenuService { +} diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/MenuCategories.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/MenuCategories.java new file mode 100644 index 0000000..42287c6 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/MenuCategories.java @@ -0,0 +1,10 @@ +package ethniconnect_backend.ChefCreateMenu; + +public enum MenuCategories { + + + Breakfast, + Lunch, + Dinner + +} diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/Week.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/Week.java new file mode 100644 index 0000000..6d1e3ce --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/Week.java @@ -0,0 +1,11 @@ +package ethniconnect_backend.ChefCreateMenu; + +public enum Week { + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, + Saturday, + Sunday +} diff --git a/src/main/java/ethniconnect_backend/registration/RegistrationController.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java similarity index 65% rename from src/main/java/ethniconnect_backend/registration/RegistrationController.java rename to src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java index 5efe567..512080f 100644 --- a/src/main/java/ethniconnect_backend/registration/RegistrationController.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java @@ -1,18 +1,17 @@ -package ethniconnect_backend.registration; +package ethniconnect_backend.ChefSignup; -import ethniconnect_backend.resetpassword.ResetPasswordRequest; import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; @RestController @RequestMapping(path = "api/v1/registration") @AllArgsConstructor -public class RegistrationController { +public class ChefSignupController { - private final RegistrationService registrationService; + private final ChefSignupService registrationService; @PostMapping - public String register(@RequestBody RegistrationRequest request) { + public String register(@RequestBody ChefSignupRequest request) { return registrationService.register(request); } diff --git a/src/main/java/ethniconnect_backend/registration/RegistrationRequest.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupRequest.java similarity index 80% rename from src/main/java/ethniconnect_backend/registration/RegistrationRequest.java rename to src/main/java/ethniconnect_backend/ChefSignup/ChefSignupRequest.java index fdfa5b6..5fa7b28 100644 --- a/src/main/java/ethniconnect_backend/registration/RegistrationRequest.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupRequest.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.registration; +package ethniconnect_backend.ChefSignup; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; @@ -9,7 +9,7 @@ @AllArgsConstructor @EqualsAndHashCode @ToString -public class RegistrationRequest { +public class ChefSignupRequest { private final String firstName; /* private final String lastName;*/ private final String email; diff --git a/src/main/java/ethniconnect_backend/registration/RegistrationService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java similarity index 79% rename from src/main/java/ethniconnect_backend/registration/RegistrationService.java rename to src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index 1a0fba9..6b6a472 100644 --- a/src/main/java/ethniconnect_backend/registration/RegistrationService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -1,13 +1,12 @@ -package ethniconnect_backend.registration; +package ethniconnect_backend.ChefSignup; -import ethniconnect_backend.appuser.UserCredentials; -import ethniconnect_backend.appuser.UserRole; -import ethniconnect_backend.appuser.AppUserService; +import ethniconnect_backend.UserCredentials.UserCredentials; +import ethniconnect_backend.UserCredentials.UserRole; +import ethniconnect_backend.UserCredentials.UserCredentialsService; import ethniconnect_backend.email.EmailSender; import ethniconnect_backend.email.EmailService; -import ethniconnect_backend.registration.token.ConfirmationToken; -import ethniconnect_backend.registration.token.ConfirmationTokenService; -import ethniconnect_backend.resetpassword.ResetPasswordRequest; +import ethniconnect_backend.ChefSignup.token.ConfirmationToken; +import ethniconnect_backend.ChefSignup.token.ConfirmationTokenService; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -16,15 +15,15 @@ @Service @AllArgsConstructor -public class RegistrationService { +public class ChefSignupService { - private final AppUserService appUserService; + private final UserCredentialsService appUserService; private final EmailValidator emailValidator; private final ConfirmationTokenService confirmationTokenService; private final EmailSender emailSender; private EmailService emailService; - public String register(RegistrationRequest request) { + public String register(ChefSignupRequest request) { boolean isValidEmail = emailValidator. test(request.getEmail()); diff --git a/src/main/java/ethniconnect_backend/registration/EmailValidator.java b/src/main/java/ethniconnect_backend/ChefSignup/EmailValidator.java similarity index 86% rename from src/main/java/ethniconnect_backend/registration/EmailValidator.java rename to src/main/java/ethniconnect_backend/ChefSignup/EmailValidator.java index 7b673a2..0225c8b 100644 --- a/src/main/java/ethniconnect_backend/registration/EmailValidator.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/EmailValidator.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.registration; +package ethniconnect_backend.ChefSignup; import org.springframework.stereotype.Service; diff --git a/src/main/java/ethniconnect_backend/registration/token/ConfirmationToken.java b/src/main/java/ethniconnect_backend/ChefSignup/token/ConfirmationToken.java similarity index 92% rename from src/main/java/ethniconnect_backend/registration/token/ConfirmationToken.java rename to src/main/java/ethniconnect_backend/ChefSignup/token/ConfirmationToken.java index 5f10a8e..e3a9afb 100644 --- a/src/main/java/ethniconnect_backend/registration/token/ConfirmationToken.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/token/ConfirmationToken.java @@ -1,6 +1,6 @@ -package ethniconnect_backend.registration.token; +package ethniconnect_backend.ChefSignup.token; -import ethniconnect_backend.appuser.UserCredentials; +import ethniconnect_backend.UserCredentials.UserCredentials; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenRepository.java b/src/main/java/ethniconnect_backend/ChefSignup/token/ConfirmationTokenRepository.java similarity index 94% rename from src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenRepository.java rename to src/main/java/ethniconnect_backend/ChefSignup/token/ConfirmationTokenRepository.java index 968338f..a78ec0b 100644 --- a/src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenRepository.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/token/ConfirmationTokenRepository.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.registration.token; +package ethniconnect_backend.ChefSignup.token; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; diff --git a/src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenService.java b/src/main/java/ethniconnect_backend/ChefSignup/token/ConfirmationTokenService.java similarity index 93% rename from src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenService.java rename to src/main/java/ethniconnect_backend/ChefSignup/token/ConfirmationTokenService.java index 5311841..e52a4d6 100644 --- a/src/main/java/ethniconnect_backend/registration/token/ConfirmationTokenService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/token/ConfirmationTokenService.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.registration.token; +package ethniconnect_backend.ChefSignup.token; import lombok.AllArgsConstructor; import org.springframework.stereotype.Service; diff --git a/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileRepository.java b/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileRepository.java deleted file mode 100644 index fe66531..0000000 --- a/src/main/java/ethniconnect_backend/Chefprofile/ChefProfileRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package ethniconnect_backend.Chefprofile; - -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ChefProfileRepository extends JpaRepository { - - - - /*Chef findByEmailId(String chef_emailid);*/ -} diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java index aac0b52..4cdf705 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java @@ -1,6 +1,5 @@ package ethniconnect_backend.ContactPage; -import ethniconnect_backend.Chefprofile.Chef; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java index 9063575..e8ab6c8 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java @@ -1,6 +1,5 @@ package ethniconnect_backend.ContactPage; -import ethniconnect_backend.Chefprofile.Chef; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/ethniconnect_backend/Customer/Customer.java b/src/main/java/ethniconnect_backend/Customer/Customer.java new file mode 100644 index 0000000..ac7676a --- /dev/null +++ b/src/main/java/ethniconnect_backend/Customer/Customer.java @@ -0,0 +1,33 @@ +package ethniconnect_backend.Customer; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Table(name = "customer") +public class Customer { + @Id + @GeneratedValue + private int cust_id; + private long login_id; + private String cust_fname; + private String cust_lname; + private String cust_emailid; + private String cust_phone; + private String cust_street; + private String cust_city; + private String cust_state; + private String cust_zip; + private String cust_ethnicity; + private String cust_image; + +} diff --git a/src/main/java/ethniconnect_backend/Customer/CustomerController.java b/src/main/java/ethniconnect_backend/Customer/CustomerController.java new file mode 100644 index 0000000..9bf5c47 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Customer/CustomerController.java @@ -0,0 +1,31 @@ +package ethniconnect_backend.Customer; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +@RestController +public class CustomerController { + + @Autowired + private CustomerService customerService; + + @PostMapping("/customer") + public Customer addCustomer(@RequestBody Customer customer) throws Exception + { + + return customerService.saveCustomer(customer); + } + + + @GetMapping({"/custById/{id}"}) + public Customer findCustById(@PathVariable int id) + { + return customerService.getCustById(id); + } + + @PutMapping("/updatecust") + public Customer updateCust(@RequestBody Customer customer) + { + return customerService.updateCust(customer); + } +} diff --git a/src/main/java/ethniconnect_backend/Customer/CustomerRepository.java b/src/main/java/ethniconnect_backend/Customer/CustomerRepository.java new file mode 100644 index 0000000..d54110e --- /dev/null +++ b/src/main/java/ethniconnect_backend/Customer/CustomerRepository.java @@ -0,0 +1,6 @@ +package ethniconnect_backend.Customer; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CustomerRepository extends JpaRepository { +} diff --git a/src/main/java/ethniconnect_backend/Customer/CustomerService.java b/src/main/java/ethniconnect_backend/Customer/CustomerService.java new file mode 100644 index 0000000..5fd6b84 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Customer/CustomerService.java @@ -0,0 +1,61 @@ +package ethniconnect_backend.Customer; + +import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import ethniconnect_backend.UserCredentials.UserCredentials; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + + @Service + public class CustomerService { + @Autowired + private CustomerRepository customerRepository; + @Autowired + private UserCredentialsRepository appUserRepository; + + public Customer saveCustomer(Customer customer) throws Exception{ + Optional userData =appUserRepository.findByEmail(customer.getCust_emailid()); + if(!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + Long loginId = userData.get().getId(); + + customer.setLogin_id(loginId); + return customerRepository.save(customer); + } + public List saveChefs(List customers){ + return customerRepository.saveAll(customers); + } + + public List getCustomers() + { + return customerRepository.findAll(); + } + public Customer getCustById(int cust_id){ + return customerRepository.findById(cust_id).orElse(null); + } + /*public Chef getChefByEmailId(String chef_emailid){ + return chefProfileRepository.findByEmailId(chef_emailid); + }*/ + public String deleteCust(int cust_id) + { + customerRepository.deleteById(cust_id); + return "customer removed !!" + cust_id; + } + public Customer updateCust(Customer customer) + { + Customer existingCustomer=customerRepository.findById(customer.getCust_id()).orElse(null); + existingCustomer.setCust_fname(customer.getCust_fname()); + existingCustomer.setCust_lname(customer.getCust_lname()); + existingCustomer.setCust_phone(customer.getCust_phone()); + existingCustomer.setCust_emailid(customer.getCust_emailid()); + existingCustomer.setCust_street(customer.getCust_street()); + existingCustomer.setCust_city(customer.getCust_city()); + existingCustomer.setCust_state(customer.getCust_state()); + existingCustomer.setCust_zip(customer.getCust_zip()); + existingCustomer.setCust_image(customer.getCust_image()); + return customerRepository.save(existingCustomer); + + } + } diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java new file mode 100644 index 0000000..975b13b --- /dev/null +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java @@ -0,0 +1,29 @@ +package ethniconnect_backend.CustomerSignup; + +import lombok.AllArgsConstructor; +import org.springframework.web.bind.annotation.*; + + + + + + +@RestController +@RequestMapping(path = "api/v1/CustSignup") +@AllArgsConstructor +public class CustSignupController { + + private final CustSignupService custSignupService; + + @PostMapping + public String register(@RequestBody CustSignupRequest request) { + return custSignupService.register(request); + } + + @GetMapping(path = "confirm") + public String confirm(@RequestParam("token") String token) { + return custSignupService.confirmToken(token); + } + + +} diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupRequest.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupRequest.java new file mode 100644 index 0000000..fee2fb1 --- /dev/null +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupRequest.java @@ -0,0 +1,19 @@ +package ethniconnect_backend.CustomerSignup; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + + +@Getter +@AllArgsConstructor +@EqualsAndHashCode +@ToString +public class CustSignupRequest { + + private final String firstName; + /* private final String lastName;*/ + private final String email; + private final String password; +} diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java new file mode 100644 index 0000000..7412095 --- /dev/null +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java @@ -0,0 +1,80 @@ +package ethniconnect_backend.CustomerSignup; + +import ethniconnect_backend.UserCredentials.UserCredentialsService; +import ethniconnect_backend.UserCredentials.UserCredentials; +import ethniconnect_backend.UserCredentials.UserRole; +import ethniconnect_backend.email.EmailSender; +import ethniconnect_backend.email.EmailService; +import ethniconnect_backend.ChefSignup.EmailValidator; +import ethniconnect_backend.ChefSignup.token.ConfirmationToken; +import ethniconnect_backend.ChefSignup.token.ConfirmationTokenService; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; + + @Service + @AllArgsConstructor + public class CustSignupService { + + private final UserCredentialsService appUserService; + private final EmailValidator emailValidator; + private final ConfirmationTokenService confirmationTokenService; + private final EmailSender emailSender; + private EmailService emailService; + + public String register(CustSignupRequest request) { + boolean isValidEmail = emailValidator. + test(request.getEmail()); + + if (!isValidEmail) { + throw new IllegalStateException("email not valid"); + } + + String token = appUserService.signUpUser( + new UserCredentials( + request.getEmail(), + request.getPassword(), + UserRole.PERSONAL + + ) + ); + + /*String link = "www.google.com";*/ + String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; + emailSender.send( + request.getEmail(), + emailService.buildEmail(request.getFirstName(), link)); + + return token; + } + + @Transactional + public String confirmToken(String token) { + ConfirmationToken confirmationToken = confirmationTokenService + .getToken(token) + .orElseThrow(() -> + new IllegalStateException("token not found")); + + if (confirmationToken.getConfirmedAt() != null) { + throw new IllegalStateException("email already confirmed"); + } + + LocalDateTime expiredAt = confirmationToken.getExpiresAt(); + + if (expiredAt.isBefore(LocalDateTime.now())) { + throw new IllegalStateException("token expired"); + } + + confirmationTokenService.setConfirmedAt(token); + appUserService.enableAppUser( + confirmationToken.getAppUser().getEmail()); + return "confirmed"; + } + + + + + + } diff --git a/src/main/java/ethniconnect_backend/appuser/UserCredentials.java b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java similarity index 97% rename from src/main/java/ethniconnect_backend/appuser/UserCredentials.java rename to src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java index 07087ea..d4a4805 100644 --- a/src/main/java/ethniconnect_backend/appuser/UserCredentials.java +++ b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.appuser; +package ethniconnect_backend.UserCredentials; import lombok.EqualsAndHashCode; import lombok.Getter; diff --git a/src/main/java/ethniconnect_backend/appuser/AppUserRepository.java b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsRepository.java similarity index 88% rename from src/main/java/ethniconnect_backend/appuser/AppUserRepository.java rename to src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsRepository.java index 0142814..5180985 100644 --- a/src/main/java/ethniconnect_backend/appuser/AppUserRepository.java +++ b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsRepository.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.appuser; +package ethniconnect_backend.UserCredentials; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; @@ -10,7 +10,7 @@ @Repository @Transactional(readOnly = true) -public interface AppUserRepository +public interface UserCredentialsRepository extends JpaRepository { Optional findByEmail(String email); diff --git a/src/main/java/ethniconnect_backend/appuser/AppUserService.java b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsService.java similarity index 89% rename from src/main/java/ethniconnect_backend/appuser/AppUserService.java rename to src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsService.java index ff5ef25..4726492 100644 --- a/src/main/java/ethniconnect_backend/appuser/AppUserService.java +++ b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsService.java @@ -1,7 +1,7 @@ -package ethniconnect_backend.appuser; +package ethniconnect_backend.UserCredentials; -import ethniconnect_backend.registration.token.ConfirmationToken; -import ethniconnect_backend.registration.token.ConfirmationTokenService; +import ethniconnect_backend.ChefSignup.token.ConfirmationToken; +import ethniconnect_backend.ChefSignup.token.ConfirmationTokenService; import lombok.AllArgsConstructor; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; @@ -15,12 +15,12 @@ @Transactional @Service @AllArgsConstructor -public class AppUserService implements UserDetailsService { +public class UserCredentialsService implements UserDetailsService { private final static String USER_NOT_FOUND_MSG = "user with email %s not found"; - private final AppUserRepository appUserRepository; + private final UserCredentialsRepository appUserRepository; private final BCryptPasswordEncoder bCryptPasswordEncoder; private final ConfirmationTokenService confirmationTokenService; diff --git a/src/main/java/ethniconnect_backend/appuser/UserRole.java b/src/main/java/ethniconnect_backend/UserCredentials/UserRole.java similarity index 58% rename from src/main/java/ethniconnect_backend/appuser/UserRole.java rename to src/main/java/ethniconnect_backend/UserCredentials/UserRole.java index 0d7dc04..087751e 100644 --- a/src/main/java/ethniconnect_backend/appuser/UserRole.java +++ b/src/main/java/ethniconnect_backend/UserCredentials/UserRole.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.appuser; +package ethniconnect_backend.UserCredentials; public enum UserRole { PERSONAL, diff --git a/src/main/java/ethniconnect_backend/email/EmailService.java b/src/main/java/ethniconnect_backend/email/EmailService.java index a3b85b3..deaf969 100644 --- a/src/main/java/ethniconnect_backend/email/EmailService.java +++ b/src/main/java/ethniconnect_backend/email/EmailService.java @@ -90,6 +90,75 @@ public String buildEmail(String name, String link) { } + public String buildResetPasswordEmail(String name, String link) { + return "
\n" + + "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " Reset Password\n" + + "
\n" + + " \n" + + "
\n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + "
\n" + + "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "


\n" + + " \n" + + "

Hi " + name + ",

Please click on the below link to reset your password:

Reset Password

\n Link will expire in 15 minutes.

See you soon

" + + " \n" + + "


\n" + + "\n" + + "
"; + } + @Override @Async public void send(String to, String email) { diff --git a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java b/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java index 59a02f3..616049e 100644 --- a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java +++ b/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java @@ -1,12 +1,12 @@ package ethniconnect_backend.resetpassword; -import ethniconnect_backend.appuser.AppUserRepository; -import ethniconnect_backend.appuser.AppUserService; -import ethniconnect_backend.appuser.UserCredentials; +import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import ethniconnect_backend.UserCredentials.UserCredentialsService; +import ethniconnect_backend.UserCredentials.UserCredentials; import ethniconnect_backend.email.EmailSender; import ethniconnect_backend.email.EmailService; -import ethniconnect_backend.registration.token.ConfirmationToken; -import ethniconnect_backend.registration.token.ConfirmationTokenService; +import ethniconnect_backend.ChefSignup.token.ConfirmationToken; +import ethniconnect_backend.ChefSignup.token.ConfirmationTokenService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,9 +17,9 @@ public class ResetPasswordService { @Autowired - AppUserService appUserService; + UserCredentialsService appUserService; @Autowired - AppUserRepository appUserRepository; + UserCredentialsRepository appUserRepository; @Autowired EmailSender emailSender; @Autowired @@ -36,7 +36,7 @@ public void resetPassword(ResetPasswordRequest resetPasswordRequest) { String link = "http://localhost:5000/api/v1/resetpassword/confirm?token=" + token; emailSender.send( resetPasswordRequest.getEmailId(), - emailService.buildEmail("User", link)); + emailService.buildResetPasswordEmail("User", link)); } } diff --git a/src/main/java/ethniconnect_backend/security/config/WebSecurityConfig.java b/src/main/java/ethniconnect_backend/security/config/WebSecurityConfig.java index e595c26..9ad8142 100644 --- a/src/main/java/ethniconnect_backend/security/config/WebSecurityConfig.java +++ b/src/main/java/ethniconnect_backend/security/config/WebSecurityConfig.java @@ -1,6 +1,6 @@ package ethniconnect_backend.security.config; -import ethniconnect_backend.appuser.AppUserService; +import ethniconnect_backend.UserCredentials.UserCredentialsService; import lombok.AllArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -16,7 +16,7 @@ @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - private final AppUserService appUserService; + private final UserCredentialsService appUserService; private final BCryptPasswordEncoder bCryptPasswordEncoder; @Override From 255a131a2030d229fc0e05f23e07df806d9c44fe Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Tue, 22 Mar 2022 15:09:19 -0400 Subject: [PATCH 08/69] Update README.md working code --- README.md | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/README.md b/README.md index 1530e9c..e69de29 100644 --- a/README.md +++ b/README.md @@ -1,33 +0,0 @@ -# Login Registration Backend - -Complete login registration backend system using Spring Boot. - -[![YouTube Video](https://user-images.githubusercontent.com/40702606/104790682-d62ac880-578f-11eb-8353-aa68739ffe42.png)](https://www.youtube.com/watch?v=QwQuro7ekvc) - -- [x] Spring Boot -- [x] Spring Security -- [x] Java Mail -- [x] Email verification with expiry -- [x] Spring Boot - -## Diagram -![Screenshot 2021-01-13 at 23 38 08](https://user-images.githubusercontent.com/40702606/104789980-15581a00-578e-11eb-998d-30f2e6a9f461.png) - -## Email verification link with expiry -![Screenshot 2021-01-13 at 23 37 33](https://user-images.githubusercontent.com/40702606/104789893-0c674880-578e-11eb-939a-2a1cd3a8dfd2.png) - -## Example requests -### Postman -![Screenshot 2021-01-13 at 23 37 57](https://user-images.githubusercontent.com/40702606/104790087-7a137480-578e-11eb-8141-307a8850c39e.png) - -### CURL -``` -curl --location --request POST 'localhost:8080/api/v1/registration' \ ---header 'Content-Type: application/json' \ ---data-raw '{ - "firstName": "Amigos", - "lastName": "Code", - "email": "hellow@amigoscode.com", - "password": "password" -}' -``` From a4f519118fcdba4eb71c4501a27af00f8348dabf Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Tue, 22 Mar 2022 15:14:30 -0400 Subject: [PATCH 09/69] Update application.yml working code --- src/main/resources/application.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3732653..d274117 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -27,8 +27,8 @@ spring: # mail: # host: smtp.gmail.com # port: 587 - #username: sravan.mummadi06@gmail.com - #password: Ishikammulu1! + #username: + #password: #properties: #mail: #smtp: From d7293a829b14cce10ef63956d029b528e856190d Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Tue, 22 Mar 2022 21:25:08 -0400 Subject: [PATCH 10/69] working working --- .../ChefSignup/ChefSignupController.java | 1 + .../ChefSignup/ChefSignupRequest.java | 2 +- .../ChefSignup/ChefSignupService.java | 8 ++++---- .../UserCredentials/UserCredentials.java | 7 ++++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java index 512080f..9901b93 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; +@CrossOrigin(origins = "http://localhost:4200") @RestController @RequestMapping(path = "api/v1/registration") @AllArgsConstructor diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupRequest.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupRequest.java index 5fa7b28..e318c79 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupRequest.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupRequest.java @@ -10,7 +10,7 @@ @EqualsAndHashCode @ToString public class ChefSignupRequest { - private final String firstName; + //private final String firstName; /* private final String lastName;*/ private final String email; private final String password; diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index 6b6a472..cadb3b1 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -17,7 +17,7 @@ @AllArgsConstructor public class ChefSignupService { - private final UserCredentialsService appUserService; + private final UserCredentialsService userCredentialsService; private final EmailValidator emailValidator; private final ConfirmationTokenService confirmationTokenService; private final EmailSender emailSender; @@ -31,7 +31,7 @@ public String register(ChefSignupRequest request) { throw new IllegalStateException("email not valid"); } - String token = appUserService.signUpUser( + String token = userCredentialsService.signUpUser( new UserCredentials( request.getEmail(), request.getPassword(), @@ -44,7 +44,7 @@ public String register(ChefSignupRequest request) { String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; emailSender.send( request.getEmail(), - emailService.buildEmail(request.getFirstName(), link)); + emailService.buildEmail("user", link)); return token; } @@ -67,7 +67,7 @@ public String confirmToken(String token) { } confirmationTokenService.setConfirmedAt(token); - appUserService.enableAppUser( + userCredentialsService.enableAppUser( confirmationToken.getAppUser().getEmail()); return "confirmed"; } diff --git a/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java index d4a4805..ae5754a 100644 --- a/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java +++ b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java @@ -21,15 +21,16 @@ public class UserCredentials implements UserDetails { @SequenceGenerator( - name = "student_sequence", - sequenceName = "student_sequence", + name = "chef_sequence", + sequenceName = "chef_sequence", allocationSize = 1 ) @Id @GeneratedValue( strategy = GenerationType.SEQUENCE, - generator = "student_sequence" + generator = "chef_sequence" ) + private Long id; private String email; private String password; From d03eb8cc7049b24cd05281d01244876c9891131a Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 26 Mar 2022 21:39:40 -0400 Subject: [PATCH 11/69] working code chef menu working code --- .../ChefCreateMenu/ChefMenu.java | 36 +++++++-- .../ChefCreateMenu/ChefMenuController.java | 42 +++++++++++ .../ChefCreateMenu/ChefMenuRepository.java | 5 ++ .../ChefCreateMenu/ChefMenuRequest.java | 30 ++++++++ .../ChefCreateMenu/ChefMenuService.java | 75 ++++++++++++++++++- .../{Chef => ChefDetails}/Chef.java | 2 +- .../{Chef => ChefDetails}/ChefController.java | 2 +- .../{Chef => ChefDetails}/ChefRepository.java | 2 +- .../{Chef => ChefDetails}/ChefService.java | 22 +++--- .../Cuisines/CuisineCategoriesController.java | 36 +++++++++ .../Cuisines/CuisineCategoriesRepository.java | 6 ++ .../Cuisines/CuisineCategory.java | 28 +++++++ .../Cuisines/CuisinesCategoriesService.java | 27 +++++++ .../Customer.java | 2 +- .../CustomerController.java | 2 +- .../CustomerRepository.java | 2 +- .../CustomerService.java | 2 +- .../ethniconnect_backend/Login/Login.java | 16 ++++ .../Login/LoginController.java | 41 ++++++++++ .../Login/LoginResponse.java | 13 ++++ .../Login/LoginService.java | 4 + .../ResetPasswordController.java | 9 ++- .../ResetPasswordRequest.java | 2 +- .../ResetPasswordService.java | 21 ++++-- .../Resetpassword/UpdatePassword.java | 15 ++++ 25 files changed, 409 insertions(+), 33 deletions(-) create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java rename src/main/java/ethniconnect_backend/{Chef => ChefDetails}/Chef.java (95%) rename src/main/java/ethniconnect_backend/{Chef => ChefDetails}/ChefController.java (95%) rename src/main/java/ethniconnect_backend/{Chef => ChefDetails}/ChefRepository.java (81%) rename src/main/java/ethniconnect_backend/{Chef => ChefDetails}/ChefService.java (73%) create mode 100644 src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java create mode 100644 src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java create mode 100644 src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java create mode 100644 src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java rename src/main/java/ethniconnect_backend/{Customer => CustomerDetails}/Customer.java (94%) rename src/main/java/ethniconnect_backend/{Customer => CustomerDetails}/CustomerController.java (93%) rename src/main/java/ethniconnect_backend/{Customer => CustomerDetails}/CustomerRepository.java (75%) rename src/main/java/ethniconnect_backend/{Customer => CustomerDetails}/CustomerService.java (98%) create mode 100644 src/main/java/ethniconnect_backend/Login/Login.java create mode 100644 src/main/java/ethniconnect_backend/Login/LoginController.java create mode 100644 src/main/java/ethniconnect_backend/Login/LoginResponse.java create mode 100644 src/main/java/ethniconnect_backend/Login/LoginService.java rename src/main/java/ethniconnect_backend/{resetpassword => Resetpassword}/ResetPasswordController.java (74%) rename src/main/java/ethniconnect_backend/{resetpassword => Resetpassword}/ResetPasswordRequest.java (89%) rename src/main/java/ethniconnect_backend/{resetpassword => Resetpassword}/ResetPasswordService.java (65%) create mode 100644 src/main/java/ethniconnect_backend/Resetpassword/UpdatePassword.java diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java index 773f947..4364d76 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java @@ -1,23 +1,47 @@ package ethniconnect_backend.ChefCreateMenu; -import ethniconnect_backend.UserCredentials.UserRole; +import ethniconnect_backend.Cuisines.CuisineCategory; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; import javax.persistence.*; +@Data +@NoArgsConstructor +@AllArgsConstructor + @Entity -@Table(name = "menu_items") +@Table(name = "chefmenu") public class ChefMenu { @Id @GeneratedValue - private int menu_item_id; + private int id; + private long login_id; @Enumerated(EnumType.STRING) - private MenuCategories menuCategories; - private int chef_cuisine_id; - private String menu_item_image; + private MenuCategories menucategories; + //private int cuisine_id; + @Lob + @Column(name = "Image", length = Integer.MAX_VALUE, nullable = true) + private byte[] menu_item_image; private int menu_item_price; private String item_ingredients; private String item_intresting_facts; @Enumerated(EnumType.STRING) private Week week; + //@ManyToOne + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "cuisine_id") + private CuisineCategory cuisineCategory; + + /*@JoinTable( + name = "selected_cuisines", + joinColumns = @JoinColumn(name = "menu_item_id"), + inverseJoinColumns = @JoinColumn(name = "cuisine_id")) + Set selectedCuisines;*/ + /* @OneToMany + @OneToMany(fetch = FetchType.EAGER, mappedBy = "menu_items", cascade = CascadeType.ALL) + @JsonIgnoreProperties("menu") + private List storyList = new ArrayList<>();*/ } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java index 0bd3bb7..e107f37 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java @@ -1,4 +1,46 @@ package ethniconnect_backend.ChefCreateMenu; +import ethniconnect_backend.ChefDetails.Chef; +import ethniconnect_backend.ChefDetails.ChefService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController public class ChefMenuController { + + @Autowired + private ChefMenuService chefMenuService; + @Autowired + private ChefMenuRepository chefMenuRepository; + + @PostMapping("/chefmenu") + public ResponseEntity addChefMenu(@RequestBody ChefMenuRequest chefMenuRequest) throws Exception + { + + //chefMenuService.saveChefMenu(ch); + chefMenuService.saveChefMenu(chefMenuRequest); + + return new ResponseEntity<>("menu item saved successfully", HttpStatus.OK); + } + /* @PostMapping("/chefs") + public List addChefs(@RequestBody List chefs) + { + return chefProfileService.saveChefs(chefs); + }*/ + + @GetMapping({"/chefmenuyId/{id}"}) + public ChefMenu findChefMenuById(@PathVariable int id) + { + return chefMenuService.getChefMenuById(id); + } + + @PutMapping("/updatechefmenu") + public ChefMenu updateChefMenu(@RequestBody ChefMenu chefMenu) + { + return chefMenuService.updateChefMenu(chefMenu); + } } + + diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java index 5d884a6..fc92563 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java @@ -2,5 +2,10 @@ import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + public interface ChefMenuRepository extends JpaRepository { + + Optional findById(Integer id); } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java new file mode 100644 index 0000000..a6c76f9 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java @@ -0,0 +1,30 @@ +package ethniconnect_backend.ChefCreateMenu; + +import ethniconnect_backend.Cuisines.CuisineCategory; +import lombok.*; + +import javax.persistence.*; + +@Data +@Builder +@Getter +@Setter +@AllArgsConstructor +@ToString +public class ChefMenuRequest { + private int id; + private long login_id; + @Enumerated(EnumType.STRING) + private MenuCategories menucategories; + private int cuisine_id; + @Lob + @Column(name = "Image", length = Integer.MAX_VALUE, nullable = true) + private byte[] menu_item_image; + private int menu_item_price; + private String item_ingredients; + private String item_intresting_facts; + @Enumerated(EnumType.STRING) + private Week week; + + +} diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 8e99af4..a90a24b 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -1,4 +1,77 @@ package ethniconnect_backend.ChefCreateMenu; -public class ChefMenuService { +import ethniconnect_backend.ChefDetails.Chef; +import ethniconnect_backend.Cuisines.CuisineCategoriesRepository; +import ethniconnect_backend.Cuisines.CuisineCategory; +import ethniconnect_backend.UserCredentials.UserCredentials; +import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import ethniconnect_backend.UserCredentials.UserCredentialsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; +@Service +public class ChefMenuService { + + @Autowired + private ChefMenuRepository chefMenuRepository; + @Autowired + private UserCredentialsRepository userCredentialsRepository; + + @Autowired + CuisineCategoriesRepository cuisineCategoriesRepository; + + public ChefMenu saveChefMenu(ChefMenuRequest chefMenuRequest) throws Exception{ + Optional userData = userCredentialsRepository.findById(chefMenuRequest.getLogin_id()); + if(!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + CuisineCategory cuisineCategory = cuisineCategoriesRepository.findById(chefMenuRequest.getCuisine_id()).get(); + // Long loginId = userData.get().getId(); + if(cuisineCategory == null) + throw new Exception("cuisine category doesn't exist"); + ChefMenu chefMenu = new ChefMenu(); + chefMenu.setLogin_id(chefMenuRequest.getLogin_id()); + chefMenu.setMenucategories(chefMenuRequest.getMenucategories()); + chefMenu.setMenu_item_image(chefMenuRequest.getMenu_item_image()); + chefMenu.setMenu_item_price(chefMenuRequest.getMenu_item_price()); + chefMenu.setItem_intresting_facts(chefMenuRequest.getItem_intresting_facts()); + chefMenu.setItem_ingredients(chefMenuRequest.getItem_ingredients()); + chefMenu.setCuisineCategory(cuisineCategory); + chefMenu.setWeek(chefMenuRequest.getWeek()); + + chefMenuRequest.setLogin_id(chefMenuRequest.getLogin_id()); + return chefMenuRepository.save(chefMenu); + } + public List saveChefMenus(List chefMenus){ + return chefMenuRepository.saveAll(chefMenus); + } + + public List getChefMenus() + { + return chefMenuRepository.findAll(); + } + public ChefMenu getChefMenuById(int chefMenu_id){ + return chefMenuRepository.findById(chefMenu_id).orElse(null); + } + + public String deleteChefMenu(int chefMenu_id) + { + chefMenuRepository.deleteById(chefMenu_id); + return "chef Menu ietem removed !!" + chefMenu_id; + } + public ChefMenu updateChefMenu(ChefMenu chefMenu) + { + ChefMenu existingChefMenu=chefMenuRepository.findById(chefMenu.getId()).orElse(null); + existingChefMenu.setMenucategories(chefMenu.getMenucategories()); + existingChefMenu.setMenu_item_image(chefMenu.getMenu_item_image()); + existingChefMenu.setMenu_item_price(chefMenu.getMenu_item_price()); + existingChefMenu.setItem_ingredients(chefMenu.getItem_ingredients()); + existingChefMenu.setItem_intresting_facts(chefMenu.getItem_intresting_facts()); + existingChefMenu.setWeek(chefMenu.getWeek()); + existingChefMenu.getCuisineCategory().setId(chefMenu.getCuisineCategory().getId()); + return chefMenuRepository.save(existingChefMenu); + + } } diff --git a/src/main/java/ethniconnect_backend/Chef/Chef.java b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java similarity index 95% rename from src/main/java/ethniconnect_backend/Chef/Chef.java rename to src/main/java/ethniconnect_backend/ChefDetails/Chef.java index 8c27684..0c3824c 100644 --- a/src/main/java/ethniconnect_backend/Chef/Chef.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.Chef; +package ethniconnect_backend.ChefDetails; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/ethniconnect_backend/Chef/ChefController.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java similarity index 95% rename from src/main/java/ethniconnect_backend/Chef/ChefController.java rename to src/main/java/ethniconnect_backend/ChefDetails/ChefController.java index 5562293..6e8a482 100644 --- a/src/main/java/ethniconnect_backend/Chef/ChefController.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.Chef; +package ethniconnect_backend.ChefDetails; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; diff --git a/src/main/java/ethniconnect_backend/Chef/ChefRepository.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java similarity index 81% rename from src/main/java/ethniconnect_backend/Chef/ChefRepository.java rename to src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java index d41fad1..bfc6287 100644 --- a/src/main/java/ethniconnect_backend/Chef/ChefRepository.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.Chef; +package ethniconnect_backend.ChefDetails; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/ethniconnect_backend/Chef/ChefService.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java similarity index 73% rename from src/main/java/ethniconnect_backend/Chef/ChefService.java rename to src/main/java/ethniconnect_backend/ChefDetails/ChefService.java index d0afe09..def90a5 100644 --- a/src/main/java/ethniconnect_backend/Chef/ChefService.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.Chef; +package ethniconnect_backend.ChefDetails; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; import ethniconnect_backend.UserCredentials.UserCredentials; @@ -12,41 +12,41 @@ @Service public class ChefService { @Autowired - private ChefRepository chefProfileRepository; + private ChefRepository chefRepository; @Autowired - private UserCredentialsRepository appUserRepository; + private UserCredentialsRepository userCredentialsRepository; public Chef saveChef(Chef chef) throws Exception{ - Optional userData =appUserRepository.findByEmail(chef.getChef_emailid()); + Optional userData = userCredentialsRepository.findByEmail(chef.getChef_emailid()); if(!userData.isPresent()) throw new Exception("user Id doesn't exist"); Long loginId = userData.get().getId(); chef.setLogin_id(loginId); - return chefProfileRepository.save(chef); + return chefRepository.save(chef); } public List saveChefs(List chefs){ - return chefProfileRepository.saveAll(chefs); + return chefRepository.saveAll(chefs); } public List getChefs() { - return chefProfileRepository.findAll(); + return chefRepository.findAll(); } public Chef getChefById(int chef_id){ - return chefProfileRepository.findById(chef_id).orElse(null); + return chefRepository.findById(chef_id).orElse(null); } /*public Chef getChefByEmailId(String chef_emailid){ return chefProfileRepository.findByEmailId(chef_emailid); }*/ public String deleteChef(int chef_id) { - chefProfileRepository.deleteById(chef_id); + chefRepository.deleteById(chef_id); return "chef removed !!" + chef_id; } public Chef updateChef(Chef chef) { - Chef existingChef=chefProfileRepository.findById(chef.getChef_id()).orElse(null); + Chef existingChef= chefRepository.findById(chef.getChef_id()).orElse(null); existingChef.setChef_fname(chef.getChef_fname()); existingChef.setChef_lname(chef.getChef_lname()); existingChef.setChef_phone(chef.getChef_phone()); @@ -61,7 +61,7 @@ public Chef updateChef(Chef chef) existingChef.setChef_zip(chef.getChef_zip()); existingChef.setChef_city(chef.getChef_city()); existingChef.setChef_experience(chef.getChef_experience()); - return chefProfileRepository.save(existingChef); + return chefRepository.save(existingChef); } } diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java new file mode 100644 index 0000000..c79c97f --- /dev/null +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java @@ -0,0 +1,36 @@ +package ethniconnect_backend.Cuisines; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +@RestController +public class CuisineCategoriesController { + + @Autowired + private CuisinesCategoriesService cuisinesCategoriesService; + + @PostMapping("/CuisineCategory") + public CuisineCategory addcuisinecategory(@RequestBody CuisineCategory cuisineCategories) + { + + return cuisinesCategoriesService.saveCuisineCatgeory(cuisineCategories); + } + + @GetMapping({"/CuisnesCategoryRequests"}) + public List findcontactrequests() + + { + return cuisinesCategoriesService.getCusineCategoriesRequets(); + } + + @GetMapping({"/ContactCategoryById/{id}"}) + public CuisineCategory findcuisinecategoryrequestbyId(@PathVariable int id) + { + return cuisinesCategoriesService.getCuisineCategoryById(id); + } + +} + + diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java new file mode 100644 index 0000000..9a808c6 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java @@ -0,0 +1,6 @@ +package ethniconnect_backend.Cuisines; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface CuisineCategoriesRepository extends JpaRepository { +} diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java new file mode 100644 index 0000000..13527f8 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java @@ -0,0 +1,28 @@ +package ethniconnect_backend.Cuisines; + +import ethniconnect_backend.ChefCreateMenu.ChefMenu; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +import javax.persistence.*; +import java.util.List; +import java.util.Set; + +@Data +@NoArgsConstructor +@AllArgsConstructor + +@Entity +@Table(name = "cuisinecategory") +public class CuisineCategory { + @Id + @GeneratedValue + private int id; + private String cuisine_name; + private String cuisine_image; + + @OneToMany(fetch = FetchType.LAZY, mappedBy = "cuisineCategory") + private List menus; +} diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java b/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java new file mode 100644 index 0000000..29f3718 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java @@ -0,0 +1,27 @@ +package ethniconnect_backend.Cuisines; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +@Service +public class CuisinesCategoriesService { + + @Autowired + public CuisineCategoriesRepository cuisineCategoriesRepository; + public CuisineCategory saveCuisineCatgeory(CuisineCategory cuisineCategories) + { + return (CuisineCategory) cuisineCategoriesRepository.save(cuisineCategories); + } + + public List getCusineCategoriesRequets() + { + return cuisineCategoriesRepository.findAll(); + } + public CuisineCategory getCuisineCategoryById(int id) + { + return (CuisineCategory) cuisineCategoriesRepository.findById(id).orElse(null); + } + +} + diff --git a/src/main/java/ethniconnect_backend/Customer/Customer.java b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java similarity index 94% rename from src/main/java/ethniconnect_backend/Customer/Customer.java rename to src/main/java/ethniconnect_backend/CustomerDetails/Customer.java index ac7676a..0249f53 100644 --- a/src/main/java/ethniconnect_backend/Customer/Customer.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.Customer; +package ethniconnect_backend.CustomerDetails; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/ethniconnect_backend/Customer/CustomerController.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java similarity index 93% rename from src/main/java/ethniconnect_backend/Customer/CustomerController.java rename to src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java index 9bf5c47..2c1514d 100644 --- a/src/main/java/ethniconnect_backend/Customer/CustomerController.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.Customer; +package ethniconnect_backend.CustomerDetails; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/main/java/ethniconnect_backend/Customer/CustomerRepository.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java similarity index 75% rename from src/main/java/ethniconnect_backend/Customer/CustomerRepository.java rename to src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java index d54110e..f70d671 100644 --- a/src/main/java/ethniconnect_backend/Customer/CustomerRepository.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.Customer; +package ethniconnect_backend.CustomerDetails; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/src/main/java/ethniconnect_backend/Customer/CustomerService.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java similarity index 98% rename from src/main/java/ethniconnect_backend/Customer/CustomerService.java rename to src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java index 5fd6b84..fb78ace 100644 --- a/src/main/java/ethniconnect_backend/Customer/CustomerService.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.Customer; +package ethniconnect_backend.CustomerDetails; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; import ethniconnect_backend.UserCredentials.UserCredentials; diff --git a/src/main/java/ethniconnect_backend/Login/Login.java b/src/main/java/ethniconnect_backend/Login/Login.java new file mode 100644 index 0000000..675098d --- /dev/null +++ b/src/main/java/ethniconnect_backend/Login/Login.java @@ -0,0 +1,16 @@ +package ethniconnect_backend.Login; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@EqualsAndHashCode +@ToString +@Setter +public class Login { + private String emailId; + private String password; +} + diff --git a/src/main/java/ethniconnect_backend/Login/LoginController.java b/src/main/java/ethniconnect_backend/Login/LoginController.java new file mode 100644 index 0000000..43fb8ff --- /dev/null +++ b/src/main/java/ethniconnect_backend/Login/LoginController.java @@ -0,0 +1,41 @@ +package ethniconnect_backend.Login; + +import ethniconnect_backend.UserCredentials.UserCredentials; +import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class LoginController +{ + + @Autowired + public UserCredentialsRepository userCredentialsRepository; + + @Autowired + BCryptPasswordEncoder bCryptPasswordEncoder; + + + + @PostMapping("/signin") + public ResponseEntity authenticateUser(@RequestBody UserCredentials userCredentials){ + UserCredentials userCredentialsFromDB = userCredentialsRepository.findByEmail(userCredentials.getEmail()).get(); + LoginResponse loginResponse = new LoginResponse(); + if(userCredentials.getEmail().equals(userCredentialsFromDB.getEmail()) + && bCryptPasswordEncoder.matches(userCredentials.getPassword(),userCredentialsFromDB.getPassword())) + { + //return new ResponseEntity<>("User signed-in successfully!.", HttpStatus.OK); + + loginResponse.setLoginId(userCredentialsFromDB.getId()); + return new ResponseEntity<>(loginResponse, HttpStatus.OK); + } + loginResponse.setErrormessage("User credentials are wrong"); + //SecurityContextHolder.getContext().setAuthentication(authentication); + return new ResponseEntity<>(loginResponse, HttpStatus.UNAUTHORIZED); + } +} diff --git a/src/main/java/ethniconnect_backend/Login/LoginResponse.java b/src/main/java/ethniconnect_backend/Login/LoginResponse.java new file mode 100644 index 0000000..a85a1e9 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Login/LoginResponse.java @@ -0,0 +1,13 @@ +package ethniconnect_backend.Login; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +@Data +@Getter +@Setter +public class LoginResponse { + private long loginId; + private String errormessage; +} diff --git a/src/main/java/ethniconnect_backend/Login/LoginService.java b/src/main/java/ethniconnect_backend/Login/LoginService.java new file mode 100644 index 0000000..45453fd --- /dev/null +++ b/src/main/java/ethniconnect_backend/Login/LoginService.java @@ -0,0 +1,4 @@ +package ethniconnect_backend.Login; + +public class LoginService { +} diff --git a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordController.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java similarity index 74% rename from src/main/java/ethniconnect_backend/resetpassword/ResetPasswordController.java rename to src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java index c09b84e..4b9c421 100644 --- a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordController.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java @@ -1,5 +1,6 @@ -package ethniconnect_backend.resetpassword; +package ethniconnect_backend.Resetpassword; +import ethniconnect_backend.UserCredentials.UserCredentials; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -29,5 +30,11 @@ public RedirectView confirm(@RequestParam("token") String token) { return redirectView; } + @PutMapping(path="updatepassword") + public String updatepassword(@RequestBody UpdatePassword updatePassword) + { + resetPasswordService.updatePassword(updatePassword); + return "Updated Password"; + } } diff --git a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordRequest.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordRequest.java similarity index 89% rename from src/main/java/ethniconnect_backend/resetpassword/ResetPasswordRequest.java rename to src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordRequest.java index 4887179..cfb2b87 100644 --- a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordRequest.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordRequest.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.resetpassword; +package ethniconnect_backend.Resetpassword; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java similarity index 65% rename from src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java rename to src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java index 616049e..6bc52e4 100644 --- a/src/main/java/ethniconnect_backend/resetpassword/ResetPasswordService.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java @@ -1,4 +1,4 @@ -package ethniconnect_backend.resetpassword; +package ethniconnect_backend.Resetpassword; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; import ethniconnect_backend.UserCredentials.UserCredentialsService; @@ -8,6 +8,7 @@ import ethniconnect_backend.ChefSignup.token.ConfirmationToken; import ethniconnect_backend.ChefSignup.token.ConfirmationTokenService; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -17,9 +18,9 @@ public class ResetPasswordService { @Autowired - UserCredentialsService appUserService; + UserCredentialsService userCredentialsService; @Autowired - UserCredentialsRepository appUserRepository; + UserCredentialsRepository userCredentialsRepository; @Autowired EmailSender emailSender; @Autowired @@ -28,11 +29,11 @@ public class ResetPasswordService { ConfirmationTokenService confirmationTokenService; public void resetPassword(ResetPasswordRequest resetPasswordRequest) { - UserCredentials userCredentials = appUserRepository.findByEmail(resetPasswordRequest.getEmailId()).get(); + UserCredentials userCredentials = userCredentialsRepository.findByEmail(resetPasswordRequest.getEmailId()).get(); - if(appUserService.isEmailIdExist(resetPasswordRequest.getEmailId())) + if(userCredentialsService.isEmailIdExist(resetPasswordRequest.getEmailId())) { - String token =appUserService.getToken(userCredentials); + String token = userCredentialsService.getToken(userCredentials); String link = "http://localhost:5000/api/v1/resetpassword/confirm?token=" + token; emailSender.send( resetPasswordRequest.getEmailId(), @@ -62,4 +63,12 @@ public String confirmToken(String token) { return confirmationToken.getAppUser().getEmail(); } + public void updatePassword(UpdatePassword updatePassword) { + BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); + String encodedPassword = passwordEncoder.encode(updatePassword.getNewPwd()); + UserCredentials userCredentials = userCredentialsRepository.findByEmail(updatePassword.getEmailId()).get(); + userCredentials.setPassword(encodedPassword); + userCredentials.setResetpasswordtoken(null); + userCredentialsRepository.save(userCredentials); + } } diff --git a/src/main/java/ethniconnect_backend/Resetpassword/UpdatePassword.java b/src/main/java/ethniconnect_backend/Resetpassword/UpdatePassword.java new file mode 100644 index 0000000..e0ce6b2 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Resetpassword/UpdatePassword.java @@ -0,0 +1,15 @@ +package ethniconnect_backend.Resetpassword; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +@Getter +@EqualsAndHashCode +@ToString +@Setter +public class UpdatePassword { + private String emailId; + private String newPwd; +} From af0a2662d85a270bde0c527d72250855b616fd5b Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Fri, 1 Apr 2022 22:06:03 -0400 Subject: [PATCH 12/69] customer image working add customer is working with image upload --- .DS_Store | Bin 6148 -> 6148 bytes pom.xml | 7 + src/.DS_Store | Bin 0 -> 6148 bytes src/main/.DS_Store | Bin 0 -> 6148 bytes src/main/java/.DS_Store | Bin 0 -> 6148 bytes src/main/java/ethniconnect_backend/.DS_Store | Bin 0 -> 6148 bytes .../ChefCreateMenu/ChefMenu.java | 9 ++ .../ChefCreateMenu/ChefMenuRequest.java | 1 + .../ChefCreateMenu/ChefMenuService.java | 6 + .../ChefDetails/Chef.java | 23 +++- .../ChefDetails/ChefController.java | 45 ++++-- .../ChefDetails/ChefRepository.java | 8 +- .../ChefDetails/ChefService.java | 60 +++++++- .../ChefDetails/ChefprofileResponse.java | 15 ++ .../Cuisines/CuisineCategory.java | 1 + .../CustomerDetails/Customer.java | 17 ++- .../CustomerDetails/CustomerController.java | 23 +++- .../CustomerDetails/CustomerRepository.java | 8 +- .../CustomerDetails/CustomerService.java | 130 ++++++++++++------ .../ethniconnect_backend/DemoApplication.java | 1 + .../ethniconnect_backend/Order/Order.java | 49 +++++++ .../Order/OrderController.java | 48 +++++++ .../Order/OrderRepository.java | 12 ++ .../Order/OrderRequest.java | 30 ++++ .../Order/OrderService.java | 93 +++++++++++++ src/main/resources/application.yml | 11 +- 26 files changed, 523 insertions(+), 74 deletions(-) create mode 100644 src/.DS_Store create mode 100644 src/main/.DS_Store create mode 100644 src/main/java/.DS_Store create mode 100644 src/main/java/ethniconnect_backend/.DS_Store create mode 100644 src/main/java/ethniconnect_backend/ChefDetails/ChefprofileResponse.java create mode 100644 src/main/java/ethniconnect_backend/Order/Order.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderController.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderRepository.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderRequest.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderService.java diff --git a/.DS_Store b/.DS_Store index ea7febd2e65262fee36b8037c1a892c8bea09758..c84e0488b4d78e8c99c940fd619d93c171f27bc9 100644 GIT binary patch delta 158 zcmZoMXfc=|#>B!ku~2NHo+2aH#(>?7ixpUy7`Z0%Fg+AzW+-MTVn|LZFD^*R$xmWn zVAwv{h`CTryt>-NSVzIc(4baFq1w{O0LV5rtF7ha5LMQ<4vNpt$<52}oP2^=Uc3va z32IDPa8X`PeqK6IgmLpLCM%}R>>T_YK-)J9a(ri=%rD}|!N|bC1e9jj93irX835Gn BCq@7O delta 71 zcmZoMXfc=|#>B)qu~2NHo+2a1#(>?7j2x4BSRPLP!^*q)E~^&P#)ijCo7p+|Ie^MG a3vzsCp3E=e$iV;vj0_Acnspring-boot-starter-test test + + + commons-io + commons-io + 2.6 + + org.springframework.security spring-security-test diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..731abbcfe13eb1887b7a4dc810a81b7e47170773 GIT binary patch literal 6148 zcmeHK!A{#i5S38)zSP$c${@kYR=;U6+h!J z(?60-C+PD7MgDyTc->=1WNA^hT92x>;4OYw z@|XOEe;!@xQB=m|u;|2tQ|=vUoh8q9oE)e9QMb9gr}HvS^Zvjjq`f{u&Q8+2r$-$< z%zK5&jqHG5_v_u}=ka)ZYc1Grw{V$&DMd&lmI}!MjC-_uKvJ)9l+3GWf2~TvZ+9us$7YoT;-r_I>tj6 zUs<&2q|BS~9QS7BDiq}k4;7ejQlUj@g#lsUH3JK_+vM~A;O+YVb&~Xi0b$_3VnBKO z(S8S0a%bz@b^99LPKrob>qF=F{BUV$2cKVSnGI;p+Op9;IA_9 E3sjq6O8@`> literal 0 HcmV?d00001 diff --git a/src/main/.DS_Store b/src/main/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2143673e5e570e658e566b7589027ef4d84ab9d4 GIT binary patch literal 6148 zcmeHKO;6)65FM8SiO@6uw? z)|>NAqBA{=`f-0yG~?b8_YSnql4m-JVHEJ6(hv|4H+X9yawL z?-V9CvICy)`K{W|(P+J~9IUU^$IHQJ^H&{qV`Dt_y@jRKt^L+TcA4uN%e=yGY2=5) zXSjtina*|8%QKyy!pHGG^{7h)X&S(4v;B&gJ4F3U47wu1fG{8od?yCn=IG6Rr;nCz z6$XTXPho)fhXBeLIxH=ktpklI0f2msGy>aP{eb~HfT6?EB0LafQ-L;Bxe`OU%0bz5 zjE641v}n^wnK$D(?#;?oD9RNcDlp-sLW|N01H!;d2BvJc#^?X;$MyfqB5Ut)_<17-`gTWjJyo#Q~)eRYSjNy1R%-^+wqyQHO{EC}X3I<^kb()_cY)M#Ek*_|CmA#+2#I zPSUSMKJIsx_l&NRLgxb;P-Hn=j=mK-Gvl5a>1=3YV>c1BgLc2OGMVgbuZ26C-RW95 z`LNZ6y}dh~wu5)88y^q*=jDYqzbrANu=%aL^*Dno7*D3{XFSlQ(LWF~%Qwp-C=3V# z!oUkN;E$PL>4o!3I$=NN6U`4B=GBagL1dvu_&B><40kyc>a$3HOS0bt~@c8C#( za-l#Ms(gu|eC?oIIOZeoUpsW+r0kcG$A4M*3Pt(SLxt9zROC=vVL%v|XQ1i29lrlR zKVJXO2T4yD5C;A$22^W5-tS>a{%*auIKFE`=n0gC{c4AQLSWdd7`}WJzlU1Ec*q7Y U@>n~>2t*zNmIi5rfq%-t9n{Wp&;S4c literal 0 HcmV?d00001 diff --git a/src/main/java/ethniconnect_backend/.DS_Store b/src/main/java/ethniconnect_backend/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..97f23b13d9cd8eaa9efbed806099d7fcc9f5566f GIT binary patch literal 6148 zcmeHK%We}f6unLpI%(84iz3({jl{MpDXowYn=}avBoL^>V*w~k9;5@4nP?u3P!uU! z;2-z}mi!6-!V1o{oisCPSRw?zk$pV&J-+rCdmIyyXr#SEqAC$tNQ}iTWS1DXb6T;2 zu3@r}eKaYeKDm@2H)a$t3jFN~@ZQ~_CY@o&z6D@<5$uCPv?#W0)#66)Aem+Lr zmETfN&ijDg;pv>*?2L)EUGArZQ4isX_mK6Jie^0@qUQlClk;R1v!0KkM342zd9r?M zJUiofq*uARbl;xbyzO-X8|xM+_b&aCk}E);NbxD3oY1^>Zf*{4n5`&Wvq31&jj!lmepIa#{^cNuRANljF12MtXz9#(pz}l7dVh$Fjgj@pU9=XtTKhtZSSp SL=DXR5s)&N%qZ|j75D{+?Gxz$ literal 0 HcmV?d00001 diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java index 4364d76..351f313 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java @@ -1,11 +1,14 @@ package ethniconnect_backend.ChefCreateMenu; +import ethniconnect_backend.ChefDetails.Chef; import ethniconnect_backend.Cuisines.CuisineCategory; +import ethniconnect_backend.Order.Order; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import javax.persistence.*; +import java.util.Set; @Data @NoArgsConstructor @@ -24,6 +27,7 @@ public class ChefMenu { @Lob @Column(name = "Image", length = Integer.MAX_VALUE, nullable = true) private byte[] menu_item_image; + private String item_name; private int menu_item_price; private String item_ingredients; private String item_intresting_facts; @@ -34,7 +38,12 @@ public class ChefMenu { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "cuisine_id") private CuisineCategory cuisineCategory; + @ManyToMany(mappedBy = "menu_items") + Set orders; + /* @OneToOne + @JoinColumn (name="login_id", insertable = false, updatable = false) + private Chef chef;*/ /*@JoinTable( name = "selected_cuisines", joinColumns = @JoinColumn(name = "menu_item_id"), diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java index a6c76f9..b1cebe0 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java @@ -20,6 +20,7 @@ public class ChefMenuRequest { @Lob @Column(name = "Image", length = Integer.MAX_VALUE, nullable = true) private byte[] menu_item_image; + private String item_name; private int menu_item_price; private String item_ingredients; private String item_intresting_facts; diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index a90a24b..e1df5fe 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -6,9 +6,11 @@ import ethniconnect_backend.UserCredentials.UserCredentials; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; import ethniconnect_backend.UserCredentials.UserCredentialsService; +import lombok.val; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import java.util.List; import java.util.Optional; @@ -36,6 +38,7 @@ public ChefMenu saveChefMenu(ChefMenuRequest chefMenuRequest) throws Exception{ chefMenu.setMenucategories(chefMenuRequest.getMenucategories()); chefMenu.setMenu_item_image(chefMenuRequest.getMenu_item_image()); chefMenu.setMenu_item_price(chefMenuRequest.getMenu_item_price()); + chefMenu.setItem_name(chefMenuRequest.getItem_name()); chefMenu.setItem_intresting_facts(chefMenuRequest.getItem_intresting_facts()); chefMenu.setItem_ingredients(chefMenuRequest.getItem_ingredients()); chefMenu.setCuisineCategory(cuisineCategory); @@ -66,6 +69,7 @@ public ChefMenu updateChefMenu(ChefMenu chefMenu) ChefMenu existingChefMenu=chefMenuRepository.findById(chefMenu.getId()).orElse(null); existingChefMenu.setMenucategories(chefMenu.getMenucategories()); existingChefMenu.setMenu_item_image(chefMenu.getMenu_item_image()); + existingChefMenu.setItem_name(chefMenu.getItem_name()); existingChefMenu.setMenu_item_price(chefMenu.getMenu_item_price()); existingChefMenu.setItem_ingredients(chefMenu.getItem_ingredients()); existingChefMenu.setItem_intresting_facts(chefMenu.getItem_intresting_facts()); @@ -74,4 +78,6 @@ public ChefMenu updateChefMenu(ChefMenu chefMenu) return chefMenuRepository.save(existingChefMenu); } + + } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java index 0c3824c..b48d8b2 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java @@ -1,19 +1,23 @@ package ethniconnect_backend.ChefDetails; +import com.sun.mail.iap.ByteArray; +import ethniconnect_backend.ChefCreateMenu.ChefMenu; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +import lombok.var; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; +import javax.persistence.*; +import java.util.List; @Data @NoArgsConstructor @AllArgsConstructor @Entity @Table(name = "chef") + //(uniqueConstraints={@UniqueConstraint(columnNames = {"chef_emailid"})}) + + public class Chef { @Id @GeneratedValue @@ -32,6 +36,17 @@ public class Chef { private int chef_experience; private String chef_fblink; private String chef_linkdin; + /*@Lob + @Column(name = "Image", length = Integer.MAX_VALUE, nullable = true) + private byte[] chef_image;*/ + @Lob + @Column(columnDefinition = "MEDIUMBLOB") private String chef_image; + + + /* @OneToMany (targetEntity = ChefMenu.class, cascade = CascadeType.ALL) + @JoinColumn(name = "cm_fk" , referencedColumnName = "login_id") + private List chefmenus;*/ + } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java index 6e8a482..cc8add6 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java @@ -1,25 +1,45 @@ package ethniconnect_backend.ChefDetails; import org.springframework.beans.factory.annotation.Autowired; + import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + @RestController public class ChefController { @Autowired private ChefService chefProfileService; + @Autowired + private ChefRepository chefRepository; + @PostMapping("/chef") + public String addchef(@RequestParam("file") MultipartFile file, + @RequestParam("chef_fname") String fname, + @RequestParam("chef_lname") String lname, + @RequestParam("chef_emailid") String emailid, + @RequestParam("chef_phone") String chef_phone, + @RequestParam("chef_street") String chef_street, + @RequestParam("chef_city") String chef_city, + @RequestParam("chef_state") String chef_state, + @RequestParam("chef_zip") String chef_zip, + @RequestParam("chef_paymode") String chef_paymode, + @RequestParam("chef_description") String chef_description, + @RequestParam("chef_experience") int chef_experience, + @RequestParam("chef_fblink") String chef_fblink, + @RequestParam("chef_linkdin") String chef_linkdin) throws Exception { + chefProfileService.saveChef(file, fname, lname,emailid,chef_phone,chef_street, + chef_city,chef_state,chef_zip,chef_paymode,chef_description, + chef_experience,chef_fblink,chef_linkdin); + return "chef details added"; + } - @PostMapping("/chef") + /* @PostMapping("/chef") public Chef addChef(@RequestBody Chef chef) throws Exception - { - - return chefProfileService.saveChef(chef); - } - /* @PostMapping("/chefs") - public List addChefs(@RequestBody List chefs) { - return chefProfileService.saveChefs(chefs); + return chefProfileService.saveChef(chef); }*/ + @GetMapping({"/chefById/{id}"}) public Chef findChefById(@PathVariable int id) { @@ -31,4 +51,13 @@ public Chef updateChef(@RequestBody Chef chef) { return chefProfileService.updateChef(chef); } + + /* @GetMapping({"/chefprofile"}) + public List getChefProfileInfo() + { + return chefRepository.getChefProfileInfo(); + }*/ + + + } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java index bfc6287..9208737 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java @@ -1,10 +1,14 @@ package ethniconnect_backend.ChefDetails; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; -public interface ChefRepository extends JpaRepository { +import java.util.List; +public interface ChefRepository extends JpaRepository { +/* *//*@Query("SELECT new ethniconnect_backend.ChefDetails.ChefprofileResponse( c.chef_fname, m.menu_item_price)" + + " FROM Chef c join c.ChefMenu m")*//* + public List getChefProfileInfo();*/ - /*Chef findByEmailId(String chef_emailid);*/ } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java index def90a5..c1bc78a 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java @@ -5,7 +5,11 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; +import java.util.Base64; import java.util.List; import java.util.Optional; @@ -16,15 +20,60 @@ public class ChefService { @Autowired private UserCredentialsRepository userCredentialsRepository; - public Chef saveChef(Chef chef) throws Exception{ + public void saveChef(MultipartFile file, String fname,String lname,String emailid, + String chef_phone,String chef_street,String chef_city, + String chef_state,String chef_zip,String chef_paymode, + String chef_description,int chef_experience,String chef_fblink, + String chef_linkdin) throws Exception + { + Chef chef =new Chef(); + Optional userData = userCredentialsRepository.findByEmail(emailid); + if(!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + + + + + Long loginId = userData.get().getId(); + + chef.setLogin_id(loginId); + String fileName = StringUtils.cleanPath(file.getOriginalFilename()); + if(fileName.contains("..")) + { + System.out.println("not a a valid file"); + } + try { + chef.setChef_image(Base64.getEncoder().encodeToString(file.getBytes())); + } catch (IOException e) { + e.printStackTrace(); + } + chef.setChef_fname(fname); + + chef.setChef_lname(lname); + chef.setChef_emailid(emailid); + chef.setChef_city(chef_city); + chef.setChef_phone(chef_phone); + chef.setChef_street(chef_street); + chef.setChef_state(chef_state); + chef.setChef_zip(chef_zip); + chef.setChef_paymode(chef_paymode); + chef.setChef_description(chef_description); + chef.setChef_experience(chef_experience); + chef.setChef_fblink(chef_fblink); + chef.setChef_linkdin(chef_linkdin); + chefRepository.save(chef); + } + + /*public Chef saveChef(Chef chef) throws Exception{ Optional userData = userCredentialsRepository.findByEmail(chef.getChef_emailid()); if(!userData.isPresent()) throw new Exception("user Id doesn't exist"); Long loginId = userData.get().getId(); chef.setLogin_id(loginId); + return chefRepository.save(chef); - } + }*/ public List saveChefs(List chefs){ return chefRepository.saveAll(chefs); } @@ -36,9 +85,7 @@ public List getChefs() public Chef getChefById(int chef_id){ return chefRepository.findById(chef_id).orElse(null); } - /*public Chef getChefByEmailId(String chef_emailid){ - return chefProfileRepository.findByEmailId(chef_emailid); - }*/ + public String deleteChef(int chef_id) { chefRepository.deleteById(chef_id); @@ -64,4 +111,7 @@ public Chef updateChef(Chef chef) return chefRepository.save(existingChef); } + + + } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefprofileResponse.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefprofileResponse.java new file mode 100644 index 0000000..a577888 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefprofileResponse.java @@ -0,0 +1,15 @@ +package ethniconnect_backend.ChefDetails; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@ToString +public class ChefprofileResponse { + private String chef_name; + private int menu_item_price; +} diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java index 13527f8..e4c5e0d 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java @@ -25,4 +25,5 @@ public class CuisineCategory { @OneToMany(fetch = FetchType.LAZY, mappedBy = "cuisineCategory") private List menus; + } diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java index 0249f53..771c610 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java @@ -1,13 +1,14 @@ package ethniconnect_backend.CustomerDetails; +import ethniconnect_backend.ChefCreateMenu.ChefMenu; +import ethniconnect_backend.Order.Order; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; +import javax.persistence.*; +import java.util.List; +import java.util.Set; @Data @NoArgsConstructor @@ -28,6 +29,14 @@ public class Customer { private String cust_state; private String cust_zip; private String cust_ethnicity; + + @Lob + @Column(columnDefinition = "MEDIUMBLOB") private String cust_image; + /*@OneToMany(fetch = FetchType.LAZY, mappedBy = "customer") + private List orders;*/ + @OneToMany(mappedBy = "customer", fetch = FetchType.LAZY, + cascade = CascadeType.ALL) + private Set orders; } diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java index 2c1514d..518cd77 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java @@ -3,6 +3,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + @RestController public class CustomerController { @@ -10,12 +12,29 @@ public class CustomerController { private CustomerService customerService; @PostMapping("/customer") - public Customer addCustomer(@RequestBody Customer customer) throws Exception + + public String addcustomer(@RequestParam("file") MultipartFile file, + @RequestParam("cust_fname") String fname, + @RequestParam("cust_lname") String lname, + @RequestParam("cust_emailid") String emailid, + @RequestParam("cust_phone") String phone, + @RequestParam("cust_street") String street, + @RequestParam("cust_city") String city, + @RequestParam("cust_state") String state, + @RequestParam("cust_zip") String zip, + @RequestParam("chef_ethnicity") String ethnicity + ) throws Exception { + customerService.saveCustomer(file, fname, lname,emailid,phone,street, + city,state,zip,ethnicity); + return "customer details added"; + } + + /* public Customer addCustomer(@RequestBody Customer customer) throws Exception { return customerService.saveCustomer(customer); } - +*/ @GetMapping({"/custById/{id}"}) public Customer findCustById(@PathVariable int id) diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java index f70d671..5cfe323 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java @@ -1,6 +1,12 @@ package ethniconnect_backend.CustomerDetails; +import ethniconnect_backend.ChefDetails.ChefprofileResponse; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.util.List; public interface CustomerRepository extends JpaRepository { -} + + +} \ No newline at end of file diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java index fb78ace..64bd882 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java @@ -1,61 +1,101 @@ package ethniconnect_backend.CustomerDetails; + import ethniconnect_backend.UserCredentials.UserCredentialsRepository; import ethniconnect_backend.UserCredentials.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; +import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; +import java.util.Base64; import java.util.List; import java.util.Optional; - @Service - public class CustomerService { - @Autowired - private CustomerRepository customerRepository; - @Autowired - private UserCredentialsRepository appUserRepository; - - public Customer saveCustomer(Customer customer) throws Exception{ - Optional userData =appUserRepository.findByEmail(customer.getCust_emailid()); - if(!userData.isPresent()) - throw new Exception("user Id doesn't exist"); - Long loginId = userData.get().getId(); - - customer.setLogin_id(loginId); - return customerRepository.save(customer); - } - public List saveChefs(List customers){ - return customerRepository.saveAll(customers); - } +@Service +public class CustomerService { + @Autowired + private CustomerRepository customerRepository; + @Autowired + private UserCredentialsRepository userCredentialsRepository; - public List getCustomers() + public void saveCustomer(MultipartFile file, String fname, String lname, String emailid, + String phone, String street, String city, + String state, String zip, String ethnicity) throws Exception + { + Customer customer =new Customer(); + Optional userData = userCredentialsRepository.findByEmail(emailid); + if(!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + Long loginId = userData.get().getId(); + + customer.setLogin_id(loginId); + String fileName = StringUtils.cleanPath(file.getOriginalFilename()); + if(fileName.contains("..")) { - return customerRepository.findAll(); + System.out.println("not a a valid file"); } - public Customer getCustById(int cust_id){ - return customerRepository.findById(cust_id).orElse(null); + try { + customer.setCust_image(Base64.getEncoder().encodeToString(file.getBytes())); + } catch (IOException e) { + e.printStackTrace(); } - /*public Chef getChefByEmailId(String chef_emailid){ - return chefProfileRepository.findByEmailId(chef_emailid); - }*/ - public String deleteCust(int cust_id) - { - customerRepository.deleteById(cust_id); - return "customer removed !!" + cust_id; - } - public Customer updateCust(Customer customer) - { - Customer existingCustomer=customerRepository.findById(customer.getCust_id()).orElse(null); - existingCustomer.setCust_fname(customer.getCust_fname()); - existingCustomer.setCust_lname(customer.getCust_lname()); - existingCustomer.setCust_phone(customer.getCust_phone()); - existingCustomer.setCust_emailid(customer.getCust_emailid()); - existingCustomer.setCust_street(customer.getCust_street()); - existingCustomer.setCust_city(customer.getCust_city()); - existingCustomer.setCust_state(customer.getCust_state()); - existingCustomer.setCust_zip(customer.getCust_zip()); - existingCustomer.setCust_image(customer.getCust_image()); - return customerRepository.save(existingCustomer); - } + customer.setCust_fname(fname); + customer.setCust_lname(lname); + customer.setCust_emailid(emailid); + customer.setCust_city(city); + customer.setCust_phone(phone); + customer.setCust_street(street); + customer.setCust_state(state); + customer.setCust_city(city); + customer.setCust_zip(zip); + customer.setCust_ethnicity(ethnicity); + customerRepository.save(customer); + } + + /*public Customer saveCustomer(Customer customer) throws Exception{ + Optional userData =appUserRepository.findByEmail(customer.getCust_emailid()); + if(!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + Long loginId = userData.get().getId(); + + customer.setLogin_id(loginId); + return customerRepository.save(customer); + }*/ + public List saveChefs(List customers){ + return customerRepository.saveAll(customers); + } + + public List getCustomers() + { + return customerRepository.findAll(); + } + public Customer getCustById(int cust_id){ + return customerRepository.findById(cust_id).orElse(null); + } + /*public Chef getChefByEmailId(String chef_emailid){ + return chefProfileRepository.findByEmailId(chef_emailid); + }*/ + public String deleteCust(int cust_id) + { + customerRepository.deleteById(cust_id); + return "customer removed !!" + cust_id; + } + public Customer updateCust(Customer customer) + { + Customer existingCustomer=customerRepository.findById(customer.getCust_id()).orElse(null); + existingCustomer.setCust_fname(customer.getCust_fname()); + existingCustomer.setCust_lname(customer.getCust_lname()); + existingCustomer.setCust_phone(customer.getCust_phone()); + existingCustomer.setCust_emailid(customer.getCust_emailid()); + existingCustomer.setCust_street(customer.getCust_street()); + existingCustomer.setCust_city(customer.getCust_city()); + existingCustomer.setCust_state(customer.getCust_state()); + existingCustomer.setCust_zip(customer.getCust_zip()); + existingCustomer.setCust_image(customer.getCust_image()); + return customerRepository.save(existingCustomer); + } +} \ No newline at end of file diff --git a/src/main/java/ethniconnect_backend/DemoApplication.java b/src/main/java/ethniconnect_backend/DemoApplication.java index 3d1086b..e716579 100644 --- a/src/main/java/ethniconnect_backend/DemoApplication.java +++ b/src/main/java/ethniconnect_backend/DemoApplication.java @@ -3,6 +3,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; + @SpringBootApplication public class DemoApplication { diff --git a/src/main/java/ethniconnect_backend/Order/Order.java b/src/main/java/ethniconnect_backend/Order/Order.java new file mode 100644 index 0000000..142fc76 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/Order.java @@ -0,0 +1,49 @@ +package ethniconnect_backend.Order; + + +import ethniconnect_backend.ChefCreateMenu.ChefMenu; +import ethniconnect_backend.Cuisines.CuisineCategory; +import ethniconnect_backend.CustomerDetails.Customer; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +import javax.persistence.*; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Table(name = "order") +public class Order { + @Id + @GeneratedValue + private int order_id; + private long login_id; + private int cust_id; + private int menu_id; + private LocalDate order_date; + private LocalDateTime pickup_time; + private String order_instructions; + private double order_amount; + + /* @OneToOne(fetch = FetchType.LAZY, + cascade = CascadeType.ALL, + mappedBy = "orders") + private Customer customer;*/ + @ManyToOne + @JoinColumn(name="cust_id", insertable = false, updatable = false) + private Customer customer; + @ManyToMany + @JoinTable( + name = "order_menu", + joinColumns = @JoinColumn(name = "order_id"), + inverseJoinColumns = @JoinColumn(name = "id")) + Set menu_items; +} diff --git a/src/main/java/ethniconnect_backend/Order/OrderController.java b/src/main/java/ethniconnect_backend/Order/OrderController.java new file mode 100644 index 0000000..d99e175 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderController.java @@ -0,0 +1,48 @@ +package ethniconnect_backend.Order; + +import ethniconnect_backend.ChefCreateMenu.*; +import ethniconnect_backend.ChefCreateMenu.OrderRequest; +import org.aspectj.weaver.ast.Or; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +@RestController +public class OrderController { + + @Autowired + private OrderService orderService; + @Autowired + private OrderRepository orderRepository; + + @PostMapping("/order") + public ResponseEntity addOrder(@RequestBody OrderRequest orderRequest) throws Exception + { + + //chefMenuService.saveChefMenu(ch); + orderService.saveOrder(orderRequest); + + return new ResponseEntity<>("order is places successfully", HttpStatus.OK); + } + /* @PostMapping("/chefs") + public List addChefs(@RequestBody List chefs) + { + return chefProfileService.saveChefs(chefs); + }*/ + + @GetMapping({"/getOrderById/{id}"}) + public Order findOrderById(@PathVariable int id) + { + return orderService.getOrderById(id); + } + + @PutMapping("/updateorder") + public Order updateOrder(@RequestBody Order order) + { + return orderService.updateOrder(order); + } +} + + + + diff --git a/src/main/java/ethniconnect_backend/Order/OrderRepository.java b/src/main/java/ethniconnect_backend/Order/OrderRepository.java new file mode 100644 index 0000000..a0b472a --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderRepository.java @@ -0,0 +1,12 @@ +package ethniconnect_backend.Order; + +import ethniconnect_backend.ChefCreateMenu.ChefMenu; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + + +public interface OrderRepository extends JpaRepository { + + //Optional findOrderById(Integer id); +} diff --git a/src/main/java/ethniconnect_backend/Order/OrderRequest.java b/src/main/java/ethniconnect_backend/Order/OrderRequest.java new file mode 100644 index 0000000..173f4c5 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderRequest.java @@ -0,0 +1,30 @@ +package ethniconnect_backend.ChefCreateMenu; + +import ethniconnect_backend.Cuisines.CuisineCategory; +import lombok.*; + +import javax.persistence.*; +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Data +@Builder +@Getter +@Setter +@AllArgsConstructor +@ToString + +public class OrderRequest { + + private int order_id; + private long login_id; + private int cust_id; + private int menu_id; + private LocalDate order_date; + private LocalDateTime pickup_time; + private String order_instructions; + private double order_amount; + +} + + diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java new file mode 100644 index 0000000..7e1eda2 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -0,0 +1,93 @@ +package ethniconnect_backend.Order; + +import ethniconnect_backend.ChefCreateMenu.ChefMenu; +import ethniconnect_backend.ChefCreateMenu.ChefMenuRepository; +import ethniconnect_backend.ChefCreateMenu.ChefMenuRequest; +import ethniconnect_backend.ChefCreateMenu.OrderRequest; +import ethniconnect_backend.Cuisines.CuisineCategoriesRepository; +import ethniconnect_backend.Cuisines.CuisineCategory; +import ethniconnect_backend.CustomerDetails.Customer; +import ethniconnect_backend.CustomerDetails.CustomerRepository; +import ethniconnect_backend.UserCredentials.UserCredentials; +import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import org.apache.maven.artifact.repository.Authentication; +import org.aspectj.weaver.ast.Or; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; +@Service +public class OrderService { + + + + @Autowired + private ChefMenuRepository chefMenuRepository; + @Autowired + private UserCredentialsRepository userCredentialsRepository; + @Autowired + private CustomerRepository customerRepository; + + @Autowired + CuisineCategoriesRepository cuisineCategoriesRepository; + @Autowired + OrderRepository orderRepository; + + public Order saveOrder(OrderRequest orderRequest) throws Exception { + + + Optional userData = userCredentialsRepository.findById(orderRequest.getLogin_id()); + if (!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + Customer customer = customerRepository.findById(orderRequest.getCust_id()).get(); + // Long loginId = userData.get().getId(); + if (customer == null) + throw new Exception("cuisine category doesn't exist"); + Order order = new Order(); + orderRequest.setLogin_id(orderRequest.getLogin_id()); + orderRequest.setCust_id(orderRequest.getCust_id()); + orderRequest.setMenu_id(orderRequest.getMenu_id()); + orderRequest.setOrder_instructions(orderRequest.getOrder_instructions()); + orderRequest.setOrder_date(orderRequest.getOrder_date()); + orderRequest.setPickup_time(orderRequest.getPickup_time()); + orderRequest.setOrder_amount(orderRequest.getOrder_amount()); + orderRequest.setLogin_id(orderRequest.getLogin_id()); + return orderRepository.save(order); + + + } + /* public List saveOrders(List orders){ + return OrderRepository.saveAll(orders); + }*/ + + public List getOrders() + { + return orderRepository.findAll(); + } + public Order getOrderById(int order_id){ + return orderRepository.findById(order_id).orElse(null); + } + + public String deleteorder(int order_id) + { + orderRepository.deleteById(order_id); + return "order deleted " + order_id; + } + public Order updateOrder(Order order) + { + Order existingOrder=orderRepository.findById(order.getOrder_id()).orElse(null); + existingOrder.setOrder_amount(order.getOrder_amount()); + existingOrder.setOrder_date(order.getOrder_date()); + existingOrder.setOrder_instructions(order.getOrder_instructions()); + existingOrder.setMenu_id(order.getMenu_id()); + existingOrder.setPickup_time(order.getPickup_time()); + existingOrder.setCust_id(order.getCust_id()); + + return orderRepository.save(existingOrder); + + } +} + + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d274117..6c6f0ce 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 5000 + port: 8080 error: include-message: always include-binding-errors: always @@ -12,12 +12,12 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver password: bharani16 initialization-mode: ALWAYS - url: jdbc:mysql://localhost:3306/registration?serverTimezone=UTC + url: jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect username: root jpa: hibernate: - ddl-auto: create-drop + ddl-auto: update properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect @@ -53,3 +53,8 @@ spring: connectiontimeout: 5000 timeout: 3000 writetimeout: 5000 + + servlet : + multipart : + max-file-size: 15MB + max-request-size: 15MB From 129cfd6f7edf9b47fc3b7fe7abe3c808187d7c70 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 2 Apr 2022 14:45:21 -0400 Subject: [PATCH 13/69] working code with image upload image upload is working --- .../java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java | 4 ++-- .../ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java | 4 +--- src/main/java/ethniconnect_backend/ChefDetails/Chef.java | 4 ---- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java index 351f313..4e2c2bd 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java @@ -25,8 +25,8 @@ public class ChefMenu { private MenuCategories menucategories; //private int cuisine_id; @Lob - @Column(name = "Image", length = Integer.MAX_VALUE, nullable = true) - private byte[] menu_item_image; + @Column(columnDefinition = "MEDIUMBLOB") + private String menu_item_image; private String item_name; private int menu_item_price; private String item_ingredients; diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java index b1cebe0..e528c8f 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java @@ -17,9 +17,7 @@ public class ChefMenuRequest { @Enumerated(EnumType.STRING) private MenuCategories menucategories; private int cuisine_id; - @Lob - @Column(name = "Image", length = Integer.MAX_VALUE, nullable = true) - private byte[] menu_item_image; + private String menu_item_image; private String item_name; private int menu_item_price; private String item_ingredients; diff --git a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java index b48d8b2..9881b74 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java @@ -1,14 +1,10 @@ package ethniconnect_backend.ChefDetails; -import com.sun.mail.iap.ByteArray; -import ethniconnect_backend.ChefCreateMenu.ChefMenu; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import lombok.var; import javax.persistence.*; -import java.util.List; @Data @NoArgsConstructor From 5a61b5d882a3aa5d51f77498f49d9c5f7c1e1ffe Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 3 Apr 2022 12:34:11 -0400 Subject: [PATCH 14/69] working code working code --- .../java/ethniconnect_backend/CustomerDetails/Customer.java | 2 +- .../CustomerDetails/CustomerController.java | 5 ++--- .../CustomerDetails/CustomerService.java | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java index 771c610..54eab73 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java @@ -28,7 +28,7 @@ public class Customer { private String cust_city; private String cust_state; private String cust_zip; - private String cust_ethnicity; + @Lob @Column(columnDefinition = "MEDIUMBLOB") diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java index 518cd77..fc55cfd 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java @@ -21,11 +21,10 @@ public String addcustomer(@RequestParam("file") MultipartFile file, @RequestParam("cust_street") String street, @RequestParam("cust_city") String city, @RequestParam("cust_state") String state, - @RequestParam("cust_zip") String zip, - @RequestParam("chef_ethnicity") String ethnicity + @RequestParam("cust_zip") String zip ) throws Exception { customerService.saveCustomer(file, fname, lname,emailid,phone,street, - city,state,zip,ethnicity); + city,state,zip); return "customer details added"; } diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java index 64bd882..f7a403a 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java @@ -22,7 +22,7 @@ public class CustomerService { public void saveCustomer(MultipartFile file, String fname, String lname, String emailid, String phone, String street, String city, - String state, String zip, String ethnicity) throws Exception + String state, String zip) throws Exception { Customer customer =new Customer(); Optional userData = userCredentialsRepository.findByEmail(emailid); @@ -51,7 +51,7 @@ public void saveCustomer(MultipartFile file, String fname, String lname, String customer.setCust_state(state); customer.setCust_city(city); customer.setCust_zip(zip); - customer.setCust_ethnicity(ethnicity); + customerRepository.save(customer); } From 7970f236221822f722de8616c86aa471bde58b16 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 3 Apr 2022 16:58:13 -0400 Subject: [PATCH 15/69] get chefmenu by id working get chefmenu by id working --- .../ChefCreateMenu/ChefMenu.java | 2 +- .../ChefCreateMenu/ChefMenuController.java | 24 +++++- .../ChefCreateMenu/ChefMenuGETResponse.java | 26 +++++++ .../ChefCreateMenu/ChefMenuRepository.java | 2 +- .../ChefCreateMenu/ChefMenuService.java | 76 +++++++++++++++++-- .../CustomerSignup/CustSignupRequest.java | 2 +- .../CustomerSignup/CustSignupService.java | 2 +- 7 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuGETResponse.java diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java index 4e2c2bd..7044b56 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java @@ -28,7 +28,7 @@ public class ChefMenu { @Column(columnDefinition = "MEDIUMBLOB") private String menu_item_image; private String item_name; - private int menu_item_price; + private double menu_item_price; private String item_ingredients; private String item_intresting_facts; @Enumerated(EnumType.STRING) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java index e107f37..43c5fdb 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java @@ -6,6 +6,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; @RestController public class ChefMenuController { @@ -16,22 +17,37 @@ public class ChefMenuController { private ChefMenuRepository chefMenuRepository; @PostMapping("/chefmenu") - public ResponseEntity addChefMenu(@RequestBody ChefMenuRequest chefMenuRequest) throws Exception + + public String addChefMenu(@RequestParam("file") MultipartFile file, + @RequestParam("login_id") long login_id, + @RequestParam("menucategories") MenuCategories menuCategories, + @RequestParam("cuisine_id") int cuisine_id, + @RequestParam("item_name") String item_name, + + @RequestParam("menu_item_price") double menu_item_price, + @RequestParam("item_ingredients") String item_ingredients, + @RequestParam("item_intresting_facts") String item_intresting_facts, + @RequestParam("week") Week week) throws Exception { + chefMenuService.saveChefMenu(file, login_id, menuCategories,cuisine_id, + item_name,menu_item_price,item_ingredients,item_intresting_facts,week); + return "chef details added"; + } + /* public ResponseEntity addChefMenu(@RequestBody ChefMenuRequest chefMenuRequest) throws Exception { //chefMenuService.saveChefMenu(ch); chefMenuService.saveChefMenu(chefMenuRequest); return new ResponseEntity<>("menu item saved successfully", HttpStatus.OK); - } + }*/ /* @PostMapping("/chefs") public List addChefs(@RequestBody List chefs) { return chefProfileService.saveChefs(chefs); }*/ - @GetMapping({"/chefmenuyId/{id}"}) - public ChefMenu findChefMenuById(@PathVariable int id) + @GetMapping({"/chefmenuById/{id}"}) + public ChefMenuGETResponse findChefMenuById(@PathVariable int id) { return chefMenuService.getChefMenuById(id); } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuGETResponse.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuGETResponse.java new file mode 100644 index 0000000..2235167 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuGETResponse.java @@ -0,0 +1,26 @@ +package ethniconnect_backend.ChefCreateMenu; + +import lombok.Builder; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + + +@Builder +@Getter +@Setter +@Data +public class ChefMenuGETResponse { + + private long login_id; + private int cuisine_id; + private MenuCategories menucategories; + private String menu_item_image; + private String item_name; + private double menu_item_price; + private String item_ingredients; + private String item_intresting_facts; + private Week week; + + +} diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java index fc92563..3556fed 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java @@ -7,5 +7,5 @@ public interface ChefMenuRepository extends JpaRepository { - Optional findById(Integer id); + //Optional findById(Integer id); } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index e1df5fe..b470ebb 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -1,17 +1,16 @@ package ethniconnect_backend.ChefCreateMenu; -import ethniconnect_backend.ChefDetails.Chef; import ethniconnect_backend.Cuisines.CuisineCategoriesRepository; import ethniconnect_backend.Cuisines.CuisineCategory; import ethniconnect_backend.UserCredentials.UserCredentials; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; -import ethniconnect_backend.UserCredentials.UserCredentialsService; -import lombok.val; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; +import java.io.IOException; +import java.util.Base64; import java.util.List; import java.util.Optional; @Service @@ -25,7 +24,52 @@ public class ChefMenuService { @Autowired CuisineCategoriesRepository cuisineCategoriesRepository; - public ChefMenu saveChefMenu(ChefMenuRequest chefMenuRequest) throws Exception{ + + + public void saveChefMenu(MultipartFile file, Long login_id,MenuCategories menucategories,int cuisine_id, + String item_name,double menu_item_price,String item_ingredients, + String item_intresting_facts,Week week + ) throws Exception + { + ChefMenu chefMenu =new ChefMenu(); + Optional userData = userCredentialsRepository.findById(login_id); + if(!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + Optional cuisineCategory = cuisineCategoriesRepository.findById(cuisine_id); + // Long loginId = userData.get().getId(); + if(cuisineCategory == null) + throw new Exception("cuisine category doesn't exist"); + + + + + /*Long loginId = userData.get().getId(); + + chefMenu.setLogin_id(loginId);*/ + String fileName = StringUtils.cleanPath(file.getOriginalFilename()); + if(fileName.contains("..")) + { + System.out.println("not a a valid file"); + } + try { + chefMenu.setMenu_item_image(Base64.getEncoder().encodeToString(file.getBytes())); + } catch (IOException e) { + e.printStackTrace(); + } + chefMenu.setLogin_id(login_id); + chefMenu.setMenucategories(menucategories); + + chefMenu.setMenu_item_price(menu_item_price); + chefMenu.setItem_name(item_name); + chefMenu.setItem_intresting_facts(item_intresting_facts); + chefMenu.setItem_ingredients(item_ingredients); + chefMenu.setCuisineCategory(cuisineCategory.get()); + chefMenu.setWeek(week); + + chefMenuRepository.save(chefMenu); + } + /*public ChefMenu saveChefMenu(ChefMenuRequest chefMenuRequest) throws Exception{ + Optional userData = userCredentialsRepository.findById(chefMenuRequest.getLogin_id()); if(!userData.isPresent()) throw new Exception("user Id doesn't exist"); @@ -46,7 +90,7 @@ public ChefMenu saveChefMenu(ChefMenuRequest chefMenuRequest) throws Exception{ chefMenuRequest.setLogin_id(chefMenuRequest.getLogin_id()); return chefMenuRepository.save(chefMenu); - } + }*/ public List saveChefMenus(List chefMenus){ return chefMenuRepository.saveAll(chefMenus); } @@ -55,8 +99,24 @@ public List getChefMenus() { return chefMenuRepository.findAll(); } - public ChefMenu getChefMenuById(int chefMenu_id){ - return chefMenuRepository.findById(chefMenu_id).orElse(null); + public ChefMenuGETResponse getChefMenuById(int id) + { + ChefMenu chefMenu = chefMenuRepository.findById(id).get(); + + ChefMenuGETResponse chefMenuGETResponse = ChefMenuGETResponse.builder() + .cuisine_id(chefMenu.getCuisineCategory().getId()) + .login_id(chefMenu.getLogin_id()) + .menucategories(chefMenu.getMenucategories()) + .item_name(chefMenu.getItem_name()) + .menu_item_image(chefMenu.getMenu_item_image()) + .menu_item_price(chefMenu.getMenu_item_price()) + .item_ingredients(chefMenu.getItem_ingredients()) + .item_intresting_facts(chefMenu.getItem_intresting_facts()) + .week(chefMenu.getWeek()) + .build(); + return chefMenuGETResponse; + + } public String deleteChefMenu(int chefMenu_id) diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupRequest.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupRequest.java index fee2fb1..f34e9eb 100644 --- a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupRequest.java +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupRequest.java @@ -12,7 +12,7 @@ @ToString public class CustSignupRequest { - private final String firstName; + //private final String firstName; /* private final String lastName;*/ private final String email; private final String password; diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java index 7412095..cad7ff4 100644 --- a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java @@ -45,7 +45,7 @@ public String register(CustSignupRequest request) { String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; emailSender.send( request.getEmail(), - emailService.buildEmail(request.getFirstName(), link)); + emailService.buildEmail("user", link)); return token; } From 3ffd0bfd70aa6f76f0c7f2ed38c76b38ddb3e4d3 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 3 Apr 2022 16:59:34 -0400 Subject: [PATCH 16/69] working working --- .../ChefCreateMenu/ChefMenuController.java | 13 --------- .../ChefCreateMenu/ChefMenuService.java | 28 ------------------- 2 files changed, 41 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java index 43c5fdb..03b6b85 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java @@ -32,19 +32,6 @@ public String addChefMenu(@RequestParam("file") MultipartFile file, item_name,menu_item_price,item_ingredients,item_intresting_facts,week); return "chef details added"; } - /* public ResponseEntity addChefMenu(@RequestBody ChefMenuRequest chefMenuRequest) throws Exception - { - - //chefMenuService.saveChefMenu(ch); - chefMenuService.saveChefMenu(chefMenuRequest); - - return new ResponseEntity<>("menu item saved successfully", HttpStatus.OK); - }*/ - /* @PostMapping("/chefs") - public List addChefs(@RequestBody List chefs) - { - return chefProfileService.saveChefs(chefs); - }*/ @GetMapping({"/chefmenuById/{id}"}) public ChefMenuGETResponse findChefMenuById(@PathVariable int id) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index b470ebb..6b17cbe 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -40,12 +40,6 @@ public void saveChefMenu(MultipartFile file, Long login_id,MenuCategories menuc if(cuisineCategory == null) throw new Exception("cuisine category doesn't exist"); - - - - /*Long loginId = userData.get().getId(); - - chefMenu.setLogin_id(loginId);*/ String fileName = StringUtils.cleanPath(file.getOriginalFilename()); if(fileName.contains("..")) { @@ -68,29 +62,7 @@ public void saveChefMenu(MultipartFile file, Long login_id,MenuCategories menuc chefMenuRepository.save(chefMenu); } - /*public ChefMenu saveChefMenu(ChefMenuRequest chefMenuRequest) throws Exception{ - Optional userData = userCredentialsRepository.findById(chefMenuRequest.getLogin_id()); - if(!userData.isPresent()) - throw new Exception("user Id doesn't exist"); - CuisineCategory cuisineCategory = cuisineCategoriesRepository.findById(chefMenuRequest.getCuisine_id()).get(); - // Long loginId = userData.get().getId(); - if(cuisineCategory == null) - throw new Exception("cuisine category doesn't exist"); - ChefMenu chefMenu = new ChefMenu(); - chefMenu.setLogin_id(chefMenuRequest.getLogin_id()); - chefMenu.setMenucategories(chefMenuRequest.getMenucategories()); - chefMenu.setMenu_item_image(chefMenuRequest.getMenu_item_image()); - chefMenu.setMenu_item_price(chefMenuRequest.getMenu_item_price()); - chefMenu.setItem_name(chefMenuRequest.getItem_name()); - chefMenu.setItem_intresting_facts(chefMenuRequest.getItem_intresting_facts()); - chefMenu.setItem_ingredients(chefMenuRequest.getItem_ingredients()); - chefMenu.setCuisineCategory(cuisineCategory); - chefMenu.setWeek(chefMenuRequest.getWeek()); - - chefMenuRequest.setLogin_id(chefMenuRequest.getLogin_id()); - return chefMenuRepository.save(chefMenu); - }*/ public List saveChefMenus(List chefMenus){ return chefMenuRepository.saveAll(chefMenus); } From bf8288611e4bc6699139dc103fc2358bc825221a Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 4 Apr 2022 15:38:44 -0400 Subject: [PATCH 17/69] working working --- .../ChefSignup/ChefSignupController.java | 12 ++++++------ .../ChefSignup/ChefSignupService.java | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java index 9901b93..b43ccec 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java @@ -3,20 +3,20 @@ import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; -@CrossOrigin(origins = "http://localhost:4200") +@CrossOrigin() @RestController -@RequestMapping(path = "api/v1/registration") +//@RequestMapping(path = "api/v1/registration") @AllArgsConstructor public class ChefSignupController { private final ChefSignupService registrationService; - @PostMapping - public String register(@RequestBody ChefSignupRequest request) { - return registrationService.register(request); + @PostMapping("api/v1/registration") + public void register(@RequestBody ChefSignupRequest request) { + registrationService.register(request); } - @GetMapping(path = "confirm") + @GetMapping("api/v1/registration/confirm") public String confirm(@RequestParam("token") String token) { return registrationService.confirmToken(token); } diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index cadb3b1..d8dc97c 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -23,7 +23,7 @@ public class ChefSignupService { private final EmailSender emailSender; private EmailService emailService; - public String register(ChefSignupRequest request) { + public void register(ChefSignupRequest request) { boolean isValidEmail = emailValidator. test(request.getEmail()); @@ -46,7 +46,7 @@ public String register(ChefSignupRequest request) { request.getEmail(), emailService.buildEmail("user", link)); - return token; + //return token; } @Transactional From d77179abd86feca732a0a435045aa00ce1c798bd Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 4 Apr 2022 15:45:52 -0400 Subject: [PATCH 18/69] crossorgins added to all controllers crossorigins working --- .../ChefCreateMenu/ChefMenuController.java | 2 +- .../ChefDetails/ChefController.java | 2 +- .../ethniconnect_backend/ContactPage/Contact.java | 1 + .../ContactPage/ContactController.java | 2 +- .../Cuisines/CuisineCategoriesController.java | 1 + .../CustomerDetails/CustomerController.java | 2 ++ .../CustomerSignup/CustSignupController.java | 12 ++++++------ .../CustomerSignup/CustSignupService.java | 4 ++-- .../ethniconnect_backend/Login/LoginController.java | 3 ++- .../Resetpassword/ResetPasswordController.java | 2 +- 10 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java index 03b6b85..2c71fc0 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java @@ -7,7 +7,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; - +@CrossOrigin() @RestController public class ChefMenuController { diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java index cc8add6..0189917 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java @@ -5,7 +5,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; - +@CrossOrigin() @RestController public class ChefController { @Autowired diff --git a/src/main/java/ethniconnect_backend/ContactPage/Contact.java b/src/main/java/ethniconnect_backend/ContactPage/Contact.java index 392dfad..34d396b 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/Contact.java +++ b/src/main/java/ethniconnect_backend/ContactPage/Contact.java @@ -19,6 +19,7 @@ public class Contact { @GeneratedValue private int id; private String name; + private String emailid; private String message; } diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java index 4cdf705..8cdbdce 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java @@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; - +@CrossOrigin() @RestController public class ContactController { @Autowired diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java index c79c97f..3b6b772 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java @@ -5,6 +5,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; +@CrossOrigin() @RestController public class CuisineCategoriesController { diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java index fc55cfd..5ecc3f9 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java @@ -5,6 +5,8 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +@CrossOrigin() + @RestController public class CustomerController { diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java index 975b13b..3803cb4 100644 --- a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java @@ -7,20 +7,20 @@ - +@CrossOrigin() @RestController -@RequestMapping(path = "api/v1/CustSignup") +//@RequestMapping @AllArgsConstructor public class CustSignupController { private final CustSignupService custSignupService; - @PostMapping - public String register(@RequestBody CustSignupRequest request) { - return custSignupService.register(request); + @PostMapping("api/v1/CustSignup") + public void register(@RequestBody CustSignupRequest request) { + custSignupService.register(request); } - @GetMapping(path = "confirm") + @GetMapping("api/v1/CustSignup/confirm") public String confirm(@RequestParam("token") String token) { return custSignupService.confirmToken(token); } diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java index cad7ff4..9c3a045 100644 --- a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java @@ -24,7 +24,7 @@ public class CustSignupService { private final EmailSender emailSender; private EmailService emailService; - public String register(CustSignupRequest request) { + public void register(CustSignupRequest request) { boolean isValidEmail = emailValidator. test(request.getEmail()); @@ -47,7 +47,7 @@ public String register(CustSignupRequest request) { request.getEmail(), emailService.buildEmail("user", link)); - return token; + //return token; } @Transactional diff --git a/src/main/java/ethniconnect_backend/Login/LoginController.java b/src/main/java/ethniconnect_backend/Login/LoginController.java index 43fb8ff..0189c28 100644 --- a/src/main/java/ethniconnect_backend/Login/LoginController.java +++ b/src/main/java/ethniconnect_backend/Login/LoginController.java @@ -6,10 +6,11 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; - +@CrossOrigin() @RestController public class LoginController { diff --git a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java index 4b9c421..693a0ce 100644 --- a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java @@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.view.RedirectView; - +@CrossOrigin() @RestController @RequestMapping(path = "api/v1") @AllArgsConstructor From 8eaa92c5a118f75455aefa1846b221d88eddac4a Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 4 Apr 2022 18:26:42 -0400 Subject: [PATCH 19/69] working code working --- .../ContactPage/ContactController.java | 5 +- .../ContactPage/ContactEmailValidator.java | 14 ++++ .../ContactPage/ContactService.java | 41 ++++++++++- .../email/EmailService.java | 70 +++++++++++++++++++ 4 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ethniconnect_backend/ContactPage/ContactEmailValidator.java diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java index 8cdbdce..c22bbb2 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java @@ -11,10 +11,11 @@ public class ContactController { private ContactService contactService; @PostMapping("/ContactRequest") - public Contact addcontactrequest(@RequestBody Contact contact) + public String addcontactrequest(@RequestBody Contact contact) { - return contactService.saveContact(contact); + contactService.saveContactRequest(contact); + return "request added"; } @GetMapping({"/ContactRequests"}) diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactEmailValidator.java b/src/main/java/ethniconnect_backend/ContactPage/ContactEmailValidator.java new file mode 100644 index 0000000..c250901 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactEmailValidator.java @@ -0,0 +1,14 @@ +package ethniconnect_backend.ContactPage; + +import org.springframework.stereotype.Service; + +import java.util.function.Predicate; + +@Service +public class ContactEmailValidator implements Predicate { + @Override + public boolean test(String s) { +// TODO: Regex to validate email + return true; + } +} diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java index e8ab6c8..cf89a56 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java @@ -1,19 +1,58 @@ package ethniconnect_backend.ContactPage; +import ethniconnect_backend.ChefSignup.ChefSignupRequest; +import ethniconnect_backend.ChefSignup.EmailValidator; +import ethniconnect_backend.ChefSignup.token.ConfirmationTokenService; +import ethniconnect_backend.UserCredentials.UserCredentials; +import ethniconnect_backend.UserCredentials.UserCredentialsService; +import ethniconnect_backend.UserCredentials.UserRole; + +import ethniconnect_backend.email.EmailSender; +import ethniconnect_backend.email.EmailService; +import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @Service +@AllArgsConstructor public class ContactService { + private final UserCredentialsService userCredentialsService; + private final EmailValidator emailValidator; + private final ConfirmationTokenService confirmationTokenService; + private final EmailSender emailSender; + private EmailService emailService; + @Autowired public ContactRepository contactRepository; - public Contact saveContact(Contact contact) + + /* public Contact saveContact(Contact contact) { return contactRepository.save(contact); + }*/ + + + public void saveContactRequest(Contact contact) { + boolean isValidEmail = emailValidator. + test(contact.getEmailid()); + + if (!isValidEmail) { + throw new IllegalStateException("email not valid"); + } + + + /*String link = "www.google.com";*/ + + emailSender.send( + "ethniconnect@gmail.com", + emailService.buildContactEmail(contact.getMessage(),contact.getEmailid())); + contactRepository.save(contact); + + //return token; } + public List getContactRequets() { return contactRepository.findAll(); diff --git a/src/main/java/ethniconnect_backend/email/EmailService.java b/src/main/java/ethniconnect_backend/email/EmailService.java index deaf969..25da61b 100644 --- a/src/main/java/ethniconnect_backend/email/EmailService.java +++ b/src/main/java/ethniconnect_backend/email/EmailService.java @@ -19,6 +19,76 @@ public class EmailService implements EmailSender{ .getLogger(EmailService.class); private final JavaMailSender mailSender; + public String buildContactEmail(String message,String useremailid) { + return "
\n" + + "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " Contact Request from User\n" + + "
\n" + + " \n" + + "
\n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + "
\n" + + "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "


\n" + + " \n" + + "

Hi Admin,

You received an contact request from "+useremailid+"

\n

Message : "+message+"

" + + " \n" + + + " \n" + + "


\n" + + "\n" + + "
"; + } public String buildEmail(String name, String link) { return "
\n" + From ac2ce51cae2c603b487f02ca9047a927b91a0a8f Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 4 Apr 2022 19:12:33 -0400 Subject: [PATCH 20/69] contact FE working working --- .../ContactPage/ContactController.java | 12 +++++++++--- .../ContactPage/ContactService.java | 13 +++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java index c22bbb2..a12e011 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java @@ -2,6 +2,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @CrossOrigin() @@ -9,13 +10,18 @@ public class ContactController { @Autowired private ContactService contactService; + @Autowired + private ContactRepository contactRepository; @PostMapping("/ContactRequest") - public String addcontactrequest(@RequestBody Contact contact) + public void addcontactrequest(@RequestParam("name") String name, + @RequestParam("email") String email, + @RequestParam("message") String message + ) { + contactService.saveContactRequest(name,email,message); - contactService.saveContactRequest(contact); - return "request added"; + //return "request added"; } @GetMapping({"/ContactRequests"}) diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java index cf89a56..a8c092f 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java @@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.xml.transform.sax.SAXTransformerFactory; import java.util.List; @Service @@ -33,9 +34,9 @@ public class ContactService { }*/ - public void saveContactRequest(Contact contact) { + public void saveContactRequest(String email, String name, String message) { boolean isValidEmail = emailValidator. - test(contact.getEmailid()); + test(email); if (!isValidEmail) { throw new IllegalStateException("email not valid"); @@ -43,10 +44,14 @@ public void saveContactRequest(Contact contact) { /*String link = "www.google.com";*/ - + Contact contact = new Contact(); + contact.setEmailid(email); + contact.setMessage(message); + contact.setName(name); + contactRepository.save(contact); emailSender.send( "ethniconnect@gmail.com", - emailService.buildContactEmail(contact.getMessage(),contact.getEmailid())); + emailService.buildContactEmail(message,email)); contactRepository.save(contact); //return token; From ad2c339a52ebaceabb5369a8e0f52b3cbca11b4b Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 4 Apr 2022 19:57:19 -0400 Subject: [PATCH 21/69] chef signup FE working --- .../ChefSignup/ChefSignupController.java | 7 +++++-- .../ChefSignup/ChefSignupService.java | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java index b43ccec..9a3798a 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java @@ -2,6 +2,7 @@ import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; @CrossOrigin() @RestController @@ -12,8 +13,10 @@ public class ChefSignupController { private final ChefSignupService registrationService; @PostMapping("api/v1/registration") - public void register(@RequestBody ChefSignupRequest request) { - registrationService.register(request); + public void register( @RequestParam("email") String email, + @RequestParam("password") String password) + { + registrationService.register(email,password); } @GetMapping("api/v1/registration/confirm") diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index d8dc97c..2214caa 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -23,9 +23,9 @@ public class ChefSignupService { private final EmailSender emailSender; private EmailService emailService; - public void register(ChefSignupRequest request) { + public void register(String email, String password) { boolean isValidEmail = emailValidator. - test(request.getEmail()); + test(email); if (!isValidEmail) { throw new IllegalStateException("email not valid"); @@ -33,8 +33,8 @@ public void register(ChefSignupRequest request) { String token = userCredentialsService.signUpUser( new UserCredentials( - request.getEmail(), - request.getPassword(), + email, + password, UserRole.BUSINESS ) @@ -43,7 +43,7 @@ public void register(ChefSignupRequest request) { /*String link = "www.google.com";*/ String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; emailSender.send( - request.getEmail(), + email, emailService.buildEmail("user", link)); //return token; From cd634872b83d4b81ff08102b5f6e3b63feb68481 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Tue, 5 Apr 2022 09:38:43 -0400 Subject: [PATCH 22/69] personal singup FE working working --- .../CustomerSignup/CustSignupController.java | 5 +++-- .../CustomerSignup/CustSignupService.java | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java index 3803cb4..b82f3e5 100644 --- a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupController.java @@ -16,8 +16,9 @@ public class CustSignupController { private final CustSignupService custSignupService; @PostMapping("api/v1/CustSignup") - public void register(@RequestBody CustSignupRequest request) { - custSignupService.register(request); + public void register(@RequestParam("email") String email, + @RequestParam("password") String password) { + custSignupService.register(email,password); } @GetMapping("api/v1/CustSignup/confirm") diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java index 9c3a045..3788322 100644 --- a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java @@ -24,9 +24,9 @@ public class CustSignupService { private final EmailSender emailSender; private EmailService emailService; - public void register(CustSignupRequest request) { + public void register(String email, String password) { boolean isValidEmail = emailValidator. - test(request.getEmail()); + test(email); if (!isValidEmail) { throw new IllegalStateException("email not valid"); @@ -34,8 +34,8 @@ public void register(CustSignupRequest request) { String token = appUserService.signUpUser( new UserCredentials( - request.getEmail(), - request.getPassword(), + email, + password, UserRole.PERSONAL ) @@ -44,7 +44,7 @@ public void register(CustSignupRequest request) { /*String link = "www.google.com";*/ String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; emailSender.send( - request.getEmail(), + email, emailService.buildEmail("user", link)); //return token; From f668f0361b3741b6805ac958590265db334fdb2e Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Wed, 6 Apr 2022 11:13:16 -0400 Subject: [PATCH 23/69] saranya changes added but commented out working --- .../ChefCreateMenu/ChefMenuController.java | 11 +++++++++++ .../ChefCreateMenu/ChefMenuService.java | 11 +++++++++++ .../ethniconnect_backend/ChefDetails/ChefService.java | 1 + 3 files changed, 23 insertions(+) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java index 2c71fc0..1708ce2 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java @@ -45,5 +45,16 @@ public ChefMenu updateChefMenu(@RequestBody ChefMenu chefMenu) return chefMenuService.updateChefMenu(chefMenu); } } +/* @GetMapping({"/chefByCuisineId/{cuisineId}"}) + public List getChefByCuisineId(@PathVariable String cuisineId) + { + return chefProfileService.getChefByCuisineId(cuisineId); + } + + @GetMapping({"/getCuisinesByZipCode/{zipCode}"}) + public List getCuisinesByZipCode(@PathVariable String zipCode) + { + return chefProfileService.getCuisinesByZipCode(zipCode); + }*/ diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 6b17cbe..1f81bd9 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -110,6 +110,17 @@ public ChefMenu updateChefMenu(ChefMenu chefMenu) return chefMenuRepository.save(existingChefMenu); } +/*public List getChefByCuisineId(String cuisine_id){ + return chefRepository.getChefsByPrefCuisine(Integer.getInteger(cuisine_id)); + } + public List getCuisinesByZipCode(String zipCode){ + CuisineCategory cuisineCategory= new CuisineCategory(); + List chefs = chefRepository.getChefsByZip(zipCode); + Set cuisineId = chefs.stream().map(Chef::getPrefCuisine).distinct().collect(Collectors.toSet()); + List cuisineCategories = cuisineCategoriesRepository.findAllById(cuisineId); + return cuisineCategories; + } +*/ } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java index c1bc78a..81a8e9c 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java @@ -114,4 +114,5 @@ public Chef updateChef(Chef chef) + } From 34b4cf36ff52d41e3645fa823a7faff968eeef23 Mon Sep 17 00:00:00 2001 From: Saranya1994 Date: Wed, 6 Apr 2022 15:52:44 -0400 Subject: [PATCH 24/69] Update application.yml application properties changes --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6c6f0ce..2a130ce 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,7 +10,7 @@ server: spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - password: bharani16 + password: Saranya1994 initialization-mode: ALWAYS url: jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect From 8e2c206284aa7392ba1cbdf01065f6e6c6ab4077 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Thu, 7 Apr 2022 10:55:28 -0400 Subject: [PATCH 25/69] working working --- .../ChefCreateMenu/ChefMenuRepository.java | 1 + .../ChefCreateMenu/ChefMenuService.java | 20 +++++++++++-------- .../ChefDetails/ChefRepository.java | 4 +++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java index 3556fed..854553c 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java @@ -8,4 +8,5 @@ public interface ChefMenuRepository extends JpaRepository { //Optional findById(Integer id); + ChefMenu findByLogin_id(long chef_login_Id); } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 1f81bd9..8709ff5 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -1,5 +1,7 @@ package ethniconnect_backend.ChefCreateMenu; +import ethniconnect_backend.ChefDetails.Chef; +import ethniconnect_backend.ChefDetails.ChefRepository; import ethniconnect_backend.Cuisines.CuisineCategoriesRepository; import ethniconnect_backend.Cuisines.CuisineCategory; import ethniconnect_backend.UserCredentials.UserCredentials; @@ -13,6 +15,8 @@ import java.util.Base64; import java.util.List; import java.util.Optional; +import java.util.Set; + @Service public class ChefMenuService { @@ -23,7 +27,8 @@ public class ChefMenuService { @Autowired CuisineCategoriesRepository cuisineCategoriesRepository; - + @Autowired + private ChefRepository chefRepository; public void saveChefMenu(MultipartFile file, Long login_id,MenuCategories menucategories,int cuisine_id, @@ -110,17 +115,16 @@ public ChefMenu updateChefMenu(ChefMenu chefMenu) return chefMenuRepository.save(existingChefMenu); } -/*public List getChefByCuisineId(String cuisine_id){ - - return chefRepository.getChefsByPrefCuisine(Integer.getInteger(cuisine_id)); - } - public List getCuisinesByZipCode(String zipCode){ +// public List getChefByCuisineId(String cuisine_id){ +// +// return chefRepository.getChefsByPrefCuisine(Integer.getInteger(cuisine_id)); +// } + public List getCuisineCategoriesByZipCode(String zipCode){ CuisineCategory cuisineCategory= new CuisineCategory(); List chefs = chefRepository.getChefsByZip(zipCode); - Set cuisineId = chefs.stream().map(Chef::getPrefCuisine).distinct().collect(Collectors.toSet()); + Set categorieId = chefs.stream().map((chef)->chefMenuRepository.findByLogin_id(chef.getLogin_id())).map((chefMenu)->chefMenu.getCuisineCategory()).map((cuisineCategory)->cuisineCategory.getCuisine_name()).distinct().collect(Collectors.toSet()); List cuisineCategories = cuisineCategoriesRepository.findAllById(cuisineId); return cuisineCategories; } -*/ } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java index 9208737..73c5407 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java @@ -7,7 +7,9 @@ public interface ChefRepository extends JpaRepository { -/* *//*@Query("SELECT new ethniconnect_backend.ChefDetails.ChefprofileResponse( c.chef_fname, m.menu_item_price)" + + List getChefsByZip(String zipCode); + + /* *//*@Query("SELECT new ethniconnect_backend.ChefDetails.ChefprofileResponse( c.chef_fname, m.menu_item_price)" + " FROM Chef c join c.ChefMenu m")*//* public List getChefProfileInfo();*/ From 98a0b49b7f415be89ccfb0d6fc516f82f79ae462 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Thu, 7 Apr 2022 13:55:02 -0400 Subject: [PATCH 26/69] login, update chef working working --- .../ChefCreateMenu/ChefMenuService.java | 1 + .../ChefDetails/ChefRepository.java | 4 ++- .../ChefDetails/ChefService.java | 30 ++++++++-------- .../ChefSignup/ChefSignupService.java | 2 ++ .../Cuisines/CuisineCategory.java | 2 ++ .../Login/LoginController.java | 10 ++++-- .../UserCredentialsService.java | 36 +++++++++++++------ src/main/resources/application.yml | 2 +- 8 files changed, 58 insertions(+), 29 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 1f81bd9..e676c1b 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -109,6 +109,7 @@ public ChefMenu updateChefMenu(ChefMenu chefMenu) existingChefMenu.getCuisineCategory().setId(chefMenu.getCuisineCategory().getId()); return chefMenuRepository.save(existingChefMenu); + } /*public List getChefByCuisineId(String cuisine_id){ diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java index 9208737..d23be44 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java @@ -4,10 +4,12 @@ import org.springframework.data.jpa.repository.Query; import java.util.List; +import java.util.Optional; public interface ChefRepository extends JpaRepository { + //Optional findByLogin_Id(long login_id); -/* *//*@Query("SELECT new ethniconnect_backend.ChefDetails.ChefprofileResponse( c.chef_fname, m.menu_item_price)" + + /* *//*@Query("SELECT new ethniconnect_backend.ChefDetails.ChefprofileResponse( c.chef_fname, m.menu_item_price)" + " FROM Chef c join c.ChefMenu m")*//* public List getChefProfileInfo();*/ diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java index 81a8e9c..8557364 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java @@ -93,21 +93,21 @@ public String deleteChef(int chef_id) } public Chef updateChef(Chef chef) { - Chef existingChef= chefRepository.findById(chef.getChef_id()).orElse(null); - existingChef.setChef_fname(chef.getChef_fname()); - existingChef.setChef_lname(chef.getChef_lname()); - existingChef.setChef_phone(chef.getChef_phone()); - existingChef.setChef_city(chef.getChef_city()); - existingChef.setChef_description(chef.getChef_description()); - existingChef.setChef_fblink(chef.getChef_fblink()); - existingChef.setChef_linkdin(chef.getChef_linkdin()); - existingChef.setChef_image(chef.getChef_image()); - existingChef.setChef_paymode(chef.getChef_paymode()); - existingChef.setChef_state(chef.getChef_state()); - existingChef.setChef_street(chef.getChef_street()); - existingChef.setChef_zip(chef.getChef_zip()); - existingChef.setChef_city(chef.getChef_city()); - existingChef.setChef_experience(chef.getChef_experience()); + Chef existingChef= (Chef) chefRepository.findById(chef.getChef_id()).orElse(null); + existingChef.setChef_fname(chef.getChef_fname()!=null?chef.getChef_fname():existingChef.getChef_fname()); + existingChef.setChef_lname(chef.getChef_lname()!=null?chef.getChef_lname():existingChef.getChef_lname()); + existingChef.setChef_phone(chef.getChef_phone()!=null?chef.getChef_phone():existingChef.getChef_phone()); + existingChef.setChef_city(chef.getChef_city()!=null?chef.getChef_city():existingChef.getChef_city()); + existingChef.setChef_description(chef.getChef_description()!=null?chef.getChef_description():existingChef.getChef_description()); + existingChef.setChef_fblink(chef.getChef_fblink()!=null?chef.getChef_fblink():existingChef.getChef_fblink()); + existingChef.setChef_linkdin(chef.getChef_linkdin()!=null?chef.getChef_linkdin():existingChef.getChef_linkdin()); + existingChef.setChef_image(chef.getChef_image()!=null?chef.getChef_image():existingChef.getChef_image()); + existingChef.setChef_paymode(chef.getChef_paymode()!=null?chef.getChef_paymode():existingChef.getChef_paymode()); + existingChef.setChef_state(chef.getChef_state()!=null?chef.getChef_state():existingChef.getChef_state()); + existingChef.setChef_street(chef.getChef_street()!=null?chef.getChef_street():existingChef.getChef_street()); + existingChef.setChef_zip(chef.getChef_zip()!=null?chef.getChef_zip():existingChef.getChef_zip()); + existingChef.setChef_city(chef.getChef_city()!=null?chef.getChef_city():existingChef.getChef_city()); + existingChef.setChef_experience(chef.getChef_experience()!=0?chef.getChef_experience():existingChef.getChef_experience()); return chefRepository.save(existingChef); } diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index 2214caa..22072a3 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -31,6 +31,8 @@ public void register(String email, String password) { throw new IllegalStateException("email not valid"); } + + String token = userCredentialsService.signUpUser( new UserCredentials( email, diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java index e4c5e0d..007a8a1 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java @@ -16,10 +16,12 @@ @Entity @Table(name = "cuisinecategory") + public class CuisineCategory { @Id @GeneratedValue private int id; + @Column(unique = true) private String cuisine_name; private String cuisine_image; diff --git a/src/main/java/ethniconnect_backend/Login/LoginController.java b/src/main/java/ethniconnect_backend/Login/LoginController.java index 0189c28..e4059f5 100644 --- a/src/main/java/ethniconnect_backend/Login/LoginController.java +++ b/src/main/java/ethniconnect_backend/Login/LoginController.java @@ -24,11 +24,13 @@ public class LoginController @PostMapping("/signin") - public ResponseEntity authenticateUser(@RequestBody UserCredentials userCredentials){ + public ResponseEntity authenticateUser(@RequestBody UserCredentials userCredentials) + { UserCredentials userCredentialsFromDB = userCredentialsRepository.findByEmail(userCredentials.getEmail()).get(); LoginResponse loginResponse = new LoginResponse(); if(userCredentials.getEmail().equals(userCredentialsFromDB.getEmail()) - && bCryptPasswordEncoder.matches(userCredentials.getPassword(),userCredentialsFromDB.getPassword())) + && bCryptPasswordEncoder.matches(userCredentials.getPassword(),userCredentialsFromDB.getPassword()) + && (userCredentialsFromDB.getEnabled().booleanValue() || userCredentialsFromDB.getEnabled() == true)) { //return new ResponseEntity<>("User signed-in successfully!.", HttpStatus.OK); @@ -36,6 +38,10 @@ public ResponseEntity authenticateUser(@RequestBody UserCredentia return new ResponseEntity<>(loginResponse, HttpStatus.OK); } loginResponse.setErrormessage("User credentials are wrong"); + if(!(userCredentialsFromDB.getEnabled().booleanValue() || userCredentialsFromDB.getEnabled() == true)) + { + loginResponse.setErrormessage("Account not activated"); + } //SecurityContextHolder.getContext().setAuthentication(authentication); return new ResponseEntity<>(loginResponse, HttpStatus.UNAUTHORIZED); } diff --git a/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsService.java b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsService.java index 4726492..e621047 100644 --- a/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsService.java +++ b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsService.java @@ -11,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional; import java.time.LocalDateTime; +import java.util.Optional; import java.util.UUID; @Transactional @Service @@ -40,26 +41,41 @@ public UserDetails loadUserByUsername(String email) String.format(USER_NOT_FOUND_MSG, email))); } - public String signUpUser(UserCredentials appUser) { + public String signUpUser(UserCredentials inputUser) { + + Optional existingUserCredentials = appUserRepository.findByEmail(inputUser.getEmail()); boolean userExists = appUserRepository - .findByEmail(appUser.getEmail()) + .findByEmail(inputUser.getEmail()) .isPresent(); - if (userExists) { + if (existingUserCredentials.isPresent() ) { // TODO check of attributes are the same and // TODO if email not confirmed send confirmation email. - - throw new IllegalStateException("email already taken"); + if(existingUserCredentials.get().isEnabled()) + { + throw new IllegalStateException("email already taken"); + } + } + else + { + existingUserCredentials= Optional.of(inputUser); } - String encodedPassword = bCryptPasswordEncoder - .encode(appUser.getPassword()); - appUser.setPassword(encodedPassword); + String encodedPassword = bCryptPasswordEncoder + .encode(inputUser.getPassword()); + + if(!existingUserCredentials.isPresent()) + { + + } + existingUserCredentials.get().setPassword(encodedPassword); + existingUserCredentials.get().setEmail(inputUser.getEmail()); + - appUserRepository.save(appUser); + appUserRepository.save(existingUserCredentials.get()); - String token = getToken(appUser); + String token = getToken(existingUserCredentials.get()); // TODO: SEND EMAIL diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6c6f0ce..aa4e801 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,7 +17,7 @@ spring: username: root jpa: hibernate: - ddl-auto: update + ddl-auto: create-drop properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect From 9f447f976e5433301d9f56e36f9a12f9b6af1da3 Mon Sep 17 00:00:00 2001 From: Saranya1994 Date: Thu, 7 Apr 2022 14:43:01 -0400 Subject: [PATCH 27/69] CuisineCategory and Zip Zip working CuisineCategory check --- .../ChefCreateMenu/ChefMenuController.java | 5 +++- .../Cuisines/CuisineCategoriesController.java | 6 +++++ .../Cuisines/CuisineCategoriesRepository.java | 3 +++ .../Cuisines/CuisineCategory.java | 3 +++ .../Cuisines/CuisinesCategoriesService.java | 4 +++ .../java/ethniconnect_backend/Zip/Zip.java | 25 +++++++++++++++++++ .../Zip/ZipController.java | 16 ++++++++++++ .../Zip/ZipRepository.java | 8 ++++++ .../ethniconnect_backend/Zip/ZipRequest.java | 4 +++ .../ethniconnect_backend/Zip/ZipService.java | 15 +++++++++++ 10 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ethniconnect_backend/Zip/Zip.java create mode 100644 src/main/java/ethniconnect_backend/Zip/ZipController.java create mode 100644 src/main/java/ethniconnect_backend/Zip/ZipRepository.java create mode 100644 src/main/java/ethniconnect_backend/Zip/ZipRequest.java create mode 100644 src/main/java/ethniconnect_backend/Zip/ZipService.java diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java index 1708ce2..428dd0e 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java @@ -7,6 +7,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; + +import java.util.List; + @CrossOrigin() @RestController public class ChefMenuController { @@ -45,7 +48,7 @@ public ChefMenu updateChefMenu(@RequestBody ChefMenu chefMenu) return chefMenuService.updateChefMenu(chefMenu); } } -/* @GetMapping({"/chefByCuisineId/{cuisineId}"}) + /*@GetMapping({"/chefByCuisineId/{cuisineId}"}) public List getChefByCuisineId(@PathVariable String cuisineId) { return chefProfileService.getChefByCuisineId(cuisineId); diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java index 3b6b772..f8ee9df 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java @@ -32,6 +32,12 @@ public CuisineCategory findcuisinecategoryrequestbyId(@PathVariable int id) return cuisinesCategoriesService.getCuisineCategoryById(id); } + @GetMapping({"/cuisineCategoryByZip/{zip}"}) + public ListcuisineCategoryByZip(@PathVariable int zip) + { + return cuisinesCategoriesService.cuisineCategoryByZip(zip); + } + } diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java index 9a808c6..e10832b 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java @@ -2,5 +2,8 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface CuisineCategoriesRepository extends JpaRepository { + public List getCuisineCategoryByZip_ZipCode(int zipCode); } diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java index e4c5e0d..9dba1dc 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java @@ -1,6 +1,7 @@ package ethniconnect_backend.Cuisines; import ethniconnect_backend.ChefCreateMenu.ChefMenu; +import ethniconnect_backend.Zip.Zip; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -22,6 +23,8 @@ public class CuisineCategory { private int id; private String cuisine_name; private String cuisine_image; + @ManyToOne + private Zip zip; @OneToMany(fetch = FetchType.LAZY, mappedBy = "cuisineCategory") private List menus; diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java b/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java index 29f3718..809f97b 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java @@ -22,6 +22,10 @@ public CuisineCategory getCuisineCategoryById(int id) { return (CuisineCategory) cuisineCategoriesRepository.findById(id).orElse(null); } + public List cuisineCategoryByZip(int zip) + { + return cuisineCategoriesRepository.getCuisineCategoryByZip_ZipCode(zip); + } } diff --git a/src/main/java/ethniconnect_backend/Zip/Zip.java b/src/main/java/ethniconnect_backend/Zip/Zip.java new file mode 100644 index 0000000..a1eae8f --- /dev/null +++ b/src/main/java/ethniconnect_backend/Zip/Zip.java @@ -0,0 +1,25 @@ +package ethniconnect_backend.Zip; + +import ethniconnect_backend.Cuisines.CuisineCategory; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import java.util.Set; + +@Entity +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Zip { + @Id + private int id; + private int zipCode; + @OneToMany + @JoinColumn (name= "zip_id") + Set cuisineCategory; +} diff --git a/src/main/java/ethniconnect_backend/Zip/ZipController.java b/src/main/java/ethniconnect_backend/Zip/ZipController.java new file mode 100644 index 0000000..d6a0a37 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Zip/ZipController.java @@ -0,0 +1,16 @@ +package ethniconnect_backend.Zip; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +public class ZipController { + @Autowired + ZipService zipService; + public List getAllZip(){ + return zipService.getAllZip(); + + } +} diff --git a/src/main/java/ethniconnect_backend/Zip/ZipRepository.java b/src/main/java/ethniconnect_backend/Zip/ZipRepository.java new file mode 100644 index 0000000..120499b --- /dev/null +++ b/src/main/java/ethniconnect_backend/Zip/ZipRepository.java @@ -0,0 +1,8 @@ +package ethniconnect_backend.Zip; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ZipRepository extends JpaRepository { +} diff --git a/src/main/java/ethniconnect_backend/Zip/ZipRequest.java b/src/main/java/ethniconnect_backend/Zip/ZipRequest.java new file mode 100644 index 0000000..f3e1eae --- /dev/null +++ b/src/main/java/ethniconnect_backend/Zip/ZipRequest.java @@ -0,0 +1,4 @@ +package ethniconnect_backend.Zip; + +public class ZipRequest { +} diff --git a/src/main/java/ethniconnect_backend/Zip/ZipService.java b/src/main/java/ethniconnect_backend/Zip/ZipService.java new file mode 100644 index 0000000..ee6563d --- /dev/null +++ b/src/main/java/ethniconnect_backend/Zip/ZipService.java @@ -0,0 +1,15 @@ +package ethniconnect_backend.Zip; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class ZipService { + @Autowired + ZipRepository zipRepository; + public List getAllZip(){ + return zipRepository.findAll(); + } +} From 909a902869091ef59b725ac24d7f4ef678f36824 Mon Sep 17 00:00:00 2001 From: Lal Prasath Date: Thu, 7 Apr 2022 23:02:32 +0100 Subject: [PATCH 28/69] getCuisinebyZip service getCuisinebyZip service --- .../Cuisines/CuisineCategoriesController.java | 6 ------ .../Cuisines/CuisineCategoriesRepository.java | 2 +- .../ethniconnect_backend/Cuisines/CuisineCategory.java | 3 +-- .../Cuisines/CuisinesCategoriesService.java | 4 ---- src/main/java/ethniconnect_backend/Zip/Zip.java | 5 ++--- .../java/ethniconnect_backend/Zip/ZipController.java | 9 +++++++++ .../java/ethniconnect_backend/Zip/ZipRepository.java | 6 ++++++ src/main/java/ethniconnect_backend/Zip/ZipService.java | 4 ++++ src/main/resources/application.yml | 2 +- 9 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java index f8ee9df..3b6b772 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java @@ -32,12 +32,6 @@ public CuisineCategory findcuisinecategoryrequestbyId(@PathVariable int id) return cuisinesCategoriesService.getCuisineCategoryById(id); } - @GetMapping({"/cuisineCategoryByZip/{zip}"}) - public ListcuisineCategoryByZip(@PathVariable int zip) - { - return cuisinesCategoriesService.cuisineCategoryByZip(zip); - } - } diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java index e10832b..cec29c6 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesRepository.java @@ -5,5 +5,5 @@ import java.util.List; public interface CuisineCategoriesRepository extends JpaRepository { - public List getCuisineCategoryByZip_ZipCode(int zipCode); + } diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java index 9dba1dc..124a87a 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java @@ -23,8 +23,7 @@ public class CuisineCategory { private int id; private String cuisine_name; private String cuisine_image; - @ManyToOne - private Zip zip; + @OneToMany(fetch = FetchType.LAZY, mappedBy = "cuisineCategory") private List menus; diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java b/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java index 809f97b..29f3718 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java @@ -22,10 +22,6 @@ public CuisineCategory getCuisineCategoryById(int id) { return (CuisineCategory) cuisineCategoriesRepository.findById(id).orElse(null); } - public List cuisineCategoryByZip(int zip) - { - return cuisineCategoriesRepository.getCuisineCategoryByZip_ZipCode(zip); - } } diff --git a/src/main/java/ethniconnect_backend/Zip/Zip.java b/src/main/java/ethniconnect_backend/Zip/Zip.java index a1eae8f..6b4e252 100644 --- a/src/main/java/ethniconnect_backend/Zip/Zip.java +++ b/src/main/java/ethniconnect_backend/Zip/Zip.java @@ -19,7 +19,6 @@ public class Zip { @Id private int id; private int zipCode; - @OneToMany - @JoinColumn (name= "zip_id") - Set cuisineCategory; + @OneToMany + Set cuisineCategory; } diff --git a/src/main/java/ethniconnect_backend/Zip/ZipController.java b/src/main/java/ethniconnect_backend/Zip/ZipController.java index d6a0a37..f391a2f 100644 --- a/src/main/java/ethniconnect_backend/Zip/ZipController.java +++ b/src/main/java/ethniconnect_backend/Zip/ZipController.java @@ -1,6 +1,8 @@ package ethniconnect_backend.Zip; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import java.util.List; @@ -9,8 +11,15 @@ public class ZipController { @Autowired ZipService zipService; + @GetMapping(path = "/getAllZip/") public List getAllZip(){ return zipService.getAllZip(); } + @GetMapping(path = "/getCuisinesByZip/{zipCode}") + public Zip getCuisinesByZip(@PathVariable int zipCode){ + return zipService.getZipByZipCode(zipCode); + + } + } diff --git a/src/main/java/ethniconnect_backend/Zip/ZipRepository.java b/src/main/java/ethniconnect_backend/Zip/ZipRepository.java index 120499b..a31ed42 100644 --- a/src/main/java/ethniconnect_backend/Zip/ZipRepository.java +++ b/src/main/java/ethniconnect_backend/Zip/ZipRepository.java @@ -1,8 +1,14 @@ package ethniconnect_backend.Zip; +import ethniconnect_backend.Cuisines.CuisineCategory; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Set; + @Repository public interface ZipRepository extends JpaRepository { + +public Zip getZipByZipCode(int zipCode); } diff --git a/src/main/java/ethniconnect_backend/Zip/ZipService.java b/src/main/java/ethniconnect_backend/Zip/ZipService.java index ee6563d..7c59eaa 100644 --- a/src/main/java/ethniconnect_backend/Zip/ZipService.java +++ b/src/main/java/ethniconnect_backend/Zip/ZipService.java @@ -12,4 +12,8 @@ public class ZipService { public List getAllZip(){ return zipRepository.findAll(); } + + public Zip getZipByZipCode(int zipCode){ + return zipRepository.getZipByZipCode(zipCode); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 2a130ce..e189385 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,7 +10,7 @@ server: spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - password: Saranya1994 + password: password initialization-mode: ALWAYS url: jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect From 2dc54d7b90f0e475c5710474ce1e8144566f0a8f Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Thu, 7 Apr 2022 20:41:58 -0400 Subject: [PATCH 29/69] working working --- .../ChefCreateMenu/ChefMenuRepository.java | 2 +- .../ChefCreateMenu/ChefMenuService.java | 4 ++-- .../ChefDetails/Chef.java | 3 +-- .../ChefSignup/ChefSignupController.java | 1 + .../CustomerDetails/Customer.java | 2 +- .../CustomerDetails/CustomerService.java | 20 ++++++++++--------- src/main/resources/application.yml | 2 +- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java index 854553c..fc0f80a 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java @@ -8,5 +8,5 @@ public interface ChefMenuRepository extends JpaRepository { //Optional findById(Integer id); - ChefMenu findByLogin_id(long chef_login_Id); + //ChefMenu findByLogin_id(long chef_login_Id); } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index d7257ba..d0f5a23 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -120,12 +120,12 @@ public ChefMenu updateChefMenu(ChefMenu chefMenu) // // return chefRepository.getChefsByPrefCuisine(Integer.getInteger(cuisine_id)); // } - public List getCuisineCategoriesByZipCode(String zipCode){ + /*public List getCuisineCategoriesByZipCode(String zipCode){ CuisineCategory cuisineCategory= new CuisineCategory(); List chefs = chefRepository.getChefsByZip(zipCode); Set categorieId = chefs.stream().map((chef)->chefMenuRepository.findByLogin_id(chef.getLogin_id())).map((chefMenu)->chefMenu.getCuisineCategory()).map((cuisineCategory)->cuisineCategory.getCuisine_name()).distinct().collect(Collectors.toSet()); List cuisineCategories = cuisineCategoriesRepository.findAllById(cuisineId); return cuisineCategories; } - +*/ } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java index 9881b74..878221f 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java @@ -10,8 +10,7 @@ @NoArgsConstructor @AllArgsConstructor @Entity -@Table(name = "chef") - //(uniqueConstraints={@UniqueConstraint(columnNames = {"chef_emailid"})}) +@Table(name = "chef",uniqueConstraints= {@UniqueConstraint(columnNames = {"chef_emailid","chef_phone"})}) public class Chef { diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java index 9a3798a..2605cf1 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java @@ -17,6 +17,7 @@ public void register( @RequestParam("email") String email, @RequestParam("password") String password) { registrationService.register(email,password); + } @GetMapping("api/v1/registration/confirm") diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java index 54eab73..0596522 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java @@ -14,7 +14,7 @@ @NoArgsConstructor @AllArgsConstructor @Entity -@Table(name = "customer") +@Table(name = "customer",uniqueConstraints= {@UniqueConstraint(columnNames = {"cust_emailid","cust_phone"})}) public class Customer { @Id @GeneratedValue diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java index f7a403a..60e8abe 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java @@ -86,15 +86,17 @@ public String deleteCust(int cust_id) public Customer updateCust(Customer customer) { Customer existingCustomer=customerRepository.findById(customer.getCust_id()).orElse(null); - existingCustomer.setCust_fname(customer.getCust_fname()); - existingCustomer.setCust_lname(customer.getCust_lname()); - existingCustomer.setCust_phone(customer.getCust_phone()); - existingCustomer.setCust_emailid(customer.getCust_emailid()); - existingCustomer.setCust_street(customer.getCust_street()); - existingCustomer.setCust_city(customer.getCust_city()); - existingCustomer.setCust_state(customer.getCust_state()); - existingCustomer.setCust_zip(customer.getCust_zip()); - existingCustomer.setCust_image(customer.getCust_image()); + existingCustomer.setCust_fname(customer.getCust_fname()!=null?customer.getCust_fname():existingCustomer.getCust_fname()); + existingCustomer.setCust_lname(customer.getCust_lname()!=null?customer.getCust_lname():existingCustomer.getCust_lname()); + + existingCustomer.setCust_phone(customer.getCust_phone()!=null?customer.getCust_phone():existingCustomer.getCust_phone()); + existingCustomer.setCust_emailid(customer.getCust_emailid()!=null?customer.getCust_emailid():existingCustomer.getCust_emailid()); + existingCustomer.setCust_street(customer.getCust_street()!=null?customer.getCust_street():existingCustomer.getCust_street()); + existingCustomer.setCust_city(customer.getCust_city()!=null?customer.getCust_city():existingCustomer.getCust_city()); + existingCustomer.setCust_state(customer.getCust_state()!=null?customer.getCust_state():existingCustomer.getCust_state()); + existingCustomer.setCust_zip(customer.getCust_zip()!=null?customer.getCust_zip():existingCustomer.getCust_zip()); + existingCustomer.setCust_image(customer.getCust_image()!=null?customer.getCust_image():existingCustomer.getCust_image()); + return customerRepository.save(existingCustomer); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index aa4e801..6c6f0ce 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,7 +17,7 @@ spring: username: root jpa: hibernate: - ddl-auto: create-drop + ddl-auto: update properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect From 2b640ff549af5a09b6382f05b1d107f04ae097ff Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Thu, 7 Apr 2022 20:45:28 -0400 Subject: [PATCH 30/69] Update application.yml working --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e189385..6c6f0ce 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,7 +10,7 @@ server: spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - password: password + password: bharani16 initialization-mode: ALWAYS url: jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect From 6f450cdb8eb689f3ae7f8a71ac60132b7953cbdc Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 9 Apr 2022 08:23:44 -0400 Subject: [PATCH 31/69] chef details json format working working --- .../ChefDetails/ChefController.java | 34 ++++--- .../ChefDetails/ChefRepository.java | 1 + .../ChefDetails/ChefService.java | 96 ++++++++++++------- 3 files changed, 84 insertions(+), 47 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java index 0189917..67be833 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java @@ -2,9 +2,12 @@ import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.print.attribute.standard.Media; + @CrossOrigin() @RestController public class ChefController { @@ -12,7 +15,8 @@ public class ChefController { private ChefService chefProfileService; @Autowired private ChefRepository chefRepository; - @PostMapping("/chef") + + /*@PostMapping("/chef") public String addchef(@RequestParam("file") MultipartFile file, @RequestParam("chef_fname") String fname, @RequestParam("chef_lname") String lname, @@ -27,11 +31,11 @@ public String addchef(@RequestParam("file") MultipartFile file, @RequestParam("chef_experience") int chef_experience, @RequestParam("chef_fblink") String chef_fblink, @RequestParam("chef_linkdin") String chef_linkdin) throws Exception { - chefProfileService.saveChef(file, fname, lname,emailid,chef_phone,chef_street, - chef_city,chef_state,chef_zip,chef_paymode,chef_description, - chef_experience,chef_fblink,chef_linkdin); + chefProfileService.saveChef(file, fname, lname, emailid, chef_phone, chef_street, + chef_city, chef_state, chef_zip, chef_paymode, chef_description, + chef_experience, chef_fblink, chef_linkdin); return "chef details added"; - } + }*/ /* @PostMapping("/chef") public Chef addChef(@RequestBody Chef chef) throws Exception @@ -40,15 +44,13 @@ public Chef addChef(@RequestBody Chef chef) throws Exception }*/ - @GetMapping({"/chefById/{id}"}) - public Chef findChefById(@PathVariable int id) - { - return chefProfileService.getChefById(id); - } + @GetMapping({"/chefById/{id}"}) + public Chef findChefById(@PathVariable int id) { + return chefProfileService.getChefById(id); + } @PutMapping("/updatechef") - public Chef updateChef(@RequestBody Chef chef) - { + public Chef updateChef(@RequestBody Chef chef) { return chefProfileService.updateChef(chef); } @@ -58,6 +60,14 @@ public List getChefProfileInfo() return chefRepository.getChefProfileInfo(); }*/ + @PostMapping(value = "/chef", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) + public String upload(@RequestPart("chef") String chef, @RequestPart("chef_image") MultipartFile chef_image) throws Exception { + chefProfileService.getJson(chef,chef_image); + return "added"; + + + } + } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java index d23be44..9067359 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java @@ -7,6 +7,7 @@ import java.util.Optional; public interface ChefRepository extends JpaRepository { + //Optional findByLogin_Id(long login_id); /* *//*@Query("SELECT new ethniconnect_backend.ChefDetails.ChefprofileResponse( c.chef_fname, m.menu_item_price)" + diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java index 8557364..f30d935 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java @@ -1,5 +1,6 @@ package ethniconnect_backend.ChefDetails; +import com.fasterxml.jackson.databind.ObjectMapper; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; import ethniconnect_backend.UserCredentials.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; @@ -20,26 +21,22 @@ public class ChefService { @Autowired private UserCredentialsRepository userCredentialsRepository; - public void saveChef(MultipartFile file, String fname,String lname,String emailid, - String chef_phone,String chef_street,String chef_city, - String chef_state,String chef_zip,String chef_paymode, - String chef_description,int chef_experience,String chef_fblink, - String chef_linkdin) throws Exception - { - Chef chef =new Chef(); + public void saveChef(MultipartFile file, String fname, String lname, String emailid, + String chef_phone, String chef_street, String chef_city, + String chef_state, String chef_zip, String chef_paymode, + String chef_description, int chef_experience, String chef_fblink, + String chef_linkdin) throws Exception { + Chef chef = new Chef(); Optional userData = userCredentialsRepository.findByEmail(emailid); - if(!userData.isPresent()) + if (!userData.isPresent()) throw new Exception("user Id doesn't exist"); - - Long loginId = userData.get().getId(); chef.setLogin_id(loginId); String fileName = StringUtils.cleanPath(file.getOriginalFilename()); - if(fileName.contains("..")) - { + if (fileName.contains("..")) { System.out.println("not a a valid file"); } try { @@ -74,45 +71,74 @@ public void saveChef(MultipartFile file, String fname,String lname,String email return chefRepository.save(chef); }*/ - public List saveChefs(List chefs){ + public List saveChefs(List chefs) { return chefRepository.saveAll(chefs); } - public List getChefs() - { + public List getChefs() { return chefRepository.findAll(); } - public Chef getChefById(int chef_id){ + + public Chef getChefById(int chef_id) { return chefRepository.findById(chef_id).orElse(null); } - public String deleteChef(int chef_id) - { + public String deleteChef(int chef_id) { chefRepository.deleteById(chef_id); return "chef removed !!" + chef_id; } - public Chef updateChef(Chef chef) - { - Chef existingChef= (Chef) chefRepository.findById(chef.getChef_id()).orElse(null); - existingChef.setChef_fname(chef.getChef_fname()!=null?chef.getChef_fname():existingChef.getChef_fname()); - existingChef.setChef_lname(chef.getChef_lname()!=null?chef.getChef_lname():existingChef.getChef_lname()); - existingChef.setChef_phone(chef.getChef_phone()!=null?chef.getChef_phone():existingChef.getChef_phone()); - existingChef.setChef_city(chef.getChef_city()!=null?chef.getChef_city():existingChef.getChef_city()); - existingChef.setChef_description(chef.getChef_description()!=null?chef.getChef_description():existingChef.getChef_description()); - existingChef.setChef_fblink(chef.getChef_fblink()!=null?chef.getChef_fblink():existingChef.getChef_fblink()); - existingChef.setChef_linkdin(chef.getChef_linkdin()!=null?chef.getChef_linkdin():existingChef.getChef_linkdin()); - existingChef.setChef_image(chef.getChef_image()!=null?chef.getChef_image():existingChef.getChef_image()); - existingChef.setChef_paymode(chef.getChef_paymode()!=null?chef.getChef_paymode():existingChef.getChef_paymode()); - existingChef.setChef_state(chef.getChef_state()!=null?chef.getChef_state():existingChef.getChef_state()); - existingChef.setChef_street(chef.getChef_street()!=null?chef.getChef_street():existingChef.getChef_street()); - existingChef.setChef_zip(chef.getChef_zip()!=null?chef.getChef_zip():existingChef.getChef_zip()); - existingChef.setChef_city(chef.getChef_city()!=null?chef.getChef_city():existingChef.getChef_city()); - existingChef.setChef_experience(chef.getChef_experience()!=0?chef.getChef_experience():existingChef.getChef_experience()); + + public Chef updateChef(Chef chef) { + Chef existingChef = (Chef) chefRepository.findById(chef.getChef_id()).orElse(null); + existingChef.setChef_fname(chef.getChef_fname() != null ? chef.getChef_fname() : existingChef.getChef_fname()); + existingChef.setChef_lname(chef.getChef_lname() != null ? chef.getChef_lname() : existingChef.getChef_lname()); + existingChef.setChef_phone(chef.getChef_phone() != null ? chef.getChef_phone() : existingChef.getChef_phone()); + existingChef.setChef_city(chef.getChef_city() != null ? chef.getChef_city() : existingChef.getChef_city()); + existingChef.setChef_description(chef.getChef_description() != null ? chef.getChef_description() : existingChef.getChef_description()); + existingChef.setChef_fblink(chef.getChef_fblink() != null ? chef.getChef_fblink() : existingChef.getChef_fblink()); + existingChef.setChef_linkdin(chef.getChef_linkdin() != null ? chef.getChef_linkdin() : existingChef.getChef_linkdin()); + existingChef.setChef_image(chef.getChef_image() != null ? chef.getChef_image() : existingChef.getChef_image()); + existingChef.setChef_paymode(chef.getChef_paymode() != null ? chef.getChef_paymode() : existingChef.getChef_paymode()); + existingChef.setChef_state(chef.getChef_state() != null ? chef.getChef_state() : existingChef.getChef_state()); + existingChef.setChef_street(chef.getChef_street() != null ? chef.getChef_street() : existingChef.getChef_street()); + existingChef.setChef_zip(chef.getChef_zip() != null ? chef.getChef_zip() : existingChef.getChef_zip()); + existingChef.setChef_city(chef.getChef_city() != null ? chef.getChef_city() : existingChef.getChef_city()); + existingChef.setChef_experience(chef.getChef_experience() != 0 ? chef.getChef_experience() : existingChef.getChef_experience()); return chefRepository.save(existingChef); } + public void getJson(String chef, MultipartFile chef_image) throws Exception { + Chef chefJson = new Chef(); + try { + ObjectMapper objectMapper = new ObjectMapper(); + chefJson = objectMapper.readValue(chef, Chef.class); + } catch (IOException err) + { + //return "error"; + System.out.printf("error", err.toString()); + } + Optional userData = userCredentialsRepository.findByEmail(chefJson.getChef_emailid()); + if (!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + Long loginId = userData.get().getId(); + + chefJson.setLogin_id(loginId); + String fileName = StringUtils.cleanPath(chef_image.getOriginalFilename()); + if (fileName.contains("..")) { + System.out.println("not a a valid file"); + } + try { + chefJson.setChef_image(Base64.getEncoder().encodeToString(chef_image.getBytes())); + } catch (IOException e) { + e.printStackTrace(); + } + chefRepository.save(chefJson); + } } + + + From 85c61fba5e5371eaa6579bb566d9b5e3ec678960 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 9 Apr 2022 16:36:44 -0400 Subject: [PATCH 32/69] all working with changes working --- .../ChefCreateMenu/ChefMenu.java | 14 +-- .../ChefCreateMenu/ChefMenuController.java | 41 ++++---- .../ChefCreateMenu/ChefMenuGETResponse.java | 14 +-- .../ChefCreateMenu/ChefMenuItem.java | 23 +++++ .../ChefCreateMenu/ChefMenuRepository.java | 6 +- .../ChefCreateMenu/ChefMenuRequest.java | 5 +- .../ChefCreateMenu/ChefMenuResponse.java | 22 +++++ .../ChefCreateMenu/ChefMenuService.java | 98 ++++++++++++++++--- .../ChefDetails/Chef.java | 8 +- .../ChefDetails/ChefController.java | 15 +-- .../ChefDetails/ChefRepository.java | 2 +- .../ChefDetails/ChefService.java | 15 +-- .../ChefSignup/ChefSignupService.java | 2 +- .../ContactPage/ContactController.java | 12 ++- .../ContactPage/ContactService.java | 62 ++++++++---- .../Cuisines/CuisineCategory.java | 8 +- .../CustomerDetails/CustomerService.java | 2 +- .../Login/LoginController.java | 2 +- .../Resetpassword/ResetPasswordService.java | 2 +- .../UserCredentials/UserCredentials.java | 2 +- .../UserCredentialsRepository.java | 2 + 21 files changed, 257 insertions(+), 100 deletions(-) create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuItem.java create mode 100644 src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuResponse.java diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java index 7044b56..d6d5c3c 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java @@ -8,6 +8,7 @@ import lombok.NoArgsConstructor; import javax.persistence.*; +import java.util.List; import java.util.Set; @Data @@ -20,7 +21,6 @@ public class ChefMenu { @Id @GeneratedValue private int id; - private long login_id; @Enumerated(EnumType.STRING) private MenuCategories menucategories; //private int cuisine_id; @@ -35,15 +35,15 @@ public class ChefMenu { private Week week; //@ManyToOne - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne @JoinColumn(name = "cuisine_id") private CuisineCategory cuisineCategory; - @ManyToMany(mappedBy = "menu_items") - Set orders; +// @ManyToMany(mappedBy = "menu_items") +// Set orders; - /* @OneToOne - @JoinColumn (name="login_id", insertable = false, updatable = false) - private Chef chef;*/ + @ManyToOne + @JoinColumn (name="loginid") + private Chef chef; /*@JoinTable( name = "selected_cuisines", joinColumns = @JoinColumn(name = "menu_item_id"), diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java index 428dd0e..4a8d84b 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java @@ -1,14 +1,7 @@ package ethniconnect_backend.ChefCreateMenu; -import ethniconnect_backend.ChefDetails.Chef; -import ethniconnect_backend.ChefDetails.ChefService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -import java.util.List; @CrossOrigin() @RestController @@ -21,27 +14,39 @@ public class ChefMenuController { @PostMapping("/chefmenu") - public String addChefMenu(@RequestParam("file") MultipartFile file, - @RequestParam("login_id") long login_id, - @RequestParam("menucategories") MenuCategories menuCategories, - @RequestParam("cuisine_id") int cuisine_id, + public String addChefMenu(@RequestBody ChefMenuRequest chefMenuRequest) throws Exception { + + chefMenuService.saveChefMenuJson(chefMenuRequest); + + /*chefMenuService.saveChefMenu(file, login_id, menuCategories,cuisine_id, + item_name,menu_item_price,item_ingredients,item_intresting_facts,week);*/ + return "Menu details added"; + } + + /* public String addChefMenu(@RequestParam("file") MultipartFile file, + @RequestParam("login_id") long login_id, + @RequestParam("menucategories") MenuCategories menuCategories, + @RequestParam("cuisine_id") int cuisine_id, @RequestParam("item_name") String item_name, - @RequestParam("menu_item_price") double menu_item_price, - @RequestParam("item_ingredients") String item_ingredients, - @RequestParam("item_intresting_facts") String item_intresting_facts, - @RequestParam("week") Week week) throws Exception { + @RequestParam("menu_item_price") double menu_item_price, + @RequestParam("item_ingredients") String item_ingredients, + @RequestParam("item_intresting_facts") String item_intresting_facts, + @RequestParam("week") Week week) throws Exception { chefMenuService.saveChefMenu(file, login_id, menuCategories,cuisine_id, item_name,menu_item_price,item_ingredients,item_intresting_facts,week); return "chef details added"; } - - @GetMapping({"/chefmenuById/{id}"}) +*/ + @GetMapping({"/ChefmenuByChefloginid/{id}"}) public ChefMenuGETResponse findChefMenuById(@PathVariable int id) { - return chefMenuService.getChefMenuById(id); + Long loginidlong = new Long(id); + return chefMenuService.getChefMenuByLoginId(loginidlong.longValue()); } + + @PutMapping("/updatechefmenu") public ChefMenu updateChefMenu(@RequestBody ChefMenu chefMenu) { diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuGETResponse.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuGETResponse.java index 2235167..50bac84 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuGETResponse.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuGETResponse.java @@ -1,18 +1,20 @@ package ethniconnect_backend.ChefCreateMenu; -import lombok.Builder; -import lombok.Data; -import lombok.Getter; -import lombok.Setter; +import lombok.*; + +import java.util.List; @Builder @Getter @Setter @Data +@NoArgsConstructor +@AllArgsConstructor public class ChefMenuGETResponse { + List chefMenuList; - private long login_id; + /* private long login_id; private int cuisine_id; private MenuCategories menucategories; private String menu_item_image; @@ -20,7 +22,7 @@ public class ChefMenuGETResponse { private double menu_item_price; private String item_ingredients; private String item_intresting_facts; - private Week week; + private Week week;*/ } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuItem.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuItem.java new file mode 100644 index 0000000..b07c22e --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuItem.java @@ -0,0 +1,23 @@ +package ethniconnect_backend.ChefCreateMenu; + +import lombok.*; + +import javax.persistence.EnumType; +import javax.persistence.Enumerated; + +@Data +@Builder +@Getter +@Setter +@AllArgsConstructor +@ToString +public class ChefMenuItem { + + @Enumerated(EnumType.STRING) + private MenuCategories menucategory; + private String menu_item_image; + private String item_name; + private double menu_item_price; + private String item_ingredients; + private String item_intresting_facts; +} diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java index fc0f80a..8af57ba 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java @@ -1,12 +1,14 @@ package ethniconnect_backend.ChefCreateMenu; +import ethniconnect_backend.ChefDetails.Chef; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface ChefMenuRepository extends JpaRepository { + List findAllByChef(Chef chef); + - //Optional findById(Integer id); - //ChefMenu findByLogin_id(long chef_login_Id); } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java index e528c8f..9a066e8 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRequest.java @@ -4,6 +4,7 @@ import lombok.*; import javax.persistence.*; +import java.util.List; @Data @Builder @@ -14,10 +15,8 @@ public class ChefMenuRequest { private int id; private long login_id; - @Enumerated(EnumType.STRING) - private MenuCategories menucategories; + private List menu; private int cuisine_id; - private String menu_item_image; private String item_name; private int menu_item_price; private String item_ingredients; diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuResponse.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuResponse.java new file mode 100644 index 0000000..eb3c06b --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuResponse.java @@ -0,0 +1,22 @@ +package ethniconnect_backend.ChefCreateMenu; + +import lombok.*; + +@Data +@Builder +@AllArgsConstructor +@ToString +public class ChefMenuResponse { + + private int menuid; + private String menucategory; + private String menu_item_image; + private String item_name; + private double menu_item_price; + private String item_ingredients; + private String item_intresting_facts; + private String week; + private String cuisineCategory; + + +} diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index d0f5a23..2c43c2a 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -12,10 +12,10 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.Optional; -import java.util.Set; @Service public class ChefMenuService { @@ -31,20 +31,55 @@ public class ChefMenuService { private ChefRepository chefRepository; - public void saveChefMenu(MultipartFile file, Long login_id,MenuCategories menucategories,int cuisine_id, + public void saveChefMenuJson(ChefMenuRequest chefMenuRequest) throws Exception{ + + + ChefMenu chefMenu =null; + + Optional userData = userCredentialsRepository.findById(chefMenuRequest.getLogin_id()); + if(!userData.isPresent()) + throw new Exception("user Id doesn't exist"); + Optional cuisineCategory = cuisineCategoriesRepository.findById(chefMenuRequest.getCuisine_id()); + if(cuisineCategory == null) + throw new Exception("cuisine category doesn't exist"); + + Optional chef = chefRepository.findByLoginid(chefMenuRequest.getLogin_id()); + if(chef==null) + throw new Exception("chef doesn't exist"); + + for(ChefMenuItem chefMenuItem:chefMenuRequest.getMenu()) + { + // Long loginId = userData.get().getId(); + if(cuisineCategory == null) + throw new Exception("cuisine category doesn't exist"); + chefMenu =new ChefMenu(); + chefMenu.setCuisineCategory(cuisineCategory.get()); + chefMenu.setChef(chef.get()); + chefMenu.setMenu_item_image(chefMenuItem.getMenu_item_image()); + chefMenu.setMenucategories(chefMenuItem.getMenucategory()); + chefMenu.setItem_ingredients(chefMenuItem.getItem_ingredients()); + chefMenu.setMenu_item_price(chefMenuItem.getMenu_item_price()); + chefMenuRepository.save(chefMenu); + } + + } + + public void saveChefMenu(MultipartFile file, int login_id,MenuCategories menucategories,int cuisine_id, String item_name,double menu_item_price,String item_ingredients, String item_intresting_facts,Week week ) throws Exception { ChefMenu chefMenu =new ChefMenu(); - Optional userData = userCredentialsRepository.findById(login_id); + Optional userData = userCredentialsRepository.findByLoginid(login_id); if(!userData.isPresent()) throw new Exception("user Id doesn't exist"); Optional cuisineCategory = cuisineCategoriesRepository.findById(cuisine_id); // Long loginId = userData.get().getId(); if(cuisineCategory == null) - throw new Exception("cuisine category doesn't exist"); - + throw new Exception("Cuisine doesn't exist"); + Optional chef = chefRepository.findByLoginid(login_id); + if(chef==null) + throw new Exception("chef doesn't exist"); String fileName = StringUtils.cleanPath(file.getOriginalFilename()); if(fileName.contains("..")) { @@ -55,7 +90,6 @@ public void saveChefMenu(MultipartFile file, Long login_id,MenuCategories menuc } catch (IOException e) { e.printStackTrace(); } - chefMenu.setLogin_id(login_id); chefMenu.setMenucategories(menucategories); chefMenu.setMenu_item_price(menu_item_price); @@ -80,7 +114,7 @@ public ChefMenuGETResponse getChefMenuById(int id) { ChefMenu chefMenu = chefMenuRepository.findById(id).get(); - ChefMenuGETResponse chefMenuGETResponse = ChefMenuGETResponse.builder() + /*ChefMenuGETResponse chefMenuGETResponse = ChefMenuGETResponse.builder() .cuisine_id(chefMenu.getCuisineCategory().getId()) .login_id(chefMenu.getLogin_id()) .menucategories(chefMenu.getMenucategories()) @@ -90,17 +124,53 @@ public ChefMenuGETResponse getChefMenuById(int id) .item_ingredients(chefMenu.getItem_ingredients()) .item_intresting_facts(chefMenu.getItem_intresting_facts()) .week(chefMenu.getWeek()) - .build(); - return chefMenuGETResponse; + .build();*/ + return new ChefMenuGETResponse(); } + public ChefMenuGETResponse getChefMenuByLoginId(long login_id) { + Chef chef = new Chef(); + chef.setLoginid(login_id); + List chefMenuList = chefMenuRepository.findAllByChef(chef); + List chefMenuResponseList = new ArrayList<>(); - public String deleteChefMenu(int chefMenu_id) - { - chefMenuRepository.deleteById(chefMenu_id); - return "chef Menu ietem removed !!" + chefMenu_id; + /* ChefMenuGETResponse chefMenuGETResponse = ChefMenuGETResponse.builder() + .cuisine_id(chefMenu.getCuisineCategory().getId()) + .login_id(chefMenu.getLogin_id()) + .menucategories(chefMenu.getMenucategories()) + .item_name(chefMenu.getItem_name()) + .menu_item_image(chefMenu.getMenu_item_image()) + .menu_item_price(chefMenu.getMenu_item_price()) + .item_ingredients(chefMenu.getItem_ingredients()) + .item_intresting_facts(chefMenu.getItem_intresting_facts()) + .week(chefMenu.getWeek()) + .build();*/ + for(ChefMenu chefMenu:chefMenuList) + { + chefMenuResponseList.add + ( ChefMenuResponse + .builder() + .menuid(chefMenu.getId()) + .menu_item_image(chefMenu.getMenu_item_image()!=null?chefMenu.getMenu_item_image():null) + .menucategory(chefMenu.getMenucategories().toString()) + .cuisineCategory(chefMenu.getCuisineCategory().getCuisine_name()) + .menu_item_price(chefMenu.getMenu_item_price()) + .item_name(chefMenu.getItem_name()) + .item_ingredients(chefMenu.getItem_ingredients()) + .item_intresting_facts(chefMenu.getItem_intresting_facts()) + .week(chefMenu.getWeek()!=null?chefMenu.getWeek().toString():null) + .build() + ); + } + return ChefMenuGETResponse.builder().chefMenuList(chefMenuResponseList).build(); } + +// public String deleteChefMenu(int chefMenu_id) +// { +// chefMenuRepository.deleteById(chefMenu_id); +// return "chef Menu ietem removed !!" + chefMenu_id; +// } public ChefMenu updateChefMenu(ChefMenu chefMenu) { ChefMenu existingChefMenu=chefMenuRepository.findById(chefMenu.getId()).orElse(null); @@ -116,6 +186,8 @@ public ChefMenu updateChefMenu(ChefMenu chefMenu) } + + // public List getChefByCuisineId(String cuisine_id){ // // return chefRepository.getChefsByPrefCuisine(Integer.getInteger(cuisine_id)); diff --git a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java index 878221f..0517c56 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java @@ -12,12 +12,12 @@ @Entity @Table(name = "chef",uniqueConstraints= {@UniqueConstraint(columnNames = {"chef_emailid","chef_phone"})}) - public class Chef { +// @Id +// @GeneratedValue +// private int chef_id; @Id - @GeneratedValue - private int chef_id; - private long login_id; + private long loginid; private String chef_fname; private String chef_lname; private String chef_emailid; diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java index 67be833..ae7be01 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java @@ -16,7 +16,7 @@ public class ChefController { @Autowired private ChefRepository chefRepository; - /*@PostMapping("/chef") + @PostMapping("/chef") public String addchef(@RequestParam("file") MultipartFile file, @RequestParam("chef_fname") String fname, @RequestParam("chef_lname") String lname, @@ -35,7 +35,7 @@ public String addchef(@RequestParam("file") MultipartFile file, chef_city, chef_state, chef_zip, chef_paymode, chef_description, chef_experience, chef_fblink, chef_linkdin); return "chef details added"; - }*/ + } /* @PostMapping("/chef") public Chef addChef(@RequestBody Chef chef) throws Exception @@ -44,9 +44,10 @@ public Chef addChef(@RequestBody Chef chef) throws Exception }*/ - @GetMapping({"/chefById/{id}"}) + @GetMapping({"/chefByLoginId/{id}"}) public Chef findChefById(@PathVariable int id) { - return chefProfileService.getChefById(id); + Long loginidlong = new Long(id); + return chefProfileService.getChefByLoginId(id); } @PutMapping("/updatechef") @@ -60,13 +61,13 @@ public List getChefProfileInfo() return chefRepository.getChefProfileInfo(); }*/ - @PostMapping(value = "/chef", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) + /*@PostMapping(value = "/chef", consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public String upload(@RequestPart("chef") String chef, @RequestPart("chef_image") MultipartFile chef_image) throws Exception { chefProfileService.getJson(chef,chef_image); - return "added"; + return "added";*/ + - } diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java index 9067359..41c797e 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java @@ -8,7 +8,7 @@ public interface ChefRepository extends JpaRepository { - //Optional findByLogin_Id(long login_id); + Optional findByLoginid(long login_id); /* *//*@Query("SELECT new ethniconnect_backend.ChefDetails.ChefprofileResponse( c.chef_fname, m.menu_item_price)" + " FROM Chef c join c.ChefMenu m")*//* diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java index f30d935..03c1b8c 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java @@ -1,6 +1,5 @@ package ethniconnect_backend.ChefDetails; -import com.fasterxml.jackson.databind.ObjectMapper; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; import ethniconnect_backend.UserCredentials.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; @@ -32,9 +31,9 @@ public void saveChef(MultipartFile file, String fname, String lname, String emai throw new Exception("user Id doesn't exist"); - Long loginId = userData.get().getId(); + Long loginId = userData.get().getLoginid(); - chef.setLogin_id(loginId); + chef.setLoginid(loginId); String fileName = StringUtils.cleanPath(file.getOriginalFilename()); if (fileName.contains("..")) { System.out.println("not a a valid file"); @@ -74,7 +73,11 @@ public void saveChef(MultipartFile file, String fname, String lname, String emai public List saveChefs(List chefs) { return chefRepository.saveAll(chefs); } + public Chef getChefByLoginId(long loginid) { + Optional chef = chefRepository.findByLoginid(loginid); + return chef.get(); + } public List getChefs() { return chefRepository.findAll(); } @@ -89,7 +92,7 @@ public String deleteChef(int chef_id) { } public Chef updateChef(Chef chef) { - Chef existingChef = (Chef) chefRepository.findById(chef.getChef_id()).orElse(null); + Chef existingChef = (Chef) chefRepository.findByLoginid(chef.getLoginid()).orElse(null); existingChef.setChef_fname(chef.getChef_fname() != null ? chef.getChef_fname() : existingChef.getChef_fname()); existingChef.setChef_lname(chef.getChef_lname() != null ? chef.getChef_lname() : existingChef.getChef_lname()); existingChef.setChef_phone(chef.getChef_phone() != null ? chef.getChef_phone() : existingChef.getChef_phone()); @@ -110,7 +113,7 @@ public Chef updateChef(Chef chef) { - public void getJson(String chef, MultipartFile chef_image) throws Exception { + /*public void getJson(String chef, MultipartFile chef_image) throws Exception { Chef chefJson = new Chef(); try { ObjectMapper objectMapper = new ObjectMapper(); @@ -137,7 +140,7 @@ public void getJson(String chef, MultipartFile chef_image) throws Exception { } chefRepository.save(chefJson); - } + }*/ } diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index 22072a3..f41845f 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -43,7 +43,7 @@ public void register(String email, String password) { ); /*String link = "www.google.com";*/ - String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; + String link = "http://localhost:8080/api/v1/registration/confirm?token=" + token; emailSender.send( email, emailService.buildEmail("user", link)); diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java index a12e011..9211a5d 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactController.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactController.java @@ -12,8 +12,16 @@ public class ContactController { private ContactService contactService; @Autowired private ContactRepository contactRepository; - @PostMapping("/ContactRequest") + public void addcontactrequest(@RequestBody Contact contact) + + { + contactService.saveContactRequest(contact); + + //return "request added"; + } + + /* @PostMapping("/ContactRequest") public void addcontactrequest(@RequestParam("name") String name, @RequestParam("email") String email, @RequestParam("message") String message @@ -22,7 +30,7 @@ public void addcontactrequest(@RequestParam("name") String name, contactService.saveContactRequest(name,email,message); //return "request added"; - } + }*/ @GetMapping({"/ContactRequests"}) public List findcontactrequests() diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java index a8c092f..abccdde 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java @@ -34,30 +34,50 @@ public class ContactService { }*/ - public void saveContactRequest(String email, String name, String message) { - boolean isValidEmail = emailValidator. - test(email); - - if (!isValidEmail) { - throw new IllegalStateException("email not valid"); - } - - - /*String link = "www.google.com";*/ - Contact contact = new Contact(); - contact.setEmailid(email); - contact.setMessage(message); - contact.setName(name); - contactRepository.save(contact); - emailSender.send( - "ethniconnect@gmail.com", - emailService.buildContactEmail(message,email)); - contactRepository.save(contact); - - //return token; +// public void saveContactRequest(String email, String name, String message) { +// boolean isValidEmail = emailValidator. +// test(email); +// +// if (!isValidEmail) { +// throw new IllegalStateException("email not valid"); +// } +// +// +// /*String link = "www.google.com";*/ +// Contact contact = new Contact(); +// contact.setEmailid(email); +// contact.setMessage(message); +// contact.setName(name); +// contactRepository.save(contact); +// emailSender.send( +// "ethniconnect@gmail.com", +// emailService.buildContactEmail(message,email)); +// contactRepository.save(contact); +// +// //return token; +// } +public void saveContactRequest(Contact contact) { + boolean isValidEmail = emailValidator. + test(contact.getEmailid()); + + if (!isValidEmail) { + throw new IllegalStateException("email not valid"); } + /*String link = "www.google.com";*/ + + + contactRepository.save(contact); + emailSender.send( + "ethniconnect@gmail.com", + emailService.buildContactEmail(contact.getMessage(),contact.getEmailid())); + contactRepository.save(contact); + + //return token; +} + + public List getContactRequets() { return contactRepository.findAll(); diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java index 50b3d53..39450aa 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java @@ -14,10 +14,8 @@ @Data @NoArgsConstructor @AllArgsConstructor - @Entity @Table(name = "cuisinecategory") - public class CuisineCategory { @Id @GeneratedValue @@ -26,8 +24,8 @@ public class CuisineCategory { private String cuisine_name; private String cuisine_image; - - @OneToMany(fetch = FetchType.LAZY, mappedBy = "cuisineCategory") - private List menus; +// +// @OneToMany(fetch = FetchType.LAZY, mappedBy = "cuisineCategory") +// private List menus; } diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java index 60e8abe..338ed49 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java @@ -28,7 +28,7 @@ public void saveCustomer(MultipartFile file, String fname, String lname, String Optional userData = userCredentialsRepository.findByEmail(emailid); if(!userData.isPresent()) throw new Exception("user Id doesn't exist"); - Long loginId = userData.get().getId(); + Long loginId = userData.get().getLoginid(); customer.setLogin_id(loginId); String fileName = StringUtils.cleanPath(file.getOriginalFilename()); diff --git a/src/main/java/ethniconnect_backend/Login/LoginController.java b/src/main/java/ethniconnect_backend/Login/LoginController.java index e4059f5..4e88388 100644 --- a/src/main/java/ethniconnect_backend/Login/LoginController.java +++ b/src/main/java/ethniconnect_backend/Login/LoginController.java @@ -34,7 +34,7 @@ public ResponseEntity authenticateUser(@RequestBody UserCredentia { //return new ResponseEntity<>("User signed-in successfully!.", HttpStatus.OK); - loginResponse.setLoginId(userCredentialsFromDB.getId()); + loginResponse.setLoginId(userCredentialsFromDB.getLoginid()); return new ResponseEntity<>(loginResponse, HttpStatus.OK); } loginResponse.setErrormessage("User credentials are wrong"); diff --git a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java index 6bc52e4..b72a672 100644 --- a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java @@ -34,7 +34,7 @@ public void resetPassword(ResetPasswordRequest resetPasswordRequest) { if(userCredentialsService.isEmailIdExist(resetPasswordRequest.getEmailId())) { String token = userCredentialsService.getToken(userCredentials); - String link = "http://localhost:5000/api/v1/resetpassword/confirm?token=" + token; + String link = "http://localhost:8080/api/v1/resetpassword/confirm?token=" + token; emailSender.send( resetPasswordRequest.getEmailId(), emailService.buildResetPasswordEmail("User", link)); diff --git a/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java index ae5754a..daa0d93 100644 --- a/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java +++ b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentials.java @@ -31,7 +31,7 @@ public class UserCredentials implements UserDetails { generator = "chef_sequence" ) - private Long id; + private long loginid; private String email; private String password; @Enumerated(EnumType.STRING) diff --git a/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsRepository.java b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsRepository.java index 5180985..41caa0d 100644 --- a/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsRepository.java +++ b/src/main/java/ethniconnect_backend/UserCredentials/UserCredentialsRepository.java @@ -13,6 +13,7 @@ public interface UserCredentialsRepository extends JpaRepository { + Optional findByLoginid(long login_id); Optional findByEmail(String email); public UserCredentials findByResetpasswordtoken(String token); @@ -24,4 +25,5 @@ public interface UserCredentialsRepository + } From c06de2876d9ccbc22ed0cdc60080402ef843ca26 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 9 Apr 2022 16:38:29 -0400 Subject: [PATCH 33/69] all API's working working --- .../java/ethniconnect_backend/ChefDetails/ChefController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java index ae7be01..7eb1f0d 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java @@ -17,7 +17,7 @@ public class ChefController { private ChefRepository chefRepository; @PostMapping("/chef") - public String addchef(@RequestParam("file") MultipartFile file, + public void addchef(@RequestParam("file") MultipartFile file, @RequestParam("chef_fname") String fname, @RequestParam("chef_lname") String lname, @RequestParam("chef_emailid") String emailid, @@ -34,7 +34,7 @@ public String addchef(@RequestParam("file") MultipartFile file, chefProfileService.saveChef(file, fname, lname, emailid, chef_phone, chef_street, chef_city, chef_state, chef_zip, chef_paymode, chef_description, chef_experience, chef_fblink, chef_linkdin); - return "chef details added"; + //return "chef details added"; } /* @PostMapping("/chef") From 5bd20df030647cfb9a42386c5caa8a6c4bccaba9 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 9 Apr 2022 16:43:32 -0400 Subject: [PATCH 34/69] working working --- .../java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java | 5 +---- .../ethniconnect_backend/ChefCreateMenu/ChefMenuService.java | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java index d6d5c3c..c4c022b 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java @@ -49,8 +49,5 @@ public class ChefMenu { joinColumns = @JoinColumn(name = "menu_item_id"), inverseJoinColumns = @JoinColumn(name = "cuisine_id")) Set selectedCuisines;*/ - /* @OneToMany - @OneToMany(fetch = FetchType.EAGER, mappedBy = "menu_items", cascade = CascadeType.ALL) - @JsonIgnoreProperties("menu") - private List storyList = new ArrayList<>();*/ + } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 2c43c2a..500c6ff 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -64,7 +64,7 @@ public void saveChefMenuJson(ChefMenuRequest chefMenuRequest) throws Exception{ } - public void saveChefMenu(MultipartFile file, int login_id,MenuCategories menucategories,int cuisine_id, + /*public void saveChefMenu(MultipartFile file, int login_id,MenuCategories menucategories,int cuisine_id, String item_name,double menu_item_price,String item_ingredients, String item_intresting_facts,Week week ) throws Exception @@ -100,7 +100,7 @@ public void saveChefMenu(MultipartFile file, int login_id,MenuCategories menuca chefMenu.setWeek(week); chefMenuRepository.save(chefMenu); - } + }*/ public List saveChefMenus(List chefMenus){ return chefMenuRepository.saveAll(chefMenus); From cc38d5b20efcf5e8671e7788e08c77777a11c2a5 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 9 Apr 2022 16:52:13 -0400 Subject: [PATCH 35/69] All updated and working working --- .../ChefDetails/ChefController.java | 4 +-- .../ChefDetails/ChefRequest.java | 27 ++++++++++++++++++ .../ChefDetails/ChefService.java | 28 ++++++++++++++++--- 3 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 src/main/java/ethniconnect_backend/ChefDetails/ChefRequest.java diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java index 7eb1f0d..99099b3 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefController.java @@ -51,8 +51,8 @@ public Chef findChefById(@PathVariable int id) { } @PutMapping("/updatechef") - public Chef updateChef(@RequestBody Chef chef) { - return chefProfileService.updateChef(chef); + public Chef updateChef(@RequestBody ChefRequest chefRequest) { + return chefProfileService.updateChef(chefRequest); } /* @GetMapping({"/chefprofile"}) diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefRequest.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefRequest.java new file mode 100644 index 0000000..8d62682 --- /dev/null +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefRequest.java @@ -0,0 +1,27 @@ +package ethniconnect_backend.ChefDetails; + +import lombok.*; + +@Data +@Builder +@Getter +@Setter +@AllArgsConstructor +@ToString +public class ChefRequest { + private long login_id; + private String chef_fname; + private String chef_lname; + private String chef_emailid; + private String chef_phone; + private String chef_street; + private String chef_city; + private String chef_state; + private String chef_zip; + private String chef_paymode; + private String chef_description; + private int chef_experience; + private String chef_fblink; + private String chef_linkdin; + private String chef_image; +} diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java index 03c1b8c..26d3af0 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefService.java @@ -91,7 +91,10 @@ public String deleteChef(int chef_id) { return "chef removed !!" + chef_id; } - public Chef updateChef(Chef chef) { + + + + /* public Chef updateChef(Chef chef) { Chef existingChef = (Chef) chefRepository.findByLoginid(chef.getLoginid()).orElse(null); existingChef.setChef_fname(chef.getChef_fname() != null ? chef.getChef_fname() : existingChef.getChef_fname()); existingChef.setChef_lname(chef.getChef_lname() != null ? chef.getChef_lname() : existingChef.getChef_lname()); @@ -109,9 +112,26 @@ public Chef updateChef(Chef chef) { existingChef.setChef_experience(chef.getChef_experience() != 0 ? chef.getChef_experience() : existingChef.getChef_experience()); return chefRepository.save(existingChef); - } - - + }*/ + public Chef updateChef(ChefRequest chefRequest) { + Chef existingChef = (Chef) chefRepository.findByLoginid(chefRequest.getLogin_id()).orElse(null); + existingChef.setChef_fname(chefRequest.getChef_fname() != null ? chefRequest.getChef_fname() : existingChef.getChef_fname()); + existingChef.setChef_lname(chefRequest.getChef_lname() != null ? chefRequest.getChef_lname() : existingChef.getChef_lname()); + existingChef.setChef_phone(chefRequest.getChef_phone() != null ? chefRequest.getChef_phone() : existingChef.getChef_phone()); + existingChef.setChef_city(chefRequest.getChef_city() != null ? chefRequest.getChef_city() : existingChef.getChef_city()); + existingChef.setChef_description(chefRequest.getChef_description() != null ? chefRequest.getChef_description() : existingChef.getChef_description()); + existingChef.setChef_fblink(chefRequest.getChef_fblink() != null ? chefRequest.getChef_fblink() : existingChef.getChef_fblink()); + existingChef.setChef_linkdin(chefRequest.getChef_linkdin() != null ? chefRequest.getChef_linkdin() : existingChef.getChef_linkdin()); + existingChef.setChef_image(chefRequest.getChef_image() != null ? chefRequest.getChef_image() : existingChef.getChef_image()); + existingChef.setChef_paymode(chefRequest.getChef_paymode() != null ? chefRequest.getChef_paymode() : existingChef.getChef_paymode()); + existingChef.setChef_state(chefRequest.getChef_state() != null ? chefRequest.getChef_state() : existingChef.getChef_state()); + existingChef.setChef_street(chefRequest.getChef_street() != null ? chefRequest.getChef_street() : existingChef.getChef_street()); + existingChef.setChef_zip(chefRequest.getChef_zip() != null ? chefRequest.getChef_zip() : existingChef.getChef_zip()); + existingChef.setChef_city(chefRequest.getChef_city() != null ? chefRequest.getChef_city() : existingChef.getChef_city()); + existingChef.setChef_experience(chefRequest.getChef_experience() != 0 ? chefRequest.getChef_experience() : existingChef.getChef_experience()); + return chefRepository.save(existingChef); + + } /*public void getJson(String chef, MultipartFile chef_image) throws Exception { Chef chefJson = new Chef(); From c46704bd9fd4308232a5e9bdd5837222f92c31dc Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sat, 9 Apr 2022 22:29:42 -0400 Subject: [PATCH 36/69] commit commit --- src/main/java/ethniconnect_backend/Zip/ZipController.java | 2 +- src/main/java/ethniconnect_backend/Zip/ZipService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ethniconnect_backend/Zip/ZipController.java b/src/main/java/ethniconnect_backend/Zip/ZipController.java index f391a2f..c17da3e 100644 --- a/src/main/java/ethniconnect_backend/Zip/ZipController.java +++ b/src/main/java/ethniconnect_backend/Zip/ZipController.java @@ -18,7 +18,7 @@ public List getAllZip(){ } @GetMapping(path = "/getCuisinesByZip/{zipCode}") public Zip getCuisinesByZip(@PathVariable int zipCode){ - return zipService.getZipByZipCode(zipCode); + return zipService.getCuisineByZipCode(zipCode); } diff --git a/src/main/java/ethniconnect_backend/Zip/ZipService.java b/src/main/java/ethniconnect_backend/Zip/ZipService.java index 7c59eaa..921cb21 100644 --- a/src/main/java/ethniconnect_backend/Zip/ZipService.java +++ b/src/main/java/ethniconnect_backend/Zip/ZipService.java @@ -13,7 +13,7 @@ public List getAllZip(){ return zipRepository.findAll(); } - public Zip getZipByZipCode(int zipCode){ + public Zip getCuisineByZipCode(int zipCode){ return zipRepository.getZipByZipCode(zipCode); } } From 7a7981142102ecedd8b5cecd61c3ae81b01d80cf Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 10 Apr 2022 11:59:35 -0400 Subject: [PATCH 37/69] updated menucategories to lower and upper case working working --- .../ethniconnect_backend/ChefCreateMenu/MenuCategories.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/MenuCategories.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/MenuCategories.java index 42287c6..88bfc8f 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/MenuCategories.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/MenuCategories.java @@ -5,6 +5,9 @@ public enum MenuCategories { Breakfast, Lunch, - Dinner + Dinner, + breakfast, + lunch, + dinner } From a198ede33e952a2b437297742ae7cde80e329609 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 10 Apr 2022 12:50:11 -0400 Subject: [PATCH 38/69] loginid chefmneu and loginid working --- .../ChefCreateMenu/ChefMenuService.java | 2 ++ .../java/ethniconnect_backend/Login/LoginController.java | 6 ++++++ src/main/java/ethniconnect_backend/Login/LoginResponse.java | 3 +++ 3 files changed, 11 insertions(+) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 500c6ff..779ce87 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -55,10 +55,12 @@ public void saveChefMenuJson(ChefMenuRequest chefMenuRequest) throws Exception{ chefMenu =new ChefMenu(); chefMenu.setCuisineCategory(cuisineCategory.get()); chefMenu.setChef(chef.get()); + chefMenu.setItem_name(chefMenuRequest.getItem_name()); chefMenu.setMenu_item_image(chefMenuItem.getMenu_item_image()); chefMenu.setMenucategories(chefMenuItem.getMenucategory()); chefMenu.setItem_ingredients(chefMenuItem.getItem_ingredients()); chefMenu.setMenu_item_price(chefMenuItem.getMenu_item_price()); + chefMenu.setWeek(chefMenuRequest.getWeek()); chefMenuRepository.save(chefMenu); } diff --git a/src/main/java/ethniconnect_backend/Login/LoginController.java b/src/main/java/ethniconnect_backend/Login/LoginController.java index 4e88388..7197fd0 100644 --- a/src/main/java/ethniconnect_backend/Login/LoginController.java +++ b/src/main/java/ethniconnect_backend/Login/LoginController.java @@ -2,6 +2,7 @@ import ethniconnect_backend.UserCredentials.UserCredentials; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import ethniconnect_backend.UserCredentials.UserRole; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -28,6 +29,10 @@ public ResponseEntity authenticateUser(@RequestBody UserCredentia { UserCredentials userCredentialsFromDB = userCredentialsRepository.findByEmail(userCredentials.getEmail()).get(); LoginResponse loginResponse = new LoginResponse(); + if(userCredentialsFromDB.getAppUserRole().toString().equalsIgnoreCase(UserRole.BUSINESS.toString())) + loginResponse.setChef(true); + if(userCredentialsFromDB.getAppUserRole().toString().equalsIgnoreCase(UserRole.PERSONAL.toString())) + loginResponse.setCustomer(true); if(userCredentials.getEmail().equals(userCredentialsFromDB.getEmail()) && bCryptPasswordEncoder.matches(userCredentials.getPassword(),userCredentialsFromDB.getPassword()) && (userCredentialsFromDB.getEnabled().booleanValue() || userCredentialsFromDB.getEnabled() == true)) @@ -42,6 +47,7 @@ public ResponseEntity authenticateUser(@RequestBody UserCredentia { loginResponse.setErrormessage("Account not activated"); } + //SecurityContextHolder.getContext().setAuthentication(authentication); return new ResponseEntity<>(loginResponse, HttpStatus.UNAUTHORIZED); } diff --git a/src/main/java/ethniconnect_backend/Login/LoginResponse.java b/src/main/java/ethniconnect_backend/Login/LoginResponse.java index a85a1e9..3846ac2 100644 --- a/src/main/java/ethniconnect_backend/Login/LoginResponse.java +++ b/src/main/java/ethniconnect_backend/Login/LoginResponse.java @@ -9,5 +9,8 @@ @Setter public class LoginResponse { private long loginId; + private boolean isChef; + private boolean isCustomer; private String errormessage; + } From f2d5aa6c38d9f9212986d155f7c9e4646354ab2c Mon Sep 17 00:00:00 2001 From: Saranya1994 Date: Sun, 10 Apr 2022 13:04:05 -0400 Subject: [PATCH 39/69] zipcontroller all working files-Chef Menu,Details --- .DS_Store | Bin 6148 -> 6148 bytes src/.DS_Store | Bin 6148 -> 6148 bytes src/main/.DS_Store | Bin 6148 -> 6148 bytes src/main/java/.DS_Store | Bin 6148 -> 6148 bytes src/main/java/ethniconnect_backend/.DS_Store | Bin 6148 -> 8196 bytes .../ChefSignup/ChefSignupService.java | 2 +- .../Zip/ZipController.java | 2 ++ src/main/resources/application.yml | 6 +++--- 8 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.DS_Store b/.DS_Store index c84e0488b4d78e8c99c940fd619d93c171f27bc9..27275abf4abb675cd26425711cf74519bd683e96 100644 GIT binary patch delta 150 zcmZoMXffFEpT*#0QbA5;afyM!bw(y;7FITP4h}93E?%zK;Eeq8;F83W(qgB?qG%8= zAh9GPX|f`#w?79b2WPy1M0K^1iKUK$k(p_&jzYDik%5kaiLqI2EhmS#s-dlCLT+VM gbxm#EOa?GuWQ5QR{7@Q3&Dy-3)sAU1JI7ys00EjKZU6uP delta 71 zcmZoMXffFEpM`PzWOcSeHSy|d6Js3(6GMYq9ffL3BLg7Y*sQjelS5Ql-#REhJ0~|U azjN|lHhIRb%_mvym?ky|ZD!~A%MSnys}=$P diff --git a/src/.DS_Store b/src/.DS_Store index 731abbcfe13eb1887b7a4dc810a81b7e47170773..8552d55aed5c573060d6063c43858bd9ed6d25f6 100644 GIT binary patch delta 136 zcmZoMXffE}%_MO$sURn_xWvHVIwKP^3o9Et2L~4i7cbZ3L?&U@fW(rFq{+EV-u@h% z9Gvk264lj4CYCx1MrNk9Itta6Mg}?xCdOv9wVWK{s)n|n3AvS3)it$sGa0~ukr6^O U@Iz@BHET07^Cy>Pjj0dgfAWB>pF delta 135 zcmZoMXffE}&7`zFsURn_xWvHV8Y2@k3o9Et2RjEhM{ICLetB?7Vo7PS)8uLS_~X9R(9ZgIXPhYD*&nAluliww9AaR9W9TC_XzUH!r`F0Sp)!Av6Ool!j4V Sn?;#Fu}o|b+RV=JmmdJx>K&{A diff --git a/src/main/.DS_Store b/src/main/.DS_Store index 2143673e5e570e658e566b7589027ef4d84ab9d4..6320f374eaf4dc15e2d6207d3cb0a2307a8fbd06 100644 GIT binary patch delta 136 zcmZoMXffE}%_MO$sURn_xWvHVIwKP^3o9Et2L~4i7cbZ3L?&U@fW(rFq{+EV-u@h% z9Gvk264lj4CYCx1MrNk9Itta6Mg}?xCdOv9wVWK{s)n|n3AvS3)it$sGa0~ukr6^O U@Iz@BHET07^Cy>Pjj0dgfAWB>pF delta 135 zcmZoMXffE}&7`zFsURn_xWvHV8Y2@k3o9Et2RjEhM{ICLetB?7Vo7PS)8uLS_~X9R(9ZgIXPhYD*&nAluliww9AaR9W9TC_XzUH!r`F0Sp)!Av6Ool!j4V Sn?;#Fu}o|b+RV=JmmdJx>K&{A diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store index 79907fd1f77ddf178405048df589de98b926e652..74e42ed1c1ab85fe5f243d6f30021da48dd65d1c 100644 GIT binary patch delta 193 zcmZoMXfc@JFUrioz`)4BAi%(o$&k#D&yWX%shbxvFK1+Ao?OMGGdYea*x+PRK~83I ziGjg&MkZz!RyKAH4lWKZUar{SjQsN8lEjkIVyDESXb>+Tu_PmD@?|D(e-2I#&UgWd z>S`ksOC1FxGt*ifg=$M9104kuW3$>?P7ZNZLtD>;+{&uzn%cUVKzD$g0(1))@Iz@B WH4EgJ%~P3+SSB`zY-Z>9%MSprbu8on delta 196 zcmZoMXfc@JFU-Qgz`)4BAi$8HoRpKF1mp>9p2)nCQ5qz{%#h5G&yeexgOCJ@I!^Xr zvY2ea6s)v8sURn_xWvHV8Y2@k3o9Et2RjEhM{ICLetB?7Vo7PS)8ySu-rk%XobdwU z)zv1(ItnI+2DLg0)s{vEK(?`2Z7nBYB{M Qq_eq^xrk*mJI7ys0Hg&e3jhEB diff --git a/src/main/java/ethniconnect_backend/.DS_Store b/src/main/java/ethniconnect_backend/.DS_Store index 97f23b13d9cd8eaa9efbed806099d7fcc9f5566f..ae5bac9dc5464b624bafd3d35bf185288ee61eb5 100644 GIT binary patch delta 353 zcmZoMXmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAD7-OXH}hr%jz7$c**Q2SHn1=X zPv&8mjX{&a8X`PeqK6Aen3IOF~C*Nn+*x0a>Nst+0fCM*?b_Mx-vmnQJ=E?jbo|FA~I5>dTfdYkL Way-v;_4PoVeE-1!tP8K%+n4~M-cR-b delta 111 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{Mvv5r;6q~50$SANeU^g?Pz+_uNg~>Vs@|$x6 x7c);RlU&Ts!6C>DR0sqD+(5z=q-SH{cjn3bGM*q47?>cYfh=Iy9M3a{82~5!5+DEo diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index f41845f..200f841 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -43,7 +43,7 @@ public void register(String email, String password) { ); /*String link = "www.google.com";*/ - String link = "http://localhost:8080/api/v1/registration/confirm?token=" + token; + String link = "http://localhost:8500/api/v1/registration/confirm?token=" + token; emailSender.send( email, emailService.buildEmail("user", link)); diff --git a/src/main/java/ethniconnect_backend/Zip/ZipController.java b/src/main/java/ethniconnect_backend/Zip/ZipController.java index c17da3e..2584bca 100644 --- a/src/main/java/ethniconnect_backend/Zip/ZipController.java +++ b/src/main/java/ethniconnect_backend/Zip/ZipController.java @@ -1,12 +1,14 @@ package ethniconnect_backend.Zip; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import java.util.List; +@CrossOrigin() @RestController public class ZipController { @Autowired diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6c6f0ce..4003e45 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8080 + port: 8500 error: include-message: always include-binding-errors: always @@ -10,14 +10,14 @@ server: spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - password: bharani16 + password: Saranya1994 initialization-mode: ALWAYS url: jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect username: root jpa: hibernate: - ddl-auto: update + ddl-auto: create-drop properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect From f1f3c0159300ca354046878941d34ce934d371e7 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 10 Apr 2022 15:09:27 -0400 Subject: [PATCH 40/69] working working --- src/main/java/ethniconnect_backend/Zip/ZipController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ethniconnect_backend/Zip/ZipController.java b/src/main/java/ethniconnect_backend/Zip/ZipController.java index c17da3e..2584bca 100644 --- a/src/main/java/ethniconnect_backend/Zip/ZipController.java +++ b/src/main/java/ethniconnect_backend/Zip/ZipController.java @@ -1,12 +1,14 @@ package ethniconnect_backend.Zip; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import java.util.List; +@CrossOrigin() @RestController public class ZipController { @Autowired From d93020a0149ecdff62c8afd7a216b16be2e481e7 Mon Sep 17 00:00:00 2001 From: Lal Prasath Date: Sun, 10 Apr 2022 20:17:09 +0100 Subject: [PATCH 41/69] API integration API integration --- .../ChefCreateMenu/ChefMenuController.java | 9 ++++++- .../ChefCreateMenu/ChefMenuRepository.java | 2 ++ .../ChefCreateMenu/ChefMenuService.java | 24 ++++++++++++++++--- .../ethniconnect_backend/DemoApplication.java | 7 +++++- .../java/ethniconnect_backend/Zip/Root.java | 14 +++++++++++ .../java/ethniconnect_backend/Zip/Zip.java | 12 +++++----- .../ethniconnect_backend/Zip/ZipCode.java | 16 +++++++++++++ 7 files changed, 73 insertions(+), 11 deletions(-) create mode 100644 src/main/java/ethniconnect_backend/Zip/Root.java create mode 100644 src/main/java/ethniconnect_backend/Zip/ZipCode.java diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java index 4a8d84b..93bf311 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuController.java @@ -1,8 +1,11 @@ package ethniconnect_backend.ChefCreateMenu; +import ethniconnect_backend.ChefDetails.Chef; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; + @CrossOrigin() @RestController public class ChefMenuController { @@ -45,7 +48,11 @@ public ChefMenuGETResponse findChefMenuById(@PathVariable int id) return chefMenuService.getChefMenuByLoginId(loginidlong.longValue()); } - + @GetMapping({"/chefByCuisineId/{id}/{zipCode}"}) + public List findChefByCuisineId(@PathVariable int id, @PathVariable int zipCode) + { + return chefMenuService.getChefByCuisineId(id,zipCode); + } @PutMapping("/updatechefmenu") public ChefMenu updateChefMenu(@RequestBody ChefMenu chefMenu) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java index 8af57ba..1f555a6 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuRepository.java @@ -10,5 +10,7 @@ public interface ChefMenuRepository extends JpaRepository { List findAllByChef(Chef chef); + List findAllByCuisineCategory_Id(int cuisineId); + } diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 779ce87..ef3a3d9 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -6,16 +6,20 @@ import ethniconnect_backend.Cuisines.CuisineCategory; import ethniconnect_backend.UserCredentials.UserCredentials; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import ethniconnect_backend.Zip.ZipCode; +import ethniconnect_backend.Zip.Root; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; - +import org.springframework.web.client.RestTemplate; import java.io.IOException; import java.util.ArrayList; import java.util.Base64; import java.util.List; import java.util.Optional; +import java.util.*; +import java.util.stream.Collectors; @Service public class ChefMenuService { @@ -29,8 +33,8 @@ public class ChefMenuService { CuisineCategoriesRepository cuisineCategoriesRepository; @Autowired private ChefRepository chefRepository; - - + @Autowired + private RestTemplate restTemplate; public void saveChefMenuJson(ChefMenuRequest chefMenuRequest) throws Exception{ @@ -130,6 +134,20 @@ public ChefMenuGETResponse getChefMenuById(int id) return new ChefMenuGETResponse(); + } + public List getChefByCuisineId(int cuisineId, int zipCode) { + String url = "https://www.zipcodeapi.com/rest/Ze6ACQDfcjCFyzV7odLA4qyMLa6QraqkfHusGNor4GHrcy5w8XnT0pS0g9VOHkp1/radius.json/"+zipCode+"/6/mile"; + List chefMenu = chefMenuRepository.findAllByCuisineCategory_Id(cuisineId); + Set chefSet = chefMenu.stream().map(ChefMenu::getChef).collect(Collectors.toSet()); + Root zipCodeApiResponse = restTemplate.getForObject(url, Root.class); + List zipCodes = zipCodeApiResponse.getZip_codes().stream().map(ZipCode::getZip_code).collect(Collectors.toList()); + List chefList = new ArrayList<>(); + for(Chef chef:chefSet){ + if(zipCodes.contains(chef.getChef_zip())){ + chefList.add(chef); + } + } + return chefList; } public ChefMenuGETResponse getChefMenuByLoginId(long login_id) { Chef chef = new Chef(); diff --git a/src/main/java/ethniconnect_backend/DemoApplication.java b/src/main/java/ethniconnect_backend/DemoApplication.java index e716579..07b26b8 100644 --- a/src/main/java/ethniconnect_backend/DemoApplication.java +++ b/src/main/java/ethniconnect_backend/DemoApplication.java @@ -2,11 +2,16 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; @SpringBootApplication public class DemoApplication { - + @Bean + public RestTemplate restTemplate() { + return new RestTemplate(); + } public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } diff --git a/src/main/java/ethniconnect_backend/Zip/Root.java b/src/main/java/ethniconnect_backend/Zip/Root.java new file mode 100644 index 0000000..2d4443b --- /dev/null +++ b/src/main/java/ethniconnect_backend/Zip/Root.java @@ -0,0 +1,14 @@ +package ethniconnect_backend.Zip; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.ArrayList; +import java.util.List; +@Data +@NoArgsConstructor +@AllArgsConstructor +public class Root { + public ArrayList zip_codes; +} diff --git a/src/main/java/ethniconnect_backend/Zip/Zip.java b/src/main/java/ethniconnect_backend/Zip/Zip.java index 6b4e252..f44865a 100644 --- a/src/main/java/ethniconnect_backend/Zip/Zip.java +++ b/src/main/java/ethniconnect_backend/Zip/Zip.java @@ -5,10 +5,7 @@ import lombok.Data; import lombok.NoArgsConstructor; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; +import javax.persistence.*; import java.util.Set; @Entity @@ -19,6 +16,9 @@ public class Zip { @Id private int id; private int zipCode; - @OneToMany - Set cuisineCategory; + + @ManyToMany(cascade = CascadeType.ALL) + @JoinTable(name = "ZIP_CUISINE", joinColumns = { @JoinColumn(name = "zip_id") }, + inverseJoinColumns = { @JoinColumn(name = "cuisine_id") }) + private Set cuisineCategory; } diff --git a/src/main/java/ethniconnect_backend/Zip/ZipCode.java b/src/main/java/ethniconnect_backend/Zip/ZipCode.java new file mode 100644 index 0000000..93f8fdd --- /dev/null +++ b/src/main/java/ethniconnect_backend/Zip/ZipCode.java @@ -0,0 +1,16 @@ +package ethniconnect_backend.Zip; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ZipCode { + private String zip_code; + private Integer distance; + private String city; + private String state; + +} From 715972956a49ae51bb3084fce80605b1d3e05201 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 10 Apr 2022 17:45:57 -0400 Subject: [PATCH 42/69] working working --- .../CustomerDetails/Customer.java | 2 +- .../CustomerDetails/CustomerController.java | 9 ++ .../CustomerDetails/CustomerRepository.java | 2 + .../CustomerDetails/CustomerService.java | 11 ++- .../ethniconnect_backend/Order/Order.java | 9 +- .../Order/OrderController.java | 48 ---------- .../Order/OrderItems.java | 23 +++++ .../Order/OrderService.java | 93 ------------------- 8 files changed, 49 insertions(+), 148 deletions(-) delete mode 100644 src/main/java/ethniconnect_backend/Order/OrderController.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderItems.java delete mode 100644 src/main/java/ethniconnect_backend/Order/OrderService.java diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java index 0596522..45bcc18 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java @@ -19,7 +19,7 @@ public class Customer { @Id @GeneratedValue private int cust_id; - private long login_id; + private long loginid; private String cust_fname; private String cust_lname; private String cust_emailid; diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java index 5ecc3f9..e7573e3 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerController.java @@ -1,6 +1,7 @@ package ethniconnect_backend.CustomerDetails; +import ethniconnect_backend.ChefDetails.Chef; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -43,6 +44,14 @@ public Customer findCustById(@PathVariable int id) return customerService.getCustById(id); } + @GetMapping({"/custByLoginId/{id}"}) + + public Customer findCustomerByLoginId(@PathVariable int id) { + Long loginidlong = new Long(id); + return customerService.getCustomerByLoginId(id); + } + + @PutMapping("/updatecust") public Customer updateCust(@RequestBody Customer customer) { diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java index 5cfe323..142a5e5 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerRepository.java @@ -5,8 +5,10 @@ import org.springframework.data.jpa.repository.Query; import java.util.List; +import java.util.Optional; public interface CustomerRepository extends JpaRepository { + Optional findByLoginid(long loginid); } \ No newline at end of file diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java index 338ed49..44815a1 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java @@ -1,6 +1,7 @@ package ethniconnect_backend.CustomerDetails; +import ethniconnect_backend.ChefDetails.Chef; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; import ethniconnect_backend.UserCredentials.UserCredentials; import org.springframework.beans.factory.annotation.Autowired; @@ -30,7 +31,7 @@ public void saveCustomer(MultipartFile file, String fname, String lname, String throw new Exception("user Id doesn't exist"); Long loginId = userData.get().getLoginid(); - customer.setLogin_id(loginId); + customer.setLoginid(loginId); String fileName = StringUtils.cleanPath(file.getOriginalFilename()); if(fileName.contains("..")) { @@ -75,6 +76,14 @@ public List getCustomers() public Customer getCustById(int cust_id){ return customerRepository.findById(cust_id).orElse(null); } + + + public Customer getCustomerByLoginId(long loginid) { + + Optional customer = customerRepository.findByLoginid(loginid); + return customer.get(); + } + /*public Chef getChefByEmailId(String chef_emailid){ return chefProfileRepository.findByEmailId(chef_emailid); }*/ diff --git a/src/main/java/ethniconnect_backend/Order/Order.java b/src/main/java/ethniconnect_backend/Order/Order.java index 142fc76..dc610b5 100644 --- a/src/main/java/ethniconnect_backend/Order/Order.java +++ b/src/main/java/ethniconnect_backend/Order/Order.java @@ -25,12 +25,11 @@ public class Order { @Id @GeneratedValue private int order_id; - private long login_id; - private int cust_id; + private long chef_loginid; + private int cust_loginid; private int menu_id; private LocalDate order_date; - private LocalDateTime pickup_time; - private String order_instructions; + private double order_amount; /* @OneToOne(fetch = FetchType.LAZY, @@ -38,7 +37,7 @@ public class Order { mappedBy = "orders") private Customer customer;*/ @ManyToOne - @JoinColumn(name="cust_id", insertable = false, updatable = false) + @JoinColumn(name="loginid", insertable = false, updatable = false) private Customer customer; @ManyToMany @JoinTable( diff --git a/src/main/java/ethniconnect_backend/Order/OrderController.java b/src/main/java/ethniconnect_backend/Order/OrderController.java deleted file mode 100644 index d99e175..0000000 --- a/src/main/java/ethniconnect_backend/Order/OrderController.java +++ /dev/null @@ -1,48 +0,0 @@ -package ethniconnect_backend.Order; - -import ethniconnect_backend.ChefCreateMenu.*; -import ethniconnect_backend.ChefCreateMenu.OrderRequest; -import org.aspectj.weaver.ast.Or; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; -@RestController -public class OrderController { - - @Autowired - private OrderService orderService; - @Autowired - private OrderRepository orderRepository; - - @PostMapping("/order") - public ResponseEntity addOrder(@RequestBody OrderRequest orderRequest) throws Exception - { - - //chefMenuService.saveChefMenu(ch); - orderService.saveOrder(orderRequest); - - return new ResponseEntity<>("order is places successfully", HttpStatus.OK); - } - /* @PostMapping("/chefs") - public List addChefs(@RequestBody List chefs) - { - return chefProfileService.saveChefs(chefs); - }*/ - - @GetMapping({"/getOrderById/{id}"}) - public Order findOrderById(@PathVariable int id) - { - return orderService.getOrderById(id); - } - - @PutMapping("/updateorder") - public Order updateOrder(@RequestBody Order order) - { - return orderService.updateOrder(order); - } -} - - - - diff --git a/src/main/java/ethniconnect_backend/Order/OrderItems.java b/src/main/java/ethniconnect_backend/Order/OrderItems.java new file mode 100644 index 0000000..3b1feeb --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderItems.java @@ -0,0 +1,23 @@ +package ethniconnect_backend.Order; + +import ethniconnect_backend.ChefCreateMenu.MenuCategories; +import org.springframework.format.annotation.DateTimeFormat; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity (name = "order_items") +public class OrderItems { + @Id + @GeneratedValue + private int id; + private MenuCategories menucategory; + private String menu_item_name; + private String menu_item_image; + private String special_instructions; + private double item_price; + private int quantity; + +} + diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java deleted file mode 100644 index 7e1eda2..0000000 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ /dev/null @@ -1,93 +0,0 @@ -package ethniconnect_backend.Order; - -import ethniconnect_backend.ChefCreateMenu.ChefMenu; -import ethniconnect_backend.ChefCreateMenu.ChefMenuRepository; -import ethniconnect_backend.ChefCreateMenu.ChefMenuRequest; -import ethniconnect_backend.ChefCreateMenu.OrderRequest; -import ethniconnect_backend.Cuisines.CuisineCategoriesRepository; -import ethniconnect_backend.Cuisines.CuisineCategory; -import ethniconnect_backend.CustomerDetails.Customer; -import ethniconnect_backend.CustomerDetails.CustomerRepository; -import ethniconnect_backend.UserCredentials.UserCredentials; -import ethniconnect_backend.UserCredentials.UserCredentialsRepository; -import org.apache.maven.artifact.repository.Authentication; -import org.aspectj.weaver.ast.Or; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Service; - -import java.util.List; -import java.util.Optional; -@Service -public class OrderService { - - - - @Autowired - private ChefMenuRepository chefMenuRepository; - @Autowired - private UserCredentialsRepository userCredentialsRepository; - @Autowired - private CustomerRepository customerRepository; - - @Autowired - CuisineCategoriesRepository cuisineCategoriesRepository; - @Autowired - OrderRepository orderRepository; - - public Order saveOrder(OrderRequest orderRequest) throws Exception { - - - Optional userData = userCredentialsRepository.findById(orderRequest.getLogin_id()); - if (!userData.isPresent()) - throw new Exception("user Id doesn't exist"); - Customer customer = customerRepository.findById(orderRequest.getCust_id()).get(); - // Long loginId = userData.get().getId(); - if (customer == null) - throw new Exception("cuisine category doesn't exist"); - Order order = new Order(); - orderRequest.setLogin_id(orderRequest.getLogin_id()); - orderRequest.setCust_id(orderRequest.getCust_id()); - orderRequest.setMenu_id(orderRequest.getMenu_id()); - orderRequest.setOrder_instructions(orderRequest.getOrder_instructions()); - orderRequest.setOrder_date(orderRequest.getOrder_date()); - orderRequest.setPickup_time(orderRequest.getPickup_time()); - orderRequest.setOrder_amount(orderRequest.getOrder_amount()); - orderRequest.setLogin_id(orderRequest.getLogin_id()); - return orderRepository.save(order); - - - } - /* public List saveOrders(List orders){ - return OrderRepository.saveAll(orders); - }*/ - - public List getOrders() - { - return orderRepository.findAll(); - } - public Order getOrderById(int order_id){ - return orderRepository.findById(order_id).orElse(null); - } - - public String deleteorder(int order_id) - { - orderRepository.deleteById(order_id); - return "order deleted " + order_id; - } - public Order updateOrder(Order order) - { - Order existingOrder=orderRepository.findById(order.getOrder_id()).orElse(null); - existingOrder.setOrder_amount(order.getOrder_amount()); - existingOrder.setOrder_date(order.getOrder_date()); - existingOrder.setOrder_instructions(order.getOrder_instructions()); - existingOrder.setMenu_id(order.getMenu_id()); - existingOrder.setPickup_time(order.getPickup_time()); - existingOrder.setCust_id(order.getCust_id()); - - return orderRepository.save(existingOrder); - - } -} - - From 0b1ca3470775587068557925f69e0ccb63b23b3b Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Sun, 10 Apr 2022 19:04:02 -0400 Subject: [PATCH 43/69] working working --- .../ethniconnect_backend/CustomerDetails/Customer.java | 8 +++----- .../CustomerDetails/CustomerService.java | 2 +- src/main/java/ethniconnect_backend/Order/Order.java | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java index 45bcc18..19d2a07 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java @@ -17,8 +17,6 @@ @Table(name = "customer",uniqueConstraints= {@UniqueConstraint(columnNames = {"cust_emailid","cust_phone"})}) public class Customer { @Id - @GeneratedValue - private int cust_id; private long loginid; private String cust_fname; private String cust_lname; @@ -35,8 +33,8 @@ public class Customer { private String cust_image; /*@OneToMany(fetch = FetchType.LAZY, mappedBy = "customer") private List orders;*/ - @OneToMany(mappedBy = "customer", fetch = FetchType.LAZY, - cascade = CascadeType.ALL) - private Set orders; +// @OneToMany(mappedBy = "customer", fetch = FetchType.LAZY, +// cascade = CascadeType.ALL) +// private Set orders; } diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java index 44815a1..484708f 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/CustomerService.java @@ -94,7 +94,7 @@ public String deleteCust(int cust_id) } public Customer updateCust(Customer customer) { - Customer existingCustomer=customerRepository.findById(customer.getCust_id()).orElse(null); + Customer existingCustomer=customerRepository.findByLoginid(customer.getLoginid()).orElse(null); existingCustomer.setCust_fname(customer.getCust_fname()!=null?customer.getCust_fname():existingCustomer.getCust_fname()); existingCustomer.setCust_lname(customer.getCust_lname()!=null?customer.getCust_lname():existingCustomer.getCust_lname()); diff --git a/src/main/java/ethniconnect_backend/Order/Order.java b/src/main/java/ethniconnect_backend/Order/Order.java index dc610b5..525ebf8 100644 --- a/src/main/java/ethniconnect_backend/Order/Order.java +++ b/src/main/java/ethniconnect_backend/Order/Order.java @@ -25,8 +25,8 @@ public class Order { @Id @GeneratedValue private int order_id; - private long chef_loginid; - private int cust_loginid; +// private long chef_loginid; +// private int cust_loginid; private int menu_id; private LocalDate order_date; From 1d71ee9afa04cdbad34ae505807dca181cb58ab5 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 11 Apr 2022 00:50:41 -0400 Subject: [PATCH 44/69] place order working --- .../ChefDetails/Chef.java | 4 -- .../ChefDetails/ChefRepository.java | 2 - .../Login/LoginService.java | 3 + .../ethniconnect_backend/Order/Order.java | 46 +++++++-------- .../Order/OrderController.java | 23 ++++++++ .../ethniconnect_backend/Order/OrderItem.java | 28 ++++++++++ .../Order/OrderItems.java | 23 -------- .../Order/OrderItemsRepository.java | 6 ++ .../Order/OrderItemsRequest.java | 18 ++++++ .../Order/OrderItemsService.java | 18 ++++++ .../Order/OrderRepository.java | 2 - .../Order/OrderRequest.java | 20 ++----- .../Order/OrderService.java | 56 +++++++++++++++++++ .../Order/PlaceOrderRequest.java | 16 ++++++ src/main/resources/application.yml | 2 +- 15 files changed, 196 insertions(+), 71 deletions(-) create mode 100644 src/main/java/ethniconnect_backend/Order/OrderController.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderItem.java delete mode 100644 src/main/java/ethniconnect_backend/Order/OrderItems.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderItemsRequest.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderItemsService.java create mode 100644 src/main/java/ethniconnect_backend/Order/OrderService.java create mode 100644 src/main/java/ethniconnect_backend/Order/PlaceOrderRequest.java diff --git a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java index 0517c56..36a5195 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/Chef.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/Chef.java @@ -11,11 +11,7 @@ @AllArgsConstructor @Entity @Table(name = "chef",uniqueConstraints= {@UniqueConstraint(columnNames = {"chef_emailid","chef_phone"})}) - public class Chef { -// @Id -// @GeneratedValue -// private int chef_id; @Id private long loginid; private String chef_fname; diff --git a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java index 41c797e..9544195 100644 --- a/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java +++ b/src/main/java/ethniconnect_backend/ChefDetails/ChefRepository.java @@ -1,9 +1,7 @@ package ethniconnect_backend.ChefDetails; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import java.util.List; import java.util.Optional; public interface ChefRepository extends JpaRepository { diff --git a/src/main/java/ethniconnect_backend/Login/LoginService.java b/src/main/java/ethniconnect_backend/Login/LoginService.java index 45453fd..64c88e7 100644 --- a/src/main/java/ethniconnect_backend/Login/LoginService.java +++ b/src/main/java/ethniconnect_backend/Login/LoginService.java @@ -1,4 +1,7 @@ package ethniconnect_backend.Login; +import org.springframework.stereotype.Service; + + public class LoginService { } diff --git a/src/main/java/ethniconnect_backend/Order/Order.java b/src/main/java/ethniconnect_backend/Order/Order.java index 525ebf8..352919a 100644 --- a/src/main/java/ethniconnect_backend/Order/Order.java +++ b/src/main/java/ethniconnect_backend/Order/Order.java @@ -1,8 +1,6 @@ package ethniconnect_backend.Order; - -import ethniconnect_backend.ChefCreateMenu.ChefMenu; -import ethniconnect_backend.Cuisines.CuisineCategory; +import ethniconnect_backend.ChefDetails.Chef; import ethniconnect_backend.CustomerDetails.Customer; import lombok.AllArgsConstructor; import lombok.Data; @@ -11,38 +9,36 @@ import javax.persistence.*; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; -import java.util.Set; @Data @NoArgsConstructor @AllArgsConstructor @Entity -@Table(name = "order") +@Table(name = "orders") public class Order { + @Id @GeneratedValue - private int order_id; -// private long chef_loginid; -// private int cust_loginid; - private int menu_id; - private LocalDate order_date; - + private int orderid; + private LocalDateTime order_date; private double order_amount; + private long cust_loginid; + private long chef_loginid; + + + @OneToMany(cascade = CascadeType.ALL,orphanRemoval = true) + @JoinColumn(name = "order_id",referencedColumnName = "orderid",insertable = false,updatable = false) + private List orderItems; + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "cust_loginid", referencedColumnName = "loginid", insertable = false, updatable = false) + private Customer customer; + + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "chef_loginid", referencedColumnName = "loginid", insertable = false, updatable = false) + private Chef chef; + + - /* @OneToOne(fetch = FetchType.LAZY, - cascade = CascadeType.ALL, - mappedBy = "orders") - private Customer customer;*/ - @ManyToOne - @JoinColumn(name="loginid", insertable = false, updatable = false) - private Customer customer; - @ManyToMany - @JoinTable( - name = "order_menu", - joinColumns = @JoinColumn(name = "order_id"), - inverseJoinColumns = @JoinColumn(name = "id")) - Set menu_items; } diff --git a/src/main/java/ethniconnect_backend/Order/OrderController.java b/src/main/java/ethniconnect_backend/Order/OrderController.java new file mode 100644 index 0000000..fd6bbf1 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderController.java @@ -0,0 +1,23 @@ +package ethniconnect_backend.Order; + +import ethniconnect_backend.ChefCreateMenu.OrderRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class OrderController { + + @Autowired + public OrderService orderService; + + @PostMapping("/placeOrder") + public ResponseEntity placeOrder(@RequestBody OrderRequest orderRequest) + { + int orderid= orderService.placeOrder(orderRequest); + return new ResponseEntity(orderid, HttpStatus.OK); + } +} diff --git a/src/main/java/ethniconnect_backend/Order/OrderItem.java b/src/main/java/ethniconnect_backend/Order/OrderItem.java new file mode 100644 index 0000000..2a05b21 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderItem.java @@ -0,0 +1,28 @@ +package ethniconnect_backend.Order; + +import ethniconnect_backend.ChefCreateMenu.ChefMenu; +import lombok.Setter; + +import javax.persistence.*; + +@Setter +@Entity (name = "order_items") +public class OrderItem { + @Id + @GeneratedValue + private int order_item_id; + private int menu_id; + private int order_id; + private String special_instructions; + private int quantity; + @ManyToOne + @JoinColumn(name = "order_id",referencedColumnName = "orderid",insertable = false,updatable = false) + private Order order; + + @OneToOne + @JoinColumn(name = "menu_id",referencedColumnName = "id",insertable = false,updatable = false) + private ChefMenu chefMenu; + + +} + diff --git a/src/main/java/ethniconnect_backend/Order/OrderItems.java b/src/main/java/ethniconnect_backend/Order/OrderItems.java deleted file mode 100644 index 3b1feeb..0000000 --- a/src/main/java/ethniconnect_backend/Order/OrderItems.java +++ /dev/null @@ -1,23 +0,0 @@ -package ethniconnect_backend.Order; - -import ethniconnect_backend.ChefCreateMenu.MenuCategories; -import org.springframework.format.annotation.DateTimeFormat; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -@Entity (name = "order_items") -public class OrderItems { - @Id - @GeneratedValue - private int id; - private MenuCategories menucategory; - private String menu_item_name; - private String menu_item_image; - private String special_instructions; - private double item_price; - private int quantity; - -} - diff --git a/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java b/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java new file mode 100644 index 0000000..16fd3a2 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java @@ -0,0 +1,6 @@ +package ethniconnect_backend.Order; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface OrderItemsRepository extends JpaRepository { +} diff --git a/src/main/java/ethniconnect_backend/Order/OrderItemsRequest.java b/src/main/java/ethniconnect_backend/Order/OrderItemsRequest.java new file mode 100644 index 0000000..77eacc6 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderItemsRequest.java @@ -0,0 +1,18 @@ +package ethniconnect_backend.Order; + +import lombok.*; + +@Data +@Builder +@Getter +@Setter +@AllArgsConstructor +@ToString +public class OrderItemsRequest { + + private double price; + private int quantity; + private int order_id; + private int menu_id; + +} diff --git a/src/main/java/ethniconnect_backend/Order/OrderItemsService.java b/src/main/java/ethniconnect_backend/Order/OrderItemsService.java new file mode 100644 index 0000000..b1f9263 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderItemsService.java @@ -0,0 +1,18 @@ +package ethniconnect_backend.Order; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.transaction.Transactional; + +@Service +@Transactional +public class OrderItemsService { + + @Autowired + private OrderItemsRepository orderItemsRepository; + + public void addOrderedProducts(OrderItem orderItem) { + orderItemsRepository.save(orderItem); + } +} \ No newline at end of file diff --git a/src/main/java/ethniconnect_backend/Order/OrderRepository.java b/src/main/java/ethniconnect_backend/Order/OrderRepository.java index a0b472a..9865061 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderRepository.java +++ b/src/main/java/ethniconnect_backend/Order/OrderRepository.java @@ -1,9 +1,7 @@ package ethniconnect_backend.Order; -import ethniconnect_backend.ChefCreateMenu.ChefMenu; import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; public interface OrderRepository extends JpaRepository { diff --git a/src/main/java/ethniconnect_backend/Order/OrderRequest.java b/src/main/java/ethniconnect_backend/Order/OrderRequest.java index 173f4c5..1d393eb 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderRequest.java +++ b/src/main/java/ethniconnect_backend/Order/OrderRequest.java @@ -1,29 +1,21 @@ package ethniconnect_backend.ChefCreateMenu; -import ethniconnect_backend.Cuisines.CuisineCategory; +import ethniconnect_backend.Order.OrderItem; import lombok.*; -import javax.persistence.*; -import java.time.LocalDate; -import java.time.LocalDateTime; - +import java.util.List; @Data @Builder @Getter @Setter @AllArgsConstructor @ToString - public class OrderRequest { - private int order_id; - private long login_id; - private int cust_id; - private int menu_id; - private LocalDate order_date; - private LocalDateTime pickup_time; - private String order_instructions; - private double order_amount; + private long chefLoginid; + private long customerLoginid; + private double totalprice; + private List orderItems; } diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java new file mode 100644 index 0000000..fa3ea11 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -0,0 +1,56 @@ +package ethniconnect_backend.Order; + +import ethniconnect_backend.ChefCreateMenu.*; +import ethniconnect_backend.ChefCreateMenu.OrderRequest; +import ethniconnect_backend.ChefDetails.Chef; +import ethniconnect_backend.ChefDetails.ChefRepository; +import ethniconnect_backend.Cuisines.CuisineCategoriesRepository; +import ethniconnect_backend.Cuisines.CuisineCategory; +import ethniconnect_backend.UserCredentials.UserCredentials; +import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import java.io.IOException; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.util.Base64; +import java.util.Optional; + +@Service +public class OrderService { + @Autowired + private ChefMenuRepository chefMenuRepository; + @Autowired + private UserCredentialsRepository userCredentialsRepository; + + @Autowired + CuisineCategoriesRepository cuisineCategoriesRepository; + @Autowired + private ChefRepository chefRepository; + @Autowired + private OrderRepository orderRepository; + + + @Autowired + OrderItemsService orderItemsService; + + public Integer placeOrder(OrderRequest orderRequest) { + + Order order = new Order(); + order.setOrder_amount(orderRequest.getTotalprice()); + order.setChef_loginid(orderRequest.getChefLoginid()); + order.setCust_loginid(orderRequest.getCustomerLoginid()); + order.setOrderItems(orderRequest.getOrderItems()); + order.setOrder_date(LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC)); + //order.setId(1); + orderRepository.save(order); + return 1; + + + + } +} \ No newline at end of file diff --git a/src/main/java/ethniconnect_backend/Order/PlaceOrderRequest.java b/src/main/java/ethniconnect_backend/Order/PlaceOrderRequest.java new file mode 100644 index 0000000..1fbabea --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/PlaceOrderRequest.java @@ -0,0 +1,16 @@ +package ethniconnect_backend.Order; + +import lombok.*; + +@Data +@Builder +@Getter +@Setter +@AllArgsConstructor +@ToString +public class PlaceOrderRequest { + private int id; + private long cust_loginid; + private double totalPrice; + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6c6f0ce..aa4e801 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,7 +17,7 @@ spring: username: root jpa: hibernate: - ddl-auto: update + ddl-auto: create-drop properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect From bed30256d70e089baa22bf600cf2a0da78e06189 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 11 Apr 2022 01:06:11 -0400 Subject: [PATCH 45/69] get order details working --- .../ethniconnect_backend/Order/OrderController.java | 11 ++++++++--- .../ethniconnect_backend/Order/OrderRepository.java | 3 ++- .../java/ethniconnect_backend/Order/OrderService.java | 5 +++++ src/main/resources/application.yml | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/ethniconnect_backend/Order/OrderController.java b/src/main/java/ethniconnect_backend/Order/OrderController.java index fd6bbf1..d5c6e53 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderController.java +++ b/src/main/java/ethniconnect_backend/Order/OrderController.java @@ -4,9 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController public class OrderController { @@ -20,4 +18,11 @@ public ResponseEntity placeOrder(@RequestBody OrderRequest orderRequest int orderid= orderService.placeOrder(orderRequest); return new ResponseEntity(orderid, HttpStatus.OK); } + + @GetMapping("/order/{orderid}") + public ResponseEntity getOrder(@PathVariable int orderid) + { + + return new ResponseEntity(orderService.getOrder(orderid), HttpStatus.OK); + } } diff --git a/src/main/java/ethniconnect_backend/Order/OrderRepository.java b/src/main/java/ethniconnect_backend/Order/OrderRepository.java index 9865061..e01684b 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderRepository.java +++ b/src/main/java/ethniconnect_backend/Order/OrderRepository.java @@ -2,9 +2,10 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; public interface OrderRepository extends JpaRepository { - //Optional findOrderById(Integer id); + Optional findByOrderid(int id); } diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java index fa3ea11..7da61f3 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -53,4 +53,9 @@ public Integer placeOrder(OrderRequest orderRequest) { } + + public Order getOrder(int orderid) { + + return orderRepository.findByOrderid(orderid).get(); + } } \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index aa4e801..6c6f0ce 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -17,7 +17,7 @@ spring: username: root jpa: hibernate: - ddl-auto: create-drop + ddl-auto: update properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect From 8085d585a7a7fab760df20fb95e4ae9cda35ac0b Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 11 Apr 2022 08:17:25 -0400 Subject: [PATCH 46/69] no errors working working --- src/main/java/ethniconnect_backend/Order/OrderItemsService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ethniconnect_backend/Order/OrderItemsService.java b/src/main/java/ethniconnect_backend/Order/OrderItemsService.java index b1f9263..90bf04a 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItemsService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItemsService.java @@ -13,6 +13,8 @@ public class OrderItemsService { private OrderItemsRepository orderItemsRepository; public void addOrderedProducts(OrderItem orderItem) { + Order order = new Order(); + orderItem.setOrder_id(order.getOrderid()); orderItemsRepository.save(orderItem); } } \ No newline at end of file From 1aa5169061a0d6a2faba6955cfe88c9c957d4866 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 11 Apr 2022 08:39:30 -0400 Subject: [PATCH 47/69] working all merged working --- src/main/resources/application.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4003e45..6c6f0ce 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8500 + port: 8080 error: include-message: always include-binding-errors: always @@ -10,14 +10,14 @@ server: spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver - password: Saranya1994 + password: bharani16 initialization-mode: ALWAYS url: jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect username: root jpa: hibernate: - ddl-auto: create-drop + ddl-auto: update properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect From 3b5c2c9023cdf684914a52525b8c10d43051b6df Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 11 Apr 2022 17:17:03 -0400 Subject: [PATCH 48/69] order addition working --- .../ChefCreateMenu/ChefMenu.java | 4 +- .../CustomerDetails/Customer.java | 4 -- .../Order/OrderController.java | 5 +-- .../ethniconnect_backend/Order/OrderItem.java | 24 +++++++++--- .../Order/OrderItemsRepository.java | 3 ++ .../Order/OrderItemsService.java | 4 +- .../Order/OrderRepository.java | 4 +- .../Order/OrderRequest.java | 4 +- .../Order/OrderService.java | 37 +++++++++++-------- .../Order/{Order.java => Orders.java} | 11 ++++-- .../email/EmailService.java | 2 + 11 files changed, 60 insertions(+), 42 deletions(-) rename src/main/java/ethniconnect_backend/Order/{Order.java => Orders.java} (77%) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java index c4c022b..0516f79 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java @@ -2,14 +2,11 @@ import ethniconnect_backend.ChefDetails.Chef; import ethniconnect_backend.Cuisines.CuisineCategory; -import ethniconnect_backend.Order.Order; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import javax.persistence.*; -import java.util.List; -import java.util.Set; @Data @NoArgsConstructor @@ -50,4 +47,5 @@ public class ChefMenu { inverseJoinColumns = @JoinColumn(name = "cuisine_id")) Set selectedCuisines;*/ + } diff --git a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java index 19d2a07..5b9428b 100644 --- a/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java +++ b/src/main/java/ethniconnect_backend/CustomerDetails/Customer.java @@ -1,14 +1,10 @@ package ethniconnect_backend.CustomerDetails; -import ethniconnect_backend.ChefCreateMenu.ChefMenu; -import ethniconnect_backend.Order.Order; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import javax.persistence.*; -import java.util.List; -import java.util.Set; @Data @NoArgsConstructor diff --git a/src/main/java/ethniconnect_backend/Order/OrderController.java b/src/main/java/ethniconnect_backend/Order/OrderController.java index d5c6e53..1189100 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderController.java +++ b/src/main/java/ethniconnect_backend/Order/OrderController.java @@ -1,6 +1,5 @@ package ethniconnect_backend.Order; -import ethniconnect_backend.ChefCreateMenu.OrderRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -20,9 +19,9 @@ public ResponseEntity placeOrder(@RequestBody OrderRequest orderRequest } @GetMapping("/order/{orderid}") - public ResponseEntity getOrder(@PathVariable int orderid) + public ResponseEntity getOrder(@PathVariable int orderid) { - return new ResponseEntity(orderService.getOrder(orderid), HttpStatus.OK); + return new ResponseEntity(orderService.getOrder(orderid), HttpStatus.OK); } } diff --git a/src/main/java/ethniconnect_backend/Order/OrderItem.java b/src/main/java/ethniconnect_backend/Order/OrderItem.java index 2a05b21..46a027f 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItem.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItem.java @@ -2,6 +2,7 @@ import ethniconnect_backend.ChefCreateMenu.ChefMenu; import lombok.Setter; +import org.springframework.transaction.annotation.Transactional; import javax.persistence.*; @@ -10,19 +11,30 @@ public class OrderItem { @Id @GeneratedValue - private int order_item_id; + private int orderitemid; private int menu_id; - private int order_id; + private int orderid; private String special_instructions; private int quantity; - @ManyToOne - @JoinColumn(name = "order_id",referencedColumnName = "orderid",insertable = false,updatable = false) - private Order order; +// @ManyToOne +// @JoinColumn(name = "orderid",referencedColumnName = "orderid",insertable = false,updatable = false) +// private Orders order; + + - @OneToOne + //@OneToOne + @ManyToOne @JoinColumn(name = "menu_id",referencedColumnName = "id",insertable = false,updatable = false) private ChefMenu chefMenu; + @ManyToOne(fetch = FetchType.LAZY) + + @JoinColumn(name = "orderid",referencedColumnName = "orderid",insertable = false,updatable = false) + //@JoinColumn (name = "orderid",insertable = false,updatable = false) + private Orders orders; + public Orders getOrders() { + return orders; + } } diff --git a/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java b/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java index 16fd3a2..cf48909 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java @@ -2,5 +2,8 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface OrderItemsRepository extends JpaRepository { + } diff --git a/src/main/java/ethniconnect_backend/Order/OrderItemsService.java b/src/main/java/ethniconnect_backend/Order/OrderItemsService.java index 90bf04a..25cd15b 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItemsService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItemsService.java @@ -13,8 +13,8 @@ public class OrderItemsService { private OrderItemsRepository orderItemsRepository; public void addOrderedProducts(OrderItem orderItem) { - Order order = new Order(); - orderItem.setOrder_id(order.getOrderid()); + Orders order = new Orders(); + //orderItem.setOrderid(order.getOrderid()); orderItemsRepository.save(orderItem); } } \ No newline at end of file diff --git a/src/main/java/ethniconnect_backend/Order/OrderRepository.java b/src/main/java/ethniconnect_backend/Order/OrderRepository.java index e01684b..6eab463 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderRepository.java +++ b/src/main/java/ethniconnect_backend/Order/OrderRepository.java @@ -5,7 +5,7 @@ import java.util.Optional; -public interface OrderRepository extends JpaRepository { +public interface OrderRepository extends JpaRepository { - Optional findByOrderid(int id); + Optional findById(int id); } diff --git a/src/main/java/ethniconnect_backend/Order/OrderRequest.java b/src/main/java/ethniconnect_backend/Order/OrderRequest.java index 1d393eb..274be68 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderRequest.java +++ b/src/main/java/ethniconnect_backend/Order/OrderRequest.java @@ -1,6 +1,5 @@ -package ethniconnect_backend.ChefCreateMenu; +package ethniconnect_backend.Order; -import ethniconnect_backend.Order.OrderItem; import lombok.*; import java.util.List; @@ -14,6 +13,7 @@ public class OrderRequest { private long chefLoginid; private long customerLoginid; + private int orderid; private double totalprice; private List orderItems; diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java index 7da61f3..0f18e01 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -1,25 +1,18 @@ package ethniconnect_backend.Order; import ethniconnect_backend.ChefCreateMenu.*; -import ethniconnect_backend.ChefCreateMenu.OrderRequest; -import ethniconnect_backend.ChefDetails.Chef; import ethniconnect_backend.ChefDetails.ChefRepository; import ethniconnect_backend.Cuisines.CuisineCategoriesRepository; -import ethniconnect_backend.Cuisines.CuisineCategory; -import ethniconnect_backend.UserCredentials.UserCredentials; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.util.StringUtils; +import org.springframework.transaction.annotation.Transactional; -import java.io.IOException; import java.time.Instant; -import java.time.LocalDate; import java.time.LocalDateTime; import java.time.ZoneOffset; -import java.util.Base64; -import java.util.Optional; +@Transactional @Service public class OrderService { @Autowired @@ -34,28 +27,40 @@ public class OrderService { @Autowired private OrderRepository orderRepository; + @Autowired + private OrderItemsRepository orderItemsRepository; + @Autowired OrderItemsService orderItemsService; - + @Transactional public Integer placeOrder(OrderRequest orderRequest) { - Order order = new Order(); + Orders order = new Orders(); + + //orderRequest.setOrderid(order.getOrderid()); order.setOrder_amount(orderRequest.getTotalprice()); order.setChef_loginid(orderRequest.getChefLoginid()); order.setCust_loginid(orderRequest.getCustomerLoginid()); - order.setOrderItems(orderRequest.getOrderItems()); + //order.setOrderItems(orderRequest.getOrderItems()); + order.setOrder_date(LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC)); //order.setId(1); - orderRepository.save(order); - return 1; + Orders savedOrder = orderRepository.save(order); + + for(OrderItem orderItem:orderRequest.getOrderItems()) + { + orderItem.setOrderid(savedOrder.getOrderid()); + orderItemsRepository.save(orderItem); + } + return savedOrder.getOrderid(); } - public Order getOrder(int orderid) { + public Orders getOrder(int orderid) { - return orderRepository.findByOrderid(orderid).get(); + return orderRepository.findById(orderid).get(); } } \ No newline at end of file diff --git a/src/main/java/ethniconnect_backend/Order/Order.java b/src/main/java/ethniconnect_backend/Order/Orders.java similarity index 77% rename from src/main/java/ethniconnect_backend/Order/Order.java rename to src/main/java/ethniconnect_backend/Order/Orders.java index 352919a..356995e 100644 --- a/src/main/java/ethniconnect_backend/Order/Order.java +++ b/src/main/java/ethniconnect_backend/Order/Orders.java @@ -17,7 +17,7 @@ @AllArgsConstructor @Entity @Table(name = "orders") -public class Order { +public class Orders { @Id @GeneratedValue @@ -28,9 +28,11 @@ public class Order { private long chef_loginid; - @OneToMany(cascade = CascadeType.ALL,orphanRemoval = true) - @JoinColumn(name = "order_id",referencedColumnName = "orderid",insertable = false,updatable = false) - private List orderItems; +// @OneToMany(mappedBy = "orders",cascade=CascadeType.ALL,orphanRemoval = true) +// // +// //@JoinColumn(name = "orderid", referencedColumnName = "orderid", insertable = false, updatable = false) +// private List orderItems; + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "cust_loginid", referencedColumnName = "loginid", insertable = false, updatable = false) private Customer customer; @@ -41,4 +43,5 @@ public class Order { + } diff --git a/src/main/java/ethniconnect_backend/email/EmailService.java b/src/main/java/ethniconnect_backend/email/EmailService.java index 25da61b..8606a7a 100644 --- a/src/main/java/ethniconnect_backend/email/EmailService.java +++ b/src/main/java/ethniconnect_backend/email/EmailService.java @@ -1,6 +1,7 @@ package ethniconnect_backend.email; import lombok.AllArgsConstructor; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.mail.javamail.JavaMailSender; @@ -20,6 +21,7 @@ public class EmailService implements EmailSender{ private final JavaMailSender mailSender; public String buildContactEmail(String message,String useremailid) { + return "
\n" + "\n" + "\n" + From 51b082f806f99dcbfeb099c1d90593d90bab3d33 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 11 Apr 2022 18:09:02 -0400 Subject: [PATCH 49/69] working working --- .../ethniconnect_backend/Order/OrderItem.java | 16 +++------------- .../Order/OrderRepository.java | 2 +- .../ethniconnect_backend/Order/OrderService.java | 2 +- .../java/ethniconnect_backend/Order/Orders.java | 9 +++++---- src/main/resources/application.yml | 2 +- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/main/java/ethniconnect_backend/Order/OrderItem.java b/src/main/java/ethniconnect_backend/Order/OrderItem.java index 46a027f..b8e0833 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItem.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItem.java @@ -16,25 +16,15 @@ public class OrderItem { private int orderid; private String special_instructions; private int quantity; -// @ManyToOne -// @JoinColumn(name = "orderid",referencedColumnName = "orderid",insertable = false,updatable = false) -// private Orders order; - - - //@OneToOne @ManyToOne @JoinColumn(name = "menu_id",referencedColumnName = "id",insertable = false,updatable = false) private ChefMenu chefMenu; - @ManyToOne(fetch = FetchType.LAZY) +// @ManyToOne +// @JoinColumn(name = "orderid",referencedColumnName = "orderid",insertable = false,updatable = false) +// private Orders orders; - @JoinColumn(name = "orderid",referencedColumnName = "orderid",insertable = false,updatable = false) - //@JoinColumn (name = "orderid",insertable = false,updatable = false) - private Orders orders; - public Orders getOrders() { - return orders; - } } diff --git a/src/main/java/ethniconnect_backend/Order/OrderRepository.java b/src/main/java/ethniconnect_backend/Order/OrderRepository.java index 6eab463..dce6922 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderRepository.java +++ b/src/main/java/ethniconnect_backend/Order/OrderRepository.java @@ -7,5 +7,5 @@ public interface OrderRepository extends JpaRepository { - Optional findById(int id); + Optional findByOrderid(int id); } diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java index 0f18e01..e2e43e7 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -61,6 +61,6 @@ public Integer placeOrder(OrderRequest orderRequest) { public Orders getOrder(int orderid) { - return orderRepository.findById(orderid).get(); + return orderRepository.findByOrderid(orderid).get(); } } \ No newline at end of file diff --git a/src/main/java/ethniconnect_backend/Order/Orders.java b/src/main/java/ethniconnect_backend/Order/Orders.java index 356995e..9f096a6 100644 --- a/src/main/java/ethniconnect_backend/Order/Orders.java +++ b/src/main/java/ethniconnect_backend/Order/Orders.java @@ -8,6 +8,7 @@ import javax.persistence.*; +import javax.transaction.Transactional; import java.time.LocalDateTime; import java.util.List; @@ -17,6 +18,7 @@ @AllArgsConstructor @Entity @Table(name = "orders") +@Transactional public class Orders { @Id @@ -28,10 +30,9 @@ public class Orders { private long chef_loginid; -// @OneToMany(mappedBy = "orders",cascade=CascadeType.ALL,orphanRemoval = true) -// // -// //@JoinColumn(name = "orderid", referencedColumnName = "orderid", insertable = false, updatable = false) -// private List orderItems; + @OneToMany + @JoinColumn(name = "orderid", referencedColumnName = "orderid", insertable = false, updatable = false) + private List orderItems; @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "cust_loginid", referencedColumnName = "loginid", insertable = false, updatable = false) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 6c6f0ce..4ef2b03 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -39,7 +39,7 @@ spring: host: smtp.gmail.com port: 587 username: ethniconnect@gmail.com - password: nftvtqgflwntjipb + password: jbjkxybezpvligxn properties: From 077c2be9059be9d2a8bb76bdfad813b960537ad6 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 11 Apr 2022 18:11:05 -0400 Subject: [PATCH 50/69] contact email update working --- src/main/java/ethniconnect_backend/email/EmailService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ethniconnect_backend/email/EmailService.java b/src/main/java/ethniconnect_backend/email/EmailService.java index 8606a7a..732442b 100644 --- a/src/main/java/ethniconnect_backend/email/EmailService.java +++ b/src/main/java/ethniconnect_backend/email/EmailService.java @@ -110,7 +110,7 @@ public String buildEmail(String name, String link) { " \n" + " \n" + " \n" + - " Confirm your email\n" + + " Contact Request\n" + " \n" + " \n" + " \n" + From eb3bc6d66ff2b09be9a23d07966d4d98ec482481 Mon Sep 17 00:00:00 2001 From: Saranya1994 Date: Mon, 11 Apr 2022 21:26:53 -0400 Subject: [PATCH 51/69] API key change API key change --- .DS_Store | Bin 6148 -> 6148 bytes src/.DS_Store | Bin 6148 -> 6148 bytes src/main/.DS_Store | Bin 6148 -> 6148 bytes src/main/java/.DS_Store | Bin 6148 -> 6148 bytes src/main/java/ethniconnect_backend/.DS_Store | Bin 8196 -> 8196 bytes .../ChefCreateMenu/ChefMenuService.java | 2 +- src/main/resources/application.yml | 5 +++-- 7 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.DS_Store b/.DS_Store index 27275abf4abb675cd26425711cf74519bd683e96..a9114bd1dcbbbe2ee58a0a35f9a6b5c2e76f9739 100644 GIT binary patch delta 20 bcmZoMXffE(!pd%Lp`&1AY__?ZwNeNGK$Hc| delta 20 bcmZoMXffE(!pd%9siRK*lhE4CS6egMQ{cd delta 20 bcmZoMXffDufr;J3Qb)na%yjd0CS6egMP>#T diff --git a/src/main/.DS_Store b/src/main/.DS_Store index 6320f374eaf4dc15e2d6207d3cb0a2307a8fbd06..c8daf0b4d00cfb556cbac3178db52c8c3488e020 100644 GIT binary patch delta 20 bcmZoMXffDufr;JRLPx>K*lhE4CS6egMQ{cd delta 20 bcmZoMXffDufr;J3Qb)na%yjd0CS6egMP>#T diff --git a/src/main/java/.DS_Store b/src/main/java/.DS_Store index 74e42ed1c1ab85fe5f243d6f30021da48dd65d1c..e8fa240eaaaa2850d79372ec42f48d2e6c384923 100644 GIT binary patch delta 20 bcmZoMXffCzz|3xLp`&1AY_?gP`K<^5IKTy0 delta 20 bcmZoMXffCzz|3x9siR diff --git a/src/main/java/ethniconnect_backend/.DS_Store b/src/main/java/ethniconnect_backend/.DS_Store index ae5bac9dc5464b624bafd3d35bf185288ee61eb5..f68ae5586e3391f1a9abe5ca6c8bd70e2baaeb2f 100644 GIT binary patch delta 20 bcmZp1XmQx^LxA1fLPx>K*lhEE0akthOF#y6 delta 20 bcmZp1XmQx^LxA1HQb)na%yjdA0akthOEv~{ diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index ef3a3d9..16fb77f 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -136,7 +136,7 @@ public ChefMenuGETResponse getChefMenuById(int id) } public List getChefByCuisineId(int cuisineId, int zipCode) { - String url = "https://www.zipcodeapi.com/rest/Ze6ACQDfcjCFyzV7odLA4qyMLa6QraqkfHusGNor4GHrcy5w8XnT0pS0g9VOHkp1/radius.json/"+zipCode+"/6/mile"; + String url = "https://www.zipcodeapi.com/rest/pD8BE4nACZcPt5FtIIhB5n10wXpPERTDFeLyuBhQq2ueQzpSozsD5weTv6keaU6N/radius.json/"+zipCode+"/6/mile"; List chefMenu = chefMenuRepository.findAllByCuisineCategory_Id(cuisineId); Set chefSet = chefMenu.stream().map(ChefMenu::getChef).collect(Collectors.toSet()); Root zipCodeApiResponse = restTemplate.getForObject(url, Root.class); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4003e45..0a1d427 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8500 + port: 8501 error: include-message: always include-binding-errors: always @@ -14,10 +14,11 @@ spring: initialization-mode: ALWAYS url: jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect + #ethni-connect.ciff6u6uo7qd.us-east-2.rds.amazonaws.com (new updated saranya's) username: root jpa: hibernate: - ddl-auto: create-drop + ddl-auto: update properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect From 2ec6cb703f7a5baafa685e12cba8b187970842cf Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Mon, 11 Apr 2022 21:49:02 -0400 Subject: [PATCH 52/69] email working email working --- .../ContactPage/ContactService.java | 6 +--- .../Resetpassword/ResetPasswordService.java | 2 +- .../email/EmailSender.java | 2 ++ .../email/EmailService.java | 33 ++++++++++++++++++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java index abccdde..68d6812 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java @@ -1,11 +1,8 @@ package ethniconnect_backend.ContactPage; -import ethniconnect_backend.ChefSignup.ChefSignupRequest; import ethniconnect_backend.ChefSignup.EmailValidator; import ethniconnect_backend.ChefSignup.token.ConfirmationTokenService; -import ethniconnect_backend.UserCredentials.UserCredentials; import ethniconnect_backend.UserCredentials.UserCredentialsService; -import ethniconnect_backend.UserCredentials.UserRole; import ethniconnect_backend.email.EmailSender; import ethniconnect_backend.email.EmailService; @@ -13,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.xml.transform.sax.SAXTransformerFactory; import java.util.List; @Service @@ -69,7 +65,7 @@ public void saveContactRequest(Contact contact) { contactRepository.save(contact); - emailSender.send( + emailSender.Contactsend( "ethniconnect@gmail.com", emailService.buildContactEmail(contact.getMessage(),contact.getEmailid())); contactRepository.save(contact); diff --git a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java index b72a672..b051a14 100644 --- a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java @@ -35,7 +35,7 @@ public void resetPassword(ResetPasswordRequest resetPasswordRequest) { { String token = userCredentialsService.getToken(userCredentials); String link = "http://localhost:8080/api/v1/resetpassword/confirm?token=" + token; - emailSender.send( + emailSender.ResentPwdSend( resetPasswordRequest.getEmailId(), emailService.buildResetPasswordEmail("User", link)); } diff --git a/src/main/java/ethniconnect_backend/email/EmailSender.java b/src/main/java/ethniconnect_backend/email/EmailSender.java index a57c2d0..52386fe 100644 --- a/src/main/java/ethniconnect_backend/email/EmailSender.java +++ b/src/main/java/ethniconnect_backend/email/EmailSender.java @@ -2,4 +2,6 @@ public interface EmailSender { void send(String to, String email); + void Contactsend(String to, String email); + void ResentPwdSend(String to, String email); } diff --git a/src/main/java/ethniconnect_backend/email/EmailService.java b/src/main/java/ethniconnect_backend/email/EmailService.java index 732442b..5916924 100644 --- a/src/main/java/ethniconnect_backend/email/EmailService.java +++ b/src/main/java/ethniconnect_backend/email/EmailService.java @@ -110,7 +110,7 @@ public String buildEmail(String name, String link) { " \n" + " \n" + " \n" + - " Contact Request\n" + + " Confirm your email\n" + " \n" + " \n" + " \n" + @@ -163,6 +163,7 @@ public String buildEmail(String name, String link) { public String buildResetPasswordEmail(String name, String link) { + return "
\n" + "\n" + "\n" + @@ -248,4 +249,34 @@ public void send(String to, String email) { throw new IllegalStateException("failed to send email"); } } + public void Contactsend(String to, String email) { + try { + MimeMessage mimeMessage = mailSender.createMimeMessage(); + MimeMessageHelper helper = + new MimeMessageHelper(mimeMessage, "utf-8"); + helper.setText(email, true); + helper.setTo(to); + helper.setSubject("Contact Request"); + helper.setFrom("ethniconnect@gmail.com"); + mailSender.send(mimeMessage); + } catch (MessagingException e) { + LOGGER.error("failed to send email", e); + throw new IllegalStateException("failed to send email"); + } + } + public void ResentPwdSend(String to, String email) { + try { + MimeMessage mimeMessage = mailSender.createMimeMessage(); + MimeMessageHelper helper = + new MimeMessageHelper(mimeMessage, "utf-8"); + helper.setText(email, true); + helper.setTo(to); + helper.setSubject("Reset Password"); + helper.setFrom("ethniconnect@gmail.com"); + mailSender.send(mimeMessage); + } catch (MessagingException e) { + LOGGER.error("failed to send email", e); + throw new IllegalStateException("failed to send email"); + } + } } From 21b3e3f6ccfa23198e830911056a44c3fa32529a Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Tue, 12 Apr 2022 00:22:28 -0400 Subject: [PATCH 53/69] get order working --- .../ethniconnect_backend/Order/OrderItem.java | 30 +++++++++++++++---- .../Order/OrderService.java | 2 +- .../ethniconnect_backend/Order/Orders.java | 17 ++++++++++- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/main/java/ethniconnect_backend/Order/OrderItem.java b/src/main/java/ethniconnect_backend/Order/OrderItem.java index b8e0833..4c9abda 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItem.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItem.java @@ -1,29 +1,47 @@ package ethniconnect_backend.Order; import ethniconnect_backend.ChefCreateMenu.ChefMenu; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; import lombok.Setter; -import org.springframework.transaction.annotation.Transactional; import javax.persistence.*; +import javax.transaction.Transactional; +@Data +@NoArgsConstructor +@AllArgsConstructor +@Transactional @Setter -@Entity (name = "order_items") +@Entity (name = "orderitems") public class OrderItem { @Id @GeneratedValue private int orderitemid; private int menu_id; - private int orderid; private String special_instructions; private int quantity; + private int orderid; @ManyToOne @JoinColumn(name = "menu_id",referencedColumnName = "id",insertable = false,updatable = false) private ChefMenu chefMenu; -// @ManyToOne -// @JoinColumn(name = "orderid",referencedColumnName = "orderid",insertable = false,updatable = false) -// private Orders orders; +// +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name = "orderid",insertable = false,updatable = false) +// private Orders order; +// +// +// public void setOrder(Orders order) { +// this.order = order; +// } +// +// public Orders getOrder(Orders order) { +// this.order = order; +// return this.order; +// } } diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java index e2e43e7..79410ea 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -42,7 +42,7 @@ public Integer placeOrder(OrderRequest orderRequest) { order.setOrder_amount(orderRequest.getTotalprice()); order.setChef_loginid(orderRequest.getChefLoginid()); order.setCust_loginid(orderRequest.getCustomerLoginid()); - //order.setOrderItems(orderRequest.getOrderItems()); + order.setOrderItems(orderRequest.getOrderItems()); order.setOrder_date(LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC)); //order.setId(1); diff --git a/src/main/java/ethniconnect_backend/Order/Orders.java b/src/main/java/ethniconnect_backend/Order/Orders.java index 9f096a6..05a4676 100644 --- a/src/main/java/ethniconnect_backend/Order/Orders.java +++ b/src/main/java/ethniconnect_backend/Order/Orders.java @@ -11,7 +11,10 @@ import javax.transaction.Transactional; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; @Data @NoArgsConstructor @@ -30,9 +33,12 @@ public class Orders { private long chef_loginid; + @OneToMany @JoinColumn(name = "orderid", referencedColumnName = "orderid", insertable = false, updatable = false) - private List orderItems; + private List orderItems = new ArrayList<>(); + + @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "cust_loginid", referencedColumnName = "loginid", insertable = false, updatable = false) @@ -42,6 +48,15 @@ public class Orders { @JoinColumn(name = "chef_loginid", referencedColumnName = "loginid", insertable = false, updatable = false) private Chef chef; +// public void addOrderItems(OrderItem orderItem) { +// orderItems.add(orderItem); +// orderItem.setOrder(this); +// } + + /* public void removeOrderItems(OrderItem orderItem) { + orderItems.remove(orderItem); + orderItem.setOrder(null); + }*/ From 8138ac3e24c2e8517365563b69b23a9f54b9e527 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Tue, 12 Apr 2022 23:21:39 -0400 Subject: [PATCH 54/69] place order is working --- .../ChefCreateMenu/ChefMenuService.java | 2 + .../ChefSignup/ChefSignupController.java | 10 ++ .../ContactPage/ContactService.java | 23 +---- .../Order/OrderController.java | 2 + .../ethniconnect_backend/Order/OrderItem.java | 12 +-- .../Order/OrderItemsService.java | 2 - .../Order/OrderRequest.java | 2 +- .../Order/OrderService.java | 53 +++++++++-- .../ethniconnect_backend/Order/Orders.java | 8 +- .../email/EmailSender.java | 7 +- .../email/EmailService.java | 91 +++++++++++++++++++ 11 files changed, 163 insertions(+), 49 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 16fb77f..68a50f9 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -61,6 +61,8 @@ public void saveChefMenuJson(ChefMenuRequest chefMenuRequest) throws Exception{ chefMenu.setChef(chef.get()); chefMenu.setItem_name(chefMenuRequest.getItem_name()); chefMenu.setMenu_item_image(chefMenuItem.getMenu_item_image()); + chefMenu.setItem_intresting_facts(chefMenuItem.getItem_intresting_facts()); + chefMenu.setItem_name(chefMenuItem.getItem_name()); chefMenu.setMenucategories(chefMenuItem.getMenucategory()); chefMenu.setItem_ingredients(chefMenuItem.getItem_ingredients()); chefMenu.setMenu_item_price(chefMenuItem.getMenu_item_price()); diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java index 2605cf1..0ccd31b 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupController.java @@ -3,6 +3,7 @@ import lombok.AllArgsConstructor; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.view.RedirectView; @CrossOrigin() @RestController @@ -25,5 +26,14 @@ public String confirm(@RequestParam("token") String token) { return registrationService.confirmToken(token); } + /* @GetMapping("api/v1/registration/confirm") + public RedirectView confirm(@RequestParam("token") String token) { + String email=registrationService.confirmToken(token); + RedirectView redirectView = new RedirectView(); + String redirectUrl = "http://localhost:4200/chefloginsetup?email="+email; + redirectView.setUrl(redirectUrl);*//* + + return redirectView; + }*/ } diff --git a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java index 68d6812..61bd22a 100644 --- a/src/main/java/ethniconnect_backend/ContactPage/ContactService.java +++ b/src/main/java/ethniconnect_backend/ContactPage/ContactService.java @@ -30,28 +30,7 @@ public class ContactService { }*/ -// public void saveContactRequest(String email, String name, String message) { -// boolean isValidEmail = emailValidator. -// test(email); -// -// if (!isValidEmail) { -// throw new IllegalStateException("email not valid"); -// } -// -// -// /*String link = "www.google.com";*/ -// Contact contact = new Contact(); -// contact.setEmailid(email); -// contact.setMessage(message); -// contact.setName(name); -// contactRepository.save(contact); -// emailSender.send( -// "ethniconnect@gmail.com", -// emailService.buildContactEmail(message,email)); -// contactRepository.save(contact); -// -// //return token; -// } + public void saveContactRequest(Contact contact) { boolean isValidEmail = emailValidator. test(contact.getEmailid()); diff --git a/src/main/java/ethniconnect_backend/Order/OrderController.java b/src/main/java/ethniconnect_backend/Order/OrderController.java index 1189100..039162f 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderController.java +++ b/src/main/java/ethniconnect_backend/Order/OrderController.java @@ -18,6 +18,8 @@ public ResponseEntity placeOrder(@RequestBody OrderRequest orderRequest return new ResponseEntity(orderid, HttpStatus.OK); } + + @GetMapping("/order/{orderid}") public ResponseEntity getOrder(@PathVariable int orderid) { diff --git a/src/main/java/ethniconnect_backend/Order/OrderItem.java b/src/main/java/ethniconnect_backend/Order/OrderItem.java index 4c9abda..921912c 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItem.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItem.java @@ -1,19 +1,15 @@ package ethniconnect_backend.Order; import ethniconnect_backend.ChefCreateMenu.ChefMenu; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.*; import javax.persistence.*; -import javax.transaction.Transactional; @Data @NoArgsConstructor @AllArgsConstructor -@Transactional @Setter +@Getter @Entity (name = "orderitems") public class OrderItem { @Id @@ -24,8 +20,8 @@ public class OrderItem { private int quantity; private int orderid; - @ManyToOne - @JoinColumn(name = "menu_id",referencedColumnName = "id",insertable = false,updatable = false) + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "menu_id",insertable = false, updatable=false) private ChefMenu chefMenu; // diff --git a/src/main/java/ethniconnect_backend/Order/OrderItemsService.java b/src/main/java/ethniconnect_backend/Order/OrderItemsService.java index 25cd15b..d0237c9 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItemsService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItemsService.java @@ -3,10 +3,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.transaction.Transactional; @Service -@Transactional public class OrderItemsService { @Autowired diff --git a/src/main/java/ethniconnect_backend/Order/OrderRequest.java b/src/main/java/ethniconnect_backend/Order/OrderRequest.java index 274be68..8069ec7 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderRequest.java +++ b/src/main/java/ethniconnect_backend/Order/OrderRequest.java @@ -11,7 +11,7 @@ @ToString public class OrderRequest { - private long chefLoginid; + //private long chefLoginid; private long customerLoginid; private int orderid; private double totalprice; diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java index 79410ea..e0044da 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -1,25 +1,39 @@ package ethniconnect_backend.Order; import ethniconnect_backend.ChefCreateMenu.*; +import ethniconnect_backend.ChefDetails.Chef; import ethniconnect_backend.ChefDetails.ChefRepository; +import ethniconnect_backend.ChefSignup.EmailValidator; +import ethniconnect_backend.ChefSignup.token.ConfirmationTokenService; import ethniconnect_backend.Cuisines.CuisineCategoriesRepository; +import ethniconnect_backend.CustomerDetails.Customer; +import ethniconnect_backend.CustomerDetails.CustomerRepository; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; +import ethniconnect_backend.UserCredentials.UserCredentialsService; +import ethniconnect_backend.email.EmailSender; +import ethniconnect_backend.email.EmailService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; +import java.util.Optional; -@Transactional @Service public class OrderService { + + @Autowired + private EmailService emailService; + @Autowired + private EmailSender emailSender; + @Autowired private ChefMenuRepository chefMenuRepository; @Autowired private UserCredentialsRepository userCredentialsRepository; - + @Autowired + private CustomerRepository customerRepository; @Autowired CuisineCategoriesRepository cuisineCategoriesRepository; @Autowired @@ -33,27 +47,49 @@ public class OrderService { @Autowired OrderItemsService orderItemsService; - @Transactional + public Integer placeOrder(OrderRequest orderRequest) { + + + /*String link = "www.google.com";*/ + + + + + + Orders order = new Orders(); //orderRequest.setOrderid(order.getOrderid()); order.setOrder_amount(orderRequest.getTotalprice()); - order.setChef_loginid(orderRequest.getChefLoginid()); + //order.setChef_loginid(orderRequest.getChefLoginid()); order.setCust_loginid(orderRequest.getCustomerLoginid()); order.setOrderItems(orderRequest.getOrderItems()); order.setOrder_date(LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC)); //order.setId(1); Orders savedOrder = orderRepository.save(order); + Optional customer = customerRepository.findByLoginid(orderRequest.getCustomerLoginid()); + String chefEmailId=null; for(OrderItem orderItem:orderRequest.getOrderItems()) { orderItem.setOrderid(savedOrder.getOrderid()); orderItemsRepository.save(orderItem); } - return savedOrder.getOrderid(); + + //savedOrder = getOrder(savedOrder.getOrderid()); + //Optional chef = chefRepository.findByLoginid(savedOrder.getOrderItems().get(0).getChefMenu().getChef().getLoginid()); + + emailSender.orderRequest( + "ethniconnect@gmail.com", + //orderRepository.findByOrderid(orderid).get().getOrderItems().get(0).getChefMenu().getChef().getChef_emailid(), + emailService.buildOrderRequestEmail(savedOrder.getOrderid(), + customer.get().getCust_emailid(), + savedOrder.getOrderItems().toString())); + + return savedOrder.getOrderid(); @@ -61,6 +97,9 @@ public Integer placeOrder(OrderRequest orderRequest) { public Orders getOrder(int orderid) { - return orderRepository.findByOrderid(orderid).get(); + Orders order= orderRepository.findByOrderid(orderid).get(); + return order; } + + } \ No newline at end of file diff --git a/src/main/java/ethniconnect_backend/Order/Orders.java b/src/main/java/ethniconnect_backend/Order/Orders.java index 05a4676..187f3b9 100644 --- a/src/main/java/ethniconnect_backend/Order/Orders.java +++ b/src/main/java/ethniconnect_backend/Order/Orders.java @@ -30,7 +30,6 @@ public class Orders { private LocalDateTime order_date; private double order_amount; private long cust_loginid; - private long chef_loginid; @@ -40,13 +39,10 @@ public class Orders { - @ManyToOne(cascade = CascadeType.ALL) + /*@ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "cust_loginid", referencedColumnName = "loginid", insertable = false, updatable = false) - private Customer customer; + private Customer customer;*/ - @ManyToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "chef_loginid", referencedColumnName = "loginid", insertable = false, updatable = false) - private Chef chef; // public void addOrderItems(OrderItem orderItem) { // orderItems.add(orderItem); diff --git a/src/main/java/ethniconnect_backend/email/EmailSender.java b/src/main/java/ethniconnect_backend/email/EmailSender.java index 52386fe..a01b676 100644 --- a/src/main/java/ethniconnect_backend/email/EmailSender.java +++ b/src/main/java/ethniconnect_backend/email/EmailSender.java @@ -1,7 +1,8 @@ package ethniconnect_backend.email; public interface EmailSender { - void send(String to, String email); - void Contactsend(String to, String email); - void ResentPwdSend(String to, String email); + void send(String to, String emailContent); + void Contactsend(String to, String emailContent); + void ResentPwdSend(String to, String emailContent); + void orderRequest(String to, String emailContent); } diff --git a/src/main/java/ethniconnect_backend/email/EmailService.java b/src/main/java/ethniconnect_backend/email/EmailService.java index 5916924..93c7023 100644 --- a/src/main/java/ethniconnect_backend/email/EmailService.java +++ b/src/main/java/ethniconnect_backend/email/EmailService.java @@ -232,6 +232,81 @@ public String buildResetPasswordEmail(String name, String link) { "
"; } + public String buildOrderRequestEmail(int orderid ,String useremailid, String orderdetails) { + + return "
\n" + + "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " New Order Request Details\n" + + "
\n" + + " \n" + + "
\n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + "
\n" + + "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "


\n" + + " \n" + + "

Hi Chef,

" + + "

" + + "You received an Order request from "+useremailid+"

" + + "

\n

Order Number : "+orderid+"

" + + " \n" + + + " \n" + + "


\n" + + "\n" + + "
"; + } + @Override @Async public void send(String to, String email) { @@ -279,4 +354,20 @@ public void ResentPwdSend(String to, String email) { throw new IllegalStateException("failed to send email"); } } + + public void orderRequest(String to, String email) { + try { + MimeMessage mimeMessage = mailSender.createMimeMessage(); + MimeMessageHelper helper = + new MimeMessageHelper(mimeMessage, "utf-8"); + helper.setText(email, true); + helper.setTo(to); + helper.setSubject("Order Request"); + helper.setFrom("ethniconnect@gmail.com"); + mailSender.send(mimeMessage); + } catch (MessagingException e) { + LOGGER.error("failed to send email", e); + throw new IllegalStateException("failed to send email"); + } + } } From 6b19e31e9a95c27821bc93a7c3b7a46c0dc4f374 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Wed, 13 Apr 2022 00:08:56 -0400 Subject: [PATCH 55/69] working --- .../java/ethniconnect_backend/ChefCreateMenu/ChefMenuItem.java | 2 +- .../ethniconnect_backend/ChefCreateMenu/ChefMenuService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuItem.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuItem.java index b07c22e..4a8085e 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuItem.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuItem.java @@ -14,7 +14,7 @@ public class ChefMenuItem { @Enumerated(EnumType.STRING) - private MenuCategories menucategory; + private MenuCategories menucategories; private String menu_item_image; private String item_name; private double menu_item_price; diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 68a50f9..b28a8fd 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -63,7 +63,7 @@ public void saveChefMenuJson(ChefMenuRequest chefMenuRequest) throws Exception{ chefMenu.setMenu_item_image(chefMenuItem.getMenu_item_image()); chefMenu.setItem_intresting_facts(chefMenuItem.getItem_intresting_facts()); chefMenu.setItem_name(chefMenuItem.getItem_name()); - chefMenu.setMenucategories(chefMenuItem.getMenucategory()); + chefMenu.setMenucategories(chefMenuItem.getMenucategories()); chefMenu.setItem_ingredients(chefMenuItem.getItem_ingredients()); chefMenu.setMenu_item_price(chefMenuItem.getMenu_item_price()); chefMenu.setWeek(chefMenuRequest.getWeek()); From d859422802338f355fa3e3e27fd4827c03e01135 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Wed, 13 Apr 2022 00:50:37 -0400 Subject: [PATCH 56/69] get chef menu working --- .../ChefCreateMenu/ChefMenuResponse.java | 2 ++ .../ChefCreateMenu/ChefMenuService.java | 36 ++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuResponse.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuResponse.java index eb3c06b..7e21b91 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuResponse.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuResponse.java @@ -4,6 +4,8 @@ @Data @Builder +@Getter +@Setter @AllArgsConstructor @ToString public class ChefMenuResponse { diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index b28a8fd..d2f377f 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -151,13 +151,13 @@ public List getChefByCuisineId(int cuisineId, int zipCode) { } return chefList; } - public ChefMenuGETResponse getChefMenuByLoginId(long login_id) { + /*public ChefMenuGETResponse getChefMenuByLoginId(long login_id) { Chef chef = new Chef(); chef.setLoginid(login_id); List chefMenuList = chefMenuRepository.findAllByChef(chef); List chefMenuResponseList = new ArrayList<>(); - /* ChefMenuGETResponse chefMenuGETResponse = ChefMenuGETResponse.builder() + *//* ChefMenuGETResponse chefMenuGETResponse = ChefMenuGETResponse.builder() .cuisine_id(chefMenu.getCuisineCategory().getId()) .login_id(chefMenu.getLogin_id()) .menucategories(chefMenu.getMenucategories()) @@ -167,7 +167,35 @@ public ChefMenuGETResponse getChefMenuByLoginId(long login_id) { .item_ingredients(chefMenu.getItem_ingredients()) .item_intresting_facts(chefMenu.getItem_intresting_facts()) .week(chefMenu.getWeek()) - .build();*/ + .build();*//* + for(ChefMenu chefMenu:chefMenuList) + { + chefMenuResponseList.add + ( ChefMenuResponse + .builder() + .menuid(chefMenu.getId()) + .menu_item_image(chefMenu.getMenu_item_image()!=null?chefMenu.getMenu_item_image():null) + .menucategory(chefMenu.getMenucategories().toString()) + .cuisineCategory(chefMenu.getCuisineCategory().getCuisine_name()) + .menu_item_price(chefMenu.getMenu_item_price()) + .item_name(chefMenu.getItem_name()) + .item_ingredients(chefMenu.getItem_ingredients()) + .item_intresting_facts(chefMenu.getItem_intresting_facts()) + .week(chefMenu.getWeek()!=null?chefMenu.getWeek().toString():null) + .build() + ); + } + return ChefMenuGETResponse.builder().chefMenuList(chefMenuResponseList).build(); + } + +*/ + public ChefMenuGETResponse getChefMenuByLoginId(long login_id) { + Chef chef = new Chef(); + chef.setLoginid(login_id); + List chefMenuList = chefMenuRepository.findAllByChef(chef); + List chefMenuResponseList = new ArrayList<>(); + + for(ChefMenu chefMenu:chefMenuList) { chefMenuResponseList.add @@ -188,7 +216,7 @@ public ChefMenuGETResponse getChefMenuByLoginId(long login_id) { return ChefMenuGETResponse.builder().chefMenuList(chefMenuResponseList).build(); } -// public String deleteChefMenu(int chefMenu_id) + // public String deleteChefMenu(int chefMenu_id) // { // chefMenuRepository.deleteById(chefMenu_id); // return "chef Menu ietem removed !!" + chefMenu_id; From 681f84b452f12d5c07681ed92c49bd984db4a0a2 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Wed, 13 Apr 2022 16:28:31 -0400 Subject: [PATCH 57/69] forgot pwd redirect url changed to FE url workinh --- .../Resetpassword/ResetPasswordController.java | 2 +- .../Resetpassword/ResetPasswordService.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java index 693a0ce..677c271 100644 --- a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java @@ -24,7 +24,7 @@ public void restpassword(@RequestBody ResetPasswordRequest resetPasswordRequest public RedirectView confirm(@RequestParam("token") String token) { String email=resetPasswordService.confirmToken(token); RedirectView redirectView = new RedirectView(); - String redirectUrl = "https://fullstackdeveloper.guru?email="+email; + String redirectUrl = "http://localhost:4200/resetpassword?email="+email; redirectView.setUrl(redirectUrl); return redirectView; diff --git a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java index b051a14..cc8ecd4 100644 --- a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java @@ -62,10 +62,13 @@ public String confirmToken(String token) { confirmationTokenService.setConfirmedAt(token); return confirmationToken.getAppUser().getEmail(); + } public void updatePassword(UpdatePassword updatePassword) { BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder(); String encodedPassword = passwordEncoder.encode(updatePassword.getNewPwd()); + + //UserCredentials userCredentials = userCredentialsRepository.findByEmail(resetPasswordRequest.getEmailId()).get() UserCredentials userCredentials = userCredentialsRepository.findByEmail(updatePassword.getEmailId()).get(); userCredentials.setPassword(encodedPassword); userCredentials.setResetpasswordtoken(null); From 016db688375475ed9399d793dd78a3b1b71cc8c6 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Wed, 13 Apr 2022 22:33:33 -0400 Subject: [PATCH 58/69] orer item lazy issue --- src/main/java/ethniconnect_backend/Order/OrderItem.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/ethniconnect_backend/Order/OrderItem.java b/src/main/java/ethniconnect_backend/Order/OrderItem.java index 921912c..1a02a4b 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItem.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItem.java @@ -20,7 +20,7 @@ public class OrderItem { private int quantity; private int orderid; - @ManyToOne(fetch = FetchType.LAZY) + @ManyToOne @JoinColumn(name = "menu_id",insertable = false, updatable=false) private ChefMenu chefMenu; From 56c0217d3c13bdeeb16a21e1b9ce79b865beff9c Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Thu, 14 Apr 2022 11:10:52 -0400 Subject: [PATCH 59/69] working --- .../Cuisines/CuisineCategoriesController.java | 7 +++++++ .../ethniconnect_backend/Cuisines/CuisineCategory.java | 2 ++ .../Cuisines/CuisinesCategoriesService.java | 10 ++++++++++ .../Resetpassword/ResetPasswordController.java | 3 ++- src/main/resources/application.yml | 2 +- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java index 3b6b772..7b5ebf1 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategoriesController.java @@ -1,6 +1,8 @@ package ethniconnect_backend.Cuisines; +import ethniconnect_backend.ChefDetails.Chef; +import ethniconnect_backend.ChefDetails.ChefRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -32,6 +34,11 @@ public CuisineCategory findcuisinecategoryrequestbyId(@PathVariable int id) return cuisinesCategoriesService.getCuisineCategoryById(id); } + @PutMapping("/updatecuisine") + public CuisineCategory updateChef(@RequestBody CuisineCategory cuisineCategory) { + return cuisinesCategoriesService.Updatecuisinecategory(cuisineCategory); + } + } diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java index 39450aa..dd4df85 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisineCategory.java @@ -22,6 +22,8 @@ public class CuisineCategory { private int id; @Column(unique = true) private String cuisine_name; + @Lob + @Column(columnDefinition = "MEDIUMBLOB") private String cuisine_image; // diff --git a/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java b/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java index 29f3718..0f71f4e 100644 --- a/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java +++ b/src/main/java/ethniconnect_backend/Cuisines/CuisinesCategoriesService.java @@ -1,5 +1,6 @@ package ethniconnect_backend.Cuisines; +import ethniconnect_backend.ChefDetails.Chef; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -22,6 +23,15 @@ public CuisineCategory getCuisineCategoryById(int id) { return (CuisineCategory) cuisineCategoriesRepository.findById(id).orElse(null); } + public CuisineCategory Updatecuisinecategory(CuisineCategory cuisineCategory) + { + CuisineCategory existingCuisine = (CuisineCategory) cuisineCategoriesRepository.findById(cuisineCategory.getId()).orElse(null); + existingCuisine.setCuisine_name(cuisineCategory.getCuisine_name() != null ? cuisineCategory.getCuisine_name() : existingCuisine.getCuisine_name()); + existingCuisine.setCuisine_image(cuisineCategory.getCuisine_image() != null ? cuisineCategory.getCuisine_image() : existingCuisine.getCuisine_image()); + + return cuisineCategoriesRepository.save(existingCuisine); + + } } diff --git a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java index 677c271..20e3dc3 100644 --- a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordController.java @@ -15,9 +15,10 @@ public class ResetPasswordController { ResetPasswordService resetPasswordService; @PostMapping(path="resetpassword") - public void restpassword(@RequestBody ResetPasswordRequest resetPasswordRequest) + public String restpassword(@RequestBody ResetPasswordRequest resetPasswordRequest) { resetPasswordService.resetPassword(resetPasswordRequest); + return resetPasswordRequest.getEmailId(); } @GetMapping(path = "/resetpassword/confirm") diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0edce5d..a3ad1be 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,7 +21,7 @@ spring: username: root jpa: hibernate: - ddl-auto: update + ddl-auto: create-drop properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect From 4a2eef0e9be98ec289cb46b78c45f302dad290ee Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Thu, 14 Apr 2022 14:26:11 -0400 Subject: [PATCH 60/69] working --- src/main/java/ethniconnect_backend/Order/OrderService.java | 4 ++-- src/main/resources/application.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java index e0044da..d04807b 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -83,8 +83,8 @@ public Integer placeOrder(OrderRequest orderRequest) { //Optional chef = chefRepository.findByLoginid(savedOrder.getOrderItems().get(0).getChefMenu().getChef().getLoginid()); emailSender.orderRequest( - "ethniconnect@gmail.com", - //orderRepository.findByOrderid(orderid).get().getOrderItems().get(0).getChefMenu().getChef().getChef_emailid(), + //"ethniconnect@gmail.com", + orderRepository.findByOrderid(orderRequest.getOrderid()).get().getOrderItems().get(0).getChefMenu().getChef().getChef_emailid(), emailService.buildOrderRequestEmail(savedOrder.getOrderid(), customer.get().getCust_emailid(), savedOrder.getOrderItems().toString())); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a3ad1be..0edce5d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -21,7 +21,7 @@ spring: username: root jpa: hibernate: - ddl-auto: create-drop + ddl-auto: update properties: hibernate: dialect: org.hibernate.dialect.MySQL8Dialect From 563a54fabbbee10daa9cd60d1d80429af49d868d Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Thu, 14 Apr 2022 16:56:02 -0400 Subject: [PATCH 61/69] order email working --- .../ChefCreateMenu/ChefMenu.java | 10 ++--- .../ChefCreateMenu/ChefMenuService.java | 1 + .../Order/OrderItemsRepository.java | 3 +- .../Order/OrderService.java | 38 +++++++++---------- .../ethniconnect_backend/Order/Orders.java | 2 +- 5 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java index 0516f79..f565e4c 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenu.java @@ -2,16 +2,15 @@ import ethniconnect_backend.ChefDetails.Chef; import ethniconnect_backend.Cuisines.CuisineCategory; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; @Data @NoArgsConstructor @AllArgsConstructor - +@Getter +@Setter @Entity @Table(name = "chefmenu") public class ChefMenu { @@ -30,6 +29,7 @@ public class ChefMenu { private String item_intresting_facts; @Enumerated(EnumType.STRING) private Week week; + private long loginid; //@ManyToOne @ManyToOne @@ -39,7 +39,7 @@ public class ChefMenu { // Set orders; @ManyToOne - @JoinColumn (name="loginid") + @JoinColumn (name="loginid", insertable = false, updatable = false) private Chef chef; /*@JoinTable( name = "selected_cuisines", diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index d2f377f..9ef09e2 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -60,6 +60,7 @@ public void saveChefMenuJson(ChefMenuRequest chefMenuRequest) throws Exception{ chefMenu.setCuisineCategory(cuisineCategory.get()); chefMenu.setChef(chef.get()); chefMenu.setItem_name(chefMenuRequest.getItem_name()); + chefMenu.setLoginid(chef.get().getLoginid()); chefMenu.setMenu_item_image(chefMenuItem.getMenu_item_image()); chefMenu.setItem_intresting_facts(chefMenuItem.getItem_intresting_facts()); chefMenu.setItem_name(chefMenuItem.getItem_name()); diff --git a/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java b/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java index cf48909..0dc729f 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItemsRepository.java @@ -2,8 +2,9 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface OrderItemsRepository extends JpaRepository { - + public List findOrderItemByOrderid(int orderid); } diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java index d04807b..8aaa7aa 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -3,13 +3,10 @@ import ethniconnect_backend.ChefCreateMenu.*; import ethniconnect_backend.ChefDetails.Chef; import ethniconnect_backend.ChefDetails.ChefRepository; -import ethniconnect_backend.ChefSignup.EmailValidator; -import ethniconnect_backend.ChefSignup.token.ConfirmationTokenService; import ethniconnect_backend.Cuisines.CuisineCategoriesRepository; import ethniconnect_backend.CustomerDetails.Customer; import ethniconnect_backend.CustomerDetails.CustomerRepository; import ethniconnect_backend.UserCredentials.UserCredentialsRepository; -import ethniconnect_backend.UserCredentials.UserCredentialsService; import ethniconnect_backend.email.EmailSender; import ethniconnect_backend.email.EmailService; import org.springframework.beans.factory.annotation.Autowired; @@ -41,6 +38,7 @@ public class OrderService { @Autowired private OrderRepository orderRepository; + @Autowired private OrderItemsRepository orderItemsRepository; @@ -52,13 +50,6 @@ public Integer placeOrder(OrderRequest orderRequest) { - /*String link = "www.google.com";*/ - - - - - - Orders order = new Orders(); //orderRequest.setOrderid(order.getOrderid()); @@ -68,33 +59,42 @@ public Integer placeOrder(OrderRequest orderRequest) { order.setOrderItems(orderRequest.getOrderItems()); order.setOrder_date(LocalDateTime.ofInstant(Instant.now(), ZoneOffset.UTC)); - //order.setId(1); + Orders savedOrder = orderRepository.save(order); Optional customer = customerRepository.findByLoginid(orderRequest.getCustomerLoginid()); - String chefEmailId=null; + for(OrderItem orderItem:orderRequest.getOrderItems()) { orderItem.setOrderid(savedOrder.getOrderid()); - orderItemsRepository.save(orderItem); + OrderItem saved=orderItemsRepository.save(orderItem); + + //Optional chef= chefRepository.findByLoginid(saved.getChefMenu().getChef().getLoginid()); + //String chefemail = chef.get().getChef_emailid(); + /*emailSender.orderRequest( + chefemail, + //"ethniconnect@gmail.com", + emailService.buildOrderRequestEmail(savedOrder.getOrderid(), + customer.get().getCust_emailid(), + savedOrder.getOrderItems().toString()));*/ } - - //savedOrder = getOrder(savedOrder.getOrderid()); - //Optional chef = chefRepository.findByLoginid(savedOrder.getOrderItems().get(0).getChefMenu().getChef().getLoginid()); + OrderItem orderItem = orderItemsRepository.findOrderItemByOrderid(savedOrder.getOrderid()).get(0); + ChefMenu chefMenu = chefMenuRepository.findById(orderItem.getMenu_id()).get(); + Optional chef = chefRepository.findByLoginid(chefMenu.getLoginid()); + String chefEmailId= chef.get().getChef_emailid(); emailSender.orderRequest( + chefEmailId, //"ethniconnect@gmail.com", - orderRepository.findByOrderid(orderRequest.getOrderid()).get().getOrderItems().get(0).getChefMenu().getChef().getChef_emailid(), emailService.buildOrderRequestEmail(savedOrder.getOrderid(), customer.get().getCust_emailid(), savedOrder.getOrderItems().toString())); return savedOrder.getOrderid(); - - } + public Orders getOrder(int orderid) { Orders order= orderRepository.findByOrderid(orderid).get(); diff --git a/src/main/java/ethniconnect_backend/Order/Orders.java b/src/main/java/ethniconnect_backend/Order/Orders.java index 187f3b9..97bb548 100644 --- a/src/main/java/ethniconnect_backend/Order/Orders.java +++ b/src/main/java/ethniconnect_backend/Order/Orders.java @@ -35,7 +35,7 @@ public class Orders { @OneToMany @JoinColumn(name = "orderid", referencedColumnName = "orderid", insertable = false, updatable = false) - private List orderItems = new ArrayList<>(); + private List orderItems = new ArrayList<>(); From d48370237c3657beb6d9814a8f18f7c19e3f2495 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Fri, 15 Apr 2022 14:37:17 -0400 Subject: [PATCH 62/69] working --- .../ethniconnect_backend/ChefSignup/ChefSignupService.java | 2 +- .../java/ethniconnect_backend/Order/OrderController.java | 2 +- src/main/java/ethniconnect_backend/Order/OrderItem.java | 3 +++ .../Resetpassword/ResetPasswordService.java | 2 +- src/main/resources/application.yml | 5 ++++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index 200f841..22072a3 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -43,7 +43,7 @@ public void register(String email, String password) { ); /*String link = "www.google.com";*/ - String link = "http://localhost:8500/api/v1/registration/confirm?token=" + token; + String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; emailSender.send( email, emailService.buildEmail("user", link)); diff --git a/src/main/java/ethniconnect_backend/Order/OrderController.java b/src/main/java/ethniconnect_backend/Order/OrderController.java index 039162f..774ba0e 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderController.java +++ b/src/main/java/ethniconnect_backend/Order/OrderController.java @@ -4,7 +4,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; - +@CrossOrigin() @RestController public class OrderController { diff --git a/src/main/java/ethniconnect_backend/Order/OrderItem.java b/src/main/java/ethniconnect_backend/Order/OrderItem.java index 1a02a4b..f2dad39 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItem.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItem.java @@ -2,8 +2,10 @@ import ethniconnect_backend.ChefCreateMenu.ChefMenu; import lombok.*; +import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.*; +import java.sql.Time; @Data @NoArgsConstructor @@ -19,6 +21,7 @@ public class OrderItem { private String special_instructions; private int quantity; private int orderid; + private Time pickuptime; @ManyToOne @JoinColumn(name = "menu_id",insertable = false, updatable=false) diff --git a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java index cc8ecd4..4eba874 100644 --- a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java @@ -34,7 +34,7 @@ public void resetPassword(ResetPasswordRequest resetPasswordRequest) { if(userCredentialsService.isEmailIdExist(resetPasswordRequest.getEmailId())) { String token = userCredentialsService.getToken(userCredentials); - String link = "http://localhost:8080/api/v1/resetpassword/confirm?token=" + token; + String link = "http://localhost:5000/api/v1/resetpassword/confirm?token=" + token; emailSender.ResentPwdSend( resetPasswordRequest.getEmailId(), emailService.buildResetPasswordEmail("User", link)); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0edce5d..af85ad3 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,7 @@ server: port: 8080 + #port:5000 error: @@ -15,7 +16,9 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver password: bharani16 initialization-mode: ALWAYS - url: jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC + url: #jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC + jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC + #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect #ethni-connect.ciff6u6uo7qd.us-east-2.rds.amazonaws.com (new updated saranya's) username: root From 8622e3f03a6409d509a274b0938fb9b73dc21342 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Fri, 15 Apr 2022 16:18:10 -0400 Subject: [PATCH 63/69] activation link address changes --- .../ethniconnect_backend/ChefSignup/ChefSignupService.java | 2 +- .../CustomerSignup/CustSignupService.java | 2 +- .../Resetpassword/ResetPasswordService.java | 2 +- src/main/resources/application.yml | 7 +++---- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index 22072a3..abce492 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -43,7 +43,7 @@ public void register(String email, String password) { ); /*String link = "www.google.com";*/ - String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; + String link = "http://backendaws-env.eba-fdddft5p.us-east-2.elasticbeanstalk.com/api/v1/registration/confirm?token=" + token; emailSender.send( email, emailService.buildEmail("user", link)); diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java index 3788322..dd93d75 100644 --- a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java @@ -42,7 +42,7 @@ public void register(String email, String password) { ); /*String link = "www.google.com";*/ - String link = "http://localhost:5000/api/v1/registration/confirm?token=" + token; + String link = "http://backendaws-env.eba-fdddft5p.us-east-2.elasticbeanstalk.com/api/v1/registration/confirm?token=" + token; emailSender.send( email, emailService.buildEmail("user", link)); diff --git a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java index 4eba874..a96fa27 100644 --- a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java @@ -34,7 +34,7 @@ public void resetPassword(ResetPasswordRequest resetPasswordRequest) { if(userCredentialsService.isEmailIdExist(resetPasswordRequest.getEmailId())) { String token = userCredentialsService.getToken(userCredentials); - String link = "http://localhost:5000/api/v1/resetpassword/confirm?token=" + token; + String link = "http://backendaws-env.eba-fdddft5p.us-east-2.elasticbeanstalk.com/api/v1/resetpassword/confirm?token=" + token; emailSender.ResentPwdSend( resetPasswordRequest.getEmailId(), emailService.buildResetPasswordEmail("User", link)); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index af85ad3..c183d41 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,7 +1,6 @@ server: + port: 5000 - port: 8080 - #port:5000 error: @@ -16,8 +15,8 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver password: bharani16 initialization-mode: ALWAYS - url: #jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC - jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC + url: jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC + #jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect #ethni-connect.ciff6u6uo7qd.us-east-2.rds.amazonaws.com (new updated saranya's) From 1539b2d6146d5e20104db316b6cb38082506849b Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Fri, 15 Apr 2022 16:23:01 -0400 Subject: [PATCH 64/69] port change to localhost --- .../ethniconnect_backend/ChefSignup/ChefSignupService.java | 2 +- .../CustomerSignup/CustSignupService.java | 2 +- .../Resetpassword/ResetPasswordService.java | 2 +- src/main/resources/application.yml | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java index abce492..f41845f 100644 --- a/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java +++ b/src/main/java/ethniconnect_backend/ChefSignup/ChefSignupService.java @@ -43,7 +43,7 @@ public void register(String email, String password) { ); /*String link = "www.google.com";*/ - String link = "http://backendaws-env.eba-fdddft5p.us-east-2.elasticbeanstalk.com/api/v1/registration/confirm?token=" + token; + String link = "http://localhost:8080/api/v1/registration/confirm?token=" + token; emailSender.send( email, emailService.buildEmail("user", link)); diff --git a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java index dd93d75..e23e184 100644 --- a/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java +++ b/src/main/java/ethniconnect_backend/CustomerSignup/CustSignupService.java @@ -42,7 +42,7 @@ public void register(String email, String password) { ); /*String link = "www.google.com";*/ - String link = "http://backendaws-env.eba-fdddft5p.us-east-2.elasticbeanstalk.com/api/v1/registration/confirm?token=" + token; + String link = "http://localhost:8080/api/v1/registration/confirm?token=" + token; emailSender.send( email, emailService.buildEmail("user", link)); diff --git a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java index a96fa27..cc8ecd4 100644 --- a/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java +++ b/src/main/java/ethniconnect_backend/Resetpassword/ResetPasswordService.java @@ -34,7 +34,7 @@ public void resetPassword(ResetPasswordRequest resetPasswordRequest) { if(userCredentialsService.isEmailIdExist(resetPasswordRequest.getEmailId())) { String token = userCredentialsService.getToken(userCredentials); - String link = "http://backendaws-env.eba-fdddft5p.us-east-2.elasticbeanstalk.com/api/v1/resetpassword/confirm?token=" + token; + String link = "http://localhost:8080/api/v1/resetpassword/confirm?token=" + token; emailSender.ResentPwdSend( resetPasswordRequest.getEmailId(), emailService.buildResetPasswordEmail("User", link)); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c183d41..cc77a13 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 5000 + port: 8080 @@ -15,8 +15,8 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver password: bharani16 initialization-mode: ALWAYS - url: jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC - #jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC + url: #jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC + jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect #ethni-connect.ciff6u6uo7qd.us-east-2.rds.amazonaws.com (new updated saranya's) From 00c8904ddb0f9d78ade481dcc4cf92204406d757 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Fri, 15 Apr 2022 18:25:17 -0400 Subject: [PATCH 65/69] Customer Order email working --- .../ethniconnect_backend/Order/OrderItem.java | 1 + .../Order/OrderService.java | 28 +++- .../Order/OrderSummaryEmail.java | 25 ++++ .../email/EmailSender.java | 4 +- .../email/EmailService.java | 136 +++++++++++++++++- src/main/resources/application.yml | 6 +- 6 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 src/main/java/ethniconnect_backend/Order/OrderSummaryEmail.java diff --git a/src/main/java/ethniconnect_backend/Order/OrderItem.java b/src/main/java/ethniconnect_backend/Order/OrderItem.java index f2dad39..8261d96 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderItem.java +++ b/src/main/java/ethniconnect_backend/Order/OrderItem.java @@ -43,5 +43,6 @@ public class OrderItem { // } + } diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java index 8aaa7aa..ead7fe5 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -15,6 +15,8 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; @Service @@ -78,18 +80,36 @@ public Integer placeOrder(OrderRequest orderRequest) { customer.get().getCust_emailid(), savedOrder.getOrderItems().toString()));*/ } - OrderItem orderItem = orderItemsRepository.findOrderItemByOrderid(savedOrder.getOrderid()).get(0); - ChefMenu chefMenu = chefMenuRepository.findById(orderItem.getMenu_id()).get(); + List orderSummary = new ArrayList<>(); + OrderSummaryEmail orderSummaryEmail=null; + List orderItems = orderItemsRepository.findOrderItemByOrderid(savedOrder.getOrderid()); + for(int i=0;i chef = chefRepository.findByLoginid(chefMenu.getLoginid()); String chefEmailId= chef.get().getChef_emailid(); + String itemname = chefMenu.getItem_name(); + int quantity = orderItems.get(0).getQuantity(); - emailSender.orderRequest( + emailSender.emailOrder( chefEmailId, //"ethniconnect@gmail.com", emailService.buildOrderRequestEmail(savedOrder.getOrderid(), customer.get().getCust_emailid(), - savedOrder.getOrderItems().toString())); + quantity)); + emailSender.emailCustomerOrderDetails( + customer.get().getCust_emailid(), + //"ethniconnect@gmail.com", + emailService.buildOrderDetailsEmail(savedOrder.getOrderid(), + chefEmailId,orderSummary)); + /*savedOrder.getOrderItems().toString())*/ return savedOrder.getOrderid(); } diff --git a/src/main/java/ethniconnect_backend/Order/OrderSummaryEmail.java b/src/main/java/ethniconnect_backend/Order/OrderSummaryEmail.java new file mode 100644 index 0000000..523b600 --- /dev/null +++ b/src/main/java/ethniconnect_backend/Order/OrderSummaryEmail.java @@ -0,0 +1,25 @@ +package ethniconnect_backend.Order; + +import lombok.Data; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@Data +public class OrderSummaryEmail { + + @Override + public String toString() { + return + " itemname='" + itemname + '\'' + + "quantity=" + quantity + + ", specialInstructions='" + specialInstructions + '\'' + + ", totalPrice=" + totalPrice; + } + + private int quantity; + private String itemname; + private String specialInstructions; + private double totalPrice; +} diff --git a/src/main/java/ethniconnect_backend/email/EmailSender.java b/src/main/java/ethniconnect_backend/email/EmailSender.java index a01b676..d875327 100644 --- a/src/main/java/ethniconnect_backend/email/EmailSender.java +++ b/src/main/java/ethniconnect_backend/email/EmailSender.java @@ -4,5 +4,7 @@ public interface EmailSender { void send(String to, String emailContent); void Contactsend(String to, String emailContent); void ResentPwdSend(String to, String emailContent); - void orderRequest(String to, String emailContent); + void emailOrder(String to, String emailContent); + + void emailCustomerOrderDetails(String to, String emailContent); } diff --git a/src/main/java/ethniconnect_backend/email/EmailService.java b/src/main/java/ethniconnect_backend/email/EmailService.java index 93c7023..4db6445 100644 --- a/src/main/java/ethniconnect_backend/email/EmailService.java +++ b/src/main/java/ethniconnect_backend/email/EmailService.java @@ -1,5 +1,8 @@ package ethniconnect_backend.email; +import ethniconnect_backend.ChefCreateMenu.ChefMenu; +import ethniconnect_backend.Order.OrderItem; +import ethniconnect_backend.Order.OrderSummaryEmail; import lombok.AllArgsConstructor; import org.slf4j.Logger; @@ -11,6 +14,7 @@ import javax.mail.MessagingException; import javax.mail.internet.MimeMessage; +import java.util.List; @Service @AllArgsConstructor @@ -232,7 +236,7 @@ public String buildResetPasswordEmail(String name, String link) { ""; } - public String buildOrderRequestEmail(int orderid ,String useremailid, String orderdetails) { + public String buildOrderRequestEmail(int orderid ,String useremailid, int quantity) { return "
\n" + "\n" + @@ -293,6 +297,9 @@ public String buildOrderRequestEmail(int orderid ,String useremailid, String ord "

" + "You received an Order request from "+useremailid+"

" + "

\n

Order Number : "+orderid+"

" + + "

" + + "Quantity:"+quantity+"

" + + "

\n

" + " \n" + " \n" + @@ -306,6 +313,113 @@ public String buildOrderRequestEmail(int orderid ,String useremailid, String ord "\n" + "
"; } + public String buildOrderDetailsEmail(int orderid, String chefemailid, List orderSummary) { + + + + return "
\n" + + "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " Order Details\n" + + "
\n" + + " \n" + + "
\n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + "
\n" + + "\n" + + "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "


\n" + + " \n" + + "

Hi Customer,

" + + "

" + + "You order request has been sent to Chef :"+chefemailid+"

" + + "

\n

Order Number : "+orderid+"

" + + "

" + + "Order Details :"+buildOrderSummaryHtml(orderSummary)+"

" + + "

\n

" + + " \n" + + + " \n" + + "


\n" + + "\n" + + "
"; + } + + private String buildOrderSummaryHtml(List orderSummary) { + + StringBuilder buf = new StringBuilder(); + buf.append("" + + "" + + "" + + "" + + "" + + "" + + "" + + ""); + for (int i = 0; i < orderSummary.size(); i++) { + buf.append(""); + } + buf.append("
Item nameQuantitySpecial instructions
") + .append(orderSummary.get(i).getItemname()) + .append("") + .append(orderSummary.get(i).getQuantity()) + .append("") + .append(orderSummary.get(i).getSpecialInstructions()) + .append("
" + + "" + + ""); + String html = buf.toString(); + return html; + + } @Override @Async @@ -355,7 +469,7 @@ public void ResentPwdSend(String to, String email) { } } - public void orderRequest(String to, String email) { + public void emailOrder(String to, String email) { try { MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper helper = @@ -370,4 +484,22 @@ public void orderRequest(String to, String email) { throw new IllegalStateException("failed to send email"); } } + + public void emailCustomerOrderDetails(String to, String email) { + try { + MimeMessage mimeMessage = mailSender.createMimeMessage(); + MimeMessageHelper helper = + new MimeMessageHelper(mimeMessage, "utf-8"); + helper.setText(email, true); + helper.setTo(to); + helper.setSubject("Order Details"); + helper.setFrom("ethniconnect@gmail.com"); + mailSender.send(mimeMessage); + } catch (MessagingException e) { + LOGGER.error("failed to send email", e); + throw new IllegalStateException("failed to send email"); + } + } + + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c183d41..cc77a13 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 5000 + port: 8080 @@ -15,8 +15,8 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver password: bharani16 initialization-mode: ALWAYS - url: jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC - #jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC + url: #jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC + jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect #ethni-connect.ciff6u6uo7qd.us-east-2.rds.amazonaws.com (new updated saranya's) From 7fe6c1bbc1392979c3ebd1fe49272de50a762fa1 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Fri, 15 Apr 2022 18:34:42 -0400 Subject: [PATCH 66/69] chef order email working --- src/main/java/ethniconnect_backend/Order/OrderService.java | 5 ++--- src/main/java/ethniconnect_backend/email/EmailSender.java | 2 +- src/main/java/ethniconnect_backend/email/EmailService.java | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/ethniconnect_backend/Order/OrderService.java b/src/main/java/ethniconnect_backend/Order/OrderService.java index ead7fe5..7ebe0cb 100644 --- a/src/main/java/ethniconnect_backend/Order/OrderService.java +++ b/src/main/java/ethniconnect_backend/Order/OrderService.java @@ -97,12 +97,11 @@ public Integer placeOrder(OrderRequest orderRequest) { String itemname = chefMenu.getItem_name(); int quantity = orderItems.get(0).getQuantity(); - emailSender.emailOrder( + emailSender.emailChefOrderDetails( chefEmailId, //"ethniconnect@gmail.com", emailService.buildOrderRequestEmail(savedOrder.getOrderid(), - customer.get().getCust_emailid(), - quantity)); + customer.get().getCust_emailid() ,orderSummary)); emailSender.emailCustomerOrderDetails( customer.get().getCust_emailid(), //"ethniconnect@gmail.com", diff --git a/src/main/java/ethniconnect_backend/email/EmailSender.java b/src/main/java/ethniconnect_backend/email/EmailSender.java index d875327..cd2b42d 100644 --- a/src/main/java/ethniconnect_backend/email/EmailSender.java +++ b/src/main/java/ethniconnect_backend/email/EmailSender.java @@ -4,7 +4,7 @@ public interface EmailSender { void send(String to, String emailContent); void Contactsend(String to, String emailContent); void ResentPwdSend(String to, String emailContent); - void emailOrder(String to, String emailContent); + void emailChefOrderDetails(String to, String emailContent); void emailCustomerOrderDetails(String to, String emailContent); } diff --git a/src/main/java/ethniconnect_backend/email/EmailService.java b/src/main/java/ethniconnect_backend/email/EmailService.java index 4db6445..a672bfe 100644 --- a/src/main/java/ethniconnect_backend/email/EmailService.java +++ b/src/main/java/ethniconnect_backend/email/EmailService.java @@ -236,7 +236,7 @@ public String buildResetPasswordEmail(String name, String link) { ""; } - public String buildOrderRequestEmail(int orderid ,String useremailid, int quantity) { + public String buildOrderRequestEmail(int orderid, String useremailid, List orderSummary) { return "
\n" + "\n" + @@ -298,7 +298,7 @@ public String buildOrderRequestEmail(int orderid ,String useremailid, int quanti "You received an Order request from "+useremailid+"

" + "

\n

Order Number : "+orderid+"

" + "

" + - "Quantity:"+quantity+"

" + + "Order Details:"+buildOrderSummaryHtml(orderSummary)+"

" + "

\n

" + " \n" + @@ -469,7 +469,7 @@ public void ResentPwdSend(String to, String email) { } } - public void emailOrder(String to, String email) { + public void emailChefOrderDetails(String to, String email) { try { MimeMessage mimeMessage = mailSender.createMimeMessage(); MimeMessageHelper helper = From 760ec3bb63d27a1e0549cfcdf9e9cfa36d59488a Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Fri, 15 Apr 2022 18:37:34 -0400 Subject: [PATCH 67/69] application.yml update --- src/main/resources/application.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index cc77a13..c183d41 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 8080 + port: 5000 @@ -15,8 +15,8 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver password: bharani16 initialization-mode: ALWAYS - url: #jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC - jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC + url: jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC + #jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect #ethni-connect.ciff6u6uo7qd.us-east-2.rds.amazonaws.com (new updated saranya's) From ee5f4d518e74ea2a4f2f49f418474f1c47317ca7 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Fri, 15 Apr 2022 19:27:49 -0400 Subject: [PATCH 68/69] zip api key changed --- .../ethniconnect_backend/ChefCreateMenu/ChefMenuService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 9ef09e2..216d7e1 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -139,7 +139,8 @@ public ChefMenuGETResponse getChefMenuById(int id) } public List getChefByCuisineId(int cuisineId, int zipCode) { - String url = "https://www.zipcodeapi.com/rest/pD8BE4nACZcPt5FtIIhB5n10wXpPERTDFeLyuBhQq2ueQzpSozsD5weTv6keaU6N/radius.json/"+zipCode+"/6/mile"; + String url = + "https://www.zipcodeapi.com/TFA6ZqDUElwxuI4zYat8jRxxH2CuNwX5fJUYwD5eF5tURtR7sz1fcD3sbviDLQGC/radius.json/"+zipCode+"/6/mile"; List chefMenu = chefMenuRepository.findAllByCuisineCategory_Id(cuisineId); Set chefSet = chefMenu.stream().map(ChefMenu::getChef).collect(Collectors.toSet()); Root zipCodeApiResponse = restTemplate.getForObject(url, Root.class); From 072b59fcc61ddd65d185fa77e58d30ee274839d5 Mon Sep 17 00:00:00 2001 From: bharani16592 Date: Fri, 15 Apr 2022 19:57:35 -0400 Subject: [PATCH 69/69] api key changed to old one --- .../ChefCreateMenu/ChefMenuService.java | 3 +-- src/main/resources/application.yml | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java index 216d7e1..9ef09e2 100644 --- a/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java +++ b/src/main/java/ethniconnect_backend/ChefCreateMenu/ChefMenuService.java @@ -139,8 +139,7 @@ public ChefMenuGETResponse getChefMenuById(int id) } public List getChefByCuisineId(int cuisineId, int zipCode) { - String url = - "https://www.zipcodeapi.com/TFA6ZqDUElwxuI4zYat8jRxxH2CuNwX5fJUYwD5eF5tURtR7sz1fcD3sbviDLQGC/radius.json/"+zipCode+"/6/mile"; + String url = "https://www.zipcodeapi.com/rest/pD8BE4nACZcPt5FtIIhB5n10wXpPERTDFeLyuBhQq2ueQzpSozsD5weTv6keaU6N/radius.json/"+zipCode+"/6/mile"; List chefMenu = chefMenuRepository.findAllByCuisineCategory_Id(cuisineId); Set chefSet = chefMenu.stream().map(ChefMenu::getChef).collect(Collectors.toSet()); Root zipCodeApiResponse = restTemplate.getForObject(url, Root.class); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c183d41..cc77a13 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 5000 + port: 8080 @@ -15,8 +15,8 @@ spring: driver-class-name: com.mysql.cj.jdbc.Driver password: bharani16 initialization-mode: ALWAYS - url: jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC - #jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC + url: #jdbc:mysql://ethniconnect.chakxnfle4p3.us-east-2.rds.amazonaws.com:3306/ethniconnect?serverTimezone=UTC + jdbc:mysql://localhost:3306/ethniconnect?serverTimezone=UTC #url: jdbc:mysql://ethniconnectdb.cs03gfixeofo.us-east-2.rds.amazonaws.com:3306/ethniconnect #ethni-connect.ciff6u6uo7qd.us-east-2.rds.amazonaws.com (new updated saranya's)