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
Binary file added PRA/Images/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PRA/Images/image-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PRA/Images/image-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PRA/Images/image-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PRA/Images/image-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PRA/Images/image-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PRA/Images/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions PRA/Postman PRA02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Postman + Spring Boot PRA
---
## Create User
![Create User](Images/image-1.png)|

---
## Get All Users
![Get All Users](Images/image-2.png)

---
## Get User By ID
![Get User By ID](Images/image-3.png)

---
## Update User
![Update User](Images/image-4.png)

---
## Delete User
![Delete User](Images/image-5.png)

---
## Delete All Users
![Delete All Users](Images/image-6.png)

---
## H2 Data Base
![H2](Images/image.png)
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package dev.pronunciationAppBack.controller;

import dev.pronunciationAppBack.model.User;
import dev.pronunciationAppBack.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/users")
public class UserController {

@Autowired
private UserService userService;

@GetMapping("/hello")
public String hello() {
return "Hello Albert, this is a test";
}

@GetMapping
public List<User> getAllUsers() {
return userService.getAllUsers();
}

@GetMapping("/{id}")
public User getUserById(@PathVariable String id) {
Optional<User> user = userService.getUserById(id);

if (user.isPresent()) {
return user.get();
} else {
return null;
}
}

@PostMapping("/createUser")
public User createUser(@RequestBody User user) {
return userService.createUser(user);
}

@PutMapping("/{id}")
public User updateUser(@PathVariable String id, @RequestBody User user) {
if (!userService.existsById(id)) {
return null;
}

user.setId(id);
return userService.updateUser(user);
}

@DeleteMapping("/{id}")
public String deleteUser(@PathVariable String id) {
if (userService.existsById(id)) {
userService.deleteUser(id);
return "User deleted";
} else {
return "User not found";
}
}

@DeleteMapping
public String deleteAllUsers() {
userService.deleteAllUsers();
return "All users deleted";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package dev.pronunciationAppBack.model;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

@Entity
@Table(name = "APP_USERS") // Because USER is an H2 reserved word
public class User {

@Id
private String id;
private String name;
private String email;
private String password;
private boolean isActive;

public User() {}

public User(String id, String name, String email, String password, boolean isActive) {
this.id = id;
this.name = name;
this.email = email;
this.password = password;
this.isActive = isActive;

}

public String getId() {
return id;
}

public void setId(String 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 getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public boolean isActive() {
return isActive;
}

public void setActive(boolean active) {
this.isActive = active;
}

@Override
public String toString() {
return "User{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", email='" + email + '\'' +
", isActive=" + isActive +
'}';
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.pronunciationAppBack.repository;

import dev.pronunciationAppBack.model.User;
import org.springframework.data.jpa.repository.JpaRepository;

public interface UserRepository extends JpaRepository<User, String> {
User getUserById(String id);
User getUserByEmail(String email);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package dev.pronunciationAppBack.service;

import dev.pronunciationAppBack.model.User;
import dev.pronunciationAppBack.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class UserService {

@Autowired
private UserRepository userRepository;

public List<User> getAllUsers() {
return userRepository.findAll();
}

public Optional<User> getUserById(String id) {
return userRepository.findById(id);
}

public User createUser(User user) {
return userRepository.save(user);
}

public User updateUser(User user) {
return userRepository.save(user);
}

public void deleteUser(String id) {
userRepository.deleteById(id);
}

public void deleteAllUsers() {
userRepository.deleteAll();
}

public boolean existsById(String id) {
return userRepository.existsById(id);
}

public long getUserCount() {
return userRepository.count();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ spring.h2.console.enabled=true


# H2 LOCAL DB SERVER
spring.datasource.url=jdbc:h2:/home/albert/MyProjects/DataBase/pronunciationDB/pronunciationDB.db
spring.datasource.username=albert
spring.datasource.password=1234
spring.datasource.url=jdbc:h2:/home/luis/projects/database/usersDB
spring.datasource.username=luis
spring.datasource.password=

# DDL OPTIONS: create-drop, create, update, none, validate
spring.jpa.hibernate.ddl-auto=none
spring.jpa.hibernate.ddl-auto=update