Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
omeryldzk committed Oct 18, 2024
2 parents deb5c64 + 851e19d commit 0eb8835
Show file tree
Hide file tree
Showing 22 changed files with 64 additions and 42 deletions.
1 change: 0 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public static void main(String[] args) {
SpringApplication.run(ProjectAtmApplication.class, args);
}

}
}
16 changes: 0 additions & 16 deletions backend/src/main/java/com/omery/projectAtm/config/CorsConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.stream.Collectors;

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

public class AccountController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@
import java.util.stream.Collectors;

@RestController
@CrossOrigin("http://67.207.86.85:3000")
@CrossOrigin("http://localhost:3000")
public class UserController {
private final UserService userService;
private final AccountService accountService;

private Mapper<UserEntity, UserDto> userMapper;

public UserController(UserService userService, Mapper<UserEntity, UserDto> userMapper) {
public UserController(UserService userService, Mapper<UserEntity, UserDto> userMapper,AccountService accountService) {
this.userService = userService;
this.userMapper = userMapper;
this.accountService = accountService;

}

@PostMapping(path = "/users/new")
@PostMapping(path = "/users")
public ResponseEntity<UserDto> createUser(@RequestBody UserDto user) {
UserEntity userEntity = userMapper.mapFrom(user);
UserEntity savedUserEntity = userService.save(userEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class AccountEntity {
@Column(nullable=false)
private Long totalCredit;

@ManyToOne(cascade = CascadeType.REMOVE)
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private UserEntity userEntity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
Expand All @@ -31,5 +33,8 @@ public class UserEntity {
@Column(nullable=false)
private String password;

@OneToMany(mappedBy = "userEntity", cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<AccountEntity> accounts;

}

Empty file.
9 changes: 9 additions & 0 deletions backend/src/main/resources/application-postgres.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=oy159753
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect


1 change: 0 additions & 1 deletion backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ spring.datasource.username=postgres
spring.datasource.password=oy159753
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.security.enabled=false


Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,20 @@ public void testThatGetAccountsReturnsWhenUserExist() throws Exception {
}

@Test
public void testThatGetAccountOneReturnsWhenUserExist() throws Exception {
public void testThatDeleteWithAccount() throws Exception{
UserEntity testUserEntityB = TestDataUtil.createTestUserEntityB();
userService.save(testUserEntityB);
AccountEntity testAccountEntityA = TestDataUtil.createTestAccountEntityA(testUserEntityB);
accountService.save(testAccountEntityA,testAccountEntityA.getUserEntity().getId());

accountService.deleteAccount(testAccountEntityA.getAcc_id()); // Assert: Try to retrieve the user and expect a 404 Not Found status
mockMvc.perform(
MockMvcRequestBuilders.get("/users/1/accounts/1")
MockMvcRequestBuilders.get("/users/" + testUserEntityB.getId() + "/accounts/" +
testAccountEntityA.getAcc_id())
.contentType(MediaType.APPLICATION_JSON)
).andExpect(
MockMvcResultMatchers.jsonPath("$.acc_id").value(1)
).andExpect(
MockMvcResultMatchers.jsonPath("$.totalCredit").value(0)
MockMvcResultMatchers.status().isNotFound()
);
}
}


Empty file.
9 changes: 9 additions & 0 deletions backend/target/classes/application-postgres.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=oy159753
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect


14 changes: 6 additions & 8 deletions backend/target/classes/application.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
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.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.security.enabled=false


spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 0 additions & 3 deletions backend/target/maven-archiver/pom.properties

This file was deleted.

Binary file not shown.
20 changes: 19 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,27 @@ services:
POSTGRES_PASSWORD: oy159753
POSTGRES_DB: appdb
ports:
- "5433:5432"
- "5432:5432"
volumes:
- app-db-data:/var/lib/postgresql/data
pgadmin:
image: dpage/pgadmin4
ports:
- "5050:80"
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: admin
depends_on:
- appdb
react-app:
build:
context: ./frontend
dockerfile: Dockerfile
container_name: react-app
ports:
- "3000:3000"
depends_on:
- spring-boot-app
spring-boot-app:
build:
context: ./backend
Expand Down

0 comments on commit 0eb8835

Please sign in to comment.