-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #4 from FusionTech-2430/develop
🚀 Release v1.0
- Loading branch information
Showing
39 changed files
with
1,092 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/co/allconnected/fussiontech/eventsservice/config/FirebaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/co/allconnected/fussiontech/eventsservice/config/FirebaseConfigProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/co/allconnected/fussiontech/eventsservice/config/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
src/main/java/co/allconnected/fussiontech/eventsservice/controllers/EventController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
src/main/java/co/allconnected/fussiontech/eventsservice/controllers/FooController.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.