diff --git a/CabManagementSystem/.metadata/.log b/CabManagementSystem/.metadata/.log index b0b6aef..261ece4 100644 --- a/CabManagementSystem/.metadata/.log +++ b/CabManagementSystem/.metadata/.log @@ -57,3 +57,155 @@ user global configuration and to define the default location to store repositori not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and EGit might behave differently since they see different configuration options. This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. +!SESSION 2024-01-10 12:36:34.121 ----------------------------------------------- +eclipse.buildId=4.18.1.202305021758 +java.version=17.0.7 +java.vendor=Eclipse Adoptium +BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_IN +Framework arguments: -product org.springframework.boot.ide.branding.sts4 +Command-line arguments: -os win32 -ws win32 -arch x86_64 -product org.springframework.boot.ide.branding.sts4 + +!ENTRY ch.qos.logback.classic 1 0 2024-01-10 12:36:35.233 +!MESSAGE Activated before the state location was initialized. Retry after the state location is initialized. + +!ENTRY org.eclipse.core.resources 4 567 2024-01-10 12:36:55.162 +!MESSAGE Workspace restored, but some problems occurred. +!SUBENTRY 1 org.eclipse.core.resources 4 567 2024-01-10 12:36:55.163 +!MESSAGE Could not read metadata for '.org.eclipse.egit.core.cmp'. +!STACK 1 +org.eclipse.core.internal.resources.ResourceException(/.org.eclipse.egit.core.cmp)[567]: java.lang.Exception: The project description file (.project) for '.org.eclipse.egit.core.cmp' is missing. This file contains important information about the project. The project will not function properly until this file is restored. + at org.eclipse.core.internal.resources.ResourceException.provideStackTrace(ResourceException.java:42) + at org.eclipse.core.internal.resources.ResourceException.(ResourceException.java:38) + at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:908) + at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:894) + at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:874) + at org.eclipse.core.internal.resources.SaveManager.restore(SaveManager.java:730) + at org.eclipse.core.internal.resources.SaveManager.startup(SaveManager.java:1584) + at org.eclipse.core.internal.resources.Workspace.startup(Workspace.java:2547) + at org.eclipse.core.internal.resources.Workspace.open(Workspace.java:2252) + at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:571) + at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:1) + at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:943) + at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1) + at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256) + at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183) + at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:321) + at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:264) + at org.eclipse.core.resources.ResourcesPlugin.start(ResourcesPlugin.java:545) + at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:818) + at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:1) + at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) + at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:810) + at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:767) + at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1032) + at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:371) + at org.eclipse.osgi.container.Module.doStart(Module.java:605) + at org.eclipse.osgi.container.Module.start(Module.java:468) + at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:513) + at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:117) + at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:570) + at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:335) + at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:397) + at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:41) + at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:496) + at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416) + at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168) + at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) + at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:153) + at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203) + at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136) + at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) + at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:402) + at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255) + at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) + at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.base/java.lang.reflect.Method.invoke(Method.java:568) + at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659) + at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596) + at org.eclipse.equinox.launcher.Main.run(Main.java:1467) +!SUBENTRY 2 org.eclipse.core.resources 4 567 2024-01-10 12:36:55.163 +!MESSAGE The project description file (.project) for '.org.eclipse.egit.core.cmp' is missing. This file contains important information about the project. The project will not function properly until this file is restored. +!STACK 0 +java.lang.Exception: The project description file (.project) for '.org.eclipse.egit.core.cmp' is missing. This file contains important information about the project. The project will not function properly until this file is restored. + at org.eclipse.core.internal.resources.ResourceException.provideStackTrace(ResourceException.java:42) + at org.eclipse.core.internal.resources.ResourceException.(ResourceException.java:38) + at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:908) + at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:894) + at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:874) + at org.eclipse.core.internal.resources.SaveManager.restore(SaveManager.java:730) + at org.eclipse.core.internal.resources.SaveManager.startup(SaveManager.java:1584) + at org.eclipse.core.internal.resources.Workspace.startup(Workspace.java:2547) + at org.eclipse.core.internal.resources.Workspace.open(Workspace.java:2252) + at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:571) + at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:1) + at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:943) + at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1) + at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256) + at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:183) + at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:321) + at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:264) + at org.eclipse.core.resources.ResourcesPlugin.start(ResourcesPlugin.java:545) + at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:818) + at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:1) + at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) + at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:810) + at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:767) + at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1032) + at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:371) + at org.eclipse.osgi.container.Module.doStart(Module.java:605) + at org.eclipse.osgi.container.Module.start(Module.java:468) + at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:513) + at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:117) + at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:570) + at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:335) + at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:397) + at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:41) + at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:496) + at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416) + at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168) + at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520) + at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:153) + at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203) + at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136) + at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) + at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:402) + at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255) + at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) + at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.base/java.lang.reflect.Method.invoke(Method.java:568) + at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659) + at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596) + at org.eclipse.equinox.launcher.Main.run(Main.java:1467) + +!ENTRY ch.qos.logback.classic 1 0 2024-01-10 12:36:55.610 +!MESSAGE Logback config file: D:\projects\onlinecabBookingApplication\Safar\CabManagementSystem\.metadata\.plugins\org.eclipse.m2e.logback\logback.2.1.100.20230106-1511.xml + +!ENTRY org.eclipse.jface 2 0 2024-01-10 12:36:57.521 +!MESSAGE Keybinding conflicts occurred. They may interfere with normal accelerator operation. +!SUBENTRY 1 org.eclipse.jface 2 0 2024-01-10 12:36:57.522 +!MESSAGE A conflict occurred for CTRL+SHIFT+T: +Binding(CTRL+SHIFT+T, + ParameterizedCommand(Command(org.eclipse.jdt.ui.navigate.open.type,Open Type, + Open a type in a Java editor, + Category(org.eclipse.ui.category.navigate,Navigate,null,true), + WorkbenchHandlerServiceHandler("org.eclipse.jdt.ui.navigate.open.type"), + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.ui.contexts.window,,,system) +Binding(CTRL+SHIFT+T, + ParameterizedCommand(Command(org.eclipse.lsp4e.symbolinworkspace,Go to Symbol in Workspace, + , + Category(org.eclipse.lsp4e.category,Language Servers,null,true), + WorkbenchHandlerServiceHandler("org.eclipse.lsp4e.symbolinworkspace"), + ,,true),null), + org.eclipse.ui.defaultAcceleratorConfiguration, + org.eclipse.ui.contexts.window,,,system) + +!ENTRY org.eclipse.egit.ui 2 0 2024-01-10 12:36:59.953 +!MESSAGE Warning: The environment variable HOME is not set. The following directory will be used to store the Git +user global configuration and to define the default location to store repositories: 'C:\Users\ankit'. If this is +not correct please set the HOME environment variable and restart Eclipse. Otherwise Git for Windows and +EGit might behave differently since they see different configuration options. +This warning can be switched off on the Team > Git > Confirmations and Warnings preference page. diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.location b/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.location index d924b6c..3d7c2ba 100644 Binary files a/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.location and b/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.projects/.org.eclipse.egit.core.cmp/.location differ diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index b/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index index d237251..cc1955f 100644 Binary files a/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index and b/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/.indexes/properties.index differ diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree b/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree deleted file mode 100644 index 4afac25..0000000 Binary files a/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/1.tree and /dev/null differ diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree b/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree new file mode 100644 index 0000000..09d27fe Binary files /dev/null and b/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.root/2.tree differ diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources b/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources index d353858..6aae9ba 100644 Binary files a/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources and b/CabManagementSystem/.metadata/.plugins/org.eclipse.core.resources/.safetable/org.eclipse.core.resources differ diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi b/CabManagementSystem/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi index 5ce3786..ea8165e 100644 --- a/CabManagementSystem/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi +++ b/CabManagementSystem/.metadata/.plugins/org.eclipse.e4.workbench/workbench.xmi @@ -362,7 +362,7 @@ Draggable - + toolbarSeparator @@ -390,7 +390,7 @@ Draggable - + toolbarSeparator @@ -510,6 +510,7 @@ + @@ -589,7 +590,6 @@ - @@ -757,6 +757,10 @@ + + + + @@ -949,28 +953,28 @@ - + Spy - - - - + + + + - - - + + + - + - - + + - + @@ -1402,6 +1406,24 @@ View categoryTag:Other + + + + View + categoryTag:Java + + + + + View + categoryTag:Java + + + + + View + categoryTag:Other + glue @@ -2398,6 +2420,15 @@ + + + + + + + + + @@ -2409,7 +2440,7 @@ - + diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.m2e.logback/0.log b/CabManagementSystem/.metadata/.plugins/org.eclipse.m2e.logback/0.log index f474cea..a445d5d 100644 --- a/CabManagementSystem/.metadata/.plugins/org.eclipse.m2e.logback/0.log +++ b/CabManagementSystem/.metadata/.plugins/org.eclipse.m2e.logback/0.log @@ -1 +1,2 @@ 2023-06-30 21:25:04,214 [Worker-1: Loading available Gradle versions] INFO o.e.b.c.i.u.g.PublishedGradleVersions - Gradle version information cache is out-of-date. Trying to update. +2024-01-10 12:36:59,935 [Worker-4: Loading available Gradle versions] INFO o.e.b.c.i.u.g.PublishedGradleVersions - Gradle version information cache is up-to-date. Trying to read. diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.1.100.20230106-1511.xml b/CabManagementSystem/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.1.100.20230106-1511.xml new file mode 100644 index 0000000..abdf1c7 --- /dev/null +++ b/CabManagementSystem/.metadata/.plugins/org.eclipse.m2e.logback/logback.2.1.100.20230106-1511.xml @@ -0,0 +1,41 @@ + + + + %date [%thread] %-5level %logger{35} - %msg%n + + + OFF + + + + + ${org.eclipse.m2e.log.dir}/0.log + + ${org.eclipse.m2e.log.dir}/%i.log + 1 + 10 + + + 10MB + + + %date [%thread] %-5level %logger{35} - %msg%n + + + + + + WARN + + + + + + + + + + + + + diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.pde.core/.cache/clean-cache.properties b/CabManagementSystem/.metadata/.plugins/org.eclipse.pde.core/.cache/clean-cache.properties index db5bb25..0af8b00 100644 --- a/CabManagementSystem/.metadata/.plugins/org.eclipse.pde.core/.cache/clean-cache.properties +++ b/CabManagementSystem/.metadata/.plugins/org.eclipse.pde.core/.cache/clean-cache.properties @@ -1,2 +1,2 @@ #Cached timestamps -#Fri Jun 30 21:26:18 IST 2023 +#Wed Jan 10 12:38:41 IST 2024 diff --git a/CabManagementSystem/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml b/CabManagementSystem/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml index e452c8d..2f9ba3e 100644 --- a/CabManagementSystem/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml +++ b/CabManagementSystem/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml @@ -1,11 +1,44 @@
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
diff --git a/CabManagementSystem/.metadata/version.ini b/CabManagementSystem/.metadata/version.ini index 8dee503..754fb28 100644 --- a/CabManagementSystem/.metadata/version.ini +++ b/CabManagementSystem/.metadata/version.ini @@ -1,3 +1,3 @@ -#Fri Jun 30 21:24:44 IST 2023 +#Wed Jan 10 12:36:55 IST 2024 org.eclipse.core.runtime=2 -org.eclipse.platform=4.26.0.v20221123-1800 +org.eclipse.platform=4.27.0.v20230302-0300 diff --git a/CabManagementSystem/src/main/java/com/safar/config/AppConfig.java b/CabManagementSystem/src/main/java/com/safar/config/AppConfig.java index 2f29a59..8b30c82 100644 --- a/CabManagementSystem/src/main/java/com/safar/config/AppConfig.java +++ b/CabManagementSystem/src/main/java/com/safar/config/AppConfig.java @@ -58,6 +58,7 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { .requestMatchers("/cabBooking/**","cabBooking","/WALLET/**").hasAnyRole("ADMIN","USER") .requestMatchers(HttpMethod.PATCH,"/users/**","/WALLET/**").hasAnyRole("ADMIN","USER") .requestMatchers("/WALLET/**").hasRole("USER") + .requestMatchers(HttpMethod.GET,"/WALLET/getWallet/**").hasRole("ADMIN") .anyRequest().authenticated(); }) .csrf(csrf -> csrf.disable()) diff --git a/CabManagementSystem/src/main/java/com/safar/controller/WalletController.java b/CabManagementSystem/src/main/java/com/safar/controller/WalletController.java index a79e50d..babc686 100644 --- a/CabManagementSystem/src/main/java/com/safar/controller/WalletController.java +++ b/CabManagementSystem/src/main/java/com/safar/controller/WalletController.java @@ -1,6 +1,7 @@ package com.safar.controller; import com.safar.entity.Users; +import com.safar.exceptions.UsersException; import com.safar.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -35,12 +36,18 @@ public class WalletController { /** * Adds money to a user's wallet. * - * @param auth The authentication object for the logged-in user. + * + * @param auth The authentication object for the logged-in user * @param amount The amount of money to add. + * @author Ankit choubey * @return The updated wallet. + * */ @PostMapping("/addMoney") public ResponseEntityaddMoneyToWallet(Authentication auth, @RequestParam("amount") Float amount){ + if(auth==null) + throw new UsersException("User not logged in"); + Users user = userService.getUserDetailsByEmail(auth.getName()); Wallet wallet = user.getWallet(); Wallet res= wService.addMoney(wallet.getWalletId(), amount); @@ -51,6 +58,7 @@ public class WalletController { * Changes the status of a wallet. * * @param auth The authentication object for the logged-in user. + * @author Ankit choubey * @return The updated wallet. */ @PatchMapping("/changeStatus") @@ -65,24 +73,26 @@ public ResponseEntity changeStatus(Authentication auth) { * Creates a wallet for a user. * * @param email The email of the user for whom to create the wallet. + * @author Ankit choubey * @return The created wallet. */ - @PostMapping("/createWallet/{email}") - public ResponseEntity createWallet(@PathVariable String email) { + @PostMapping("/createWallet") + public ResponseEntity createWallet(@RequestParam("email") String email) { Wallet res = wService.createWallet(email); return new ResponseEntity<>(res, HttpStatus.CREATED); } /** - * Retrieves a user's wallet. + * Retrieves a wallet details using its id. * - * @param auth The authentication object for the logged-in user. - * @return The user's wallet. + * @param wid Wallet id + * @author Ankit choubey + * @return The wallet details */ - @GetMapping("/getWallet") - public ResponseEntity getWallet(Authentication auth) { - Users user = userService.getUserDetailsByEmail(auth.getName()); - Wallet wallet = user.getWallet(); + @GetMapping("/getWallet/{wid}") + public ResponseEntity getWallet( @PathVariable("wid") Integer wid ) { + + Wallet wallet = wService.getWallet(wid); return new ResponseEntity<>(wallet, HttpStatus.ACCEPTED); } @@ -91,10 +101,11 @@ public ResponseEntity getWallet(Authentication auth) { * * @param auth The authentication object for the logged-in user. * @return The wallet details of the logged-in user. + * @author Ankit choubey */ @GetMapping("/WalletDetails") public ResponseEntity getLoggedUserWallet(Authentication auth) { - if (auth.getName() == null) + if (auth.getName() == "") throw new WalletException("User is not logged into the system"); Wallet res = wService.getLoggedUserWallet(auth.getName()); return new ResponseEntity<>(res, HttpStatus.ACCEPTED); diff --git a/CabManagementSystem/src/main/java/com/safar/service/serviceImpl/WalletServicesImpl.java b/CabManagementSystem/src/main/java/com/safar/service/serviceImpl/WalletServicesImpl.java index d092461..60e07e9 100644 --- a/CabManagementSystem/src/main/java/com/safar/service/serviceImpl/WalletServicesImpl.java +++ b/CabManagementSystem/src/main/java/com/safar/service/serviceImpl/WalletServicesImpl.java @@ -215,7 +215,7 @@ public Wallet getLoggedUserWallet(String email) { if(email==null) throw new UsersException("Invalid user details provided"); - Users user= urepo.findByEmail(email).orElseThrow(()->new UsersException(" No logged User not found")); + Users user= urepo.findByEmail(email).orElseThrow(()->new UsersException(" User not found OR You should logged in")); Wallet res= user.getWallet(); if(res==null) throw new WalletException("NO Wallet found "); diff --git a/CabManagementSystem/src/main/resources/application.properties b/CabManagementSystem/src/main/resources/application.properties index 6451658..3192594 100644 --- a/CabManagementSystem/src/main/resources/application.properties +++ b/CabManagementSystem/src/main/resources/application.properties @@ -5,7 +5,7 @@ server.port=8888 spring.datasource.url=jdbc:mysql://localhost:3306/safar spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.username=root -spring.datasource.password=Sushil8081 +spring.datasource.password=ankitchoubey9807 #ORM s/w specific properties diff --git a/CabManagementSystem/src/test/java/com/safar/controller/WalletControllerTest.java b/CabManagementSystem/src/test/java/com/safar/controller/WalletControllerTest.java new file mode 100644 index 0000000..cd89f47 --- /dev/null +++ b/CabManagementSystem/src/test/java/com/safar/controller/WalletControllerTest.java @@ -0,0 +1,128 @@ +package com.safar.controller; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.safar.entity.Users; +import com.safar.entity.Wallet; +import com.safar.entity.WalletStatus; +import com.safar.service.UserService; +import com.safar.service.WalletServices; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.MvcResult; +import org.springframework.test.web.servlet.RequestBuilder; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; + +import static org.mockito.ArgumentMatchers.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@WebMvcTest(controllers = WalletController.class) +@AutoConfigureMockMvc(addFilters=false) +public class WalletControllerTest { + + @Autowired + private MockMvc mockMvc; + + @MockBean + private WalletServices walletServices; + + @MockBean + private UserService userService; + + private Wallet requestWallet; + + private Wallet responseWallet; + + private Users user; + + private Authentication auth; + + @BeforeEach + public void init(){ + requestWallet = new Wallet(); + requestWallet.setBalance(0.0f); + requestWallet.setStatus(WalletStatus.Active); + + responseWallet= new Wallet(); + responseWallet.setWalletId(1); + responseWallet.setBalance(0.0f); + responseWallet.setStatus(WalletStatus.Active); + user= new Users(); + user.setWallet(responseWallet); + auth = new UsernamePasswordAuthenticationToken("testusername","testpassword"); + + } + + @Test + @DisplayName("Wallet can be created") + public void testCreateWallet_WhenValidEmailPassed_shouldReturnWalletEnity() throws Exception { + Mockito.when(walletServices.createWallet(anyString())).thenReturn(responseWallet); + RequestBuilder builder = MockMvcRequestBuilders.post("/WALLET/createWallet").param("email","ankit@gmail.com").contentType(MediaType.APPLICATION_JSON_VALUE); + + MvcResult mvcResult = mockMvc.perform(builder).andExpect(status().isCreated()).andReturn(); + + String responseBodyAsString = mvcResult.getResponse().getContentAsString(); + + Wallet resWallet= new ObjectMapper().readValue(responseBodyAsString,Wallet.class); + + Assertions.assertNotNull(resWallet.getWalletId(),"Created wallet should have a id"); + Assertions.assertEquals(responseWallet.getWalletId(),resWallet.getWalletId(),"Walled id should equal to 1"); + Mockito.verify(walletServices, Mockito.times(1)).createWallet(anyString()); + + + } + + + + @Test + @DisplayName("Money can be added to wallet") + public void testAddMoneyToWallet_WhenAmountPassed_ThenMoneyShouldBeAddedIntoWallet() throws Exception { + + + + Mockito.when(userService.getUserDetailsByEmail(auth.getName())).thenReturn(user); + responseWallet.setBalance(10.0f); + Mockito.when(walletServices.addMoney(anyInt(), anyFloat())).thenReturn(responseWallet); + + RequestBuilder requestBuilder = MockMvcRequestBuilders.post("/WALLET/addMoney") + .param("amount", "10") // remove double quotes + .principal(auth) + .contentType(MediaType.APPLICATION_JSON_VALUE); + + MvcResult mvcResult = mockMvc.perform(requestBuilder).andExpect(status().isAccepted()).andReturn(); + String responseBodyAsString = mvcResult.getResponse().getContentAsString(); + Wallet resWallet = new ObjectMapper().readValue(responseBodyAsString, Wallet.class); + + Assertions.assertNotNull(resWallet.getWalletId(), "wallet should have a id"); + Assertions.assertEquals(10.0f, resWallet.getBalance(), "Walled should have added balance"); + Mockito.verify(walletServices, Mockito.times(1)).addMoney(anyInt(), anyFloat()); + } + + @Test + @DisplayName("wallet status can be change") + public void testChangeStatus_WhenValidUserLoggedIn_thenWalletStatusCanBeChanged() throws Exception { + Mockito.when(userService.getUserDetailsByEmail(auth.getName())).thenReturn(user); + responseWallet.setStatus(WalletStatus.Inactive); + Mockito.when(walletServices.changeStatus(anyInt())).thenReturn(responseWallet); + RequestBuilder requestBuilder= MockMvcRequestBuilders.patch("/WALLET/changeStatus").principal(auth).contentType(MediaType.APPLICATION_JSON_VALUE); + MvcResult mvcResult= mockMvc.perform(requestBuilder).andExpect(status().isAccepted()).andReturn(); + String responseBodyAsString= mvcResult.getResponse().getContentAsString(); + Wallet resWallet= new ObjectMapper().readValue(responseBodyAsString,Wallet.class); + + Assertions.assertNotNull(resWallet.getWalletId(),"Wallet should have a id"); + Assertions.assertEquals(WalletStatus.Inactive,resWallet.getStatus(),"status should be Inactive"); + + } + +}