Compare commits
2 Commits
41547d6034
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a46a1a379 | ||
|
|
ec342f77a6 |
@@ -1,36 +0,0 @@
|
||||
name: Build e Deploy
|
||||
run-name: Build & Deploy por ${{ gitea.actor }} 🚀
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main", "master" ]
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout do código
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configurar JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
cache: 'maven' # Esta linha ativa o cache automático das dependências do Maven
|
||||
|
||||
- name: Corrigir Instalador e Instalar Maven
|
||||
run: |
|
||||
sudo dpkg --configure -a
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y maven
|
||||
|
||||
- name: Build do JAR (Sem Testes)
|
||||
run: |
|
||||
# O -DskipTests ignora os testes e foca só em gerar o arquivo
|
||||
mvn clean install -DskipTests
|
||||
|
||||
- name: Chamar Webhook do Coolify
|
||||
run: |
|
||||
curl -X GET "https://coolify.stackpanel.com.br/api/v1/deploy?uuid=iwwcg08c04css0o444k08sgg&force=false" \
|
||||
-H "Authorization: Bearer 6|JDmqzDFYjZbHKGEt3jjMERvvMTKNsDjsugQQkZtg28e56c42"
|
||||
@@ -1,20 +1,20 @@
|
||||
package br.com.stackpanel.api.config;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
@Configuration
|
||||
public class RestClientConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public RestClient customRestClient(){
|
||||
return RestClient.builder()
|
||||
.baseUrl("https://coolify.stackpanel.com.br")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
package br.com.stackpanel.api.config;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
@Configuration
|
||||
public class RestClientConfig {
|
||||
|
||||
|
||||
@Bean
|
||||
public RestClient customRestClient(){
|
||||
return RestClient.builder()
|
||||
.baseUrl("https://coolify.stackpanel.com.br")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,38 +1,40 @@
|
||||
package br.com.stackpanel.api.controller;
|
||||
|
||||
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponse;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponseProjects;
|
||||
import br.com.stackpanel.api.service.CoolifyService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
@RequestMapping("/projects")
|
||||
public class CoolifyController {
|
||||
|
||||
|
||||
private final CoolifyService coolifyService;
|
||||
|
||||
public CoolifyController(CoolifyService coolifyService) {
|
||||
this.coolifyService = coolifyService;
|
||||
}
|
||||
|
||||
@GetMapping("/buscar")
|
||||
public List<CoolifyResponse> buscarProjects(){
|
||||
return coolifyService.buscarProjects();
|
||||
}
|
||||
|
||||
@GetMapping("/buscarProject")
|
||||
public CoolifyResponseProjects buscarProjectsUuid(@RequestParam(name = "uuid") String uuid){
|
||||
return coolifyService.buscarProjetosUuid(uuid);
|
||||
}
|
||||
|
||||
@GetMapping("/buscarTodos")
|
||||
public CoolifyResponseProjects buscarTodosProjects(){
|
||||
return coolifyService.buscarProjetosUuids();
|
||||
}
|
||||
|
||||
}
|
||||
package br.com.stackpanel.api.controller;
|
||||
|
||||
|
||||
import br.com.stackpanel.api.entity.CoolifyPersistence;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponse;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponseProjects;
|
||||
import br.com.stackpanel.api.service.CoolifyService;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
@RequestMapping("/projects")
|
||||
public class CoolifyController {
|
||||
|
||||
|
||||
private final CoolifyService coolifyService;
|
||||
|
||||
public CoolifyController(CoolifyService coolifyService) {
|
||||
this.coolifyService = coolifyService;
|
||||
}
|
||||
|
||||
@GetMapping("/buscar")
|
||||
public ResponseEntity<List<CoolifyPersistence>> buscarProjects(){
|
||||
return ResponseEntity.ok(coolifyService.buscarProjects());
|
||||
}
|
||||
|
||||
@GetMapping("/buscarProject")
|
||||
public CoolifyResponseProjects buscarProjectsUuid(@RequestParam(name = "uuid") String uuid){
|
||||
return coolifyService.buscarProjetosUuid(uuid);
|
||||
}
|
||||
|
||||
@GetMapping("/buscarTodos")
|
||||
public CoolifyResponseProjects buscarTodosProjects(){
|
||||
return coolifyService.buscarProjetosUuids();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,64 +1,73 @@
|
||||
package br.com.stackpanel.api.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TPROJECT", schema = "CLFADM")
|
||||
public class CoolifyPersistence {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "CODPRT")
|
||||
private Long sequence;
|
||||
|
||||
@Column(name = "NAMPRT")
|
||||
private String nameProject;
|
||||
|
||||
@Column(name = "UUID")
|
||||
private String uudi;
|
||||
|
||||
@Column(name = "DSCPRT")
|
||||
private String description;
|
||||
|
||||
public CoolifyPersistence() {
|
||||
}
|
||||
|
||||
public CoolifyPersistence(Long sequence, String nameProject, String uudi, String description) {
|
||||
this.sequence = sequence;
|
||||
this.nameProject = nameProject;
|
||||
this.uudi = uudi;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Long getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public void setSequence(Long sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
public String getNameProject() {
|
||||
return nameProject;
|
||||
}
|
||||
|
||||
public void setNameProject(String nameProject) {
|
||||
this.nameProject = nameProject;
|
||||
}
|
||||
|
||||
public String getUudi() {
|
||||
return uudi;
|
||||
}
|
||||
|
||||
public void setUudi(String uudi) {
|
||||
this.uudi = uudi;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
}
|
||||
package br.com.stackpanel.api.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "TPROJECT", schema = "CLFADM")
|
||||
public class CoolifyPersistence {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "CODPRT")
|
||||
private Long sequence;
|
||||
|
||||
@Column(name = "NAMPRT")
|
||||
private String nameProject;
|
||||
|
||||
@Column(name = "UUID", unique = true)
|
||||
private String uuid;
|
||||
|
||||
@Column(name = "DSCPRT")
|
||||
private String description;
|
||||
|
||||
public CoolifyPersistence() {
|
||||
}
|
||||
|
||||
public CoolifyPersistence(String nameProject, String uuid, String description) {
|
||||
this.nameProject = nameProject;
|
||||
this.uuid = uuid;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Long getSequence() {
|
||||
return sequence;
|
||||
}
|
||||
|
||||
public void setSequence(Long sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
public String getNameProject() {
|
||||
return nameProject;
|
||||
}
|
||||
|
||||
public void setNameProject(String nameProject) {
|
||||
this.nameProject = nameProject;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CoolifyPersistence{" +
|
||||
"sequence=" + sequence +
|
||||
", nameProject='" + nameProject + '\'' +
|
||||
", uuid='" + uuid + '\'' +
|
||||
", description='" + description + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
public record ApplicationResponse(String name, String uuid) {
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
public record CoolifyResponse(Long id, String uuid, String name, String description) {
|
||||
}
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
public record CoolifyResponse(Long id, String uuid, String name, String description) {
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record CoolifyResponseProjects(List<MysqlResponse> mysqls, List<ServiceResponse> services) {
|
||||
}
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record CoolifyResponseProjects(List<MysqlResponse> mysqls, List<ServiceResponse> services, List<ApplicationResponse> applications, List<PostgreResponse> postgresqls) {
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record MysqlResponse(String name, String uuid, String image, @JsonProperty("public_port") Long publicPort) {
|
||||
}
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record MysqlResponse(String name, String uuid, String image, @JsonProperty("public_port") Long publicPort) {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
public record PostgreResponse(String name, String uuid, String image) {
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ServiceResponse(String name, String uuid) {
|
||||
}
|
||||
package br.com.stackpanel.api.entity.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record ServiceResponse(String name, String uuid) {
|
||||
}
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
package br.com.stackpanel.api.entity.mapper;
|
||||
|
||||
|
||||
import br.com.stackpanel.api.entity.CoolifyPersistence;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CoolifyMapper {
|
||||
|
||||
public CoolifyPersistence toDomain(CoolifyResponse response){
|
||||
if (response == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CoolifyPersistence(
|
||||
response.id(),
|
||||
response.name(),
|
||||
response.uuid(),
|
||||
response.description()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public List<CoolifyPersistence> toDomainList(List<CoolifyResponse> responses){
|
||||
if (responses == null){
|
||||
return List.of();
|
||||
}
|
||||
|
||||
return responses.stream()
|
||||
.map(this::toDomain)
|
||||
.toList();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
package br.com.stackpanel.api.entity.mapper;
|
||||
|
||||
|
||||
import br.com.stackpanel.api.entity.CoolifyPersistence;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CoolifyMapper {
|
||||
|
||||
public CoolifyPersistence toDomain(CoolifyResponse response){
|
||||
if (response == null){
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CoolifyPersistence(
|
||||
response.name(),
|
||||
response.uuid(),
|
||||
response.description()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public List<CoolifyPersistence> toDomainList(List<CoolifyResponse> responses){
|
||||
if (responses == null){
|
||||
return List.of();
|
||||
}
|
||||
|
||||
return responses.stream()
|
||||
.map(this::toDomain)
|
||||
.toList();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
package br.com.stackpanel.api.integration;
|
||||
|
||||
|
||||
import br.com.stackpanel.api.config.RestClientConfig;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponse;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponseProjects;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CoolifyClient {
|
||||
|
||||
private final RestClient restClientConfig;
|
||||
|
||||
public CoolifyClient(RestClient restClientConfig) {
|
||||
this.restClientConfig = restClientConfig;
|
||||
}
|
||||
|
||||
public List<CoolifyResponse> buscarProjects(){
|
||||
return this.restClientConfig.get()
|
||||
.uri("/api/v1/projects/")
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer 6|JDmqzDFYjZbHKGEt3jjMERvvMTKNsDjsugQQkZtg28e56c42")
|
||||
.retrieve()
|
||||
.body(new ParameterizedTypeReference<List<CoolifyResponse>>() {});
|
||||
}
|
||||
|
||||
public CoolifyResponseProjects buscarProjectsUuid(String uuid){
|
||||
return this.restClientConfig.get()
|
||||
.uri("/api/v1/projects/{uuid}/production", uuid)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer 6|JDmqzDFYjZbHKGEt3jjMERvvMTKNsDjsugQQkZtg28e56c42")
|
||||
.retrieve()
|
||||
.body(new ParameterizedTypeReference<CoolifyResponseProjects>() {});
|
||||
}
|
||||
|
||||
}
|
||||
package br.com.stackpanel.api.integration;
|
||||
|
||||
|
||||
import br.com.stackpanel.api.config.RestClientConfig;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponse;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponseProjects;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CoolifyClient {
|
||||
|
||||
private final RestClient restClientConfig;
|
||||
|
||||
public CoolifyClient(RestClient restClientConfig) {
|
||||
this.restClientConfig = restClientConfig;
|
||||
}
|
||||
|
||||
public List<CoolifyResponse> buscarProjects(){
|
||||
return this.restClientConfig.get()
|
||||
.uri("/api/v1/projects/")
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer 6|JDmqzDFYjZbHKGEt3jjMERvvMTKNsDjsugQQkZtg28e56c42")
|
||||
.retrieve()
|
||||
.body(new ParameterizedTypeReference<List<CoolifyResponse>>() {});
|
||||
}
|
||||
|
||||
public CoolifyResponseProjects buscarProjectsUuid(String uuid){
|
||||
return this.restClientConfig.get()
|
||||
.uri("/api/v1/projects/{uuid}/production", uuid)
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer 6|JDmqzDFYjZbHKGEt3jjMERvvMTKNsDjsugQQkZtg28e56c42")
|
||||
.retrieve()
|
||||
.body(new ParameterizedTypeReference<CoolifyResponseProjects>() {});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package br.com.stackpanel.api.repository;
|
||||
|
||||
import br.com.stackpanel.api.entity.CoolifyPersistence;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CoolifyRepository extends JpaRepository<CoolifyPersistence, Long> {
|
||||
|
||||
@Query(value = "SELECT col FROM CoolifyPersistence col WHERE col.uudi in (:uuid)")
|
||||
CoolifyPersistence buscarProjectsUUIDs(String uuid);
|
||||
|
||||
}
|
||||
package br.com.stackpanel.api.repository;
|
||||
|
||||
import br.com.stackpanel.api.entity.CoolifyPersistence;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface CoolifyRepository extends JpaRepository<CoolifyPersistence, Long> {
|
||||
|
||||
@Query(value = "SELECT col.uuid FROM CoolifyPersistence col")
|
||||
List<String> buscarListaUuids();
|
||||
|
||||
@Query(value = "SELECT col FROM CoolifyPersistence col")
|
||||
List<CoolifyPersistence> buscarProjects();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package br.com.stackpanel.api.service;
|
||||
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponse;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponseProjects;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CoolifyService {
|
||||
|
||||
List<CoolifyResponse> buscarProjects();
|
||||
|
||||
CoolifyResponseProjects buscarProjetosUuid(String uuid);
|
||||
|
||||
CoolifyResponseProjects buscarProjetosUuids();
|
||||
|
||||
}
|
||||
package br.com.stackpanel.api.service;
|
||||
|
||||
import br.com.stackpanel.api.entity.CoolifyPersistence;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponse;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponseProjects;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CoolifyService {
|
||||
|
||||
List<CoolifyPersistence> buscarProjects();
|
||||
|
||||
CoolifyResponseProjects buscarProjetosUuid(String uuid);
|
||||
|
||||
CoolifyResponseProjects buscarProjetosUuids();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,73 +1,93 @@
|
||||
package br.com.stackpanel.api.service.impl;
|
||||
|
||||
import br.com.stackpanel.api.entity.CoolifyPersistence;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponse;
|
||||
import br.com.stackpanel.api.entity.dto.CoolifyResponseProjects;
|
||||
import br.com.stackpanel.api.entity.dto.MysqlResponse;
|
||||
import br.com.stackpanel.api.entity.dto.ServiceResponse;
|
||||
import br.com.stackpanel.api.entity.mapper.CoolifyMapper;
|
||||
import br.com.stackpanel.api.integration.CoolifyClient;
|
||||
import br.com.stackpanel.api.repository.CoolifyRepository;
|
||||
import br.com.stackpanel.api.service.CoolifyService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CoolifyServiceImpl implements CoolifyService {
|
||||
|
||||
private final CoolifyClient coolifyClient;
|
||||
private final CoolifyRepository repository;
|
||||
private final CoolifyMapper mapper;
|
||||
|
||||
public CoolifyServiceImpl(CoolifyClient coolifyClient, CoolifyRepository repository, CoolifyMapper mapper) {
|
||||
this.coolifyClient = coolifyClient;
|
||||
this.repository = repository;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public List<CoolifyResponse> buscarProjects(){
|
||||
return coolifyClient.buscarProjects();
|
||||
}
|
||||
|
||||
// public List<CoolifyPersistence> salvarProjetos(){
|
||||
// List<CoolifyResponse> response = coolifyClient.buscarProjects();
|
||||
//
|
||||
// List<String> uuids = new ArrayList<>();
|
||||
//
|
||||
// for (CoolifyResponse unique: response) {
|
||||
// uuids.add(unique.uuid());
|
||||
// }
|
||||
//
|
||||
// return uuids;
|
||||
//
|
||||
// }
|
||||
|
||||
@Override
|
||||
public CoolifyResponseProjects buscarProjetosUuid(String uuid){
|
||||
return coolifyClient.buscarProjectsUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoolifyResponseProjects buscarProjetosUuids(){
|
||||
|
||||
List<CoolifyResponseProjects> buscarPorUuids = coolifyClient.buscarProjects().stream()
|
||||
.map(uuids -> coolifyClient.buscarProjectsUuid(uuids.uuid()))
|
||||
.toList();
|
||||
|
||||
List<MysqlResponse> listaDeMysqls = buscarPorUuids.stream()
|
||||
.flatMap(flat -> flat.mysqls().stream())
|
||||
.toList();
|
||||
|
||||
List<ServiceResponse> listaDeServices = buscarPorUuids.stream()
|
||||
.flatMap(flat -> flat.services().stream())
|
||||
.toList();
|
||||
|
||||
return new CoolifyResponseProjects(listaDeMysqls, listaDeServices);
|
||||
|
||||
}
|
||||
}
|
||||
package br.com.stackpanel.api.service.impl;
|
||||
|
||||
import br.com.stackpanel.api.entity.CoolifyPersistence;
|
||||
import br.com.stackpanel.api.entity.dto.*;
|
||||
import br.com.stackpanel.api.entity.mapper.CoolifyMapper;
|
||||
import br.com.stackpanel.api.integration.CoolifyClient;
|
||||
import br.com.stackpanel.api.repository.CoolifyRepository;
|
||||
import br.com.stackpanel.api.service.CoolifyService;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CoolifyServiceImpl implements CoolifyService {
|
||||
|
||||
private final CoolifyClient coolifyClient;
|
||||
private final CoolifyRepository repository;
|
||||
private final CoolifyMapper mapper;
|
||||
|
||||
public CoolifyServiceImpl(CoolifyClient coolifyClient, CoolifyRepository repository, CoolifyMapper mapper) {
|
||||
this.coolifyClient = coolifyClient;
|
||||
this.repository = repository;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public List<CoolifyPersistence> buscarProjects(){
|
||||
|
||||
List<CoolifyResponse> projects = coolifyClient.buscarProjects();
|
||||
|
||||
List<String> dbProjects = repository.buscarListaUuids();
|
||||
|
||||
|
||||
if (!projects.isEmpty()) {
|
||||
projects.stream()
|
||||
.filter(item -> !dbProjects.contains(item.uuid()))
|
||||
.map(mapper::toDomain)
|
||||
.map(this::salvarProjects)
|
||||
.forEach(System.out::println);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return repository.buscarProjects().stream()
|
||||
.toList();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private CoolifyPersistence salvarProjects(CoolifyPersistence coolifyPersistence){
|
||||
return repository.save(coolifyPersistence);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoolifyResponseProjects buscarProjetosUuid(String uuid){
|
||||
return coolifyClient.buscarProjectsUuid(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CoolifyResponseProjects buscarProjetosUuids(){
|
||||
|
||||
List<CoolifyResponseProjects> buscarPorUuids = coolifyClient.buscarProjects().stream()
|
||||
.map(uuids -> coolifyClient.buscarProjectsUuid(uuids.uuid()))
|
||||
.toList();
|
||||
|
||||
List<MysqlResponse> listaDeMysqls = buscarPorUuids.stream()
|
||||
.flatMap(flat -> flat.mysqls().stream())
|
||||
.toList();
|
||||
|
||||
List<ServiceResponse> listaDeServices = buscarPorUuids.stream()
|
||||
.flatMap(flat -> flat.services().stream())
|
||||
.toList();
|
||||
|
||||
List<ApplicationResponse> listaDeApplications = buscarPorUuids.stream()
|
||||
.flatMap(item -> item.applications().stream())
|
||||
.toList();
|
||||
|
||||
List<PostgreResponse> listaDePostgreSql = buscarPorUuids.stream()
|
||||
.flatMap(item -> item.postgresqls().stream())
|
||||
.toList();
|
||||
|
||||
return new CoolifyResponseProjects(listaDeMysqls, listaDeServices, listaDeApplications, listaDePostgreSql);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ spring.config.activate.on-profile=local
|
||||
|
||||
spring.datasource.password=SnLcLToyTLVlTmODy9X8WkJLxD5M6i7rFJEQPUgnrIqwH9zYpkX7rczfH8wcPSD1
|
||||
spring.datasource.username=nexus
|
||||
spring.datasource.url=jdbc:postgresql://129.153.206.118:5676/nexusdb
|
||||
spring.datasource.url=jdbc:postgresql://db.stackpanel.com.br/nexusdb
|
||||
spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
|
||||
|
||||
Reference in New Issue
Block a user