Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
omeryldzk committed Oct 18, 2024
1 parent 0eb8835 commit fc4d0b0
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 77 deletions.
5 changes: 5 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.33</version> <!-- You can use the latest version available -->
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.util.stream.Collectors;

@RestController
@CrossOrigin("http://localhost:3000")

public class AccountController {

Expand Down Expand Up @@ -52,5 +51,20 @@ public ResponseEntity<AccountDto> 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<Void> 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();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions backend/src/main/resources/application-mysql.properties
Original file line number Diff line number Diff line change
@@ -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
15 changes: 8 additions & 7 deletions backend/src/main/resources/application-postgres.properties
Original file line number Diff line number Diff line change
@@ -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
11 changes: 2 additions & 9 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -108,4 +109,3 @@ public void testThatDeleteWithAccount() throws Exception{
}
}


10 changes: 10 additions & 0 deletions backend/target/classes/application-mysql.properties
Original file line number Diff line number Diff line change
@@ -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
15 changes: 8 additions & 7 deletions backend/target/classes/application-postgres.properties
Original file line number Diff line number Diff line change
@@ -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
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

0 comments on commit fc4d0b0

Please sign in to comment.