From fc4d0b09faedfef1c62047314f1ac442f09b57fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=B6mer=20y=C4=B1ld=C4=B1z?= Date: Fri, 18 Oct 2024 20:03:49 +0300 Subject: [PATCH] demo --- backend/pom.xml | 5 ++++ .../controller/AccountController.java | 16 ++++++++++++- .../projectAtm/controller/UserController.java | 1 - .../resources/application-mysql.properties | 10 ++++++++ .../resources/application-postgres.properties | 15 ++++++------ .../src/main/resources/application.properties | 11 ++------- .../AccountControllerIntegrationtest.java | 4 ++-- .../classes/application-mysql.properties | 10 ++++++++ .../classes/application-postgres.properties | 15 ++++++------ .../omery/projectAtm/config/CorsConfig.class | Bin 1226 -> 0 bytes .../compile/default-compile/createdFiles.lst | 22 ------------------ .../compile/default-compile/inputFiles.lst | 18 -------------- .../default-testCompile/createdFiles.lst | 5 ---- .../default-testCompile/inputFiles.lst | 5 ---- .../AccountControllerIntegrationtest.class | Bin 6427 -> 6427 bytes 15 files changed, 60 insertions(+), 77 deletions(-) delete mode 100644 backend/target/classes/com/omery/projectAtm/config/CorsConfig.class delete mode 100644 backend/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst delete mode 100644 backend/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst delete mode 100644 backend/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst delete mode 100644 backend/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst diff --git a/backend/pom.xml b/backend/pom.xml index 1fc28d8d0..b911b5f70 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -39,6 +39,11 @@ org.springframework.boot spring-boot-starter-web + + mysql + mysql-connector-java + 8.0.33 + org.springframework.boot spring-boot-starter-test diff --git a/backend/src/main/java/com/omery/projectAtm/controller/AccountController.java b/backend/src/main/java/com/omery/projectAtm/controller/AccountController.java index 53036750c..763da04b0 100644 --- a/backend/src/main/java/com/omery/projectAtm/controller/AccountController.java +++ b/backend/src/main/java/com/omery/projectAtm/controller/AccountController.java @@ -16,7 +16,6 @@ import java.util.stream.Collectors; @RestController -@CrossOrigin("http://localhost:3000") public class AccountController { @@ -52,5 +51,20 @@ public ResponseEntity getUser(@PathVariable("id") Long id,@PathVaria return new ResponseEntity<>(accountDto, HttpStatus.OK); }).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND)); } + @DeleteMapping(path = "/users/{id}/accounts/{acc_id}") + public ResponseEntity deleteAccount(@PathVariable("id") Long id,@PathVariable("acc_id") Long acc_id) { + try { + if (accountService.isExists(acc_id)) { + accountService.deleteAccount(acc_id); + return ResponseEntity.noContent().build(); + } else { + return ResponseEntity.notFound().build(); + } + } catch (Exception e) { + // Log the error details + System.err.println("Error deleting account: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + } } diff --git a/backend/src/main/java/com/omery/projectAtm/controller/UserController.java b/backend/src/main/java/com/omery/projectAtm/controller/UserController.java index 26fdee396..7407a655a 100644 --- a/backend/src/main/java/com/omery/projectAtm/controller/UserController.java +++ b/backend/src/main/java/com/omery/projectAtm/controller/UserController.java @@ -14,7 +14,6 @@ import java.util.stream.Collectors; @RestController -@CrossOrigin("http://localhost:3000") public class UserController { private final UserService userService; private final AccountService accountService; diff --git a/backend/src/main/resources/application-mysql.properties b/backend/src/main/resources/application-mysql.properties index e69de29bb..71c4a7e23 100644 --- a/backend/src/main/resources/application-mysql.properties +++ b/backend/src/main/resources/application-mysql.properties @@ -0,0 +1,10 @@ +# MySQL-specific configuration +spring.datasource.url=jdbc:mysql://localhost:3306/mydb +spring.datasource.username=mysql_user +spring.datasource.password=mysql_password +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + +# Hibernate settings +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true diff --git a/backend/src/main/resources/application-postgres.properties b/backend/src/main/resources/application-postgres.properties index cab8cfb94..d96b0eff1 100644 --- a/backend/src/main/resources/application-postgres.properties +++ b/backend/src/main/resources/application-postgres.properties @@ -1,9 +1,10 @@ - -spring.datasource.url=jdbc:postgresql://localhost:5432/postgres -spring.datasource.username=postgres -spring.datasource.password=oy159753 +# PostgreSQL-specific configuration +spring.datasource.url=jdbc:postgresql://localhost:5432/mydb +spring.datasource.username=myuser +spring.datasource.password=123456 spring.datasource.driver-class-name=org.postgresql.Driver -spring.jpa.hibernate.ddl-auto=update -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect - +# Hibernate settings +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index bd00691e3..8a83d28b0 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -1,9 +1,2 @@ -spring.datasource.database-platform=org.hibernate.dialect.PostgreSQLDialect -spring.database.driverClassName=org.postgresql.Driver -spring.datasource.url=jdbc:postgresql://appdb:5432/appdb -spring.datasource.username=postgres -spring.datasource.password=oy159753 -spring.datasource.driver-class-name=org.postgresql.Driver -spring.jpa.hibernate.ddl-auto=update - - +# Activate PostgreSQL profile +spring.profiles.active=postgresql diff --git a/backend/src/test/java/com/omery/projectAtm/controller/AccountControllerIntegrationtest.java b/backend/src/test/java/com/omery/projectAtm/controller/AccountControllerIntegrationtest.java index 2511cdf3c..f0f1c6c53 100644 --- a/backend/src/test/java/com/omery/projectAtm/controller/AccountControllerIntegrationtest.java +++ b/backend/src/test/java/com/omery/projectAtm/controller/AccountControllerIntegrationtest.java @@ -48,7 +48,8 @@ public void testThatGetUserReturnsWhenAccountExist() throws Exception { userService.save(userEntity); AccountEntity testAccountEntityA = TestDataUtil.createTestAccountEntityA(userEntity); accountService.save(testAccountEntityA,testAccountEntityA.getUserEntity().getId()); - String accountJson = objectMapper.writeValueAsString(testAccountEntityA); + String accountJson; + accountJson = objectMapper.writeValueAsString(testAccountEntityA); mockMvc.perform( MockMvcRequestBuilders.post("/users/1/accounts/new") @@ -108,4 +109,3 @@ public void testThatDeleteWithAccount() throws Exception{ } } - diff --git a/backend/target/classes/application-mysql.properties b/backend/target/classes/application-mysql.properties index e69de29bb..71c4a7e23 100644 --- a/backend/target/classes/application-mysql.properties +++ b/backend/target/classes/application-mysql.properties @@ -0,0 +1,10 @@ +# MySQL-specific configuration +spring.datasource.url=jdbc:mysql://localhost:3306/mydb +spring.datasource.username=mysql_user +spring.datasource.password=mysql_password +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver + +# Hibernate settings +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true diff --git a/backend/target/classes/application-postgres.properties b/backend/target/classes/application-postgres.properties index cab8cfb94..d96b0eff1 100644 --- a/backend/target/classes/application-postgres.properties +++ b/backend/target/classes/application-postgres.properties @@ -1,9 +1,10 @@ - -spring.datasource.url=jdbc:postgresql://localhost:5432/postgres -spring.datasource.username=postgres -spring.datasource.password=oy159753 +# PostgreSQL-specific configuration +spring.datasource.url=jdbc:postgresql://localhost:5432/mydb +spring.datasource.username=myuser +spring.datasource.password=123456 spring.datasource.driver-class-name=org.postgresql.Driver -spring.jpa.hibernate.ddl-auto=update -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect - +# Hibernate settings +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +spring.jpa.hibernate.ddl-auto=update +spring.jpa.show-sql=true diff --git a/backend/target/classes/com/omery/projectAtm/config/CorsConfig.class b/backend/target/classes/com/omery/projectAtm/config/CorsConfig.class deleted file mode 100644 index f2278ec9bfbf2c7dce8fc1ee30d6de293514a05a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1226 zcmcIkTW=CU6#k|_7jcD(TCG(}z0`$j_stiyv6A=%)|7_Y_~Nikw^Lz<%nl$w%a@v% z=nwEm8PBk^*u)1T@#S1*cE0nS+y40Z^*ewU*ver6DFECv-YPp|$&!`Kl-M*zap)d%I(LXMM5Fs7+erVC|oBKM?K4Fi0>4T4;uJO?3oAp)Mow zX3%R3z0ccSIw{swz`HH3rS+$WX>%;8K3@IrXjTcBM#l1?BL%`J@@?OyvvM=gIXtNqY@sai64{e1Hdd zNFKu@Y!FC^><^?qLl8 diff --git a/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst deleted file mode 100644 index ac5a251fe..000000000 --- a/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +++ /dev/null @@ -1,22 +0,0 @@ -com/omery/projectAtm/domain/dto/AccountDto.class -com/omery/projectAtm/mappers/impl/AccountMapperImpl.class -com/omery/projectAtm/domain/entities/AccountEntity$AccountEntityBuilder.class -com/omery/projectAtm/services/impl/AccountServiceImpl.class -com/omery/projectAtm/domain/dto/UserDto$UserDtoBuilder.class -com/omery/projectAtm/services/AccountService.class -com/omery/projectAtm/mappers/impl/UserMapperImpl.class -com/omery/projectAtm/domain/entities/UserEntity$UserEntityBuilder.class -com/omery/projectAtm/repositories/UserRepository.class -com/omery/projectAtm/domain/dto/UserDto.class -com/omery/projectAtm/config/CorsConfig.class -com/omery/projectAtm/domain/entities/AccountEntity.class -com/omery/projectAtm/repositories/AccountRepository.class -com/omery/projectAtm/controller/UserController.class -com/omery/projectAtm/config/MapperConfig.class -com/omery/projectAtm/mappers/Mapper.class -com/omery/projectAtm/domain/dto/AccountDto$AccountDtoBuilder.class -com/omery/projectAtm/services/impl/UserServiceImpl.class -com/omery/projectAtm/domain/entities/UserEntity.class -com/omery/projectAtm/controller/AccountController.class -com/omery/projectAtm/ProjectAtmApplication.class -com/omery/projectAtm/services/UserService.class diff --git a/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst deleted file mode 100644 index 8f2f8a362..000000000 --- a/backend/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ /dev/null @@ -1,18 +0,0 @@ -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/mappers/Mapper.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/controller/UserController.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/mappers/impl/UserMapperImpl.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/services/impl/AccountServiceImpl.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/domain/dto/UserDto.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/services/AccountService.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/config/CorsConfig.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/ProjectAtmApplication.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/repositories/AccountRepository.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/services/UserService.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/mappers/impl/AccountMapperImpl.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/domain/entities/UserEntity.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/repositories/UserRepository.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/controller/AccountController.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/config/MapperConfig.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/services/impl/UserServiceImpl.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/domain/dto/AccountDto.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/main/java/com/omery/projectAtm/domain/entities/AccountEntity.java diff --git a/backend/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst b/backend/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst deleted file mode 100644 index 6ed13043b..000000000 --- a/backend/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/createdFiles.lst +++ /dev/null @@ -1,5 +0,0 @@ -com/omery/projectAtm/controller/UserControllerIntegrationTest.class -com/omery/projectAtm/controller/AccountControllerIntegrationtest.class -com/omery/projectAtm/ProjectAtmApplicationTests.class -com/omery/projectAtm/TestDataUtil.class -com/omery/projectAtm/repositories/UserRepoIntegrationTest.class diff --git a/backend/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/backend/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst deleted file mode 100644 index db2d40fdb..000000000 --- a/backend/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst +++ /dev/null @@ -1,5 +0,0 @@ -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/test/java/com/omery/projectAtm/controller/AccountControllerIntegrationtest.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/test/java/com/omery/projectAtm/TestDataUtil.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/test/java/com/omery/projectAtm/ProjectAtmApplicationTests.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/test/java/com/omery/projectAtm/repositories/UserRepoIntegrationTest.java -/Users/omeryildiz/Documents/GitHub/spring-boot-atmProject/backend/src/test/java/com/omery/projectAtm/controller/UserControllerIntegrationTest.java diff --git a/backend/target/test-classes/com/omery/projectAtm/controller/AccountControllerIntegrationtest.class b/backend/target/test-classes/com/omery/projectAtm/controller/AccountControllerIntegrationtest.class index fddc953184c03678a1b5e46bfdc33d9ad0a7548b..6157003866f1d7aabb482d82e88b664fc456323c 100644 GIT binary patch delta 219 zcmWN~y>bCj7>Dtv&}(dHHCnPPi|mLn@hw@bB#ar0SRa!+&}uTeEfu+iT!TvCqWtGH z=RNcO&T}@;=Kt16=17yLNP!AAHQin{w;6WYw_g@=R_ULQ`6@6xXHKzboy=$!GeIk!^UwR-tlpaYtq?BwjQG=tr8C|A23)ajzu=H-xx3Q91OKqgK cQag3J>fB>#$JX29s7zNGXW5fFFY0{$03#MAz5oCK