From 429045b6c54af9ef9ece5b2e4a574f1ee3715fe6 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 10 Sep 2024 02:41:19 -0500 Subject: [PATCH 01/99] =?UTF-8?q?=F0=9F=9A=A7=20add=20basic=20entities=20f?= =?UTF-8?q?rom=20db?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/RolesController.java | 49 +++++++++++++ .../controllers/UsersController.java | 59 +++++++++++++++ .../usersservice/controllers/fileToRemove.txt | 1 - .../usersservice/dtos/UserCreateDTO.java | 20 +++++ .../usersservice/dtos/fileToRemove.txt | 1 - .../usersservice/model/Deleted.java | 27 +++++++ .../fussiontech/usersservice/model/Rol.java | 27 +++++++ .../fussiontech/usersservice/model/User.java | 46 ++++++++++++ .../usersservice/model/fileToRemove.txt | 1 - .../repository/DeletedRepository.java | 7 ++ .../repository/RolRepository.java | 7 ++ .../repository/UserRepository.java | 7 ++ .../usersservice/repository/fileToRemove.txt | 1 - .../usersservice/services/RolService.java | 40 ++++++++++ .../usersservice/services/UserService.java | 73 +++++++++++++++++++ .../usersservice/services/fileToRemove.txt | 1 - 16 files changed, 362 insertions(+), 5 deletions(-) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/controllers/RolesController.java create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java delete mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/controllers/fileToRemove.txt create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java delete mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/dtos/fileToRemove.txt create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/model/Deleted.java create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/model/User.java delete mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/model/fileToRemove.txt create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/repository/DeletedRepository.java create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/repository/RolRepository.java create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/repository/UserRepository.java delete mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/repository/fileToRemove.txt create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/services/RolService.java create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java delete mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/services/fileToRemove.txt diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/RolesController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/RolesController.java new file mode 100644 index 0000000..ce96d25 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/RolesController.java @@ -0,0 +1,49 @@ +package co.allconnected.fussiontech.usersservice.controllers; + +import co.allconnected.fussiontech.usersservice.model.Rol; +import co.allconnected.fussiontech.usersservice.services.RolService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/v1/roles") +public class RolesController { + + private final RolService rolService; + + @Autowired + public RolesController(RolService rolService) { + this.rolService = rolService; + } + + @PostMapping + public ResponseEntity createRol(@RequestBody Rol rol) { + return ResponseEntity.ok(rolService.createRol(rol)); + } + + @GetMapping("/{id}") + public ResponseEntity getRol(@PathVariable String id) { + return rolService.getRol(id) + .map(ResponseEntity::ok) + .orElse(ResponseEntity.notFound().build()); + } + + @GetMapping + public ResponseEntity> getAllRoles() { + return ResponseEntity.ok(rolService.getAllRoles()); + } + + @PutMapping("/{id}") + public ResponseEntity updateRol(@PathVariable String id, @RequestBody Rol rol) { + return ResponseEntity.ok(rolService.updateRol(rol)); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteRol(@PathVariable String id) { + rolService.deleteRol(id); + return ResponseEntity.noContent().build(); + } +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java new file mode 100644 index 0000000..f7b098b --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -0,0 +1,59 @@ +package co.allconnected.fussiontech.usersservice.controllers; + +import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; +import co.allconnected.fussiontech.usersservice.model.User; +import co.allconnected.fussiontech.usersservice.services.UserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequestMapping("/api/v1/users") +public class UsersController { + + private final UserService userService; + + @Autowired + public UsersController(UserService userService) { + this.userService = userService; + } + + @GetMapping + public ResponseEntity> getAllUsers() { + return ResponseEntity.ok(userService.getAllUsers()); + } + + @GetMapping("/{id}") + public ResponseEntity getUserById(@PathVariable String id) { + User user = userService.getUserById(id); + if (user != null) { + return ResponseEntity.ok(user); + } else { + return ResponseEntity.notFound().build(); + } + } + + @PostMapping + public ResponseEntity createUser(@RequestBody UserCreateDTO user) { + return ResponseEntity.ok(userService.createUser(user)); + } +/* + @PutMapping("/{id}") + public ResponseEntity updateUser(@PathVariable String id, @RequestBody User user) { + User updatedUser = userService.updateUser(id, user); + if (updatedUser != null) { + return ResponseEntity.ok(updatedUser); + } else { + return ResponseEntity.notFound().build(); + } + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteUser(@PathVariable String id) { + userService.deleteUser(id); + return ResponseEntity.noContent().build(); + } + */ +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/fileToRemove.txt b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/fileToRemove.txt deleted file mode 100644 index 7755816..0000000 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/fileToRemove.txt +++ /dev/null @@ -1 +0,0 @@ -Este archivo es para dejar la estructura de carpetas del proyecto. Eliminar cuando se tenga el proyecto. \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java new file mode 100644 index 0000000..ae1aa46 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java @@ -0,0 +1,20 @@ +package co.allconnected.fussiontech.usersservice.dtos; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.math.BigDecimal; + +@Getter +@Setter +@NoArgsConstructor +public class UserCreateDTO { + private String fullname; + private String username; + private String mail; + private String photoUrl; + private BigDecimal locationLat; + private BigDecimal locationLng; + private Boolean active; +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/fileToRemove.txt b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/fileToRemove.txt deleted file mode 100644 index 7755816..0000000 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/fileToRemove.txt +++ /dev/null @@ -1 +0,0 @@ -Este archivo es para dejar la estructura de carpetas del proyecto. Eliminar cuando se tenga el proyecto. \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/Deleted.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/Deleted.java new file mode 100644 index 0000000..bf8e905 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/Deleted.java @@ -0,0 +1,27 @@ +package co.allconnected.fussiontech.usersservice.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import jakarta.persistence.Table; +import lombok.Getter; +import lombok.Setter; + +import java.time.Instant; + +@Getter +@Setter +@Entity +@Table(name = "deleted", schema = "all_connected_users") +public class Deleted { + @Id + @Column(name = "id_user", nullable = false, length = 28) + private String idUser; + + @Column(name = "reason", nullable = false, length = 200) + private String reason; + + @Column(name = "delete_date", nullable = false) + private Instant deleteDate; + +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java new file mode 100644 index 0000000..4e39457 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java @@ -0,0 +1,27 @@ +package co.allconnected.fussiontech.usersservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +import java.util.LinkedHashSet; +import java.util.Set; + +@Getter +@Setter +@Entity +@Table(name = "rol", schema = "all_connected_users") +public class Rol { + @Id + @Column(name = "id_rol", nullable = false, length = Integer.MAX_VALUE) + private String idRol; + + @JsonIgnore + @ManyToMany + @JoinTable(name = "user_rol", + joinColumns = @JoinColumn(name = "id_rol"), + inverseJoinColumns = @JoinColumn(name = "id_user")) + private Set users = new LinkedHashSet<>(); + +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java new file mode 100644 index 0000000..4e19723 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -0,0 +1,46 @@ +package co.allconnected.fussiontech.usersservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +import java.math.BigDecimal; +import java.util.LinkedHashSet; +import java.util.Set; + +@Getter +@Setter +@Entity +@Table(name = "\"user\"", schema = "all_connected_users") +public class User { + @Id + @Column(name = "id_user", nullable = false, length = 28) + private String idUser; + + @Column(name = "fullname", length = 100) + private String fullname; + + @Column(name = "username", nullable = false, length = 45) + private String username; + + @Column(name = "mail", length = 45) + private String mail; + + @Column(name = "photo_url", length = 200) + private String photoUrl; + + @Column(name = "location_lat", precision = 9, scale = 6) + private BigDecimal locationLat; + + @Column(name = "location_lng", precision = 9, scale = 6) + private BigDecimal locationLng; + + @Column(name = "active", nullable = false) + private Boolean active = false; + + @JsonIgnore + @ManyToMany(mappedBy = "users") + private Set rols = new LinkedHashSet<>(); + +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/fileToRemove.txt b/src/main/java/co/allconnected/fussiontech/usersservice/model/fileToRemove.txt deleted file mode 100644 index 7755816..0000000 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/fileToRemove.txt +++ /dev/null @@ -1 +0,0 @@ -Este archivo es para dejar la estructura de carpetas del proyecto. Eliminar cuando se tenga el proyecto. \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/repository/DeletedRepository.java b/src/main/java/co/allconnected/fussiontech/usersservice/repository/DeletedRepository.java new file mode 100644 index 0000000..86dc627 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/repository/DeletedRepository.java @@ -0,0 +1,7 @@ +package co.allconnected.fussiontech.usersservice.repository; + +import co.allconnected.fussiontech.usersservice.model.Deleted; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface DeletedRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/repository/RolRepository.java b/src/main/java/co/allconnected/fussiontech/usersservice/repository/RolRepository.java new file mode 100644 index 0000000..1950f71 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/repository/RolRepository.java @@ -0,0 +1,7 @@ +package co.allconnected.fussiontech.usersservice.repository; + +import co.allconnected.fussiontech.usersservice.model.Rol; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RolRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/repository/UserRepository.java b/src/main/java/co/allconnected/fussiontech/usersservice/repository/UserRepository.java new file mode 100644 index 0000000..029d854 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/repository/UserRepository.java @@ -0,0 +1,7 @@ +package co.allconnected.fussiontech.usersservice.repository; + +import co.allconnected.fussiontech.usersservice.model.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/repository/fileToRemove.txt b/src/main/java/co/allconnected/fussiontech/usersservice/repository/fileToRemove.txt deleted file mode 100644 index 7755816..0000000 --- a/src/main/java/co/allconnected/fussiontech/usersservice/repository/fileToRemove.txt +++ /dev/null @@ -1 +0,0 @@ -Este archivo es para dejar la estructura de carpetas del proyecto. Eliminar cuando se tenga el proyecto. \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/RolService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/RolService.java new file mode 100644 index 0000000..caff223 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/RolService.java @@ -0,0 +1,40 @@ +package co.allconnected.fussiontech.usersservice.services; + +import co.allconnected.fussiontech.usersservice.model.Rol; +import co.allconnected.fussiontech.usersservice.repository.RolRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +public class RolService { + + private final RolRepository rolRepository; + + @Autowired + public RolService(RolRepository rolRepository) { + this.rolRepository = rolRepository; + } + + public Rol createRol(Rol rol) { + return rolRepository.save(rol); + } + + public Optional getRol(String id) { + return rolRepository.findById(id); + } + + public List getAllRoles() { + return rolRepository.findAll(); + } + + public Rol updateRol(Rol rol) { + return rolRepository.save(rol); + } + + public void deleteRol(String id) { + rolRepository.deleteById(id); + } +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java new file mode 100644 index 0000000..1ec3359 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -0,0 +1,73 @@ +package co.allconnected.fussiontech.usersservice.services; + +import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; +import co.allconnected.fussiontech.usersservice.model.User; +import co.allconnected.fussiontech.usersservice.model.Deleted; +import co.allconnected.fussiontech.usersservice.repository.UserRepository; +import co.allconnected.fussiontech.usersservice.repository.DeletedRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.util.List; +import java.util.UUID; + +@Service +public class UserService { + + private final UserRepository userRepository; + // private final DeletedRepository deletedRepository; + + @Autowired + public UserService(UserRepository userRepository, DeletedRepository deletedRepository) { + this.userRepository = userRepository; + // this.deletedRepository = deletedRepository; + } + + public List getAllUsers() { + return userRepository.findAll(); + } + + public User getUserById(String id) { + return userRepository.findById(id).orElse(null); + } + + public User createUser(UserCreateDTO userDto) { + User user = new User(); + user.setIdUser(UUID.randomUUID().toString().substring(0, 28)); + user.setUsername(userDto.getUsername()); + user.setMail(userDto.getMail()); + user.setFullname(userDto.getFullname()); + user.setPhotoUrl(userDto.getPhotoUrl()); + user.setLocationLat(userDto.getLocationLat()); + user.setLocationLng(userDto.getLocationLng()); + user.setActive(userDto.getActive()); + return userRepository.save(user); + } +/* + public User updateUser(String id, User user) { + User existingUser = getUserById(id); + if (existingUser != null) { + existingUser.setName(user.getName()); + existingUser.setEmail(user.getEmail()); + // Add other fields to be updated + return userRepository.save(existingUser); + } + return null; + } + + + public void deleteUser(String id) { + User user = getUserById(id); + if (user != null) { + Deleted deleted = new Deleted(); + deleted.setId(user.getId()); + deleted.setName(user.getName()); + deleted.setEmail(user.getEmail()); + // Add other fields to be transferred + deletedRepository.save(deleted); + userRepository.deleteById(id); + } + } + */ +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/fileToRemove.txt b/src/main/java/co/allconnected/fussiontech/usersservice/services/fileToRemove.txt deleted file mode 100644 index 7755816..0000000 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/fileToRemove.txt +++ /dev/null @@ -1 +0,0 @@ -Este archivo es para dejar la estructura de carpetas del proyecto. Eliminar cuando se tenga el proyecto. \ No newline at end of file From 4ea22c5e148ad120ca89a51c8c6fdbdca612f811 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 10 Sep 2024 13:38:49 -0500 Subject: [PATCH 02/99] =?UTF-8?q?=F0=9F=99=88=20update=20gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 549e00a..eeab570 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ build/ ### VS Code ### .vscode/ + +### Firebase ### +spring-firebase-key.json.json \ No newline at end of file From bea33341d668fa29f8f6274ed171eac19ed1b4d4 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 10 Sep 2024 14:44:51 -0500 Subject: [PATCH 03/99] =?UTF-8?q?=F0=9F=99=88=20fix=20gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index eeab570..50aa500 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,4 @@ build/ .vscode/ ### Firebase ### -spring-firebase-key.json.json \ No newline at end of file +spring-firebase-key.json \ No newline at end of file From 12f68b28a74195a72f113ef31b86bfcf6772dd3c Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 10 Sep 2024 23:59:23 -0500 Subject: [PATCH 04/99] =?UTF-8?q?=E2=9C=A8=20Add=20Firebase=20Storage=20fi?= =?UTF-8?q?le=20uploads?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 11 ++++ .../usersservice/config/FirebaseConfig.java | 31 +++++++++++ .../controllers/UsersController.java | 34 +----------- .../usersservice/dtos/UserCreateDTO.java | 3 + .../fussiontech/usersservice/model/User.java | 13 +++++ .../services/FirebaseService.java | 19 +++++++ .../usersservice/services/UserService.java | 55 ++++--------------- 7 files changed, 90 insertions(+), 76 deletions(-) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java diff --git a/pom.xml b/pom.xml index 38890cf..e420d3a 100644 --- a/pom.xml +++ b/pom.xml @@ -74,6 +74,17 @@ reactor-test test + + + com.google.firebase + firebase-admin + 9.1.0 + + + com.google.cloud + google-cloud-storage + 2.11.0 + diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java new file mode 100644 index 0000000..76cc1ca --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java @@ -0,0 +1,31 @@ +package co.allconnected.fussiontech.usersservice.config; + +import com.google.auth.oauth2.GoogleCredentials; +import com.google.firebase.FirebaseApp; +import com.google.firebase.FirebaseOptions; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.io.FileInputStream; +import java.io.IOException; + +@Configuration +public class FirebaseConfig { + + @Bean + public FirebaseApp initializeFirebase() throws IOException { + String serviceAccounPath = System.getProperty("user.dir") + "/spring-firebase-key.json"; + FileInputStream serviceAccount = new FileInputStream(serviceAccounPath); + + FirebaseOptions options = FirebaseOptions.builder() + .setCredentials(GoogleCredentials.fromStream(serviceAccount)) + .setStorageBucket("allconnected-4855c.appspot.com") + .build(); + + if(FirebaseApp.getApps().isEmpty()) { + FirebaseApp.initializeApp(options); + } + + return FirebaseApp.getInstance(); + } +} diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index f7b098b..6b20d20 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -20,40 +20,8 @@ public UsersController(UserService userService) { this.userService = userService; } - @GetMapping - public ResponseEntity> getAllUsers() { - return ResponseEntity.ok(userService.getAllUsers()); - } - - @GetMapping("/{id}") - public ResponseEntity getUserById(@PathVariable String id) { - User user = userService.getUserById(id); - if (user != null) { - return ResponseEntity.ok(user); - } else { - return ResponseEntity.notFound().build(); - } - } - @PostMapping - public ResponseEntity createUser(@RequestBody UserCreateDTO user) { + public ResponseEntity createUser(@ModelAttribute UserCreateDTO user) { return ResponseEntity.ok(userService.createUser(user)); } -/* - @PutMapping("/{id}") - public ResponseEntity updateUser(@PathVariable String id, @RequestBody User user) { - User updatedUser = userService.updateUser(id, user); - if (updatedUser != null) { - return ResponseEntity.ok(updatedUser); - } else { - return ResponseEntity.notFound().build(); - } - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteUser(@PathVariable String id) { - userService.deleteUser(id); - return ResponseEntity.noContent().build(); - } - */ } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java index ae1aa46..9a4c792 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java @@ -3,6 +3,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.springframework.web.multipart.MultipartFile; import java.math.BigDecimal; @@ -14,7 +15,9 @@ public class UserCreateDTO { private String username; private String mail; private String photoUrl; + private String[] roles; private BigDecimal locationLat; private BigDecimal locationLng; private Boolean active; + private MultipartFile photo_url; } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java index 4e19723..7c543ed 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -1,8 +1,10 @@ package co.allconnected.fussiontech.usersservice.model; +import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import java.math.BigDecimal; @@ -12,8 +14,19 @@ @Getter @Setter @Entity +@NoArgsConstructor @Table(name = "\"user\"", schema = "all_connected_users") public class User { + + public User(UserCreateDTO dto){ + this.fullname = dto.getFullname(); + this.username = dto.getUsername(); + this.mail = dto.getMail(); + this.locationLat = dto.getLocationLat(); + this.locationLng = dto.getLocationLng(); + this.active = true; + } + @Id @Column(name = "id_user", nullable = false, length = 28) private String idUser; diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java new file mode 100644 index 0000000..52ce976 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -0,0 +1,19 @@ +package co.allconnected.fussiontech.usersservice.services; + +import com.google.cloud.storage.Bucket; +import com.google.firebase.cloud.StorageClient; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.io.InputStream; + +@Service +public class FirebaseService { + + public void upload(String imageName, MultipartFile imageFile) throws IOException { + InputStream inputStream = imageFile.getInputStream(); + Bucket bucket = StorageClient.getInstance().bucket(); + bucket.create("user_photos/"+imageName, inputStream, "image/*"); + } +} diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 1ec3359..0ba1adc 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; import java.math.BigDecimal; import java.util.List; import java.util.UUID; @@ -16,58 +17,26 @@ public class UserService { private final UserRepository userRepository; - // private final DeletedRepository deletedRepository; + private final FirebaseService firebaseService; @Autowired - public UserService(UserRepository userRepository, DeletedRepository deletedRepository) { + public UserService(UserRepository userRepository, FirebaseService firebaseService) { this.userRepository = userRepository; - // this.deletedRepository = deletedRepository; - } - - public List getAllUsers() { - return userRepository.findAll(); - } - - public User getUserById(String id) { - return userRepository.findById(id).orElse(null); + this.firebaseService = firebaseService; } public User createUser(UserCreateDTO userDto) { - User user = new User(); + User user = new User(userDto); user.setIdUser(UUID.randomUUID().toString().substring(0, 28)); - user.setUsername(userDto.getUsername()); - user.setMail(userDto.getMail()); - user.setFullname(userDto.getFullname()); - user.setPhotoUrl(userDto.getPhotoUrl()); - user.setLocationLat(userDto.getLocationLat()); - user.setLocationLng(userDto.getLocationLng()); - user.setActive(userDto.getActive()); - return userRepository.save(user); - } -/* - public User updateUser(String id, User user) { - User existingUser = getUserById(id); - if (existingUser != null) { - existingUser.setName(user.getName()); - existingUser.setEmail(user.getEmail()); - // Add other fields to be updated - return userRepository.save(existingUser); - } - return null; - } - public void deleteUser(String id) { - User user = getUserById(id); - if (user != null) { - Deleted deleted = new Deleted(); - deleted.setId(user.getId()); - deleted.setName(user.getName()); - deleted.setEmail(user.getEmail()); - // Add other fields to be transferred - deletedRepository.save(deleted); - userRepository.deleteById(id); + String mail = userDto.getMail().replace(".","_"); + try { + firebaseService.upload(mail, userDto.getPhoto_url()); + } catch(IOException e){ + System.out.println(e.getMessage()); } + + return userRepository.save(user); } - */ } \ No newline at end of file From b817f93feba118460384ab33688bb75710a45661 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Wed, 11 Sep 2024 00:26:03 -0500 Subject: [PATCH 05/99] =?UTF-8?q?=E2=9E=95=20add=20apache=20commons=20io?= =?UTF-8?q?=20for=20filename?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index e420d3a..9e8d8b5 100644 --- a/pom.xml +++ b/pom.xml @@ -85,6 +85,12 @@ google-cloud-storage 2.11.0 + + + commons-io + commons-io + 2.16.1 + From 3df8464d2da3749bc355efdd47b2e3fc5ac35720 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Wed, 11 Sep 2024 00:26:54 -0500 Subject: [PATCH 06/99] =?UTF-8?q?=E2=9C=A8=20add=20support=20for=20differe?= =?UTF-8?q?nt=20img=20formats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usersservice/services/FirebaseService.java | 4 ++-- .../fussiontech/usersservice/services/UserService.java | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index 52ce976..b2f7192 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -11,9 +11,9 @@ @Service public class FirebaseService { - public void upload(String imageName, MultipartFile imageFile) throws IOException { + public void upload(String imageName, String extension, MultipartFile imageFile) throws IOException { InputStream inputStream = imageFile.getInputStream(); Bucket bucket = StorageClient.getInstance().bucket(); - bucket.create("user_photos/"+imageName, inputStream, "image/*"); + bucket.create("user_photos/"+imageName, inputStream, "image/"+extension); } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 0ba1adc..6743ee8 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -2,9 +2,8 @@ import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; import co.allconnected.fussiontech.usersservice.model.User; -import co.allconnected.fussiontech.usersservice.model.Deleted; import co.allconnected.fussiontech.usersservice.repository.UserRepository; -import co.allconnected.fussiontech.usersservice.repository.DeletedRepository; +import org.apache.commons.io.FilenameUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -30,9 +29,11 @@ public User createUser(UserCreateDTO userDto) { user.setIdUser(UUID.randomUUID().toString().substring(0, 28)); - String mail = userDto.getMail().replace(".","_"); + String photoName = userDto.getMail().replace(".","_"); + String extension = FilenameUtils.getExtension(userDto.getPhoto_url().getOriginalFilename()); + try { - firebaseService.upload(mail, userDto.getPhoto_url()); + firebaseService.upload(photoName, extension, userDto.getPhoto_url()); } catch(IOException e){ System.out.println(e.getMessage()); } From fccdb75db9748b22291fb8f6d041b2c777862fc4 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Wed, 11 Sep 2024 19:12:58 -0500 Subject: [PATCH 07/99] =?UTF-8?q?=E2=9C=A8=20add=20roles=20to=20user=20and?= =?UTF-8?q?=20optional=20photo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 7 +++-- .../usersservice/dtos/UserCreateDTO.java | 3 +-- .../fussiontech/usersservice/model/Rol.java | 5 +--- .../fussiontech/usersservice/model/User.java | 6 ++++- .../usersservice/services/UserService.java | 27 ++++++++++++------- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 6b20d20..d268738 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -21,7 +22,9 @@ public UsersController(UserService userService) { } @PostMapping - public ResponseEntity createUser(@ModelAttribute UserCreateDTO user) { - return ResponseEntity.ok(userService.createUser(user)); + public ResponseEntity createUser( + @ModelAttribute UserCreateDTO user, + @RequestParam(value = "photo", required = false) MultipartFile photo) { + return ResponseEntity.ok(userService.createUser(user, photo)); } } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java index 9a4c792..e6d65a8 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java @@ -5,6 +5,7 @@ import lombok.Setter; import org.springframework.web.multipart.MultipartFile; +import javax.annotation.Nullable; import java.math.BigDecimal; @Getter @@ -14,10 +15,8 @@ public class UserCreateDTO { private String fullname; private String username; private String mail; - private String photoUrl; private String[] roles; private BigDecimal locationLat; private BigDecimal locationLng; private Boolean active; - private MultipartFile photo_url; } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java index 4e39457..1ced325 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java @@ -18,10 +18,7 @@ public class Rol { private String idRol; @JsonIgnore - @ManyToMany - @JoinTable(name = "user_rol", - joinColumns = @JoinColumn(name = "id_rol"), - inverseJoinColumns = @JoinColumn(name = "id_user")) + @ManyToMany(mappedBy = "rols") private Set users = new LinkedHashSet<>(); } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java index 7c543ed..6e6230a 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -53,7 +53,11 @@ public User(UserCreateDTO dto){ private Boolean active = false; @JsonIgnore - @ManyToMany(mappedBy = "users") + @ManyToMany + @JoinTable(name = "user_rol", + schema = "all_connected_users", + joinColumns = @JoinColumn(name = "id_user"), + inverseJoinColumns = @JoinColumn(name = "id_rol")) private Set rols = new LinkedHashSet<>(); } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 6743ee8..ab5db15 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -1,39 +1,48 @@ package co.allconnected.fussiontech.usersservice.services; import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; +import co.allconnected.fussiontech.usersservice.model.Rol; import co.allconnected.fussiontech.usersservice.model.User; import co.allconnected.fussiontech.usersservice.repository.UserRepository; import org.apache.commons.io.FilenameUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; import java.io.IOException; -import java.math.BigDecimal; -import java.util.List; import java.util.UUID; @Service public class UserService { private final UserRepository userRepository; + private final RolService rolService; private final FirebaseService firebaseService; @Autowired - public UserService(UserRepository userRepository, FirebaseService firebaseService) { + public UserService(UserRepository userRepository, RolService rolService, FirebaseService firebaseService) { this.userRepository = userRepository; this.firebaseService = firebaseService; + this.rolService = rolService; } - public User createUser(UserCreateDTO userDto) { + public User createUser(UserCreateDTO userDto, MultipartFile photo) { User user = new User(userDto); - user.setIdUser(UUID.randomUUID().toString().substring(0, 28)); + // Generate user id (TODO: Move to Firebase) + user.setIdUser(UUID.randomUUID().toString().substring(0, 28)); - String photoName = userDto.getMail().replace(".","_"); - String extension = FilenameUtils.getExtension(userDto.getPhoto_url().getOriginalFilename()); + // Add roles to user + for(String rol : userDto.getRoles()){ + Rol rolEntity = rolService.getRol(rol).orElseThrow(); + user.getRols().add(rolEntity); + } - try { - firebaseService.upload(photoName, extension, userDto.getPhoto_url()); + // Upload photo to firebase + if(photo != null) try { + String photoName = user.getIdUser(); + String extension = FilenameUtils.getExtension(photo.getOriginalFilename()); + firebaseService.upload(photoName, extension, photo); } catch(IOException e){ System.out.println(e.getMessage()); } From 4dbd1aa3785ce813db3e2a4914cd1f1893800b23 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Thu, 12 Sep 2024 19:23:20 -0500 Subject: [PATCH 08/99] =?UTF-8?q?=F0=9F=94=A5=20delete=20unused=20variable?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fussiontech/usersservice/dtos/UserCreateDTO.java | 4 +--- .../co/allconnected/fussiontech/usersservice/model/User.java | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java index e6d65a8..5eba457 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java @@ -14,9 +14,7 @@ public class UserCreateDTO { private String fullname; private String username; + private String password; private String mail; private String[] roles; - private BigDecimal locationLat; - private BigDecimal locationLng; - private Boolean active; } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java index 6e6230a..50ef35c 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -22,8 +22,6 @@ public User(UserCreateDTO dto){ this.fullname = dto.getFullname(); this.username = dto.getUsername(); this.mail = dto.getMail(); - this.locationLat = dto.getLocationLat(); - this.locationLng = dto.getLocationLng(); this.active = true; } From fb17ddc84447fd7c9c82b53273865ee991f243ca Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Thu, 12 Sep 2024 20:04:13 -0500 Subject: [PATCH 09/99] =?UTF-8?q?=F0=9F=90=9B=20save=20user=20photo=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usersservice/services/FirebaseService.java | 8 +++++++- .../fussiontech/usersservice/services/UserService.java | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index b2f7192..a142463 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -11,9 +11,15 @@ @Service public class FirebaseService { - public void upload(String imageName, String extension, MultipartFile imageFile) throws IOException { + public String upload(String imageName, String extension, MultipartFile imageFile) throws IOException { InputStream inputStream = imageFile.getInputStream(); Bucket bucket = StorageClient.getInstance().bucket(); bucket.create("user_photos/"+imageName, inputStream, "image/"+extension); + return bucket.get("user_photos/"+imageName).signUrl(360, java.util.concurrent.TimeUnit.DAYS).toString(); + } + + public void delete(String imageName) { + Bucket bucket = StorageClient.getInstance().bucket(); + bucket.get("user_photos/"+imageName).delete(); } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index ab5db15..59a2fda 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -42,7 +42,7 @@ public User createUser(UserCreateDTO userDto, MultipartFile photo) { if(photo != null) try { String photoName = user.getIdUser(); String extension = FilenameUtils.getExtension(photo.getOriginalFilename()); - firebaseService.upload(photoName, extension, photo); + user.setPhotoUrl(firebaseService.upload(photoName, extension, photo)); } catch(IOException e){ System.out.println(e.getMessage()); } From b00fd0a9653cd5afe439826e19e5993bc0bc866b Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Thu, 12 Sep 2024 20:47:02 -0500 Subject: [PATCH 10/99] =?UTF-8?q?=E2=9C=A8=20finish=20user=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 13 ++++---- .../usersservice/dtos/UserDTO.java | 30 +++++++++++++++++++ .../fussiontech/usersservice/model/Rol.java | 2 +- .../fussiontech/usersservice/model/User.java | 3 +- .../services/FirebaseService.java | 12 ++++++++ .../usersservice/services/UserService.java | 14 ++++----- 6 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index d268738..bf4f3a7 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -1,14 +1,15 @@ package co.allconnected.fussiontech.usersservice.controllers; import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; -import co.allconnected.fussiontech.usersservice.model.User; +import co.allconnected.fussiontech.usersservice.dtos.UserDTO; import co.allconnected.fussiontech.usersservice.services.UserService; +import com.google.firebase.auth.FirebaseAuthException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.util.List; +import java.io.IOException; @RestController @RequestMapping("/api/v1/users") @@ -22,9 +23,9 @@ public UsersController(UserService userService) { } @PostMapping - public ResponseEntity createUser( - @ModelAttribute UserCreateDTO user, - @RequestParam(value = "photo", required = false) MultipartFile photo) { - return ResponseEntity.ok(userService.createUser(user, photo)); + public ResponseEntity createUser(@ModelAttribute UserCreateDTO user, + @RequestParam(value = "photo", required = false) MultipartFile photo) + throws IOException, FirebaseAuthException { + return ResponseEntity.ok(new UserDTO(userService.createUser(user, photo))); } } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java new file mode 100644 index 0000000..1d88214 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java @@ -0,0 +1,30 @@ +package co.allconnected.fussiontech.usersservice.dtos; + +import co.allconnected.fussiontech.usersservice.model.User; +import co.allconnected.fussiontech.usersservice.model.Rol; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class UserDTO { + private String id_user; + private String fullname; + private String username; + private String mail; + private String photo_url; + private String[] roles; + private String[] organizations; + + public UserDTO(User user){ + this.id_user = user.getIdUser(); + this.fullname = user.getFullname(); + this.username = user.getUsername(); + this.mail = user.getMail(); + this.photo_url = user.getPhotoUrl(); + this.roles = user.getRoles().stream().map(Rol::getIdRol).toArray(String[]::new); + // this.organizations = user.getOrganizations().stream().map(Organization::getIdOrganization).toArray(String[]::new); + } +} diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java index 1ced325..7b2bd69 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java @@ -18,7 +18,7 @@ public class Rol { private String idRol; @JsonIgnore - @ManyToMany(mappedBy = "rols") + @ManyToMany(mappedBy = "roles") private Set users = new LinkedHashSet<>(); } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java index 50ef35c..808882e 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -50,12 +50,11 @@ public User(UserCreateDTO dto){ @Column(name = "active", nullable = false) private Boolean active = false; - @JsonIgnore @ManyToMany @JoinTable(name = "user_rol", schema = "all_connected_users", joinColumns = @JoinColumn(name = "id_user"), inverseJoinColumns = @JoinColumn(name = "id_rol")) - private Set rols = new LinkedHashSet<>(); + private Set roles = new LinkedHashSet<>(); } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index a142463..f026d37 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -1,6 +1,9 @@ package co.allconnected.fussiontech.usersservice.services; import com.google.cloud.storage.Bucket; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseAuthException; +import com.google.firebase.auth.UserRecord; import com.google.firebase.cloud.StorageClient; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @@ -22,4 +25,13 @@ public void delete(String imageName) { Bucket bucket = StorageClient.getInstance().bucket(); bucket.get("user_photos/"+imageName).delete(); } + + public String createUser(String email, String password) throws FirebaseAuthException { + UserRecord.CreateRequest request = new UserRecord.CreateRequest() + .setEmail(email) + .setPassword(password); + + UserRecord userRecord = FirebaseAuth.getInstance().createUser(request); + return userRecord.getUid(); + } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 59a2fda..286d884 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -4,13 +4,13 @@ import co.allconnected.fussiontech.usersservice.model.Rol; import co.allconnected.fussiontech.usersservice.model.User; import co.allconnected.fussiontech.usersservice.repository.UserRepository; +import com.google.firebase.auth.FirebaseAuthException; import org.apache.commons.io.FilenameUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; -import java.util.UUID; @Service public class UserService { @@ -26,25 +26,23 @@ public UserService(UserRepository userRepository, RolService rolService, Firebas this.rolService = rolService; } - public User createUser(UserCreateDTO userDto, MultipartFile photo) { + public User createUser(UserCreateDTO userDto, MultipartFile photo) throws FirebaseAuthException, IOException { User user = new User(userDto); - // Generate user id (TODO: Move to Firebase) - user.setIdUser(UUID.randomUUID().toString().substring(0, 28)); + // Create user in firebase + user.setIdUser(firebaseService.createUser(userDto.getMail(), userDto.getPassword())); // Add roles to user for(String rol : userDto.getRoles()){ Rol rolEntity = rolService.getRol(rol).orElseThrow(); - user.getRols().add(rolEntity); + user.getRoles().add(rolEntity); } // Upload photo to firebase - if(photo != null) try { + if(photo != null) { String photoName = user.getIdUser(); String extension = FilenameUtils.getExtension(photo.getOriginalFilename()); user.setPhotoUrl(firebaseService.upload(photoName, extension, photo)); - } catch(IOException e){ - System.out.println(e.getMessage()); } return userRepository.save(user); From d96a5b2d1fc915d153199882ca65dd4fa5e4830b Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Thu, 12 Sep 2024 20:50:49 -0500 Subject: [PATCH 11/99] =?UTF-8?q?=F0=9F=94=A5=20optimize=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fussiontech/usersservice/dtos/UserCreateDTO.java | 4 ---- .../allconnected/fussiontech/usersservice/dtos/UserDTO.java | 2 +- .../co/allconnected/fussiontech/usersservice/model/Rol.java | 3 --- .../co/allconnected/fussiontech/usersservice/model/User.java | 1 - 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java index 5eba457..dcbd556 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java @@ -3,10 +3,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import org.springframework.web.multipart.MultipartFile; - -import javax.annotation.Nullable; -import java.math.BigDecimal; @Getter @Setter diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java index 1d88214..febbb66 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java @@ -1,7 +1,7 @@ package co.allconnected.fussiontech.usersservice.dtos; -import co.allconnected.fussiontech.usersservice.model.User; import co.allconnected.fussiontech.usersservice.model.Rol; +import co.allconnected.fussiontech.usersservice.model.User; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java index 7b2bd69..371d3b4 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/Rol.java @@ -1,6 +1,5 @@ package co.allconnected.fussiontech.usersservice.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.Getter; import lombok.Setter; @@ -17,8 +16,6 @@ public class Rol { @Column(name = "id_rol", nullable = false, length = Integer.MAX_VALUE) private String idRol; - @JsonIgnore @ManyToMany(mappedBy = "roles") private Set users = new LinkedHashSet<>(); - } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java index 808882e..3513776 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -1,7 +1,6 @@ package co.allconnected.fussiontech.usersservice.model; import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; -import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; From 41f2680d740572e2fadbff3d68bd7134f18edd26 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Thu, 12 Sep 2024 22:31:32 -0500 Subject: [PATCH 12/99] =?UTF-8?q?=E2=9A=B0=EF=B8=8F=20delete=20unused=20co?= =?UTF-8?q?ntroller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/RolesController.java | 49 ------------------- 1 file changed, 49 deletions(-) delete mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/controllers/RolesController.java diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/RolesController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/RolesController.java deleted file mode 100644 index ce96d25..0000000 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/RolesController.java +++ /dev/null @@ -1,49 +0,0 @@ -package co.allconnected.fussiontech.usersservice.controllers; - -import co.allconnected.fussiontech.usersservice.model.Rol; -import co.allconnected.fussiontech.usersservice.services.RolService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -@RestController -@RequestMapping("/api/v1/roles") -public class RolesController { - - private final RolService rolService; - - @Autowired - public RolesController(RolService rolService) { - this.rolService = rolService; - } - - @PostMapping - public ResponseEntity createRol(@RequestBody Rol rol) { - return ResponseEntity.ok(rolService.createRol(rol)); - } - - @GetMapping("/{id}") - public ResponseEntity getRol(@PathVariable String id) { - return rolService.getRol(id) - .map(ResponseEntity::ok) - .orElse(ResponseEntity.notFound().build()); - } - - @GetMapping - public ResponseEntity> getAllRoles() { - return ResponseEntity.ok(rolService.getAllRoles()); - } - - @PutMapping("/{id}") - public ResponseEntity updateRol(@PathVariable String id, @RequestBody Rol rol) { - return ResponseEntity.ok(rolService.updateRol(rol)); - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteRol(@PathVariable String id) { - rolService.deleteRol(id); - return ResponseEntity.noContent().build(); - } -} \ No newline at end of file From e8782936049fe62732291fc0fb785a4b9157c38b Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Thu, 12 Sep 2024 22:58:31 -0500 Subject: [PATCH 13/99] =?UTF-8?q?=F0=9F=A5=85=20add=20error=20catching?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 20 +++++++++++++++---- .../usersservice/dtos/ErrorResponse.java | 16 +++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/dtos/ErrorResponse.java diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index bf4f3a7..6c42e6b 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -1,10 +1,12 @@ package co.allconnected.fussiontech.usersservice.controllers; +import co.allconnected.fussiontech.usersservice.dtos.ErrorResponse; import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; import co.allconnected.fussiontech.usersservice.dtos.UserDTO; import co.allconnected.fussiontech.usersservice.services.UserService; import com.google.firebase.auth.FirebaseAuthException; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -23,9 +25,19 @@ public UsersController(UserService userService) { } @PostMapping - public ResponseEntity createUser(@ModelAttribute UserCreateDTO user, - @RequestParam(value = "photo", required = false) MultipartFile photo) - throws IOException, FirebaseAuthException { - return ResponseEntity.ok(new UserDTO(userService.createUser(user, photo))); + public ResponseEntity createUser( + @ModelAttribute UserCreateDTO user, + @RequestParam(value = "photo", required = false) MultipartFile photo) { + try{ + UserDTO userDTO = new UserDTO(userService.createUser(user, photo)); + return ResponseEntity.status(HttpStatus.CREATED).body(userDTO); + } + catch (FirebaseAuthException e) { + ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Firebase authentication error: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.CONFLICT).body(errorResponse); + } catch (Exception e) { + ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); + } } } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/ErrorResponse.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/ErrorResponse.java new file mode 100644 index 0000000..f7691b4 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/ErrorResponse.java @@ -0,0 +1,16 @@ +package co.allconnected.fussiontech.usersservice.dtos; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ErrorResponse { + private int code; + private String message; + + public ErrorResponse(int code, String message) { + this.code = code; + this.message = message; + } +} From 8029e7b4ace4dfb5ad3d897350352efc00b509ca Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Thu, 12 Sep 2024 23:52:01 -0500 Subject: [PATCH 14/99] =?UTF-8?q?=F0=9F=99=88=20update=20gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 50aa500..6378a64 100644 --- a/.gitignore +++ b/.gitignore @@ -33,4 +33,7 @@ build/ .vscode/ ### Firebase ### -spring-firebase-key.json \ No newline at end of file +spring-firebase-key.json + +### Enviroment variables ### +.env \ No newline at end of file From fdc126c0d0f86868615b14f31c66b5c8517839a9 Mon Sep 17 00:00:00 2001 From: Esteban Salazar <68300629+Estebans441@users.noreply.github.com> Date: Thu, 12 Sep 2024 23:53:26 -0500 Subject: [PATCH 15/99] =?UTF-8?q?=F0=9F=92=9A=20Add=20missing=20env=20vars?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b9ed93e..05e46b4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,4 +31,11 @@ jobs: DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} + GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} + GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} + GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} run: mvn clean install From ae5aefad6beb5e90e201e441a60e0e78ee198e36 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Thu, 12 Sep 2024 23:56:51 -0500 Subject: [PATCH 16/99] =?UTF-8?q?=F0=9F=94=90=20Add=20firebase=20env=20sec?= =?UTF-8?q?rets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 +++++++++++-- .../usersservice/config/FirebaseConfig.java | 22 +++++++++++++++---- .../config/FirebaseConfigProperties.java | 22 +++++++++++++++++++ src/main/resources/application.yml | 14 ++++++++++++ 4 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfigProperties.java diff --git a/README.md b/README.md index aec6ca9..f1ef191 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,23 @@ Microservicio encargado del CRUD de usuarios de la aplicación AllConnected Para ejecutar este proyecto, necesitarás agregar las siguientes variables de entorno a tu archivo .env -`DATASOURCE_URL` +### Conexion a la base de datos +`DATASOURCE_URL` `DATASOURCE_USERNAME` - `DATASOURCE_PASSWORD` +### Configuración de Firebase +Estas variables son extraidas del archivo de configuración de Firebase en formato JSON + +`GOOGLE_ADMIN_CONFIG_TYPE` +`GOOGLE_ADMIN_CONFIG_PROJECT_ID` +`GOOGLE_ADMIN_CONFIG_PRIVATE_KEY` +`GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID` +`GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL` +`GOOGLE_ADMIN_CONFIG_CLIENT_ID` +`GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL` + --- ## Ejecutar Localmente 💻 diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java index 76cc1ca..de34363 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java @@ -3,22 +3,36 @@ import com.google.auth.oauth2.GoogleCredentials; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; +import com.google.gson.Gson; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import javax.annotation.PostConstruct; +import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.IOException; @Configuration public class FirebaseConfig { - @Bean + private final FirebaseConfigProperties firebaseConfigProperties; + + public FirebaseConfig(FirebaseConfigProperties firebaseConfigProperties) { + this.firebaseConfigProperties = firebaseConfigProperties; + } + + @PostConstruct public FirebaseApp initializeFirebase() throws IOException { - String serviceAccounPath = System.getProperty("user.dir") + "/spring-firebase-key.json"; - FileInputStream serviceAccount = new FileInputStream(serviceAccounPath); + firebaseConfigProperties.setPrivate_key( + firebaseConfigProperties.getPrivate_key().replace("\\n", "\n") + ); + + String json = new Gson().toJson(firebaseConfigProperties); + + GoogleCredentials credentials = GoogleCredentials.fromStream(new ByteArrayInputStream(json.getBytes())); FirebaseOptions options = FirebaseOptions.builder() - .setCredentials(GoogleCredentials.fromStream(serviceAccount)) + .setCredentials(credentials) .setStorageBucket("allconnected-4855c.appspot.com") .build(); diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfigProperties.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfigProperties.java new file mode 100644 index 0000000..80482e0 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfigProperties.java @@ -0,0 +1,22 @@ +package co.allconnected.fussiontech.usersservice.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@Component +@ConfigurationProperties(prefix = "firebase") +@Data +public class FirebaseConfigProperties { + private String type; + private String project_id; + private String private_key; + private String private_key_id; + private String client_email; + private String client_id; + private String auth_uri; + private String token_uri; + private String auth_provider_x509_cert_url; + private String client_x509_cert_url; + private String universe_domain; +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8024e8d..5a582e5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -10,3 +10,17 @@ spring: eureka: client: enabled: false + +firebase: + type: ${GOOGLE_ADMIN_CONFIG_TYPE} + project-id: ${GOOGLE_ADMIN_CONFIG_PROJECT_ID} + private-key: ${GOOGLE_ADMIN_CONFIG_PRIVATE_KEY} + private-key-id: ${GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID} + client-email: ${GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL} + client-id: ${GOOGLE_ADMIN_CONFIG_CLIENT_ID} + auth-uri: https://accounts.google.com/o/oauth2/auth + token-uri: https://oauth2.googleapis.com/token + auth-provider-x509-cert-url: https://www.googleapis.com/oauth2/v1/certs + client-x509-cert-url: ${GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL} + universe-domain: googleapis.com + From 02a2b481e81303ef318b19b60ce6f65d78b86272 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Fri, 13 Sep 2024 00:01:56 -0500 Subject: [PATCH 17/99] =?UTF-8?q?=E2=9C=85=20actions=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fussiontech/usersservice/utils/fileToRemove.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/utils/fileToRemove.txt b/src/main/java/co/allconnected/fussiontech/usersservice/utils/fileToRemove.txt index 7755816..4fcccbf 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/utils/fileToRemove.txt +++ b/src/main/java/co/allconnected/fussiontech/usersservice/utils/fileToRemove.txt @@ -1 +1 @@ -Este archivo es para dejar la estructura de carpetas del proyecto. Eliminar cuando se tenga el proyecto. \ No newline at end of file +Este archivo es para dejar la estructura de carpetas del proyecto. Eliminar cuando se tenga el proyecto. From 263847856bbedf861d68e2889092f79cdaa17fdb Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Fri, 13 Sep 2024 01:37:20 -0500 Subject: [PATCH 18/99] =?UTF-8?q?=F0=9F=94=A5optimize=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fussiontech/usersservice/config/FirebaseConfig.java | 4 +--- .../usersservice/controllers/UsersController.java | 5 ++--- .../allconnected/fussiontech/usersservice/model/User.java | 7 ------- .../fussiontech/usersservice/services/FirebaseService.java | 3 ++- 4 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java index de34363..b8a89ec 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/FirebaseConfig.java @@ -4,12 +4,10 @@ import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; import com.google.gson.Gson; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.annotation.PostConstruct; import java.io.ByteArrayInputStream; -import java.io.FileInputStream; import java.io.IOException; @Configuration @@ -33,7 +31,7 @@ public FirebaseApp initializeFirebase() throws IOException { FirebaseOptions options = FirebaseOptions.builder() .setCredentials(credentials) - .setStorageBucket("allconnected-4855c.appspot.com") + .setStorageBucket(firebaseConfigProperties.getProject_id()+".appspot.com") .build(); if(FirebaseApp.getApps().isEmpty()) { diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 6c42e6b..c656666 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -11,8 +11,6 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import java.io.IOException; - @RestController @RequestMapping("/api/v1/users") public class UsersController { @@ -40,4 +38,5 @@ public ResponseEntity createUser( return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); } } -} \ No newline at end of file +} + diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java index 3513776..7d7d7f6 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -6,7 +6,6 @@ import lombok.NoArgsConstructor; import lombok.Setter; -import java.math.BigDecimal; import java.util.LinkedHashSet; import java.util.Set; @@ -40,12 +39,6 @@ public User(UserCreateDTO dto){ @Column(name = "photo_url", length = 200) private String photoUrl; - @Column(name = "location_lat", precision = 9, scale = 6) - private BigDecimal locationLat; - - @Column(name = "location_lng", precision = 9, scale = 6) - private BigDecimal locationLng; - @Column(name = "active", nullable = false) private Boolean active = false; diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index f026d37..91ba1c4 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -18,7 +18,8 @@ public String upload(String imageName, String extension, MultipartFile imageFile InputStream inputStream = imageFile.getInputStream(); Bucket bucket = StorageClient.getInstance().bucket(); bucket.create("user_photos/"+imageName, inputStream, "image/"+extension); - return bucket.get("user_photos/"+imageName).signUrl(360, java.util.concurrent.TimeUnit.DAYS).toString(); + return bucket.get("user_photos/"+imageName) + .signUrl(360, java.util.concurrent.TimeUnit.DAYS).toString(); } public void delete(String imageName) { From 0c26917d3e5a7d6aad042f4b0bae888560912fe6 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 14 Sep 2024 11:43:05 -0500 Subject: [PATCH 19/99] =?UTF-8?q?=F0=9F=9A=A7=20delete=20user=20in=20progr?= =?UTF-8?q?ess?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 25 +++++++++++++++---- .../{ErrorResponse.java => Response.java} | 4 +-- .../services/FirebaseService.java | 8 ++++-- .../usersservice/services/UserService.java | 19 +++++++++++++- 4 files changed, 46 insertions(+), 10 deletions(-) rename src/main/java/co/allconnected/fussiontech/usersservice/dtos/{ErrorResponse.java => Response.java} (74%) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index c656666..1e47f47 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -1,6 +1,6 @@ package co.allconnected.fussiontech.usersservice.controllers; -import co.allconnected.fussiontech.usersservice.dtos.ErrorResponse; +import co.allconnected.fussiontech.usersservice.dtos.Response; import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; import co.allconnected.fussiontech.usersservice.dtos.UserDTO; import co.allconnected.fussiontech.usersservice.services.UserService; @@ -31,12 +31,27 @@ public ResponseEntity createUser( return ResponseEntity.status(HttpStatus.CREATED).body(userDTO); } catch (FirebaseAuthException e) { - ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Firebase authentication error: " + e.getMessage()); - return ResponseEntity.status(HttpStatus.CONFLICT).body(errorResponse); + Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Firebase authentication error: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.CONFLICT).body(response); } catch (Exception e) { - ErrorResponse errorResponse = new ErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred: " + e.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResponse); + Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); } } + + @DeleteMapping("/{id}") + public ResponseEntity deleteUser( + @PathVariable String id) { + try{ + userService.deleteUser(id); + Response response = new Response(HttpStatus.NO_CONTENT.value(), "User deleted successfully"); + return ResponseEntity.status(HttpStatus.NO_CONTENT).body(response); + } + catch (RuntimeException e) { + Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + + } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/ErrorResponse.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/Response.java similarity index 74% rename from src/main/java/co/allconnected/fussiontech/usersservice/dtos/ErrorResponse.java rename to src/main/java/co/allconnected/fussiontech/usersservice/dtos/Response.java index f7691b4..f4e4299 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/ErrorResponse.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/Response.java @@ -5,11 +5,11 @@ @Getter @Setter -public class ErrorResponse { +public class Response { private int code; private String message; - public ErrorResponse(int code, String message) { + public Response(int code, String message) { this.code = code; this.message = message; } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index 91ba1c4..95dc44b 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -14,7 +14,7 @@ @Service public class FirebaseService { - public String upload(String imageName, String extension, MultipartFile imageFile) throws IOException { + public String uploadImg(String imageName, String extension, MultipartFile imageFile) throws IOException { InputStream inputStream = imageFile.getInputStream(); Bucket bucket = StorageClient.getInstance().bucket(); bucket.create("user_photos/"+imageName, inputStream, "image/"+extension); @@ -22,7 +22,7 @@ public String upload(String imageName, String extension, MultipartFile imageFile .signUrl(360, java.util.concurrent.TimeUnit.DAYS).toString(); } - public void delete(String imageName) { + public void deleteImg(String imageName) { Bucket bucket = StorageClient.getInstance().bucket(); bucket.get("user_photos/"+imageName).delete(); } @@ -35,4 +35,8 @@ public String createUser(String email, String password) throws FirebaseAuthExcep UserRecord userRecord = FirebaseAuth.getInstance().createUser(request); return userRecord.getUid(); } + + public void deleteUser(String uid) throws FirebaseAuthException { + FirebaseAuth.getInstance().deleteUser(uid); + } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 286d884..4ba015e 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -42,9 +42,26 @@ public User createUser(UserCreateDTO userDto, MultipartFile photo) throws Fireba if(photo != null) { String photoName = user.getIdUser(); String extension = FilenameUtils.getExtension(photo.getOriginalFilename()); - user.setPhotoUrl(firebaseService.upload(photoName, extension, photo)); + user.setPhotoUrl(firebaseService.uploadImg(photoName, extension, photo)); } return userRepository.save(user); } + + public void deleteUser(String id) throws RuntimeException { + userRepository.findById(id).ifPresentOrElse(user -> { + if(user.getPhotoUrl() != null) + firebaseService.deleteImg(user.getIdUser()); + try { + firebaseService.deleteUser(user.getIdUser()); + } catch (FirebaseAuthException e) { + throw new RuntimeException("Firebase authentication error: " + e.getMessage()); + } + userRepository.delete(user); + }, () -> { + throw new RuntimeException("User not found"); + }); + + userRepository.deleteById(id); + } } \ No newline at end of file From 443cbff9dd70be89529f8ad92caad1af1742cc85 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 14 Sep 2024 12:05:43 -0500 Subject: [PATCH 20/99] =?UTF-8?q?=E2=9C=A8=20feat=20delete=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fussiontech/usersservice/controllers/UsersController.java | 3 +-- .../fussiontech/usersservice/services/UserService.java | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 1e47f47..76566d5 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -44,8 +44,7 @@ public ResponseEntity deleteUser( @PathVariable String id) { try{ userService.deleteUser(id); - Response response = new Response(HttpStatus.NO_CONTENT.value(), "User deleted successfully"); - return ResponseEntity.status(HttpStatus.NO_CONTENT).body(response); + return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } catch (RuntimeException e) { Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 4ba015e..71c924c 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -49,7 +49,7 @@ public User createUser(UserCreateDTO userDto, MultipartFile photo) throws Fireba } public void deleteUser(String id) throws RuntimeException { - userRepository.findById(id).ifPresentOrElse(user -> { + userRepository.findById(id).ifPresent(user -> { if(user.getPhotoUrl() != null) firebaseService.deleteImg(user.getIdUser()); try { @@ -58,8 +58,6 @@ public void deleteUser(String id) throws RuntimeException { throw new RuntimeException("Firebase authentication error: " + e.getMessage()); } userRepository.delete(user); - }, () -> { - throw new RuntimeException("User not found"); }); userRepository.deleteById(id); From c6633adfc60336e63baa82e5114dee0b59f34fc3 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 14 Sep 2024 13:30:34 -0500 Subject: [PATCH 21/99] =?UTF-8?q?=E2=9C=A8=20feat=20deactivate=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 18 ++++++++++++--- .../usersservice/dtos/DeleteRequestDTO.java | 3 +++ .../usersservice/dtos/DeletedDTO.java | 8 +++++++ .../usersservice/model/Deleted.java | 20 ++++++++++++----- .../fussiontech/usersservice/model/User.java | 2 ++ .../services/FirebaseService.java | 14 ++++++++++++ .../usersservice/services/UserService.java | 22 ++++++++++++++++++- 7 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeleteRequestDTO.java create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 76566d5..b4e6ef7 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -1,8 +1,6 @@ package co.allconnected.fussiontech.usersservice.controllers; -import co.allconnected.fussiontech.usersservice.dtos.Response; -import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; -import co.allconnected.fussiontech.usersservice.dtos.UserDTO; +import co.allconnected.fussiontech.usersservice.dtos.*; import co.allconnected.fussiontech.usersservice.services.UserService; import com.google.firebase.auth.FirebaseAuthException; import org.springframework.beans.factory.annotation.Autowired; @@ -52,5 +50,19 @@ public ResponseEntity deleteUser( } } + + @PostMapping("/{id}/deactivate") + public ResponseEntity deactivateUser( + @PathVariable String id, @RequestBody DeleteRequestDTO deleteRequest) { + try{ + DeletedDTO deletedDTO = userService.deactivateUser(id, deleteRequest.delete_reason()); + return ResponseEntity.status(HttpStatus.OK).body(deletedDTO); + } + catch (RuntimeException e) { + Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + + } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeleteRequestDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeleteRequestDTO.java new file mode 100644 index 0000000..092bb2c --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeleteRequestDTO.java @@ -0,0 +1,3 @@ +package co.allconnected.fussiontech.usersservice.dtos; +public record DeleteRequestDTO(String delete_reason) { +} diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java new file mode 100644 index 0000000..125e49e --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java @@ -0,0 +1,8 @@ +// src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java +package co.allconnected.fussiontech.usersservice.dtos; + +import java.io.Serializable; +import java.time.Instant; + +public record DeletedDTO(String idUser, String reason, Instant deleteDate) implements Serializable { +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/Deleted.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/Deleted.java index bf8e905..8f5c71d 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/Deleted.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/Deleted.java @@ -1,10 +1,8 @@ package co.allconnected.fussiontech.usersservice.model; -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; +import jakarta.persistence.*; import lombok.Getter; +import lombok.NoArgsConstructor; import lombok.Setter; import java.time.Instant; @@ -12,16 +10,26 @@ @Getter @Setter @Entity +@NoArgsConstructor @Table(name = "deleted", schema = "all_connected_users") public class Deleted { + public Deleted(String idUser, String reason) { + this.idUser = idUser; + this.reason = reason; + this.deleteDate = Instant.now(); + } + @Id - @Column(name = "id_user", nullable = false, length = 28) + @Column(name = "id_user", nullable = false, length = 50) private String idUser; + @OneToOne + @JoinColumn(name = "id_user") + private User user; + @Column(name = "reason", nullable = false, length = 200) private String reason; @Column(name = "delete_date", nullable = false) private Instant deleteDate; - } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java index 7d7d7f6..0064d99 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -49,4 +49,6 @@ public User(UserCreateDTO dto){ inverseJoinColumns = @JoinColumn(name = "id_rol")) private Set roles = new LinkedHashSet<>(); + @OneToOne(mappedBy = "user", cascade = CascadeType.ALL) + private Deleted deleted; } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index 95dc44b..75986ac 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -39,4 +39,18 @@ public String createUser(String email, String password) throws FirebaseAuthExcep public void deleteUser(String uid) throws FirebaseAuthException { FirebaseAuth.getInstance().deleteUser(uid); } + + public void disableUser(String uid) throws FirebaseAuthException { + UserRecord.UpdateRequest request = new UserRecord.UpdateRequest(uid) + .setDisabled(true); + FirebaseAuth.getInstance().updateUser(request); + } + + public void updateUser(String uid, String email, String password) throws FirebaseAuthException { + UserRecord.UpdateRequest request = new UserRecord.UpdateRequest(uid) + .setEmail(email) + .setPassword(password); + + FirebaseAuth.getInstance().updateUser(request); + } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 71c924c..bf9cc1d 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -1,8 +1,11 @@ package co.allconnected.fussiontech.usersservice.services; +import co.allconnected.fussiontech.usersservice.dtos.DeletedDTO; import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; +import co.allconnected.fussiontech.usersservice.model.Deleted; import co.allconnected.fussiontech.usersservice.model.Rol; import co.allconnected.fussiontech.usersservice.model.User; +import co.allconnected.fussiontech.usersservice.repository.DeletedRepository; import co.allconnected.fussiontech.usersservice.repository.UserRepository; import com.google.firebase.auth.FirebaseAuthException; import org.apache.commons.io.FilenameUtils; @@ -16,14 +19,16 @@ public class UserService { private final UserRepository userRepository; + private final DeletedRepository deletedRepository; private final RolService rolService; private final FirebaseService firebaseService; @Autowired - public UserService(UserRepository userRepository, RolService rolService, FirebaseService firebaseService) { + public UserService(UserRepository userRepository, DeletedRepository deletedRepository, RolService rolService, FirebaseService firebaseService) { this.userRepository = userRepository; this.firebaseService = firebaseService; this.rolService = rolService; + this.deletedRepository = deletedRepository; } public User createUser(UserCreateDTO userDto, MultipartFile photo) throws FirebaseAuthException, IOException { @@ -62,4 +67,19 @@ public void deleteUser(String id) throws RuntimeException { userRepository.deleteById(id); } + + public DeletedDTO deactivateUser(String id, String reason) throws RuntimeException { + return userRepository.findById(id).map(user -> { + Deleted deleted = new Deleted(user.getIdUser(), reason); + user.setActive(false); + user.setDeleted(deletedRepository.save(deleted)); + userRepository.save(user); + try { + firebaseService.disableUser(user.getIdUser()); + } catch (FirebaseAuthException e) { + throw new RuntimeException(e); + } + return new DeletedDTO(deleted.getIdUser(), deleted.getReason(), deleted.getDeleteDate()); + }).orElseThrow(() -> new RuntimeException("User not found")); + } } \ No newline at end of file From 9a9859537b944000800ec243a48886eafa1094fa Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 14 Sep 2024 13:39:04 -0500 Subject: [PATCH 22/99] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20chang?= =?UTF-8?q?e=20dtos=20to=20records?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fussiontech/usersservice/dtos/Response.java | 14 +------------- .../usersservice/dtos/UserCreateDTO.java | 14 +------------- .../fussiontech/usersservice/model/User.java | 6 +++--- .../usersservice/services/UserService.java | 4 ++-- 4 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/Response.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/Response.java index f4e4299..85a6af6 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/Response.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/Response.java @@ -1,16 +1,4 @@ package co.allconnected.fussiontech.usersservice.dtos; -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class Response { - private int code; - private String message; - - public Response(int code, String message) { - this.code = code; - this.message = message; - } +public record Response(int code, String message) { } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java index dcbd556..4c5915d 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserCreateDTO.java @@ -1,16 +1,4 @@ package co.allconnected.fussiontech.usersservice.dtos; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@NoArgsConstructor -public class UserCreateDTO { - private String fullname; - private String username; - private String password; - private String mail; - private String[] roles; +public record UserCreateDTO(String fullname, String username, String password, String mail, String[] roles) { } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java index 0064d99..1ce04fb 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -17,9 +17,9 @@ public class User { public User(UserCreateDTO dto){ - this.fullname = dto.getFullname(); - this.username = dto.getUsername(); - this.mail = dto.getMail(); + this.fullname = dto.fullname(); + this.username = dto.username(); + this.mail = dto.mail(); this.active = true; } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index bf9cc1d..91f1f83 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -35,10 +35,10 @@ public User createUser(UserCreateDTO userDto, MultipartFile photo) throws Fireba User user = new User(userDto); // Create user in firebase - user.setIdUser(firebaseService.createUser(userDto.getMail(), userDto.getPassword())); + user.setIdUser(firebaseService.createUser(userDto.mail(), userDto.password())); // Add roles to user - for(String rol : userDto.getRoles()){ + for(String rol : userDto.roles()){ Rol rolEntity = rolService.getRol(rol).orElseThrow(); user.getRoles().add(rolEntity); } From 413e66363f732bee2e79145439bac1e557cd2057 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 14 Sep 2024 21:28:49 -0500 Subject: [PATCH 23/99] =?UTF-8?q?=E2=9C=A8=20feat=20get=20users=20by=20id?= =?UTF-8?q?=20or=20query=20params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 32 +++++++++++++++++++ .../usersservice/dtos/DeletedDTO.java | 2 +- .../usersservice/dtos/InactiveUserDTO.java | 21 ++++++++++++ .../usersservice/dtos/UserDTO.java | 2 ++ .../repository/UserRepository.java | 17 ++++++++++ .../usersservice/services/UserService.java | 14 ++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/dtos/InactiveUserDTO.java diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index b4e6ef7..ef648b4 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -37,6 +37,38 @@ public ResponseEntity createUser( } } + @GetMapping + public ResponseEntity getUsers( + @RequestParam(value = "fullname", required = false) String fullname, + @RequestParam(value = "username", required = false) String username, + @RequestParam(value = "mail", required = false) String mail, + @RequestParam(value = "rol", required = false) String rol, + @RequestParam(value = "active", required = false) Boolean active + ) { + try{ + UserDTO[] listUsersDTO = userService.getUsers(fullname, username, mail, rol, active); + if (listUsersDTO.length == 0) + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new Response(HttpStatus.NOT_FOUND.value(), "No users found")); + return ResponseEntity.status(HttpStatus.OK).body(listUsersDTO); + } + catch (RuntimeException e) { + Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + + @GetMapping("/{id}") + public ResponseEntity getUser( + @PathVariable String id) { + try{ + return ResponseEntity.status(HttpStatus.OK).body(userService.getUser(id)); + } + catch (RuntimeException e) { + Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } + } + @DeleteMapping("/{id}") public ResponseEntity deleteUser( @PathVariable String id) { diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java index 125e49e..8bd7723 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java @@ -4,5 +4,5 @@ import java.io.Serializable; import java.time.Instant; -public record DeletedDTO(String idUser, String reason, Instant deleteDate) implements Serializable { +public record DeletedDTO(String idUser, String reason, Instant delete_date) implements Serializable { } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/InactiveUserDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/InactiveUserDTO.java new file mode 100644 index 0000000..0525dcf --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/InactiveUserDTO.java @@ -0,0 +1,21 @@ +package co.allconnected.fussiontech.usersservice.dtos; + +import co.allconnected.fussiontech.usersservice.model.User; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.time.Instant; + +@Getter +@Setter +@NoArgsConstructor +public class InactiveUserDTO extends UserDTO{ + private String delete_reason; + private Instant delete_date; + public InactiveUserDTO(User user){ + super(user); + this.delete_reason = user.getDeleted().getReason(); + this.delete_date = user.getDeleted().getDeleteDate(); + } +} diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java index febbb66..b618d13 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java @@ -17,6 +17,7 @@ public class UserDTO { private String photo_url; private String[] roles; private String[] organizations; + private boolean active; public UserDTO(User user){ this.id_user = user.getIdUser(); @@ -26,5 +27,6 @@ public UserDTO(User user){ this.photo_url = user.getPhotoUrl(); this.roles = user.getRoles().stream().map(Rol::getIdRol).toArray(String[]::new); // this.organizations = user.getOrganizations().stream().map(Organization::getIdOrganization).toArray(String[]::new); + this.active = user.getActive(); } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/repository/UserRepository.java b/src/main/java/co/allconnected/fussiontech/usersservice/repository/UserRepository.java index 029d854..6939a9f 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/repository/UserRepository.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/repository/UserRepository.java @@ -2,6 +2,23 @@ import co.allconnected.fussiontech.usersservice.model.User; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; public interface UserRepository extends JpaRepository { + @Query("SELECT u FROM User u " + + "LEFT JOIN u.roles r " + + "WHERE (:fullname IS NULL OR u.fullname LIKE %:fullname%) " + + "AND (:username IS NULL OR u.username LIKE %:username%) " + + "AND (:mail IS NULL OR u.mail LIKE %:mail%) " + + "AND (:rol IS NULL OR r.idRol LIKE %:rol%) " + + "AND (:active IS NULL OR u.active = :active)") + List findUsersByFilters(@Param("fullname") String fullname, + @Param("username") String username, + @Param("mail") String mail, + @Param("rol") String rol, + @Param("active") Boolean active); + } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 91f1f83..31cebd0 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -1,7 +1,9 @@ package co.allconnected.fussiontech.usersservice.services; import co.allconnected.fussiontech.usersservice.dtos.DeletedDTO; +import co.allconnected.fussiontech.usersservice.dtos.InactiveUserDTO; import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; +import co.allconnected.fussiontech.usersservice.dtos.UserDTO; import co.allconnected.fussiontech.usersservice.model.Deleted; import co.allconnected.fussiontech.usersservice.model.Rol; import co.allconnected.fussiontech.usersservice.model.User; @@ -82,4 +84,16 @@ public DeletedDTO deactivateUser(String id, String reason) throws RuntimeExcepti return new DeletedDTO(deleted.getIdUser(), deleted.getReason(), deleted.getDeleteDate()); }).orElseThrow(() -> new RuntimeException("User not found")); } + + public UserDTO[] getUsers(String fullname, String username, String mail, String rol, Boolean active) { + return userRepository.findUsersByFilters(fullname, username, mail, rol, active).stream() + .map(user -> user.getActive() ? new UserDTO(user) : new InactiveUserDTO(user)) + .toArray(UserDTO[]::new); + } + + public UserDTO getUser(String id) { + return userRepository.findById(id) + .map(user -> user.getActive() ? new UserDTO(user) : new InactiveUserDTO(user)) + .orElseThrow(() -> new RuntimeException("User not found")); + } } \ No newline at end of file From 27ceb026415bf0f70befefba6f6591df723514ec Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 14 Sep 2024 21:40:26 -0500 Subject: [PATCH 24/99] =?UTF-8?q?=F0=9F=A5=85=20improve=20error=20codes=20?= =?UTF-8?q?and=20exceptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 60 +++++++------------ .../usersservice/dtos/DeletedDTO.java | 2 +- .../usersservice/services/UserService.java | 30 ++++++---- .../utils/OperationException.java | 14 +++++ .../usersservice/utils/fileToRemove.txt | 1 - 5 files changed, 55 insertions(+), 52 deletions(-) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/utils/OperationException.java delete mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/utils/fileToRemove.txt diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index ef648b4..12fcfa6 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -2,6 +2,7 @@ import co.allconnected.fussiontech.usersservice.dtos.*; import co.allconnected.fussiontech.usersservice.services.UserService; +import co.allconnected.fussiontech.usersservice.utils.OperationException; import com.google.firebase.auth.FirebaseAuthException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -24,16 +25,13 @@ public UsersController(UserService userService) { public ResponseEntity createUser( @ModelAttribute UserCreateDTO user, @RequestParam(value = "photo", required = false) MultipartFile photo) { - try{ + try { UserDTO userDTO = new UserDTO(userService.createUser(user, photo)); return ResponseEntity.status(HttpStatus.CREATED).body(userDTO); - } - catch (FirebaseAuthException e) { - Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Firebase authentication error: " + e.getMessage()); - return ResponseEntity.status(HttpStatus.CONFLICT).body(response); + } catch (FirebaseAuthException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Firebase authentication error: " + e.getMessage())); } catch (Exception e) { - Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred: " + e.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred: " + e.getMessage())); } } @@ -45,56 +43,44 @@ public ResponseEntity getUsers( @RequestParam(value = "rol", required = false) String rol, @RequestParam(value = "active", required = false) Boolean active ) { - try{ + try { UserDTO[] listUsersDTO = userService.getUsers(fullname, username, mail, rol, active); if (listUsersDTO.length == 0) return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new Response(HttpStatus.NOT_FOUND.value(), "No users found")); return ResponseEntity.status(HttpStatus.OK).body(listUsersDTO); - } - catch (RuntimeException e) { - Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); + } catch (RuntimeException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage())); } } @GetMapping("/{id}") - public ResponseEntity getUser( - @PathVariable String id) { - try{ + public ResponseEntity getUser(@PathVariable String id) { + try { return ResponseEntity.status(HttpStatus.OK).body(userService.getUser(id)); - } - catch (RuntimeException e) { - Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); } } @DeleteMapping("/{id}") - public ResponseEntity deleteUser( - @PathVariable String id) { - try{ + public ResponseEntity deleteUser(@PathVariable String id) { + try { userService.deleteUser(id); return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); } - catch (RuntimeException e) { - Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); - } - } @PostMapping("/{id}/deactivate") - public ResponseEntity deactivateUser( - @PathVariable String id, @RequestBody DeleteRequestDTO deleteRequest) { - try{ + public ResponseEntity deactivateUser(@PathVariable String id, @RequestBody DeleteRequestDTO deleteRequest) { + try { DeletedDTO deletedDTO = userService.deactivateUser(id, deleteRequest.delete_reason()); return ResponseEntity.status(HttpStatus.OK).body(deletedDTO); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); } - catch (RuntimeException e) { - Response response = new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage()); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response); - } - } -} - +} \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java index 8bd7723..44d8c0c 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/DeletedDTO.java @@ -4,5 +4,5 @@ import java.io.Serializable; import java.time.Instant; -public record DeletedDTO(String idUser, String reason, Instant delete_date) implements Serializable { +public record DeletedDTO(String id_user, String delete_reason, Instant delete_date) implements Serializable { } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 31cebd0..9f5e34b 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -9,6 +9,7 @@ import co.allconnected.fussiontech.usersservice.model.User; import co.allconnected.fussiontech.usersservice.repository.DeletedRepository; import co.allconnected.fussiontech.usersservice.repository.UserRepository; +import co.allconnected.fussiontech.usersservice.utils.OperationException; import com.google.firebase.auth.FirebaseAuthException; import org.apache.commons.io.FilenameUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -16,6 +17,7 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.Optional; @Service public class UserService { @@ -40,13 +42,13 @@ public User createUser(UserCreateDTO userDto, MultipartFile photo) throws Fireba user.setIdUser(firebaseService.createUser(userDto.mail(), userDto.password())); // Add roles to user - for(String rol : userDto.roles()){ + for (String rol : userDto.roles()) { Rol rolEntity = rolService.getRol(rol).orElseThrow(); user.getRoles().add(rolEntity); } // Upload photo to firebase - if(photo != null) { + if (photo != null) { String photoName = user.getIdUser(); String extension = FilenameUtils.getExtension(photo.getOriginalFilename()); user.setPhotoUrl(firebaseService.uploadImg(photoName, extension, photo)); @@ -55,22 +57,24 @@ public User createUser(UserCreateDTO userDto, MultipartFile photo) throws Fireba return userRepository.save(user); } - public void deleteUser(String id) throws RuntimeException { - userRepository.findById(id).ifPresent(user -> { - if(user.getPhotoUrl() != null) + public void deleteUser(String id) { + Optional userOptional = userRepository.findById(id); + if (userOptional.isPresent()) { + User user = userOptional.get(); + if (user.getPhotoUrl() != null) firebaseService.deleteImg(user.getIdUser()); try { firebaseService.deleteUser(user.getIdUser()); } catch (FirebaseAuthException e) { - throw new RuntimeException("Firebase authentication error: " + e.getMessage()); + throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); } userRepository.delete(user); - }); - - userRepository.deleteById(id); + } else { + throw new OperationException(404, "User not found"); + } } - public DeletedDTO deactivateUser(String id, String reason) throws RuntimeException { + public DeletedDTO deactivateUser(String id, String reason) { return userRepository.findById(id).map(user -> { Deleted deleted = new Deleted(user.getIdUser(), reason); user.setActive(false); @@ -79,10 +83,10 @@ public DeletedDTO deactivateUser(String id, String reason) throws RuntimeExcepti try { firebaseService.disableUser(user.getIdUser()); } catch (FirebaseAuthException e) { - throw new RuntimeException(e); + throw new OperationException(500, e.getMessage()); } return new DeletedDTO(deleted.getIdUser(), deleted.getReason(), deleted.getDeleteDate()); - }).orElseThrow(() -> new RuntimeException("User not found")); + }).orElseThrow(() -> new OperationException(404, "User not found")); } public UserDTO[] getUsers(String fullname, String username, String mail, String rol, Boolean active) { @@ -94,6 +98,6 @@ public UserDTO[] getUsers(String fullname, String username, String mail, String public UserDTO getUser(String id) { return userRepository.findById(id) .map(user -> user.getActive() ? new UserDTO(user) : new InactiveUserDTO(user)) - .orElseThrow(() -> new RuntimeException("User not found")); + .orElseThrow(() -> new OperationException(404, "User not found")); } } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/utils/OperationException.java b/src/main/java/co/allconnected/fussiontech/usersservice/utils/OperationException.java new file mode 100644 index 0000000..e826e6f --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/utils/OperationException.java @@ -0,0 +1,14 @@ +package co.allconnected.fussiontech.usersservice.utils; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class OperationException extends RuntimeException { + private final Integer code; + public OperationException(Integer code, String message) { + super(message); + this.code = code; + } +} diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/utils/fileToRemove.txt b/src/main/java/co/allconnected/fussiontech/usersservice/utils/fileToRemove.txt deleted file mode 100644 index 4fcccbf..0000000 --- a/src/main/java/co/allconnected/fussiontech/usersservice/utils/fileToRemove.txt +++ /dev/null @@ -1 +0,0 @@ -Este archivo es para dejar la estructura de carpetas del proyecto. Eliminar cuando se tenga el proyecto. From 01e2eb188128ab1b28cbcb93bb6e46d8e3df8e9e Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 15 Sep 2024 14:21:04 -0500 Subject: [PATCH 25/99] =?UTF-8?q?=E2=9C=A8=20add=20guestuser=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 12 +++++++++- .../usersservice/services/UserService.java | 22 ++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 12fcfa6..cbbff5e 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -26,7 +26,7 @@ public ResponseEntity createUser( @ModelAttribute UserCreateDTO user, @RequestParam(value = "photo", required = false) MultipartFile photo) { try { - UserDTO userDTO = new UserDTO(userService.createUser(user, photo)); + UserDTO userDTO = userService.createUser(user, photo); return ResponseEntity.status(HttpStatus.CREATED).body(userDTO); } catch (FirebaseAuthException e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Firebase authentication error: " + e.getMessage())); @@ -35,6 +35,16 @@ public ResponseEntity createUser( } } + @PostMapping("/guest") + public ResponseEntity createGuestUser() { + try { + UserDTO userDTO = userService.createGuestUser(); + return ResponseEntity.status(HttpStatus.CREATED).body(userDTO); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); + } + } + @GetMapping public ResponseEntity getUsers( @RequestParam(value = "fullname", required = false) String fullname, diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 9f5e34b..e7321ed 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.Optional; +import java.util.UUID; @Service public class UserService { @@ -35,7 +36,7 @@ public UserService(UserRepository userRepository, DeletedRepository deletedRepos this.deletedRepository = deletedRepository; } - public User createUser(UserCreateDTO userDto, MultipartFile photo) throws FirebaseAuthException, IOException { + public UserDTO createUser(UserCreateDTO userDto, MultipartFile photo) throws FirebaseAuthException, IOException { User user = new User(userDto); // Create user in firebase @@ -54,7 +55,21 @@ public User createUser(UserCreateDTO userDto, MultipartFile photo) throws Fireba user.setPhotoUrl(firebaseService.uploadImg(photoName, extension, photo)); } - return userRepository.save(user); + return new UserDTO(userRepository.save(user)); + } + + public UserDTO createGuestUser(){ + User user = new User(); + user.setIdUser(UUID.randomUUID().toString().replace("-", "").substring(0, 28)); + + user.setUsername("Guest<" + user.getIdUser() + ">"); + user.setFullname("Guest"); + user.setActive(true); + + Rol rolEntity = rolService.getRol("guest").orElseThrow(); + user.getRoles().add(rolEntity); + + return new UserDTO(userRepository.save(user)); } public void deleteUser(String id) { @@ -63,7 +78,8 @@ public void deleteUser(String id) { User user = userOptional.get(); if (user.getPhotoUrl() != null) firebaseService.deleteImg(user.getIdUser()); - try { + // check if user is guest + if (user.getRoles().stream().noneMatch(rol -> rol.getIdRol().equals("guest"))) try { firebaseService.deleteUser(user.getIdUser()); } catch (FirebaseAuthException e) { throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); From 9db42a57a231bcb757d07b644603d3f452d9143e Mon Sep 17 00:00:00 2001 From: Moyano1711 Date: Mon, 16 Sep 2024 17:58:42 -0500 Subject: [PATCH 26/99] =?UTF-8?q?=F0=9F=99=88=20update=20gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6378a64..8c68a52 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,4 @@ build/ spring-firebase-key.json ### Enviroment variables ### -.env \ No newline at end of file +.env From 769830f35ab7e838fa151f404ddea5fe9706c4a0 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 22 Sep 2024 19:03:52 -0500 Subject: [PATCH 27/99] =?UTF-8?q?=F0=9F=91=B7=20Add=20Dockerization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 24 ++++++++++++++++++++++++ README.md | 18 ++++++++++++++++++ docker-compose.yaml | 20 ++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d8ac2ee --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Etapa 1: Build +FROM maven:3.9.4-eclipse-temurin-21 AS build + +WORKDIR /app + +# Copiar el pom y código fuente +COPY pom.xml ./ +RUN mvn dependency:go-offline + +COPY src ./src + +RUN mvn clean package -DskipTests + +# Etapa 2: Run +FROM eclipse-temurin:21-jdk-jammy + +WORKDIR /app + +# Copiar el jar generado desde la etapa de build +COPY --from=build /app/target/*.jar app.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/README.md b/README.md index f1ef191..0705277 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,24 @@ Inicia el servidor mvn spring-boot:run ``` +--- +## Ejecutar con Docker 🐋 + +```bash + git clone https://github.com/FusionTech-2430/users-service +``` + +Ve al directorio del proyecto + +```bash + cd users-service +``` + +```bash + docker-compose up +``` + +Es importante crear el archivo .env con las variables mencionadas en el punto anterior. --- ## Autores 🧑🏻‍💻 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..e6de309 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,20 @@ +version: '3.8' + +services: + spring-app: + build: . + ports: + - "8080:8080" + env_file: + - .env + environment: + - DATASOURCE_URL=${DATASOURCE_URL} + - DATASOURCE_USERNAME=${DATASOURCE_USERNAME} + - DATASOURCE_PASSWORD=${DATASOURCE_PASSWORD} + - GOOGLE_ADMIN_CONFIG_TYPE=${GOOGLE_ADMIN_CONFIG_TYPE} + - GOOGLE_ADMIN_CONFIG_PROJECT_ID=${GOOGLE_ADMIN_CONFIG_PROJECT_ID} + - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${GOOGLE_ADMIN_CONFIG_PRIVATE_KEY} + - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID} + - GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL} + - GOOGLE_ADMIN_CONFIG_CLIENT_ID=${GOOGLE_ADMIN_CONFIG_CLIENT_ID} + - GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL=${GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL} From 5ce8efbad97173c15f66b689fbc7c2e8e8f1dac6 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 22 Sep 2024 22:29:51 -0500 Subject: [PATCH 28/99] =?UTF-8?q?=F0=9F=90=9B=20add=20guest=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fussiontech/usersservice/services/UserService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index e7321ed..d00f46b 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -96,7 +96,7 @@ public DeletedDTO deactivateUser(String id, String reason) { user.setActive(false); user.setDeleted(deletedRepository.save(deleted)); userRepository.save(user); - try { + if (user.getRoles().stream().noneMatch(rol -> rol.getIdRol().equals("guest"))) try { firebaseService.disableUser(user.getIdUser()); } catch (FirebaseAuthException e) { throw new OperationException(500, e.getMessage()); From 8eb3d4400b2e5502449eeaba7edeed9edf9c7172 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 22 Sep 2024 22:59:58 -0500 Subject: [PATCH 29/99] =?UTF-8?q?=E2=9C=A8=20add=20user=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 23 +++++++-- .../services/FirebaseService.java | 9 ++-- .../usersservice/services/UserService.java | 49 +++++++++++++++++-- 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index cbbff5e..59fc7cd 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -28,10 +28,10 @@ public ResponseEntity createUser( try { UserDTO userDTO = userService.createUser(user, photo); return ResponseEntity.status(HttpStatus.CREATED).body(userDTO); - } catch (FirebaseAuthException e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Firebase authentication error: " + e.getMessage())); - } catch (Exception e) { - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Unexpected error occurred: " + e.getMessage())); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); + } catch (RuntimeException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage())); } } @@ -74,6 +74,21 @@ public ResponseEntity getUser(@PathVariable String id) { } } + @PutMapping("/{id}") + public ResponseEntity updateUser( + @PathVariable String id, + @ModelAttribute UserCreateDTO user, + @RequestParam(value = "photo", required = false) MultipartFile photo) { + try { + UserDTO userDTO = userService.updateUser(id, user, photo); + return ResponseEntity.status(HttpStatus.OK).body(userDTO); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); + } catch (RuntimeException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage())); + } + } + @DeleteMapping("/{id}") public ResponseEntity deleteUser(@PathVariable String id) { try { diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index 75986ac..8fc842f 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -47,10 +47,11 @@ public void disableUser(String uid) throws FirebaseAuthException { } public void updateUser(String uid, String email, String password) throws FirebaseAuthException { - UserRecord.UpdateRequest request = new UserRecord.UpdateRequest(uid) - .setEmail(email) - .setPassword(password); - + UserRecord.UpdateRequest request = new UserRecord.UpdateRequest(uid); + if (email != null) + request.setEmail(email); + if (password != null) + request.setPassword(password); FirebaseAuth.getInstance().updateUser(request); } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index d00f46b..549b429 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -36,11 +36,15 @@ public UserService(UserRepository userRepository, DeletedRepository deletedRepos this.deletedRepository = deletedRepository; } - public UserDTO createUser(UserCreateDTO userDto, MultipartFile photo) throws FirebaseAuthException, IOException { + public UserDTO createUser(UserCreateDTO userDto, MultipartFile photo) { User user = new User(userDto); // Create user in firebase - user.setIdUser(firebaseService.createUser(userDto.mail(), userDto.password())); + try { + user.setIdUser(firebaseService.createUser(userDto.mail(), userDto.password())); + } catch (FirebaseAuthException e) { + throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); + } // Add roles to user for (String rol : userDto.roles()) { @@ -52,9 +56,12 @@ public UserDTO createUser(UserCreateDTO userDto, MultipartFile photo) throws Fir if (photo != null) { String photoName = user.getIdUser(); String extension = FilenameUtils.getExtension(photo.getOriginalFilename()); - user.setPhotoUrl(firebaseService.uploadImg(photoName, extension, photo)); + try{ + user.setPhotoUrl(firebaseService.uploadImg(photoName, extension, photo)); + } catch (IOException e) { + throw new OperationException(500, "Error uploading photo: " + e.getMessage()); + } } - return new UserDTO(userRepository.save(user)); } @@ -116,4 +123,38 @@ public UserDTO getUser(String id) { .map(user -> user.getActive() ? new UserDTO(user) : new InactiveUserDTO(user)) .orElseThrow(() -> new OperationException(404, "User not found")); } + + public UserDTO updateUser(String id, UserCreateDTO userDTO, MultipartFile photo) { + User user = userRepository.findById(id).orElseThrow(() -> new OperationException(404, "User not found")); + + if(userDTO.fullname() != null && !user.getFullname().equals(userDTO.fullname())) + user.setFullname(userDTO.fullname()); + + if(userDTO.username() != null && !user.getUsername().equals(userDTO.username())) + user.setUsername(userDTO.username()); + + // Update mail and password in firebase if they changed + if (userDTO.mail() != null && !user.getMail().equals(userDTO.mail()) || userDTO.password() != null) { + try { + firebaseService.updateUser(user.getIdUser(), userDTO.mail(), userDTO.password()); + user.setMail(userDTO.mail()); + } catch (FirebaseAuthException e) { + throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); + } + } + + // Update photo if not null + if (photo != null) { + if (user.getPhotoUrl() != null) + firebaseService.deleteImg(user.getIdUser()); + String photoName = user.getIdUser(); + String extension = FilenameUtils.getExtension(photo.getOriginalFilename()); + try{ + user.setPhotoUrl(firebaseService.uploadImg(photoName, extension, photo)); + } catch (IOException e) { + throw new OperationException(500, "Error uploading photo: " + e.getMessage()); + } + } + return new UserDTO(userRepository.save(user)); + } } \ No newline at end of file From a4d0ce781f99a6fc34cdc89d960fb3629c056a04 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 22 Sep 2024 23:14:23 -0500 Subject: [PATCH 30/99] =?UTF-8?q?=E2=9C=A8=20add=20roles=20administration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/UsersController.java | 20 +++++++++++++++++++ .../usersservice/dtos/RolesDTO.java | 4 ++++ .../usersservice/services/UserService.java | 16 +++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/dtos/RolesDTO.java diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 59fc7cd..4e18822 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -108,4 +108,24 @@ public ResponseEntity deactivateUser(@PathVariable String id, @RequestBody De return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); } } + + @PostMapping("/{id}/roles") + public ResponseEntity addRole(@PathVariable String id, @RequestBody RolesDTO roles) { + try { + UserDTO userDTO = userService.addRoles(id, roles.roles()); + return ResponseEntity.status(HttpStatus.CREATED).body(userDTO); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); + } + } + + @DeleteMapping("/{id}/roles/{rol}") + public ResponseEntity removeRole(@PathVariable String id, @PathVariable String rol) { + try { + UserDTO userDTO = userService.removeRoles(id, rol); + return ResponseEntity.status(HttpStatus.OK).body(userDTO); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); + } + } } \ No newline at end of file diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/RolesDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/RolesDTO.java new file mode 100644 index 0000000..a1a7073 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/RolesDTO.java @@ -0,0 +1,4 @@ +package co.allconnected.fussiontech.usersservice.dtos; + +public record RolesDTO(String[] roles) { +} diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 549b429..8613d7e 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -157,4 +157,20 @@ public UserDTO updateUser(String id, UserCreateDTO userDTO, MultipartFile photo) } return new UserDTO(userRepository.save(user)); } + + public UserDTO addRoles(String id, String[] roles) { + User user = userRepository.findById(id).orElseThrow(() -> new OperationException(404, "User not found")); + for (String rol : roles) { + Rol rolEntity = rolService.getRol(rol).orElseThrow(); + user.getRoles().add(rolEntity); + } + return new UserDTO(userRepository.save(user)); + } + + public UserDTO removeRoles(String id, String rol) { + User user = userRepository.findById(id).orElseThrow(() -> new OperationException(404, "User not found")); + Rol rolEntity = rolService.getRol(rol).orElseThrow(() -> new OperationException(404, "Rol not found")); + user.getRoles().remove(rolEntity); + return new UserDTO(userRepository.save(user)); + } } \ No newline at end of file From bb2284bd302e88ec5bab9dfa84e07fe83fa661ab Mon Sep 17 00:00:00 2001 From: Esteban Salazar <68300629+Estebans441@users.noreply.github.com> Date: Sun, 22 Sep 2024 23:23:16 -0500 Subject: [PATCH 31/99] =?UTF-8?q?=F0=9F=93=9D=20Update=20README.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 0705277..79467bd 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,6 @@ Ve al directorio del proyecto docker-compose up ``` -Es importante crear el archivo .env con las variables mencionadas en el punto anterior. --- ## Autores 🧑🏻‍💻 From fc130b214153cf77091e892d354e90612f37b561 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 22 Sep 2024 23:26:24 -0500 Subject: [PATCH 32/99] =?UTF-8?q?=F0=9F=94=A5optimize=20imports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fussiontech/usersservice/controllers/UsersController.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 4e18822..23ea977 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -3,7 +3,6 @@ import co.allconnected.fussiontech.usersservice.dtos.*; import co.allconnected.fussiontech.usersservice.services.UserService; import co.allconnected.fussiontech.usersservice.utils.OperationException; -import com.google.firebase.auth.FirebaseAuthException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; From 9a0a1fe2fac7daa02c1d27df923120712b77db38 Mon Sep 17 00:00:00 2001 From: Esteban Salazar <68300629+Estebans441@users.noreply.github.com> Date: Mon, 23 Sep 2024 14:59:13 -0500 Subject: [PATCH 33/99] :construction_worker: Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3cd9797..fc41d74 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ on: jobs: build: - runs-on: self-hosted + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 From 5cfa983aa718c6f75e638a92a727e6d2f0753164 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 15:49:27 -0500 Subject: [PATCH 34/99] :construction_worker: Add deploy action --- .github/workflows/deploy.yml | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..4cc8f6b --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,39 @@ +on: + push: + branches: + - develop + pull_request: + branches: + - develop + workflow_dispatch: +jobs: + run_pull: + name: Run Pull + runs-on: self-hosted + steps: + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DEV_HOST }} + username: ${{ secrets.HOSTS_USERNAME }} + key: ${{ secrets.DEV_SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd AllConnected/users-service + git fetch + git checkout develop + git pull + sudo docker build -t users-service . + sudo docker run --rm -d \ + -p 8080:8080 \ + -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} \ + -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} \ + -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \ + -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} \ + -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} \ + -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} \ + -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} \ + -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} \ + -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} \ + -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} \ + users-service \ No newline at end of file From 8292f862ae73d4c46b8085bee21fc7710e40c970 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:05:16 -0500 Subject: [PATCH 35/99] :construction_worker: fix deploy script --- .github/workflows/deploy.yml | 74 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4cc8f6b..9c3f3af 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,39 +1,39 @@ on: - push: - branches: - - develop - pull_request: - branches: - - develop - workflow_dispatch: + push: + branches: + - develop + pull_request: + branches: + - develop + workflow_dispatch: jobs: - run_pull: - name: Run Pull - runs-on: self-hosted - steps: - - name: executing remote ssh commands using ssh key - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.DEV_HOST }} - username: ${{ secrets.HOSTS_USERNAME }} - key: ${{ secrets.DEV_SSH_KEY }} - port: ${{ secrets.SSH_PORT }} - script: | - cd AllConnected/users-service - git fetch - git checkout develop - git pull - sudo docker build -t users-service . - sudo docker run --rm -d \ - -p 8080:8080 \ - -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} \ - -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} \ - -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \ - -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} \ - -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} \ - -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} \ - -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} \ - -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} \ - -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} \ - -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} \ - users-service \ No newline at end of file + run_pull: + name: Run Pull + runs-on: self-hosted + steps: + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DEV_HOST }} + username: ${{ secrets.HOSTS_USERNAME }} + key: ${{ secrets.DEV_SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd AllConnected/users-service + git fetch + git checkout develop + git pull + sudo docker build -t users-service . + sudo docker run --rm -d \ + -p 8080:8080 \ + -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} \ + -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} \ + -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \ + -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} \ + -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} \ + -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY="${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" \ + -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} \ + -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} \ + -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} \ + -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} \ + users-service From 646ef2fd161cbd7cdb706515698e4a4685c4ace7 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:07:32 -0500 Subject: [PATCH 36/99] :construction_worker: fix deploy script --- .github/workflows/deploy.yml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9c3f3af..a650678 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -24,16 +24,4 @@ jobs: git checkout develop git pull sudo docker build -t users-service . - sudo docker run --rm -d \ - -p 8080:8080 \ - -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} \ - -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} \ - -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \ - -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} \ - -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} \ - -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY="${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" \ - -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} \ - -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} \ - -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} \ - -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} \ - users-service + sudo docker run --rm -d -p 8080:8080 -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY="${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} users-service From b11603f5538bfc92075f7cd260530c00d85deeaf Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:14:55 -0500 Subject: [PATCH 37/99] :construction_worker: Update actions scripts --- .github/workflows/build.yml | 83 ++++++++++++++++++++++++------------ .github/workflows/deploy.yml | 27 ------------ 2 files changed, 56 insertions(+), 54 deletions(-) delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fc41d74..40828a2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,38 +6,67 @@ # separate terms of service, privacy policy, and support # documentation. -name: Build Project +name: Deploy to Dev on: push: - branches: [ "main", "develop" ] + branches: ["develop"] pull_request: - branches: [ "main" ] - + branches: ["develop"] + workflow_dispatch: jobs: build: - runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Maven + run: sudo apt-get install -y maven + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: "temurin" + cache: maven + - name: Build with Maven + env: + DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} + DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} + DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} + GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} + GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} + GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} + run: mvn clean install + deploy: + name: Run Pull + runs-on: self-hosted steps: - - uses: actions/checkout@v4 - - name: Install Maven - run: sudo apt-get install -y maven - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - cache: maven - - name: Build with Maven - env: - DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} - DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} - DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} - GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} - GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} - GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} - GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} - GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} - run: mvn clean install + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DEV_HOST }} + username: ${{ secrets.HOSTS_USERNAME }} + key: ${{ secrets.DEV_SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd AllConnected/users-service + git fetch + git checkout develop + git pull + sudo docker build -t users-service . + sudo docker run --rm -d \ + -p 8080:8080 \ + -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} \ + -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} \ + -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \ + -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} \ + -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} \ + -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY="${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" \ + -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} \ + -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} \ + -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} \ + -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} \ + users-service diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index a650678..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,27 +0,0 @@ -on: - push: - branches: - - develop - pull_request: - branches: - - develop - workflow_dispatch: -jobs: - run_pull: - name: Run Pull - runs-on: self-hosted - steps: - - name: executing remote ssh commands using ssh key - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.DEV_HOST }} - username: ${{ secrets.HOSTS_USERNAME }} - key: ${{ secrets.DEV_SSH_KEY }} - port: ${{ secrets.SSH_PORT }} - script: | - cd AllConnected/users-service - git fetch - git checkout develop - git pull - sudo docker build -t users-service . - sudo docker run --rm -d -p 8080:8080 -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY="${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} users-service From c84189154911ee5d9c467848fc4e6ed701f2f928 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:17:57 -0500 Subject: [PATCH 38/99] =?UTF-8?q?=F0=9F=92=9A=20create=20separate=20yml=20?= =?UTF-8?q?for=20build=20and=20deploy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 40828a2..fc87276 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ # separate terms of service, privacy policy, and support # documentation. -name: Deploy to Dev +name: Build on: push: branches: ["develop"] diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..22255e1 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,42 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Deploy Develop +on: + workflow_dispatch: +jobs: + deploy: + name: Run Pull + runs-on: self-hosted + steps: + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.DEV_HOST }} + username: ${{ secrets.HOSTS_USERNAME }} + key: ${{ secrets.DEV_SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd AllConnected/users-service + git fetch + git checkout develop + git pull + sudo docker build -t users-service . + sudo docker run --rm -d \ + -p 8080:8080 \ + -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} \ + -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} \ + -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \ + -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} \ + -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} \ + -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY="${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" \ + -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} \ + -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} \ + -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} \ + -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} \ + users-service From d91e21da8fb50684ec2f33483b50eaa05ace1360 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:19:20 -0500 Subject: [PATCH 39/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20build=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fc87276..e87a40d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,33 +40,3 @@ jobs: GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} run: mvn clean install - deploy: - name: Run Pull - runs-on: self-hosted - steps: - - name: executing remote ssh commands using ssh key - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.DEV_HOST }} - username: ${{ secrets.HOSTS_USERNAME }} - key: ${{ secrets.DEV_SSH_KEY }} - port: ${{ secrets.SSH_PORT }} - script: | - cd AllConnected/users-service - git fetch - git checkout develop - git pull - sudo docker build -t users-service . - sudo docker run --rm -d \ - -p 8080:8080 \ - -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} \ - -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} \ - -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \ - -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} \ - -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} \ - -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY="${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" \ - -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} \ - -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} \ - -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} \ - -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} \ - users-service From 5ec6b78b6f9251b72ef3da9a8b1b364b64c0ca78 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:26:13 -0500 Subject: [PATCH 40/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20deploy=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 22255e1..fa932a2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,20 +23,23 @@ jobs: port: ${{ secrets.SSH_PORT }} script: | cd AllConnected/users-service + echo "Fetching latest code..." git fetch git checkout develop git pull + echo "Building Docker image..." sudo docker build -t users-service . - sudo docker run --rm -d \ - -p 8080:8080 \ - -e DATASOURCE_URL=${{ secrets.DATASOURCE_URL }} \ - -e DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }} \ - -e DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }} \ - -e GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} \ - -e GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} \ - -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY="${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" \ - -e GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} \ - -e GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} \ - -e GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} \ - -e GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} \ - users-service + echo "Creating .env file..." + echo "DATASOURCE_URL=${{ secrets.DATASOURCE_URL }}" >> .env + echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env + echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=\"${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}\"" >> .env + echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env + sudo docker run --rm -d -p 8080:8080 --env-file .env users-service + echo "Docker container running..." + rm .env \ No newline at end of file From 1242c1b917ba12dd5be2b0d7ae13f874b0787c2b Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:28:52 -0500 Subject: [PATCH 41/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20deploy=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fa932a2..2ce7912 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,6 +8,10 @@ name: Deploy Develop on: + push: + branches: ["develop"] + pull_request: + branches: ["develop"] workflow_dispatch: jobs: deploy: @@ -42,4 +46,4 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env sudo docker run --rm -d -p 8080:8080 --env-file .env users-service echo "Docker container running..." - rm .env \ No newline at end of file + rm .env From fa76eef2328cba54196c66135e82d1e16e748158 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:32:08 -0500 Subject: [PATCH 42/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20deploy=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2ce7912..4b29445 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -44,6 +44,5 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env - sudo docker run --rm -d -p 8080:8080 --env-file .env users-service + sudo docker run -d -p 8080:8080 --env-file .env users-service echo "Docker container running..." - rm .env From b5d296e4738f38ed59e70b5ae37f32c3c99186c9 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:40:34 -0500 Subject: [PATCH 43/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20deploy=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4b29445..c61cec6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -46,3 +46,4 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env sudo docker run -d -p 8080:8080 --env-file .env users-service echo "Docker container running..." + \ No newline at end of file From 2daeec7da4579cbd0d2725bb05e31d9ed375ee48 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:44:50 -0500 Subject: [PATCH 44/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20.env=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c61cec6..5436658 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -39,7 +39,7 @@ jobs: echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=\"${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}\"" >> .env + echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" >> .env echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env From 606656fb3f31ea5606c5cd55ed41833e480d2b0f Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 16:55:23 -0500 Subject: [PATCH 45/99] =?UTF-8?q?=F0=9F=92=9A=20add=20general=20security?= =?UTF-8?q?=20fixes=20to=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5436658..acdca61 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -32,7 +32,7 @@ jobs: git checkout develop git pull echo "Building Docker image..." - sudo docker build -t users-service . + docker build -t users-service . echo "Creating .env file..." echo "DATASOURCE_URL=${{ secrets.DATASOURCE_URL }}" >> .env echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env @@ -44,6 +44,7 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env - sudo docker run -d -p 8080:8080 --env-file .env users-service + docker rm -f users-service + docker run -d -p 8080:8080 --env-file .env users-service --name users-service echo "Docker container running..." - \ No newline at end of file + rm .env \ No newline at end of file From 8805351844eb508be73109b890d1f5a21d4f63df Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 17:16:49 -0500 Subject: [PATCH 46/99] :construction_worker: refactor actions dev scripts --- .github/workflows/build.yml | 42 ------------------- .../workflows/{deploy.yml => deploy-dev.yml} | 39 ++++++++++++----- 2 files changed, 29 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/build.yml rename .github/workflows/{deploy.yml => deploy-dev.yml} (60%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index e87a40d..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,42 +0,0 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Build -on: - push: - branches: ["develop"] - pull_request: - branches: ["develop"] - workflow_dispatch: -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install Maven - run: sudo apt-get install -y maven - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: "21" - distribution: "temurin" - cache: maven - - name: Build with Maven - env: - DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} - DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} - DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} - GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} - GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} - GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} - GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} - GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} - run: mvn clean install - diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy-dev.yml similarity index 60% rename from .github/workflows/deploy.yml rename to .github/workflows/deploy-dev.yml index acdca61..c9eebdb 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy-dev.yml @@ -1,12 +1,4 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Deploy Develop +name: Build on: push: branches: ["develop"] @@ -14,9 +6,36 @@ on: branches: ["develop"] workflow_dispatch: jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Maven + run: sudo apt-get install -y maven + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: "temurin" + cache: maven + - name: Build with Maven + env: + DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} + DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} + DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} + GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} + GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} + GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} + run: mvn clean install + deploy: - name: Run Pull + name: Deploy on Develop runs-on: self-hosted + needs: build steps: - name: executing remote ssh commands using ssh key uses: appleboy/ssh-action@master From ffeb00987fc49462d2de212ce8170b6068222785 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 17:25:08 -0500 Subject: [PATCH 47/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20docker=20container?= =?UTF-8?q?=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index c9eebdb..873588c 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -64,6 +64,6 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env docker rm -f users-service - docker run -d -p 8080:8080 --env-file .env users-service --name users-service + docker run --name users-service -d -p 8080:8080 --env-file .env users-service echo "Docker container running..." rm .env \ No newline at end of file From 48d64b9e1687f2113ee0f82afbcbe0114059f91e Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 17:27:04 -0500 Subject: [PATCH 48/99] =?UTF-8?q?=F0=9F=92=9A=20test=20docker=20container?= =?UTF-8?q?=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 873588c..ce35314 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -6,7 +6,7 @@ on: branches: ["develop"] workflow_dispatch: jobs: - build: + Build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -35,7 +35,7 @@ jobs: deploy: name: Deploy on Develop runs-on: self-hosted - needs: build + needs: Build steps: - name: executing remote ssh commands using ssh key uses: appleboy/ssh-action@master From e6d9adb5ca9b74f356f44e9d6527b6b8e89b8eec Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 23 Sep 2024 22:20:08 -0500 Subject: [PATCH 49/99] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20add=20cors=20conf?= =?UTF-8?q?iguration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usersservice/config/WebConfig.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java new file mode 100644 index 0000000..3473bc3 --- /dev/null +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java @@ -0,0 +1,18 @@ +package co.allconnected.fussiontech.usersservice.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.CorsRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addCorsMappings(CorsRegistry registry) { + registry.addMapping("/**") + .allowedOriginPatterns("*") + .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") + .allowedHeaders("*") + .allowCredentials(true); + } +} From 0fb27e0b3ce3daafdf9186e7a548fa7792cd0e1d Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 24 Sep 2024 11:01:03 -0500 Subject: [PATCH 50/99] :construction_worker: add deploy-qa script --- .github/workflows/deploy-qa.yml | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/deploy-qa.yml diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml new file mode 100644 index 0000000..04a56cf --- /dev/null +++ b/.github/workflows/deploy-qa.yml @@ -0,0 +1,69 @@ +name: Build +on: + push: + branches: ["release"] + pull_request: + branches: ["release"] + workflow_dispatch: +jobs: + Build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Maven + run: sudo apt-get install -y maven + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: "temurin" + cache: maven + - name: Build with Maven + env: + DATASOURCE_PASSWORD: ${{ secrets.QA_DATASOURCE_PASSWORD }} + DATASOURCE_URL: ${{ secrets.QA_DATASOURCE_URL }} + DATASOURCE_USERNAME: ${{ secrets.QA_DATASOURCE_USERNAME }} + GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} + GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} + GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} + GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} + GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} + run: mvn clean install + + deploy: + name: Deploy on Develop + runs-on: self-hosted + needs: Build + steps: + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.QA_HOST }} + username: ${{ secrets.HOSTS_USERNAME }} + key: ${{ secrets.QA_SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd AllConnected/users-service + echo "Fetching latest code..." + git fetch + git checkout release + git pull + echo "Building Docker image..." + docker build -t users-service . + echo "Creating .env file..." + echo "DATASOURCE_URL=${{ secrets.QA_DATASOURCE_URL }}" >> .env + echo "DATASOURCE_USERNAME=${{ secrets.QA_DATASOURCE_USERNAME }}" >> .env + echo "DATASOURCE_PASSWORD=${{ secrets.QA_DATASOURCE_PASSWORD }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env + echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env + docker rm -f users-service + docker run --name users-service -d -p 8080:8080 --env-file .env users-service + echo "Docker container running..." + rm .env \ No newline at end of file From 128e2476445ca07809a78d2b989e8d7c09a9270d Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 24 Sep 2024 11:06:51 -0500 Subject: [PATCH 51/99] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20change=20step=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-qa.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 04a56cf..61505c2 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -33,7 +33,7 @@ jobs: run: mvn clean install deploy: - name: Deploy on Develop + name: Deploy on QA runs-on: self-hosted needs: Build steps: From 295ceac07e83d3629750803df42c0ea6f51e394f Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 24 Sep 2024 21:29:45 -0500 Subject: [PATCH 52/99] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20change=20deploy=20wo?= =?UTF-8?q?rkflows=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 2 +- .github/workflows/deploy-qa.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index ce35314..197190c 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -1,4 +1,4 @@ -name: Build +name: Deploy Develop on: push: branches: ["develop"] diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 61505c2..6544d66 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -1,4 +1,4 @@ -name: Build +name: Deploy QA on: push: branches: ["release"] From b4cd69638994274550fa2bf58f7fa07c765aace3 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 30 Sep 2024 18:28:39 -0500 Subject: [PATCH 53/99] =?UTF-8?q?=F0=9F=A5=85=20add=20rol=20not=20found=20?= =?UTF-8?q?exception=20in=20user=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fussiontech/usersservice/services/UserService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 8613d7e..d334136 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -48,8 +48,9 @@ public UserDTO createUser(UserCreateDTO userDto, MultipartFile photo) { // Add roles to user for (String rol : userDto.roles()) { - Rol rolEntity = rolService.getRol(rol).orElseThrow(); - user.getRoles().add(rolEntity); + Optional rolEntity = rolService.getRol(rol); + if(rolEntity.isEmpty()) throw new OperationException(404, "Rol not found"); + user.getRoles().add(rolEntity.get()); } // Upload photo to firebase From 393a9390141e0a5d862a3d61e7d6737ff9619945 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 30 Sep 2024 18:32:16 -0500 Subject: [PATCH 54/99] :construction_worker: change runner for build jobs --- .github/workflows/deploy-dev.yml | 2 +- .github/workflows/deploy-qa.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 197190c..85c8325 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -7,7 +7,7 @@ on: workflow_dispatch: jobs: Build: - runs-on: ubuntu-latest + runs-on: self-hosted steps: - uses: actions/checkout@v4 - name: Install Maven diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 6544d66..7a0b71c 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -7,7 +7,7 @@ on: workflow_dispatch: jobs: Build: - runs-on: ubuntu-latest + runs-on: self-hosted steps: - uses: actions/checkout@v4 - name: Install Maven From 2219c768a2547adfbc22463d0e847b3972c7edef Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 30 Sep 2024 18:35:59 -0500 Subject: [PATCH 55/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20runner=20configs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 4 ++-- .github/workflows/deploy-qa.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 85c8325..81163f4 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -7,7 +7,7 @@ on: workflow_dispatch: jobs: Build: - runs-on: self-hosted + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install Maven @@ -53,7 +53,7 @@ jobs: echo "Building Docker image..." docker build -t users-service . echo "Creating .env file..." - echo "DATASOURCE_URL=${{ secrets.DATASOURCE_URL }}" >> .env + echo "DATASOURCE_URL=${{ secrets.DEV_DATASOURCE_URL }}" >> .env echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 7a0b71c..6544d66 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -7,7 +7,7 @@ on: workflow_dispatch: jobs: Build: - runs-on: self-hosted + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Install Maven From 64164e014d1a2e72039024cf747d8a8378c10e80 Mon Sep 17 00:00:00 2001 From: Esteban Salazar <68300629+Estebans441@users.noreply.github.com> Date: Tue, 1 Oct 2024 07:42:08 -0500 Subject: [PATCH 56/99] :construction_worker: Update deploy-dev.yml --- .github/workflows/deploy-dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 81163f4..a446116 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -64,6 +64,6 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env docker rm -f users-service - docker run --name users-service -d -p 8080:8080 --env-file .env users-service + docker run --name users-service --network all_connected -d -p 8080:8080 --env-file .env users-service echo "Docker container running..." - rm .env \ No newline at end of file + rm .env From 957f4f02c14f67895ea950658e501b89cf1419a6 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 1 Oct 2024 08:38:28 -0500 Subject: [PATCH 57/99] :construction_worker: Update deploy-qa.yml --- .github/workflows/deploy-qa.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 6544d66..960d655 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -20,9 +20,9 @@ jobs: cache: maven - name: Build with Maven env: - DATASOURCE_PASSWORD: ${{ secrets.QA_DATASOURCE_PASSWORD }} - DATASOURCE_URL: ${{ secrets.QA_DATASOURCE_URL }} - DATASOURCE_USERNAME: ${{ secrets.QA_DATASOURCE_USERNAME }} + DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} + DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} + DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} @@ -64,6 +64,6 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env docker rm -f users-service - docker run --name users-service -d -p 8080:8080 --env-file .env users-service + docker run --name users-service --network all_connected -d -p 8080:8080 --env-file .env users-service echo "Docker container running..." rm .env \ No newline at end of file From f924b0066c9f3ac59276216e54f2652482ff6265 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 1 Oct 2024 10:04:45 -0500 Subject: [PATCH 58/99] :construction_worker: update secrets and scripts for gh actions --- .github/workflows/deploy-dev.yml | 12 ++++++------ .github/workflows/deploy-qa.yml | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index a446116..7c002b0 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -21,7 +21,7 @@ jobs: - name: Build with Maven env: DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} - DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} + DATASOURCE_URL: ${{ secrets.NEON_DATASOURCE_URL }}/${{ secrets.DB_NAME }} DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} @@ -45,15 +45,15 @@ jobs: key: ${{ secrets.DEV_SSH_KEY }} port: ${{ secrets.SSH_PORT }} script: | - cd AllConnected/users-service + cd AllConnected/${{ github.event.repository.name }} echo "Fetching latest code..." git fetch git checkout develop git pull echo "Building Docker image..." - docker build -t users-service . + docker build -t ${{ github.event.repository.name }} . echo "Creating .env file..." - echo "DATASOURCE_URL=${{ secrets.DEV_DATASOURCE_URL }}" >> .env + echo "DATASOURCE_URL=${{ secrets.DEV_DATASOURCE_URL }}/${{ secrets.DB_NAME }}" >> .env echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env @@ -63,7 +63,7 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env - docker rm -f users-service - docker run --name users-service --network all_connected -d -p 8080:8080 --env-file .env users-service + docker rm -f ${{ github.event.repository.name }} + docker run --name ${{ github.event.repository.name }} --network all_connected -d -p 8080:8080 --env-file .env ${{ github.event.repository.name }} echo "Docker container running..." rm .env diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 960d655..5f1d583 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -21,7 +21,7 @@ jobs: - name: Build with Maven env: DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} - DATASOURCE_URL: ${{ secrets.DATASOURCE_URL }} + DATASOURCE_URL: ${{ secrets.NEON_DATASOURCE_URL }}/${{ secrets.DB_NAME }} DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} @@ -32,7 +32,7 @@ jobs: GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} run: mvn clean install - deploy: + Deploy: name: Deploy on QA runs-on: self-hosted needs: Build @@ -45,15 +45,15 @@ jobs: key: ${{ secrets.QA_SSH_KEY }} port: ${{ secrets.SSH_PORT }} script: | - cd AllConnected/users-service + cd AllConnected/${{ github.event.repository.name }} echo "Fetching latest code..." git fetch git checkout release git pull echo "Building Docker image..." - docker build -t users-service . + docker build -t ${{ github.event.repository.name }} . echo "Creating .env file..." - echo "DATASOURCE_URL=${{ secrets.QA_DATASOURCE_URL }}" >> .env + echo "DATASOURCE_URL=${{ secrets.QA_DATASOURCE_URL }}/${{ secrets.DB_NAME }}" >> .env echo "DATASOURCE_USERNAME=${{ secrets.QA_DATASOURCE_USERNAME }}" >> .env echo "DATASOURCE_PASSWORD=${{ secrets.QA_DATASOURCE_PASSWORD }}" >> .env echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env @@ -63,7 +63,7 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env - docker rm -f users-service - docker run --name users-service --network all_connected -d -p 8080:8080 --env-file .env users-service + docker rm -f ${{ github.event.repository.name }} + docker run --name ${{ github.event.repository.name }} --network all_connected -d -p 8080:8080 --env-file .env ${{ github.event.repository.name }} echo "Docker container running..." rm .env \ No newline at end of file From ccb88677c42486400f89927569310eb9d37d471b Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 1 Oct 2024 10:13:04 -0500 Subject: [PATCH 59/99] =?UTF-8?q?=F0=9F=92=9A=20add=20service=20port=20sec?= =?UTF-8?q?ret?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dev.yml | 2 +- .github/workflows/deploy-qa.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 7c002b0..f700652 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -64,6 +64,6 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env docker rm -f ${{ github.event.repository.name }} - docker run --name ${{ github.event.repository.name }} --network all_connected -d -p 8080:8080 --env-file .env ${{ github.event.repository.name }} + docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }} echo "Docker container running..." rm .env diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 5f1d583..fd3f424 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -64,6 +64,6 @@ jobs: echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env docker rm -f ${{ github.event.repository.name }} - docker run --name ${{ github.event.repository.name }} --network all_connected -d -p 8080:8080 --env-file .env ${{ github.event.repository.name }} + docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }} echo "Docker container running..." rm .env \ No newline at end of file From 170d47a9fabca8f3c29e756110557cf2d45d8882 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 1 Oct 2024 10:33:22 -0500 Subject: [PATCH 60/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20qa=20group?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-qa.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index fd3f424..afab2ea 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -40,9 +40,9 @@ jobs: - name: executing remote ssh commands using ssh key uses: appleboy/ssh-action@master with: - host: ${{ secrets.QA_HOST }} + host: ${{ secrets.QA_G1_HOST }} username: ${{ secrets.HOSTS_USERNAME }} - key: ${{ secrets.QA_SSH_KEY }} + key: ${{ secrets.QA_G1_SSH_KEY }} port: ${{ secrets.SSH_PORT }} script: | cd AllConnected/${{ github.event.repository.name }} @@ -53,9 +53,9 @@ jobs: echo "Building Docker image..." docker build -t ${{ github.event.repository.name }} . echo "Creating .env file..." - echo "DATASOURCE_URL=${{ secrets.QA_DATASOURCE_URL }}/${{ secrets.DB_NAME }}" >> .env - echo "DATASOURCE_USERNAME=${{ secrets.QA_DATASOURCE_USERNAME }}" >> .env - echo "DATASOURCE_PASSWORD=${{ secrets.QA_DATASOURCE_PASSWORD }}" >> .env + echo "DATASOURCE_URL=${{ secrets.QA_G1_DATASOURCE_URL }}/${{ secrets.DB_NAME }}" >> .env + echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env + echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" >> .env From 69124e312552f8f46c7154bd5ffef7138025b574 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 1 Oct 2024 23:01:44 -0500 Subject: [PATCH 61/99] =?UTF-8?q?=F0=9F=92=9A=20fix=20secret=20variable=20?= =?UTF-8?q?name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-qa.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index afab2ea..716f605 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -53,7 +53,7 @@ jobs: echo "Building Docker image..." docker build -t ${{ github.event.repository.name }} . echo "Creating .env file..." - echo "DATASOURCE_URL=${{ secrets.QA_G1_DATASOURCE_URL }}/${{ secrets.DB_NAME }}" >> .env + echo "DATASOURCE_URL=${{ secrets.QA_DATASOURCE_G1_URL }}/${{ secrets.DB_NAME }}" >> .env echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env From 3a979381984624a8d088cefa09c8b266cf279afb Mon Sep 17 00:00:00 2001 From: Diego Pardo Montero Date: Sat, 5 Oct 2024 18:52:43 -0500 Subject: [PATCH 62/99] :sparkles: Add config server configuration --- pom.xml | 8 ++++++++ src/main/resources/application.yml | 24 +++--------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index 9e8d8b5..257104b 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,14 @@ lombok true + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-config + org.springframework.boot spring-boot-starter-test diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5a582e5..eef593a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,26 +1,8 @@ - spring: application: name: users-service - datasource: - url: ${DATASOURCE_URL} - username: ${DATASOURCE_USERNAME} - password: ${DATASOURCE_PASSWORD} - driver-class-name: org.postgresql.Driver -eureka: - client: - enabled: false + + config: + import: configserver:http://10.43.101.114:8888 -firebase: - type: ${GOOGLE_ADMIN_CONFIG_TYPE} - project-id: ${GOOGLE_ADMIN_CONFIG_PROJECT_ID} - private-key: ${GOOGLE_ADMIN_CONFIG_PRIVATE_KEY} - private-key-id: ${GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID} - client-email: ${GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL} - client-id: ${GOOGLE_ADMIN_CONFIG_CLIENT_ID} - auth-uri: https://accounts.google.com/o/oauth2/auth - token-uri: https://oauth2.googleapis.com/token - auth-provider-x509-cert-url: https://www.googleapis.com/oauth2/v1/certs - client-x509-cert-url: ${GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL} - universe-domain: googleapis.com From f62f92424463e0ba9619e587d319c7f522c53033 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 20:44:52 -0500 Subject: [PATCH 63/99] :sparkles: add profile config --- .github/workflows/deploy-dev.yml | 38 ++---------------------------- src/main/resources/application.yml | 7 +++--- 2 files changed, 6 insertions(+), 39 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index f700652..144b540 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -6,32 +6,6 @@ on: branches: ["develop"] workflow_dispatch: jobs: - Build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install Maven - run: sudo apt-get install -y maven - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: "21" - distribution: "temurin" - cache: maven - - name: Build with Maven - env: - DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} - DATASOURCE_URL: ${{ secrets.NEON_DATASOURCE_URL }}/${{ secrets.DB_NAME }} - DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} - GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} - GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} - GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} - GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} - GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} - run: mvn clean install - deploy: name: Deploy on Develop runs-on: self-hosted @@ -53,16 +27,8 @@ jobs: echo "Building Docker image..." docker build -t ${{ github.event.repository.name }} . echo "Creating .env file..." - echo "DATASOURCE_URL=${{ secrets.DEV_DATASOURCE_URL }}/${{ secrets.DB_NAME }}" >> .env - echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env - echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env + echo "PROFILE=dev" >> .env + echo "CONFIG_IP=10.43.101.114" >> .env docker rm -f ${{ github.event.repository.name }} docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }} echo "Docker container running..." diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index eef593a..694c9ec 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,8 +1,9 @@ spring: application: name: users-service - - config: - import: configserver:http://10.43.101.114:8888 + config: + import: configserver:http://${CONFIG_IP}:8888 + profiles: + active: ${PROFILE:dev} \ No newline at end of file From 5953ee1e36fb044fdc03c8dd39fbf7384e06fbf2 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 20:47:02 -0500 Subject: [PATCH 64/99] :bug: fix dev deploy script --- .github/workflows/deploy-dev.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 144b540..97d52de 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -9,7 +9,6 @@ jobs: deploy: name: Deploy on Develop runs-on: self-hosted - needs: Build steps: - name: executing remote ssh commands using ssh key uses: appleboy/ssh-action@master From a2229f6637f2f8a737be9dbcce97bfddf2b98414 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 20:52:29 -0500 Subject: [PATCH 65/99] :bug: fix config profile --- src/main/resources/application.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 694c9ec..1f5b720 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,9 +1,8 @@ spring: application: name: users-service - - config: - import: configserver:http://${CONFIG_IP}:8888 - - profiles: - active: ${PROFILE:dev} \ No newline at end of file + cloud: + config: + uri: configserver:http://${CONFIG_IP}:8888 + profile: ${PROFILE:dev} + \ No newline at end of file From 103f0853823c6e31789b24f3db2eacbbe63e60b7 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 20:55:58 -0500 Subject: [PATCH 66/99] :bug: fix config profile --- src/main/resources/application.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 1f5b720..5dce849 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,8 +1,7 @@ spring: application: name: users-service - cloud: - config: - uri: configserver:http://${CONFIG_IP}:8888 - profile: ${PROFILE:dev} - \ No newline at end of file + config: + import: configserver:http://${CONFIG_IP}:8888 + profiles: + active: ${PROFILE:dev} \ No newline at end of file From 7f681263745f27ac3619e070934295f3cb3063f3 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 22:04:33 -0500 Subject: [PATCH 67/99] :construction_worker: fix deploy qa script --- .github/workflows/deploy-qa.yml | 57 +++++++-------------------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 716f605..61e95a8 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -1,69 +1,34 @@ -name: Deploy QA +name: Deploy Develop on: push: - branches: ["release"] + branches: ["develop"] pull_request: - branches: ["release"] + branches: ["develop"] workflow_dispatch: jobs: - Build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Install Maven - run: sudo apt-get install -y maven - - name: Set up JDK 21 - uses: actions/setup-java@v4 - with: - java-version: "21" - distribution: "temurin" - cache: maven - - name: Build with Maven - env: - DATASOURCE_PASSWORD: ${{ secrets.DATASOURCE_PASSWORD }} - DATASOURCE_URL: ${{ secrets.NEON_DATASOURCE_URL }}/${{ secrets.DB_NAME }} - DATASOURCE_USERNAME: ${{ secrets.DATASOURCE_USERNAME }} - GOOGLE_ADMIN_CONFIG_TYPE: ${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }} - GOOGLE_ADMIN_CONFIG_PROJECT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }} - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }} - GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }} - GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }} - GOOGLE_ADMIN_CONFIG_CLIENT_ID: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }} - GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL: ${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }} - run: mvn clean install - - Deploy: - name: Deploy on QA + deploy: + name: Deploy on Develop runs-on: self-hosted - needs: Build steps: - name: executing remote ssh commands using ssh key uses: appleboy/ssh-action@master with: - host: ${{ secrets.QA_G1_HOST }} + host: ${{ secrets.DEV_HOST }} username: ${{ secrets.HOSTS_USERNAME }} - key: ${{ secrets.QA_G1_SSH_KEY }} + key: ${{ secrets.DEV_SSH_KEY }} port: ${{ secrets.SSH_PORT }} script: | cd AllConnected/${{ github.event.repository.name }} echo "Fetching latest code..." git fetch - git checkout release + git checkout develop git pull echo "Building Docker image..." docker build -t ${{ github.event.repository.name }} . echo "Creating .env file..." - echo "DATASOURCE_URL=${{ secrets.QA_DATASOURCE_G1_URL }}/${{ secrets.DB_NAME }}" >> .env - echo "DATASOURCE_USERNAME=${{ secrets.DATASOURCE_USERNAME }}" >> .env - echo "DATASOURCE_PASSWORD=${{ secrets.DATASOURCE_PASSWORD }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_TYPE=${{ secrets.GOOGLE_ADMIN_CONFIG_TYPE }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_PROJECT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PROJECT_ID }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_PRIVATE_KEY_ID }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_EMAIL }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_CLIENT_ID=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_ID }}" >> .env - echo "GOOGLE_ADMIN_CONFIG_X509_CERT_URL=${{ secrets.GOOGLE_ADMIN_CONFIG_CLIENT_X509_CERT_URL }}" >> .env + echo "PROFILE=qa1" >> .env + echo "CONFIG_IP=10.43.100.223" >> .env docker rm -f ${{ github.event.repository.name }} docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }} echo "Docker container running..." - rm .env \ No newline at end of file + rm .env From a158a9efedc9bdd1437a03030aa5a74a1c573364 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 22:48:31 -0500 Subject: [PATCH 68/99] :wrench: add default config --- src/main/resources/application.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5dce849..965c9f9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -2,6 +2,6 @@ spring: application: name: users-service config: - import: configserver:http://${CONFIG_IP}:8888 + import: configserver:http://${CONFIG_IP:localhost}:8888 profiles: - active: ${PROFILE:dev} \ No newline at end of file + active: ${PROFILE:keveldev} \ No newline at end of file From 413144bc5e1aae099802790f050f9fd2c0d5f1cb Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 22:54:01 -0500 Subject: [PATCH 69/99] :bug: fix qa deploy script --- .github/workflows/deploy-qa.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 61e95a8..81941bd 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -1,27 +1,27 @@ -name: Deploy Develop +name: Deploy QA on: push: - branches: ["develop"] + branches: ["release"] pull_request: - branches: ["develop"] + branches: ["release"] workflow_dispatch: jobs: deploy: - name: Deploy on Develop + name: Deploy on QA runs-on: self-hosted steps: - name: executing remote ssh commands using ssh key uses: appleboy/ssh-action@master with: - host: ${{ secrets.DEV_HOST }} + host: ${{ secrets.QA_G1_HOST }} username: ${{ secrets.HOSTS_USERNAME }} - key: ${{ secrets.DEV_SSH_KEY }} + key: ${{ secrets.QA_G1_SSH_KEY }} port: ${{ secrets.SSH_PORT }} script: | cd AllConnected/${{ github.event.repository.name }} echo "Fetching latest code..." git fetch - git checkout develop + git checkout release git pull echo "Building Docker image..." docker build -t ${{ github.event.repository.name }} . From aa02a55f1aafe2d9af9cfb2a30400be16292cc24 Mon Sep 17 00:00:00 2001 From: Diego Pardo Montero <78668255+DiegoPardoMontero@users.noreply.github.com> Date: Sat, 5 Oct 2024 23:26:33 -0500 Subject: [PATCH 70/99] :heavy_plus_sign: Update pom.xml --- pom.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 257104b..2873cd8 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,14 @@ org.springframework.cloud spring-cloud-starter-netflix-eureka-client - + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-config + org.springframework.boot spring-boot-devtools From 8f3977fd6de2408af4e95dfe77714bdccf96a03b Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 23:46:16 -0500 Subject: [PATCH 71/99] =?UTF-8?q?=F0=9F=91=B7=20add=20build=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b75d3dd --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +name: Build Project +on: + push: + branches: [ "main", "develop", "release" ] + pull_request: + branches: [ "main", "develop", "release" ] + +jobs: + Build: + runs-on: self-hosted + steps: + - uses: actions/checkout@v4 + - name: Install Maven + run: apt-get install -y maven + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn clean install From f59e7ce9c18612cb4ffca59d344fb4de14357ec3 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 23:51:20 -0500 Subject: [PATCH 72/99] :fire: fix actions script --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b75d3dd..ba873cb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,13 +10,13 @@ jobs: runs-on: self-hosted steps: - uses: actions/checkout@v4 - - name: Install Maven - run: apt-get install -y maven + - name: Set up JDK 21 uses: actions/setup-java@v4 with: java-version: '21' distribution: 'temurin' cache: maven + - name: Build with Maven run: mvn clean install From 83bd8eaf4c26fcb9630ff737961ef6a048660638 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sat, 5 Oct 2024 23:58:12 -0500 Subject: [PATCH 73/99] :bug: fix actions script --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba873cb..0ebcece 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,4 +19,6 @@ jobs: cache: maven - name: Build with Maven + env: + CONFIG_IP: ${{ secrets.DEV_INTEG_HOST }} run: mvn clean install From b111ddb18d5fb13f4844dc30df8f59cfc4597f3f Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 6 Oct 2024 00:12:27 -0500 Subject: [PATCH 74/99] :rocket: add deployment script configurations --- .github/workflows/deploy-dev.yml | 10 ++++++---- .github/workflows/deploy-qa.yml | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index 97d52de..8a79107 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -1,13 +1,15 @@ name: Deploy Develop on: - push: - branches: ["develop"] pull_request: - branches: ["develop"] + branches: + - develop + types: + - closed workflow_dispatch: jobs: - deploy: + Deploy: name: Deploy on Develop + if: ${{ github.event.pull_request.merged == true }} runs-on: self-hosted steps: - name: executing remote ssh commands using ssh key diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 81941bd..12b532f 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -1,13 +1,15 @@ name: Deploy QA on: - push: - branches: ["release"] pull_request: - branches: ["release"] + branches: + - release + types: + - closed workflow_dispatch: jobs: - deploy: + Deploy: name: Deploy on QA + if: ${{ github.event.pull_request.merged == true }} runs-on: self-hosted steps: - name: executing remote ssh commands using ssh key From 2b46c3eada8c29f2e9f83bdf2b2bd6352ccd5562 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 6 Oct 2024 00:15:19 -0500 Subject: [PATCH 75/99] =?UTF-8?q?=F0=9F=A7=AA=20test=20actions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ebcece..63d25c8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,7 @@ on: branches: [ "main", "develop", "release" ] jobs: - Build: + Build: runs-on: self-hosted steps: - uses: actions/checkout@v4 From c2b1f086c7e076695b092c0efa3b74c59c95b4a9 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 6 Oct 2024 00:21:41 -0500 Subject: [PATCH 76/99] :bug: fix actions trigger --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 63d25c8..f3f71d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,5 @@ name: Build Project on: - push: - branches: [ "main", "develop", "release" ] pull_request: branches: [ "main", "develop", "release" ] From c1d10ff732db97162d74ff4a4b73391a015f2e46 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 6 Oct 2024 09:00:01 -0500 Subject: [PATCH 77/99] =?UTF-8?q?=F0=9F=A7=AA=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3f71d9..868293e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: branches: [ "main", "develop", "release" ] jobs: - Build: + Build: runs-on: self-hosted steps: - uses: actions/checkout@v4 From 14bf5749aa7b694961008297d607be5d8ca1f759 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 6 Oct 2024 09:00:43 -0500 Subject: [PATCH 78/99] =?UTF-8?q?=F0=9F=A7=AA=20test=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 868293e..f3f71d9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: branches: [ "main", "develop", "release" ] jobs: - Build: + Build: runs-on: self-hosted steps: - uses: actions/checkout@v4 From 582fe10ecd2c4553818b896932fa89bc9c8d77a7 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 6 Oct 2024 09:01:04 -0500 Subject: [PATCH 79/99] =?UTF-8?q?=F0=9F=A7=AA=20test=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f3f71d9..868293e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: branches: [ "main", "develop", "release" ] jobs: - Build: + Build: runs-on: self-hosted steps: - uses: actions/checkout@v4 From 89a9ddab3e1588d03188e5240af21c82ae16c0e5 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 6 Oct 2024 14:25:27 -0500 Subject: [PATCH 80/99] :recycle: change trigger build --- .github/workflows/build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 868293e..f6917b1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,8 @@ name: Build Project on: pull_request: branches: [ "main", "develop", "release" ] - + push: + branches: [ "main", "develop", "release" ] jobs: Build: runs-on: self-hosted From 25fa0667644d893e786ba1bcde1ad4930e94e5de Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 6 Oct 2024 14:33:50 -0500 Subject: [PATCH 81/99] :recycle: change trigger build --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f6917b1..868293e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,8 +2,7 @@ name: Build Project on: pull_request: branches: [ "main", "develop", "release" ] - push: - branches: [ "main", "develop", "release" ] + jobs: Build: runs-on: self-hosted From e0beef4d294e8951cc7993d359ecd922aaf3939c Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 6 Oct 2024 19:11:50 -0500 Subject: [PATCH 82/99] :recycle: change return of get all users when empty --- .../fussiontech/usersservice/controllers/UsersController.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 23ea977..542f279 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -54,8 +54,6 @@ public ResponseEntity getUsers( ) { try { UserDTO[] listUsersDTO = userService.getUsers(fullname, username, mail, rol, active); - if (listUsersDTO.length == 0) - return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new Response(HttpStatus.NOT_FOUND.value(), "No users found")); return ResponseEntity.status(HttpStatus.OK).body(listUsersDTO); } catch (OperationException e) { return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); From 3007305ad34f767abd7b0606665899fa5004414a Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 8 Oct 2024 15:23:39 -0500 Subject: [PATCH 83/99] :lock: update cors config --- .../allconnected/fussiontech/usersservice/config/WebConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java index 3473bc3..87ba1b8 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java @@ -13,6 +13,7 @@ public void addCorsMappings(CorsRegistry registry) { .allowedOriginPatterns("*") .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") .allowedHeaders("*") + .exposedHeaders("Content-Type", "Authorization") .allowCredentials(true); } } From 79294e6e7711539647239d5b34e90fb27034258f Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 8 Oct 2024 15:52:06 -0500 Subject: [PATCH 84/99] :lock: update cors --- .../fussiontech/usersservice/config/WebConfig.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java index 87ba1b8..fe15db3 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java @@ -12,8 +12,9 @@ public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOriginPatterns("*") .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") - .allowedHeaders("*") - .exposedHeaders("Content-Type", "Authorization") + .allowedHeaders("Content-Type", "Authorization", "Accept", "X-Requested-With", "Access-Control-Allow-Headers", "Origin", "multipart/form-data") // Asegúrate de permitir 'multipart/form-data' + .exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials") .allowCredentials(true); } + } From 55926af21033236de4e0e4556c9ebdd3351f3c3e Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 8 Oct 2024 15:57:57 -0500 Subject: [PATCH 85/99] :lock: update cors config --- .../usersservice/config/WebConfig.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java index fe15db3..04c32d5 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java @@ -1,6 +1,10 @@ package co.allconnected.fussiontech.usersservice.config; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -17,4 +21,20 @@ public void addCorsMappings(CorsRegistry registry) { .allowCredentials(true); } + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + CorsConfiguration config = new CorsConfiguration(); + config.setAllowCredentials(true); + config.addAllowedOriginPattern("*"); + config.addAllowedHeader("*"); + config.addAllowedMethod("OPTIONS"); + config.addAllowedMethod("GET"); + config.addAllowedMethod("POST"); + config.addAllowedMethod("PUT"); + config.addAllowedMethod("DELETE"); + config.setMaxAge(3600L); + source.registerCorsConfiguration("/**", config); + return new CorsFilter(source); + } } From 8e76ee48a326c19cd0e0b6312f41fc5eb1a695cc Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 8 Oct 2024 16:08:15 -0500 Subject: [PATCH 86/99] :lock: update cors config --- .../usersservice/config/WebConfig.java | 17 ----------------- .../controllers/UsersController.java | 1 + 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java index 04c32d5..ed5012d 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java @@ -20,21 +20,4 @@ public void addCorsMappings(CorsRegistry registry) { .exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials") .allowCredentials(true); } - - @Bean - public CorsFilter corsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - config.addAllowedOriginPattern("*"); - config.addAllowedHeader("*"); - config.addAllowedMethod("OPTIONS"); - config.addAllowedMethod("GET"); - config.addAllowedMethod("POST"); - config.addAllowedMethod("PUT"); - config.addAllowedMethod("DELETE"); - config.setMaxAge(3600L); - source.registerCorsConfiguration("/**", config); - return new CorsFilter(source); - } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 542f279..4ea184e 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -71,6 +71,7 @@ public ResponseEntity getUser(@PathVariable String id) { } } + @CrossOrigin @PutMapping("/{id}") public ResponseEntity updateUser( @PathVariable String id, From 360ec1626375256130c348133711486b5064b4d2 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 13 Oct 2024 16:46:21 -0500 Subject: [PATCH 87/99] :lock: update cors config --- .../fussiontech/usersservice/config/WebConfig.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java index ed5012d..711cb71 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java @@ -1,10 +1,6 @@ package co.allconnected.fussiontech.usersservice.config; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; -import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -16,8 +12,7 @@ public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOriginPatterns("*") .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") - .allowedHeaders("Content-Type", "Authorization", "Accept", "X-Requested-With", "Access-Control-Allow-Headers", "Origin", "multipart/form-data") // Asegúrate de permitir 'multipart/form-data' - .exposedHeaders("Access-Control-Allow-Origin", "Access-Control-Allow-Credentials") + .allowedHeaders("*") .allowCredentials(true); } -} +} \ No newline at end of file From ccf83173e015cb94a38ea538e4445b70c25d342a Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Sun, 13 Oct 2024 17:22:04 -0500 Subject: [PATCH 88/99] :fire: delete cors config --- .../usersservice/config/WebConfig.java | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java b/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java deleted file mode 100644 index 711cb71..0000000 --- a/src/main/java/co/allconnected/fussiontech/usersservice/config/WebConfig.java +++ /dev/null @@ -1,18 +0,0 @@ -package co.allconnected.fussiontech.usersservice.config; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.CorsRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; - -@Configuration -public class WebConfig implements WebMvcConfigurer { - - @Override - public void addCorsMappings(CorsRegistry registry) { - registry.addMapping("/**") - .allowedOriginPatterns("*") - .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") - .allowedHeaders("*") - .allowCredentials(true); - } -} \ No newline at end of file From b4587354913265729d0446143f9aad353b03fd39 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 14 Oct 2024 15:13:04 -0500 Subject: [PATCH 89/99] :fire: remove cors config from controller --- .../usersservice/controllers/UsersController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 4ea184e..de14c94 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -71,15 +71,17 @@ public ResponseEntity getUser(@PathVariable String id) { } } - @CrossOrigin @PutMapping("/{id}") public ResponseEntity updateUser( @PathVariable String id, @ModelAttribute UserCreateDTO user, @RequestParam(value = "photo", required = false) MultipartFile photo) { try { + System.out.println("Actualizando usuario"); UserDTO userDTO = userService.updateUser(id, user, photo); - return ResponseEntity.status(HttpStatus.OK).body(userDTO); + ResponseEntity response = ResponseEntity.status(HttpStatus.OK).body(userDTO); + System.out.println(response.getHeaders()); + return response; } catch (OperationException e) { return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); } catch (RuntimeException e) { From 7b03a89c5b4d8085ffac24daf79462e3bb6b9e3f Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 21 Oct 2024 15:13:27 -0500 Subject: [PATCH 90/99] =?UTF-8?q?=F0=9F=9A=A7=20add=20user=20claims=20when?= =?UTF-8?q?=20created?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit not tested --- .../usersservice/services/FirebaseService.java | 10 ++++++++-- .../fussiontech/usersservice/services/UserService.java | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index 8fc842f..c30a389 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -10,6 +10,8 @@ import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; @Service public class FirebaseService { @@ -27,12 +29,16 @@ public void deleteImg(String imageName) { bucket.get("user_photos/"+imageName).delete(); } - public String createUser(String email, String password) throws FirebaseAuthException { + public String createUser(String email, String password, String[] roles) throws FirebaseAuthException { UserRecord.CreateRequest request = new UserRecord.CreateRequest() .setEmail(email) .setPassword(password); - + Map claims = new HashMap<>(); + for(String rol : roles) { + claims.put(rol, true); + } UserRecord userRecord = FirebaseAuth.getInstance().createUser(request); + FirebaseAuth.getInstance().setCustomUserClaims(userRecord.getUid(), claims); return userRecord.getUid(); } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index d334136..8a5da1f 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -41,7 +41,7 @@ public UserDTO createUser(UserCreateDTO userDto, MultipartFile photo) { // Create user in firebase try { - user.setIdUser(firebaseService.createUser(userDto.mail(), userDto.password())); + user.setIdUser(firebaseService.createUser(userDto.mail(), userDto.password(), userDto.roles())); } catch (FirebaseAuthException e) { throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); } From 1e85cc9da826670b4b6c449fa4e4c0265fbd35af Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 22 Oct 2024 08:14:55 -0500 Subject: [PATCH 91/99] :sparkles: firebase custom claims management --- .../services/FirebaseService.java | 13 ++++++-- .../usersservice/services/UserService.java | 30 +++++++++++++++++-- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index c30a389..43dc2ad 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.InputStream; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -33,10 +34,12 @@ public String createUser(String email, String password, String[] roles) throws F UserRecord.CreateRequest request = new UserRecord.CreateRequest() .setEmail(email) .setPassword(password); + + // Add custom claims Map claims = new HashMap<>(); - for(String rol : roles) { - claims.put(rol, true); - } + Arrays.stream(roles).forEach(role -> claims.put(role, true)); + + // Create user and set custom claims UserRecord userRecord = FirebaseAuth.getInstance().createUser(request); FirebaseAuth.getInstance().setCustomUserClaims(userRecord.getUid(), claims); return userRecord.getUid(); @@ -60,4 +63,8 @@ public void updateUser(String uid, String email, String password) throws Firebas request.setPassword(password); FirebaseAuth.getInstance().updateUser(request); } + + public void updateCustomClaims(String uid, Map claims) throws FirebaseAuthException { + FirebaseAuth.getInstance().setCustomUserClaims(uid, claims); + } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 8a5da1f..0271f95 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -17,8 +17,10 @@ import org.springframework.web.multipart.MultipartFile; import java.io.IOException; +import java.util.Map; import java.util.Optional; import java.util.UUID; +import java.util.stream.Collectors; @Service public class UserService { @@ -165,13 +167,35 @@ public UserDTO addRoles(String id, String[] roles) { Rol rolEntity = rolService.getRol(rol).orElseThrow(); user.getRoles().add(rolEntity); } + + // Update custom claims in firebase + Map claims = user.getRoles().stream() + .collect(Collectors.toMap(Rol::getIdRol, rol -> true)); + + try { + firebaseService.updateCustomClaims(user.getIdUser(), claims); + } catch (FirebaseAuthException e) { + throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); + } + return new UserDTO(userRepository.save(user)); } - public UserDTO removeRoles(String id, String rol) { + public UserDTO removeRoles(String id, String role) { User user = userRepository.findById(id).orElseThrow(() -> new OperationException(404, "User not found")); - Rol rolEntity = rolService.getRol(rol).orElseThrow(() -> new OperationException(404, "Rol not found")); + Rol rolEntity = rolService.getRol(role).orElseThrow(() -> new OperationException(404, "Rol not found")); user.getRoles().remove(rolEntity); - return new UserDTO(userRepository.save(user)); + user = userRepository.save(user); + + // Update custom claims in firebase + Map claims = user.getRoles().stream() + .collect(Collectors.toMap(Rol::getIdRol, rol -> true)); + try { + firebaseService.updateCustomClaims(user.getIdUser(), claims); + } catch (FirebaseAuthException e) { + throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); + } + + return new UserDTO(user); } } \ No newline at end of file From da24aa3cb66b11e55ab34b63c99d5d161759ec04 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 22 Oct 2024 11:44:41 -0500 Subject: [PATCH 92/99] :recycle: firebase custom claims refactor --- .../usersservice/services/FirebaseService.java | 9 +++++---- .../usersservice/services/UserService.java | 13 ++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index 43dc2ad..25916a7 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -37,7 +37,7 @@ public String createUser(String email, String password, String[] roles) throws F // Add custom claims Map claims = new HashMap<>(); - Arrays.stream(roles).forEach(role -> claims.put(role, true)); + claims.put("roles", roles); // Create user and set custom claims UserRecord userRecord = FirebaseAuth.getInstance().createUser(request); @@ -64,7 +64,8 @@ public void updateUser(String uid, String email, String password) throws Firebas FirebaseAuth.getInstance().updateUser(request); } - public void updateCustomClaims(String uid, Map claims) throws FirebaseAuthException { - FirebaseAuth.getInstance().setCustomUserClaims(uid, claims); - } + public void updateCustomClaims(String uid, String[] roles) throws FirebaseAuthException { + Map claims = new HashMap<>(); + claims.put("roles", roles); + FirebaseAuth.getInstance().setCustomUserClaims(uid, claims); } } diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 0271f95..9b31399 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -169,11 +169,8 @@ public UserDTO addRoles(String id, String[] roles) { } // Update custom claims in firebase - Map claims = user.getRoles().stream() - .collect(Collectors.toMap(Rol::getIdRol, rol -> true)); - try { - firebaseService.updateCustomClaims(user.getIdUser(), claims); + firebaseService.updateCustomClaims(user.getIdUser(), roles); } catch (FirebaseAuthException e) { throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); } @@ -188,10 +185,12 @@ public UserDTO removeRoles(String id, String role) { user = userRepository.save(user); // Update custom claims in firebase - Map claims = user.getRoles().stream() - .collect(Collectors.toMap(Rol::getIdRol, rol -> true)); + String[] roles = user.getRoles().stream() + .map(Rol::getIdRol) + .toArray(String[]::new); + try { - firebaseService.updateCustomClaims(user.getIdUser(), claims); + firebaseService.updateCustomClaims(user.getIdUser(), roles); } catch (FirebaseAuthException e) { throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); } From 8f6854d2ce647ebdc3f6b849189d2b0fcb5e5add Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Wed, 30 Oct 2024 22:56:33 -0500 Subject: [PATCH 93/99] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20fix=20firebase=20?= =?UTF-8?q?user=20creation=20repetition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usersservice/controllers/UsersController.java | 2 +- .../fussiontech/usersservice/model/User.java | 10 ++++++++++ .../usersservice/services/UserService.java | 12 ++---------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index de14c94..8b1c6e4 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -22,7 +22,7 @@ public UsersController(UserService userService) { @PostMapping public ResponseEntity createUser( - @ModelAttribute UserCreateDTO user, + @ModelAttribute UserDTO user, @RequestParam(value = "photo", required = false) MultipartFile photo) { try { UserDTO userDTO = userService.createUser(user, photo); diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java index 1ce04fb..7e79832 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/model/User.java @@ -1,6 +1,7 @@ package co.allconnected.fussiontech.usersservice.model; import co.allconnected.fussiontech.usersservice.dtos.UserCreateDTO; +import co.allconnected.fussiontech.usersservice.dtos.UserDTO; import jakarta.persistence.*; import lombok.Getter; import lombok.NoArgsConstructor; @@ -23,6 +24,15 @@ public User(UserCreateDTO dto){ this.active = true; } + public User(UserDTO dto){ + this.idUser = dto.getId_user(); + this.fullname = dto.getFullname(); + this.username = dto.getUsername(); + this.mail = dto.getMail(); + this.photoUrl = dto.getMail(); + this.active = true; + } + @Id @Column(name = "id_user", nullable = false, length = 28) private String idUser; diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 9b31399..ca94169 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -38,18 +38,10 @@ public UserService(UserRepository userRepository, DeletedRepository deletedRepos this.deletedRepository = deletedRepository; } - public UserDTO createUser(UserCreateDTO userDto, MultipartFile photo) { + public UserDTO createUser(UserDTO userDto, MultipartFile photo) { User user = new User(userDto); - - // Create user in firebase - try { - user.setIdUser(firebaseService.createUser(userDto.mail(), userDto.password(), userDto.roles())); - } catch (FirebaseAuthException e) { - throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); - } - // Add roles to user - for (String rol : userDto.roles()) { + for (String rol : userDto.getRoles()) { Optional rolEntity = rolService.getRol(rol); if(rolEntity.isEmpty()) throw new OperationException(404, "Rol not found"); user.getRoles().add(rolEntity.get()); From 48d8195821ef2cdd49e7fa1403db24d03d0aafa1 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Wed, 30 Oct 2024 23:06:36 -0500 Subject: [PATCH 94/99] :sparkles: add method to create users from admin --- .../controllers/UsersController.java | 14 +++++++++ .../usersservice/services/UserService.java | 30 +++++++++++++++++++ src/main/resources/application.yml | 5 +++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 8b1c6e4..0322eb2 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -34,6 +34,20 @@ public ResponseEntity createUser( } } + @PostMapping("/from-admin") + public ResponseEntity createUserFromAdmin( + @ModelAttribute UserCreateDTO user, + @RequestParam(value = "photo", required = false) MultipartFile photo) { + try { + UserDTO userDTO = userService.createUserFromAdmin(user, photo); + return ResponseEntity.status(HttpStatus.CREATED).body(userDTO); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); + } catch (RuntimeException e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new Response(HttpStatus.INTERNAL_SERVER_ERROR.value(), e.getMessage())); + } + } + @PostMapping("/guest") public ResponseEntity createGuestUser() { try { diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index ca94169..40a7c79 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -60,6 +60,36 @@ public UserDTO createUser(UserDTO userDto, MultipartFile photo) { return new UserDTO(userRepository.save(user)); } + public UserDTO createUserFromAdmin(UserCreateDTO userDto, MultipartFile photo) { + User user = new User(userDto); + + // Create user in firebase + try { + user.setIdUser(firebaseService.createUser(userDto.mail(), userDto.password(), userDto.roles())); + } catch (FirebaseAuthException e) { + throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); + } + + // Add roles to user + for (String rol : userDto.roles()) { + Optional rolEntity = rolService.getRol(rol); + if(rolEntity.isEmpty()) throw new OperationException(404, "Rol not found"); + user.getRoles().add(rolEntity.get()); + } + + // Upload photo to firebase + if (photo != null) { + String photoName = user.getIdUser(); + String extension = FilenameUtils.getExtension(photo.getOriginalFilename()); + try{ + user.setPhotoUrl(firebaseService.uploadImg(photoName, extension, photo)); + } catch (IOException e) { + throw new OperationException(500, "Error uploading photo: " + e.getMessage()); + } + } + return new UserDTO(userRepository.save(user)); + } + public UserDTO createGuestUser(){ User user = new User(); user.setIdUser(UUID.randomUUID().toString().replace("-", "").substring(0, 28)); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 965c9f9..65f60df 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -4,4 +4,7 @@ spring: config: import: configserver:http://${CONFIG_IP:localhost}:8888 profiles: - active: ${PROFILE:keveldev} \ No newline at end of file + active: ${PROFILE:keveldev} + +server: + port: 8081 \ No newline at end of file From 9573c43ac2aa1b1e60c512c5d28127b9ebe42ee0 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Wed, 30 Oct 2024 23:07:48 -0500 Subject: [PATCH 95/99] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20fix=20ports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/application.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 65f60df..4884193 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -5,6 +5,3 @@ spring: import: configserver:http://${CONFIG_IP:localhost}:8888 profiles: active: ${PROFILE:keveldev} - -server: - port: 8081 \ No newline at end of file From f65a577f4cad4f5852529b76029579f7e92270eb Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 4 Nov 2024 14:25:20 -0500 Subject: [PATCH 96/99] :fire: delete unused atribute --- .../co/allconnected/fussiontech/usersservice/dtos/UserDTO.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java index b618d13..2757db0 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/dtos/UserDTO.java @@ -16,7 +16,6 @@ public class UserDTO { private String mail; private String photo_url; private String[] roles; - private String[] organizations; private boolean active; public UserDTO(User user){ @@ -26,7 +25,6 @@ public UserDTO(User user){ this.mail = user.getMail(); this.photo_url = user.getPhotoUrl(); this.roles = user.getRoles().stream().map(Rol::getIdRol).toArray(String[]::new); - // this.organizations = user.getOrganizations().stream().map(Organization::getIdOrganization).toArray(String[]::new); this.active = user.getActive(); } } From cf1cef19c0a5c6d56736f76fecab6e659cbe802a Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 4 Nov 2024 14:33:48 -0500 Subject: [PATCH 97/99] :sparkles: activate user --- .../usersservice/controllers/UsersController.java | 10 ++++++++++ .../usersservice/services/FirebaseService.java | 6 ++++++ .../usersservice/services/UserService.java | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java index 0322eb2..2ff4bfd 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/controllers/UsersController.java @@ -123,6 +123,16 @@ public ResponseEntity deactivateUser(@PathVariable String id, @RequestBody De } } + @PostMapping("/{id}/activate") + public ResponseEntity activateUser(@PathVariable String id) { + try { + UserDTO user = userService.activateUser(id); + return ResponseEntity.status(HttpStatus.OK).body(user); + } catch (OperationException e) { + return ResponseEntity.status(e.getCode()).body(new Response(e.getCode(), e.getMessage())); + } + } + @PostMapping("/{id}/roles") public ResponseEntity addRole(@PathVariable String id, @RequestBody RolesDTO roles) { try { diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java index 25916a7..23ff78e 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/FirebaseService.java @@ -55,6 +55,12 @@ public void disableUser(String uid) throws FirebaseAuthException { FirebaseAuth.getInstance().updateUser(request); } + public void enableUser(String uid) throws FirebaseAuthException { + UserRecord.UpdateRequest request = new UserRecord.UpdateRequest(uid) + .setDisabled(false); + FirebaseAuth.getInstance().updateUser(request); + } + public void updateUser(String uid, String email, String password) throws FirebaseAuthException { UserRecord.UpdateRequest request = new UserRecord.UpdateRequest(uid); if (email != null) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 40a7c79..30e96fd 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -137,6 +137,20 @@ public DeletedDTO deactivateUser(String id, String reason) { }).orElseThrow(() -> new OperationException(404, "User not found")); } + public UserDTO activateUser(String id){ + return userRepository.findById(id).map(user -> { + user.setActive(true); + user.setDeleted(null); + userRepository.save(user); + if (user.getRoles().stream().noneMatch(rol -> rol.getIdRol().equals("guest"))) try { + firebaseService.enableUser(user.getIdUser()); + } catch (FirebaseAuthException e) { + throw new OperationException(500, e.getMessage()); + } + return new UserDTO(user); + }).orElseThrow(() -> new OperationException(404, "User not found")); + } + public UserDTO[] getUsers(String fullname, String username, String mail, String rol, Boolean active) { return userRepository.findUsersByFilters(fullname, username, mail, rol, active).stream() .map(user -> user.getActive() ? new UserDTO(user) : new InactiveUserDTO(user)) From e5e3e1a6d2d02fe83e46290b4f04d6c27338cb70 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Tue, 5 Nov 2024 07:29:06 -0500 Subject: [PATCH 98/99] :ambulance: add custom claims when creating user --- .../fussiontech/usersservice/services/UserService.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java index 30e96fd..e6e686f 100644 --- a/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java +++ b/src/main/java/co/allconnected/fussiontech/usersservice/services/UserService.java @@ -47,6 +47,13 @@ public UserDTO createUser(UserDTO userDto, MultipartFile photo) { user.getRoles().add(rolEntity.get()); } + // Update claims + try{ + firebaseService.updateCustomClaims(user.getIdUser(), userDto.getRoles()); + } catch (FirebaseAuthException e) { + throw new OperationException(500, "Firebase authentication error: " + e.getMessage()); + } + // Upload photo to firebase if (photo != null) { String photoName = user.getIdUser(); From 9908308e36f022edbd39137125fd2f8f2362b0b0 Mon Sep 17 00:00:00 2001 From: Estebans441 Date: Mon, 18 Nov 2024 11:54:30 -0500 Subject: [PATCH 99/99] :rocket: add production deploy script --- .github/workflows/deploy-prod.yml | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/deploy-prod.yml diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml new file mode 100644 index 0000000..b292e56 --- /dev/null +++ b/.github/workflows/deploy-prod.yml @@ -0,0 +1,33 @@ +name: Deploy PROD +on: + push: + tags: + - '*' + workflow_dispatch: +jobs: + Deploy: + name: Deploy on PROD + runs-on: self-hosted + steps: + - name: executing remote ssh commands using ssh key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.PROD_G1_HOST }} + username: ${{ secrets.HOSTS_USERNAME }} + key: ${{ secrets.PROD_G1_SSH_KEY }} + port: ${{ secrets.SSH_PORT }} + script: | + cd AllConnected/${{ github.event.repository.name }} + echo "Fetching latest code..." + git fetch + git checkout main + git pull + echo "Building Docker image..." + docker build -t ${{ github.event.repository.name }} . + echo "Creating .env file..." + echo "PROFILE=prod1" >> .env + echo "CONFIG_IP=10.43.101.72" >> .env + docker rm -f ${{ github.event.repository.name }} + docker run --name ${{ github.event.repository.name }} --network all_connected -d -p ${{ secrets.SERVICE_PORT }}:8080 --env-file .env ${{ github.event.repository.name }} + echo "Docker container running..." + rm .env