Add Departamento entity and repository; fix registration endpoint typo
This commit is contained in:
parent
4ad3ed7f51
commit
a880ee6d92
|
|
@ -9,12 +9,12 @@ import org.springframework.context.annotation.Configuration;
|
|||
@Configuration
|
||||
public class DataInitializer {
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner initData(UserService userService) {
|
||||
return args -> {
|
||||
userService.registerUser("admin", "admin123", Role.ADMIN.name(), "admin123@ejemplo.com",null);
|
||||
userService.registerUser("user", "user123", Role.USER.name(), "user123@ejemplo.com",null);
|
||||
};
|
||||
}
|
||||
// @Bean
|
||||
// public CommandLineRunner initData(UserService userService) {
|
||||
// return args -> {
|
||||
// userService.registerUser("admin", "admin123", Role.ADMIN.name(), "admin123@ejemplo.com",null);
|
||||
// userService.registerUser("user", "user123", Role.USER.name(), "user123@ejemplo.com",null);
|
||||
// };
|
||||
// }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public class AuthController {
|
|||
this.userService = userService;
|
||||
}
|
||||
|
||||
@PostMapping("/regisater")
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<String> register(@RequestParam String username, @RequestParam String password, @RequestParam String role, @RequestParam String mail) {
|
||||
userService.registerUser(username, password, role, mail,null);
|
||||
return ResponseEntity.ok("User registered successfully");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package com.ieslamar.GestionInventario.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table(name = "departamentos") // Nombre de la tabla en MySQL
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Departamento {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY) // ID autoincremental
|
||||
private int id;
|
||||
|
||||
@Column(nullable = false, unique = true) // No se permite usuarios duplicados
|
||||
private String nombre;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package com.ieslamar.GestionInventario.repos;
|
||||
|
||||
import com.ieslamar.GestionInventario.entities.Departamento;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface DepartamentoRepository extends JpaRepository<Departamento, Integer> {
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.ieslamar.GestionInventario.services;
|
||||
|
||||
import com.ieslamar.GestionInventario.entities.Departamento;
|
||||
import com.ieslamar.GestionInventario.repos.DepartamentoRepository;
|
||||
import com.ieslamar.GestionInventario.repos.UserRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DepartamentoService {
|
||||
private final DepartamentoRepository departamentoRepository;
|
||||
|
||||
public DepartamentoService(DepartamentoRepository departamentoRepository) {
|
||||
this.departamentoRepository = departamentoRepository;
|
||||
}
|
||||
public List<Departamento> getAllDepartamentos() {
|
||||
return departamentoRepository.findAll();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue