Skip to content

Commit

Permalink
🔀 Merge pull request #4 from FusionTech-2430/develop
Browse files Browse the repository at this point in the history
🚀 Release v1.0
  • Loading branch information
Estebans441 authored Nov 6, 2024
2 parents 5cb48c8 + 429bf9e commit 505b3c9
Show file tree
Hide file tree
Showing 39 changed files with 1,092 additions and 85 deletions.
33 changes: 7 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,22 @@
# 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 Project
on:
push:
branches: [ "main", "develop" ]
pull_request:
branches: [ "main" ]
branches: [ "main", "develop", "release" ]

jobs:
build:

runs-on: ubuntu-latest

Build:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4

- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'corretto'
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 }}
CONFIG_IP: ${{ secrets.DEV_INTEG_HOST }}
run: mvn clean install
36 changes: 36 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy Develop
on:
pull_request:
branches:
- develop
types:
- closed
workflow_dispatch:
jobs:
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
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/${{ github.event.repository.name }}
echo "Fetching latest code..."
git fetch
git checkout develop
git pull
echo "Building Docker image..."
docker build -t ${{ github.event.repository.name }} .
echo "Creating .env file..."
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..."
rm .env
36 changes: 36 additions & 0 deletions .github/workflows/deploy-qa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Deploy QA
on:
pull_request:
branches:
- release
types:
- closed
workflow_dispatch:
jobs:
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
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.QA_G1_HOST }}
username: ${{ secrets.HOSTS_USERNAME }}
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 release
git pull
echo "Building Docker image..."
docker build -t ${{ github.event.repository.name }} .
echo "Creating .env file..."
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
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ Microservicio encargado de gestionar los eventos de la plataforma __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 💻

Expand Down
26 changes: 25 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand All @@ -74,6 +81,23 @@
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<!-- FIREBASE DEPENDENCIES -->
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>9.1.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.11.0</version>
</dependency>
<!-- FILENAME -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package co.allconnected.fussiontech.eventsservice.config;

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.Configuration;

import javax.annotation.PostConstruct;
import java.io.ByteArrayInputStream;
import java.io.IOException;

@Configuration
public class FirebaseConfig {

private final FirebaseConfigProperties firebaseConfigProperties;

public FirebaseConfig(FirebaseConfigProperties firebaseConfigProperties) {
this.firebaseConfigProperties = firebaseConfigProperties;
}

@PostConstruct
public FirebaseApp initializeFirebase() throws IOException {
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(credentials)
.setStorageBucket(firebaseConfigProperties.getProject_id()+".appspot.com")
.build();

if(FirebaseApp.getApps().isEmpty()) {
FirebaseApp.initializeApp(options);
}

return FirebaseApp.getInstance();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package co.allconnected.fussiontech.eventsservice.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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package co.allconnected.fussiontech.eventsservice.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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package co.allconnected.fussiontech.eventsservice.controllers;

import co.allconnected.fussiontech.eventsservice.dtos.EventCreateDto;
import co.allconnected.fussiontech.eventsservice.dtos.EventDto;
import co.allconnected.fussiontech.eventsservice.dtos.Response;
import co.allconnected.fussiontech.eventsservice.services.EventService;
import co.allconnected.fussiontech.eventsservice.utils.OperationException;
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;
import java.util.List;

@RestController
@RequestMapping("/api/v0/events")
public class EventController {
// Services
private final EventService eventService;

@Autowired
public EventController(EventService eventService) {
this.eventService = eventService;
}

// Get all events
@GetMapping
public ResponseEntity<List<EventDto>> getAllEvents() {
List<EventDto> events = eventService.getAllEvents();
return new ResponseEntity<>(events, HttpStatus.OK);
}

// Get event by ID
@GetMapping("/{id_event}")
public ResponseEntity<EventDto> getEventById(@PathVariable("id_event") Integer id) {
EventDto event = eventService.getEventById(id);
return new ResponseEntity<>(event, HttpStatus.OK);
}

// Create a new event
@PostMapping
public ResponseEntity<?> createEvent(
@ModelAttribute EventCreateDto eventDto,
@RequestParam(value = "photo", required = false) MultipartFile photo) {
try {
EventDto newEvent = eventService.createEvent(eventDto, photo);
return new ResponseEntity<>(newEvent, HttpStatus.CREATED);
} 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()));
}
}

// Update an event
@PutMapping("/{id_event}")
public ResponseEntity<EventDto> updateEvent(
@PathVariable("id_event") Integer id,
@RequestBody EventDto eventDto,
@RequestParam MultipartFile photo) {
EventDto updatedEvent = eventService.updateEvent(id, eventDto, photo);
return new ResponseEntity<>(updatedEvent, HttpStatus.OK);
}

// Delete an event
@DeleteMapping("/{id_event}")
public ResponseEntity<Void> deleteEvent(@PathVariable("id_event") Integer id) {
eventService.deleteEvent(id);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

// Add a label to an event
@PostMapping("/{id_event}/labels")
public ResponseEntity<EventDto> addLabelToEvent(@PathVariable("id_event") Integer eventId, @RequestBody Integer labelId) {
EventDto updatedEvent = eventService.addLabelToEvent(eventId, labelId);
return new ResponseEntity<>(updatedEvent, HttpStatus.CREATED);
}

// Remove a label from an event
@DeleteMapping("/{id_event}/labels/{id_label}")
public ResponseEntity<Void> removeLabelFromEvent(@PathVariable("id_event") Integer eventId, @PathVariable("id_label") Integer labelId) {
eventService.removeLabelFromEvent(eventId, labelId);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}

This file was deleted.

Loading

0 comments on commit 505b3c9

Please sign in to comment.