Skip to content

Commit

Permalink
Merge branch 'main' into mahmoud/users-profile
Browse files Browse the repository at this point in the history
  • Loading branch information
MahmoudHosamGaber committed May 6, 2024
2 parents 1c2cf53 + a62b1cd commit 5b37b74
Show file tree
Hide file tree
Showing 40 changed files with 1,054 additions and 102 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/maven-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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: Publish Docker Packeges

on:
push:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -DskipTests -B package --file pom.xml

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Jobs Image
run: |
docker build ./services/jobs --tag ahmad45123/workup:service_jobs
docker push ahmad45123/workup:service_jobs
- name: Build and push Payments Image
run: |
docker build ./services/payments --tag ahmad45123/workup:service_payments
docker push ahmad45123/workup:service_payments
- name: Build and push Users Image
run: |
docker build ./services/users --tag ahmad45123/workup:service_users
docker push ahmad45123/workup:service_users
- name: Build and push Contracts Image
run: |
docker build ./services/contracts --tag ahmad45123/workup:service_contracts
docker push ahmad45123/workup:service_contracts
16 changes: 15 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ services:
- "5672:5672"
- "15672:15672"

service_redis:
image: redis:latest
healthcheck:
test: redis-cli ping
interval: 30s
timeout: 30s
retries: 3
networks:
- microservices
ports:
- "6379:6379"

# ----- JOBS MICROSERVICE -------
service_jobs:
build: ./services/jobs
Expand All @@ -35,7 +47,9 @@ services:
payments_db:
condition: service_healthy
service_mq:
condition: service_started
condition: service_healthy
service_redis:
condition: service_healthy
networks:
- microservices
- payments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.workup.shared.commands.jobs.proposals.responses.AcceptProposalResponse;
import com.workup.shared.enums.HttpStatusCode;
import com.workup.shared.enums.ServiceQueueNames;
import java.util.ArrayList;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -99,16 +100,18 @@ private String initiateContract(
.withClientId(acceptedJob.getClientId())
.withUserId(request.getUserId())
.withJobMilestones(
acceptedProposal.getMilestones().stream()
.map(
milestone -> {
return Milestone.builder()
.withAmount(milestone.getAmount())
.withDescription(milestone.getDescription())
.withDueDate(milestone.getDueDate())
.build();
})
.collect(Collectors.toList()))
acceptedProposal.getMilestones() != null
? acceptedProposal.getMilestones().stream()
.map(
milestone -> {
return Milestone.builder()
.withAmount(milestone.getAmount())
.withDescription(milestone.getDescription())
.withDueDate(milestone.getDueDate())
.build();
})
.collect(Collectors.toList())
: new ArrayList<>())
.build()))
.getContractId();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.workup.jobs.commands;

import com.workup.jobs.models.Attachment;
import com.workup.jobs.models.Job;
import com.workup.jobs.models.Milestone;
import com.workup.jobs.models.Proposal;
import com.workup.shared.commands.jobs.proposals.ProposalStatus;
Expand All @@ -9,6 +10,7 @@
import com.workup.shared.enums.HttpStatusCode;
import java.util.ArrayList;
import java.util.Date;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

