Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>com.ironhack</groupId> <artifactId>accounts_micro</artifactId> <version>1.0-SNAPSHOT</version>
</dependency>

</dependencies>
</dependencyManagement>
<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ironhack.users_micro.controller;

import com.ironhack.users_micro.dto.UserWithAccountsDTO;
import com.ironhack.users_micro.dto.UserPatchAccountDTO;
import com.ironhack.users_micro.exception.UserNotFoundException;
import com.ironhack.users_micro.model.User;
Expand All @@ -24,22 +25,6 @@ public List<User> getAllUsers() {
return userService.getAllUsers();
}

@GetMapping("/{id}")
public ResponseEntity<?> getUserById(@PathVariable long id) {
try {
User foundUser = userService.getUserById(id);
return new ResponseEntity<>(foundUser, HttpStatus.FOUND);
} catch (UserNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}

@PostMapping
public ResponseEntity<User> createUser(@RequestBody User user) {
User createdUser = userService.createUser(user);
return new ResponseEntity<>(createdUser, HttpStatus.CREATED);
}

@PatchMapping("/account/{userId}")
public ResponseEntity<?> patchAccountId(@RequestBody UserPatchAccountDTO userPatchAccountDTO, @PathVariable("userId") Long userId) {
try {
Expand All @@ -49,4 +34,4 @@ public ResponseEntity<?> patchAccountId(@RequestBody UserPatchAccountDTO userPat
return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND);
}
}
}
}
57 changes: 57 additions & 0 deletions src/main/java/com/ironhack/users_micro/dto/AccountDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.ironhack.users_micro.dto;





public class AccountDTO {
private Long id;
private Long ownerId;
private String isbn;
private java.math.BigDecimal balance;

public AccountDTO() {
// Constructor sin argumentos (puede estar vacío o tener lógica de inicialización)
}

// Constructor con argumentos (si lo necesitas)
public AccountDTO(Long id, Long ownerId, String isbn, java.math.BigDecimal balance) {
this.id = id;
this.ownerId = ownerId;
this.isbn = isbn;
this.balance = balance;
}

// Getters y setters (necesarios para acceder a los atributos)
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Long getOwnerId() {
return ownerId;
}

public void setOwnerId(Long ownerId) {
this.ownerId = ownerId;
}

public String getIsbn() {
return isbn;
}

public void setIsbn(String isbn) {
this.isbn = isbn;
}

public java.math.BigDecimal getBalance() {
return balance;
}

public void setBalance(java.math.BigDecimal balance) {
this.balance = balance;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.ironhack.users_micro.dto;

import java.util.List;

public class UserWithAccountsDTO {
private Integer id;
private String name;
private String email;
private String username;
private List<AccountDTO> accounts;

// Constructor vacío
public UserWithAccountsDTO() {
}

// Constructor con parámetros
public UserWithAccountsDTO(Integer id, String name, String email, String username, List<AccountDTO> accounts) {
this.id = id;
this.name = name;
this.email = email;
this.username = username;
this.accounts = accounts;
}
// Getters y setters
public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}

public List<AccountDTO> getAccounts() {
return accounts;
}

public void setAccounts(List<AccountDTO> accounts) {
this.accounts = accounts;
}

@Override
public String toString() {
return "UserWithAccountsDTO{" +
"id=" + id +
", name='" + name + '\'' +
", email='" + email + '\'' +
", username='" + username + '\'' +
", accounts=" + accounts +
'}';
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring.application.name=users-micro
spring.datasource.url=jdbc:mysql://localhost:3306/users_micro
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
Expand Down