Skip to content

Commit

Permalink
added remaining cli actions (#111)
Browse files Browse the repository at this point in the history
* added remaining cli actions

* Fix bug with search job and create proposal

* upload to attachments bucket

---------

Co-authored-by: shimaabetah <shimaabetah1911@gmail.com>
  • Loading branch information
HusseinYasser and ShimaaBetah authored May 22, 2024
1 parent 00cbad8 commit 3834089
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public GetMyProposalsResponse Run(GetMyProposalsRequest request) {
attachments.add(
ProposalAttachment.builder()
.withName(attachment.getName())
.withName(attachment.getUrl())
.withUrl(attachment.getUrl())
.build());
}
}
Expand Down
17 changes: 17 additions & 0 deletions workup-bash/commands/get_attachments.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

YELLOW='\033[0;33m'
NC='\033[0m'

#reading the array from the json attachments response
readarray -t attachments < <(echo $1 | jq -c '.[]')

mkdir -p "./media/proposal"$2"_attachments"

for attachment in ${attachments[@]}; do

url=$(echo "$attachment" | jq -r '.url')
curl --request GET \
--url http://localhost:8080"$url" \
--output "./media/proposal"$2"_attachments/$2.pdf"
done
42 changes: 42 additions & 0 deletions workup-bash/commands/jobs/create_proposal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

YELLOW='\033[0;33m'
NC='\033[0m'

read -p "job id: " jobId
read -p "cover letter: " coverLetter

echo "what is the proposed duration"
DURATIONS=("LESS_THAN_A_MONTH" "ONE_TO_THREE_MONTHS" "THREE_TO_SIX_MONTHS" "MORE_THAN_SIX_MONTHS")
jobDuration=$(bash ./commands/dropdown.sh ${DURATIONS[@]})

#attachements list
attachments=$(bash ./entities/attachment/attachment_list.sh)

#milestones list
milestones=$(bash ./entities/milestone/milestone_list.sh)

json_payload=$(cat <<EOF
{
"coverLetter": "$coverLetter",
"jobId": "$jobId",
"jobDuration": "$jobDuration",
"attachments": $attachments,
"milestones": $milestones
}
EOF
)

echo "$json_payload"

echo -e "${YELLOW}Sending your request to the server...${NC}"

bearerToken=$(cat ./token.txt)