Expand All @@ -18,6 +20,14 @@ public class CreateProposalCommand
@Override
public CreateProposalResponse Run(CreateProposalRequest request) {
try {
Optional<Job> job = jobRepository.findById(UUID.fromString(request.getJobId()));
if (!job.isPresent()) {
return CreateProposalResponse.builder()
.withStatusCode(HttpStatusCode.NOT_FOUND)
.withErrorMessage("Job Not Found")
.withId(null)
.build();
}
Proposal proposal =
Proposal.builder()
.withPrimaryKey(
Expand All @@ -29,30 +39,35 @@ public CreateProposalResponse Run(CreateProposalRequest request) {
.withCoverLetter(request.getCoverLetter())
.withDuration(request.getJobDuration())
.withAttachments(
request.getAttachments().stream()
.map(
attachment ->
Attachment.builder()
.withName(attachment.getName())
.withUrl(attachment.getUrl())
.build())
.collect(Collectors.toCollection(ArrayList::new)))
request.getAttachments() != null
? request.getAttachments().stream()
.map(
attachment ->
Attachment.builder()
.withName(attachment.getName())
.withUrl(attachment.getUrl())
.build())
.collect(Collectors.toCollection(ArrayList::new))
: null)
.withMilestones(
request.getMilestones().stream()
.map(
milestone ->
Milestone.builder()
.withAmount(milestone.getAmount())
.withDescription(milestone.getDescription())
.withDueDate(milestone.getDueDate())
.build())
.collect(Collectors.toCollection(ArrayList::new)))
request.getMilestones() != null
? request.getMilestones().stream()
.map(
milestone ->
Milestone.builder()
.withAmount(milestone.getAmount())
.withDescription(milestone.getDescription())
.withDueDate(milestone.getDueDate())
.build())
.collect(Collectors.toCollection(ArrayList::new))
: null)
.withCreatedAt(new Date())
.withUpdatedAt(new Date())
.withStatus(ProposalStatus.PENDING)
.build();
Proposal savedProposal = proposalRepository.save(proposal);
System.out.println(" [x] Saved Proposal '" + savedProposal.getCoverLetter());
System.out.println(" [x] Saved Proposal '" + savedProposal.getAttachments());
System.out.println(" [x] Saved Proposal '" + savedProposal.getMilestones());
return CreateProposalResponse.builder()
.withStatusCode(HttpStatusCode.CREATED)
.withId(savedProposal.getPrimaryKey().getId().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,32 @@ public class GetMyProposalsCommand
@Override
public GetMyProposalsResponse Run(GetMyProposalsRequest request) {
try {
System.out.println(" [x] Fetching proposals for freelancer " + request.getUserId());
List<Proposal> response = proposalRepository.findByFreelancerId(request.getUserId());
System.out.println(" [x] Found " + response.size() + " proposals");

List<ProposalModel> proposals = new ArrayList<>();
for (Proposal proposal : response) {
ArrayList<ProposalAttachment> attachments = new ArrayList<>();
for (Attachment attachment : proposal.getAttachments()) {
attachments.add(
ProposalAttachment.builder()
.withName(attachment.getName())
.withName(attachment.getUrl())
.build());
if (proposal.getAttachments() != null) {
for (Attachment attachment : proposal.getAttachments()) {
attachments.add(
ProposalAttachment.builder()
.withName(attachment.getName())
.withName(attachment.getUrl())
.build());
}
}
ArrayList<ProposalMilestone> milestones = new ArrayList<>();
for (Milestone milestone : proposal.getMilestones()) {
milestones.add(
ProposalMilestone.builder()
.withAmount(milestone.getAmount())
.withDescription(milestone.getDescription())
.withDueDate(milestone.getDueDate())
.build());
if (proposal.getMilestones() != null) {
for (Milestone milestone : proposal.getMilestones()) {
milestones.add(
ProposalMilestone.builder()
.withAmount(milestone.getAmount())
.withDescription(milestone.getDescription())
.withDueDate(milestone.getDueDate())
.build());
}
}
proposals.add(
ProposalModel.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@ public GetProposalsByJobIdResponse Run(GetProposalsByJobIdRequest request) {
List<ProposalModel> proposals = new ArrayList<>();
for (Proposal proposal : response) {
ArrayList<ProposalAttachment> attachments = new ArrayList<>();
for (Attachment attachment : proposal.getAttachments()) {
attachments.add(
ProposalAttachment.builder()
.withName(attachment.getName())
.withName(attachment.getUrl())
.build());
if (proposal.getAttachments() != null) {
for (Attachment attachment : proposal.getAttachments()) {
attachments.add(
ProposalAttachment.builder()
.withName(attachment.getName())
.withUrl(attachment.getUrl())
.build());
}
}
ArrayList<ProposalMilestone> milestones = new ArrayList<>();
for (Milestone milestone : proposal.getMilestones()) {
milestones.add(
ProposalMilestone.builder()
.withAmount(milestone.getAmount())
.withDescription(milestone.getDescription())
.withDueDate(milestone.getDueDate())
.build());
if (proposal.getMilestones() != null) {
for (Milestone milestone : proposal.getMilestones()) {
milestones.add(
ProposalMilestone.builder()
.withAmount(milestone.getAmount())
.withDescription(milestone.getDescription())
.withDueDate(milestone.getDueDate())
.build());
}
}
proposals.add(
ProposalModel.builder()
Expand Down
12 changes: 12 additions & 0 deletions services/payments/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@
<version>1.19.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.redis.testcontainers</groupId>
<artifactId>testcontainers-redis-junit-jupiter</artifactId>
<version>1.4.6</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = "com.workup")
@EnableCaching
public class PaymentsApplication {

public static void main(String[] args) {
Expand Down
Loading

0 comments on commit 5b37b74

Please sign in to comment.