status_code=$(curl -s -o response_body -w "%{http_code}" -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $bearerToken" -d "$json_payload" http://localhost:80/api/v1/jobs/{$jobId}/proposals)

response_body=$(cat response_body)

rm response_body

bash ./response_formatter.sh "$status_code" "$response_body"
14 changes: 13 additions & 1 deletion workup-bash/commands/jobs/get_job_proposals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NC='\033[0m'

read -p "job id: " id

echo -e "${YELLOW}Sending your request to the server...${NC}"
echo -e "{$YELLOW}Sending your request to the server...{$NC}"

bearerToken=$(cat ./token.txt)

Expand All @@ -15,4 +15,16 @@ response_body=$(cat response_body)

rm response_body

proposalsArr=$(echo $response_body | jq -r '.proposals')

readarray -t proposals < <(echo $proposalsArr | jq -c '.[]')

i=1

for proposal in ${proposals[@]}; do
attachements=$(echo $proposal | jq -r '.attachments')
bash ./commands/get_attachments.sh "$attachements" "$i"
i=$(($i+1))
done

bash ./response_formatter.sh "$status_code" "$response_body"
12 changes: 12 additions & 0 deletions workup-bash/commands/jobs/get_my_proposals.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ response_body=$(cat response_body)

rm response_body

proposalsArr=$(echo $response_body | jq -r '.proposals')

readarray -t proposals < <(echo $proposalsArr | jq -c '.[]')

i=1

for proposal in ${proposals[@]}; do
attachements=$(echo $proposal | jq -r '.attachments')
bash ./commands/get_attachments.sh "$attachements" "$i"
i=$(($i+1))
done

bash ./response_formatter.sh "$status_code" "$response_body"
41 changes: 41 additions & 0 deletions workup-bash/commands/jobs/search_jobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

YELLOW='\033[0;33m'
NC='\033[0m'

pageState="null"
read -p "query: " query
read -p "pageLimit: " pageLimit

while true; do



base_url="http://localhost:80/api/v1/jobs/search"

url="${base_url}?query="$query"&pageLimit=${pageLimit}"

if [[ "$pageState" != "null" ]]; then
url="${base_url}?query="$query"&pageLimit=${pageLimit}&pagingState="$pageState""
fi

echo -e "${YELLOW}Sending your request to the server...${NC}"

bearerToken=$(cat ./token.txt)

status_code=$(curl -s -o response_body -w "%{http_code}" -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $bearerToken" "$url")

response_body=$(cat response_body)

rm response_body

bash ./response_formatter.sh "$status_code" "$response_body"

pageState=$(echo $response_body | jq -r '.pagingState')

read -p "enough or otherwise for next " breaker

if [[ $breaker == "enough" ]]; then
break
fi
done
35 changes: 35 additions & 0 deletions workup-bash/entities/attachment/attachment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

source ./.env

read -p "attachement name: " name

if [[ "$name" == "done" ]]; then
echo "done"
exit 0
fi

read -p "attachement path: " path

bearerToken=$(cat ./token.txt)

filename="${bearerToken}${name}"

status_code=$(curl -o response_body --location 'http://localhost:8080/upload/attachments/' \
-u "$UPLOAD_USER:$UPLOAD_PASSWORD" \
--form "resource=@"$path"" \
--form "filename="$filename"")

response_body=$(cat response_body)

resumeLink=$(echo "$response_body" | jq -r '.path')

json_payload=$(cat <<EOF
{
"name": "$name",
"url": "$resumeLink"
}
EOF
)

echo "$json_payload"
20 changes: 20 additions & 0 deletions workup-bash/entities/attachment/attachment_list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

YELLOW='\033[0;33m'
NC='\033[0m'

inputs=()

while true; do
echo -e "${YELLOW}enter attachment or done${NC}" >&2
item=$(bash ./entities/attachment/attachment.sh)
if [[ "$item" == "done" ]]; then
break
else
inputs+=("$item")
fi
done

json_output=$(printf "%s\n" "${inputs[@]}" | jq -s '.')

echo "$json_output"
22 changes: 22 additions & 0 deletions workup-bash/entities/milestone/milestone.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

read -p "milestone description: " description

if [[ "$description" == "done" ]]; then
echo "done"
exit 0
fi

read -p "amount: " amount
read -p "due date (YYYY-MM-DD): " dueDate

json_payload=$(cat <<EOF
{
"description": "$description",
"amount": $amount,
"dueDate": "$dueDate"
}
EOF
)

echo "$json_payload"
20 changes: 20 additions & 0 deletions workup-bash/entities/milestone/milestone_list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

YELLOW='\033[0;33m'
NC='\033[0m'

inputs=()

while true; do
echo -e "${YELLOW}enter milestone or done${NC}" >&2
item=$(bash ./entities/milestone/milestone.sh)
if [[ "$item" == "done" ]]; then
break
else
inputs+=("$item")
fi
done

json_output=$(printf "%s\n" "${inputs[@]}" | jq -s '.')

echo "$json_output"
6 changes: 6 additions & 0 deletions workup-bash/services/jobs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ handle_jobs_command() {
accept-proposal)
bash ./commands/jobs/accept_proposal.sh
;;
create-proposal)
bash ./commands/jobs/create_proposal.sh
;;
search-jobs)
bash ./commands/jobs/search_jobs.sh
;;
exit)
echo -e "${CYAN}Exiting Jobs service.${NC}"
exit 0
Expand Down

0 comments on commit 3834089

Please sign in to comment.