-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request service and endpoints #14
Open
agyen
wants to merge
21
commits into
master
Choose a base branch
from
request-service
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
8265989
request service and endpoints
c465e75
getting specific colomn from requests table
c140556
getting specific columns
5cabb13
employee db extended with docker files
bill-n 515aae1
before adding request files
bill-n 2f320f8
added requestController
bill-n de71051
added email
bill-n c844e7f
added gmail service
bill-n 3ccd12b
added RequestTo
bill-n 2c771ca
added docker-compose.yml
bill-n 195724d
added files on dockerfile
bill-n 5eca1cc
added files into init.sh
bill-n 5f5091c
added holiday sql files
bill-n ec6fa0f
mofified
bill-n 8afdc29
Merge branch 'employeeUpdate' of https://github.com/Kwakyesamuelosei/…
bill-n b34ce9e
merged
bill-n 035ce69
modified api operation
bill-n e6d4a8b
modified file
bill-n 035447f
oidc
67a6643
requests services
97e1e35
gmail service for gsuite domain
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM adoptopenjdk:11-jre-hotspot | ||
COPY build/libs/employement-profiling-system-0.0.1-SNAPSHOT.jar app.jar | ||
RUN chmod 777 app.jar | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
DROP TABLE IF EXISTS employee cascade; | ||
|
||
CREATE TABLE employee ( | ||
employee_id serial primary key, | ||
employee_firstName text , | ||
employee_lastName text , | ||
employee_phoneNumber text, | ||
employee_email text, | ||
employee_address text, | ||
employee_role text, | ||
employee_dev_level text, | ||
employee_hire_date DATE, | ||
employee_onLeave BOOLEAN, | ||
employee_gender text, | ||
employee_status text | ||
); | ||
|
||
--- DATABASE FOR HOLIDAY ME --- | ||
|
||
DROP TABLE IF EXISTS requests cascade; | ||
DROP TABLE IF EXISTS request_status cascade; | ||
|
||
--- REQUEST STATUS --- | ||
|
||
CREATE TABLE request_status( | ||
request_status_id serial primary key NOT NULL, | ||
req_status varchar(10) | ||
); | ||
|
||
INSERT INTO request_status(request_status_id, req_status) VALUES (1, 'PENDING'); | ||
INSERT INTO request_status(request_status_id, req_status) VALUES (2, 'DECLINED'); | ||
INSERT INTO request_status(request_status_id, req_status) VALUES (3, 'APPROVED'); | ||
|
||
--- REQUESTS TABLE --- | ||
|
||
CREATE TABLE requests( | ||
request_id serial primary key NOT NULL, | ||
requester_id int references employee(employee_id) NOT NULL, | ||
request_start_date date NOT NULL, | ||
request_report_date date NOT NULL, | ||
request_status_id int references request_status(request_status_id) NOT NULL default 1 | ||
); |
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,21 @@ | ||
--- DATABASE FOR HOLIDAY ME --- | ||
|
||
DROP TABLE IF EXISTS requests cascade; | ||
DROP TABLE IF EXISTS request_status cascade; | ||
|
||
--- REQUEST STATUS --- | ||
|
||
CREATE TABLE request_status( | ||
request_status_id serial primary key NOT NULL, | ||
req_status varchar(10) | ||
); | ||
|
||
--- REQUESTS TABLE --- | ||
|
||
CREATE TABLE requests( | ||
request_id serial primary key NOT NULL, | ||
requester_id int references employee(employee_id) NOT NULL, | ||
request_start_date date NOT NULL, | ||
request_report_date date NOT NULL, | ||
request_status_id int references request_status(request_status_id) NOT NULL default 1 | ||
); |
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,3 @@ | ||
INSERT INTO request_status(req_status) VALUES ('PENDING'); | ||
INSERT INTO request_status(req_status) VALUES ('DECLINED'); | ||
INSERT INTO request_status(req_status) VALUES ('APPROVED'); |
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,3 @@ | ||
INSERT INTO requests(requester_id, request_start_date, request_report_date, request_status_id) values(1,'2020-02-20', '2020-02-25', 2); | ||
INSERT INTO requests(requester_id, request_start_date, request_report_date, request_status_id) values(1,'2020-02-20', '2020-02-25', 3); | ||
INSERT INTO requests(requester_id, request_start_date, request_report_date, request_status_id) values(1,'2020-02-20', '2020-02-25', 1); |
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,33 @@ | ||
version: '3' | ||
services: | ||
apigateway: | ||
image: "idawud/turntablapigateway:latest" | ||
env_file: | ||
- .envs/.apigateway | ||
ports: | ||
- "80:8081" | ||
permission: | ||
image: "idawud/accperm:v3" | ||
env_file: | ||
- .envs/.permission | ||
ports: | ||
- "5000:5000" | ||
gis: | ||
image: "isammyk/gis-docker:latest" | ||
env_file: | ||
- .envs/.gis | ||
ports: | ||
- "5004:5004" | ||
chess: | ||
image: "francisbilla/chess:latest" | ||
env_file: | ||
- .envs/.chess | ||
ports: | ||
- "8080:8080" | ||
holidayrequest: | ||
image: " billalidocker/employee-service:latest" | ||
env_file: | ||
- .envs/.holidayrequest | ||
ports: | ||
- "7070:7070" | ||
|
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,45 @@ | ||
#!/bin/bash | ||
|
||
#create init env files: list all services in the array, separeted by space | ||
declare -a arr=("apigateway" "gis" "permission" "chess" "holidayrequest") | ||
|
||
for i in "${arr[@]}" | ||
do | ||
filename="./.envs/.$i" | ||
if [[ ! -e "$filename" ]]; then | ||
mkdir -p ./.envs | ||
touch $filename | ||
fi | ||
done | ||
|
||
# install docker | ||
if docker --version 2>&1 >/dev/null ; then | ||
echo >&2 "docker installed" | ||
else | ||
sudo apt install docker -y | ||
fi | ||
|
||
#install docker-compose | ||
if docker-compose --version 2>&1 >/dev/null ; then | ||
echo >&2 "docker-compose installed" | ||
else | ||
sudo apt install docker-compose -y | ||
fi | ||
|
||
# run docker-compose | ||
declare -i count=$(docker-compose ps | wc -l) | ||
if [ $count -gt 2 ]; then | ||
echo "Restarting services:...." | ||
sudo docker-compose down | ||
sudo docker-compose pull | ||
sudo docker rmi $(docker images -a | grep '<none>' | awk '{print $3}') | ||
sudo docker-compose build --no-cache | ||
sudo docker-compose up -d | ||
else | ||
echo "Starting all services:....." | ||
sudo docker-compose down | ||
sudo docker-compose pull | ||
sudo docker rmi $(docker images -a | grep '<none>' | awk '{print $3}') | ||
sudo docker-compose build --no-cache | ||
sudo docker-compose up -d | ||
fi |
Empty file.
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
148 changes: 148 additions & 0 deletions
148
src/main/java/io/turntabl/employementprofilingsystem/Controllers/RequestController.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,148 @@ | ||
package io.turntabl.employementprofilingsystem.Controllers; | ||
|
||
import io.fusionauth.jwt.JWTException; | ||
import io.fusionauth.jwt.Verifier; | ||
import io.fusionauth.jwt.domain.JWT; | ||
import io.fusionauth.jwt.rsa.RSAVerifier; | ||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
|
||
import io.turntabl.employementprofilingsystem.Models.AddEmployee; | ||
import io.turntabl.employementprofilingsystem.Gmail.Email; | ||
import io.turntabl.employementprofilingsystem.Models.RequestTO; | ||
import io.turntabl.employementprofilingsystem.Transfers.Employee; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; | ||
import org.springframework.web.bind.annotation.*; | ||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
import java.security.GeneralSecurityException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Api | ||
@RestController | ||
public class RequestController { | ||
|
||
@Autowired | ||
JdbcTemplate jdbcTemplate; | ||
|
||
@CrossOrigin | ||
@ApiOperation("Make a holiday request") | ||
@PostMapping("/api/v1/request") | ||
public void makeARequest(@RequestBody RequestTO request) { | ||
jdbcTemplate.update("insert into requests(requester_id, request_start_date, request_report_date) values(?,?,?)", | ||
request.getRequester_id(), request.getRequest_start_date(), request.getRequest_report_date()); | ||
|
||
SimpleDateFormat DateFor = new SimpleDateFormat("E, dd MMMM yyyy"); | ||
String startDate = DateFor.format(request.getRequest_start_date()); | ||
String reportDate = DateFor.format(request.getRequest_report_date()); | ||
|
||
try { | ||
Email.requestMessage("[email protected]", request.getFrom() ,"Holiday request", startDate, reportDate, request.getRequester_name()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} catch (GeneralSecurityException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@CrossOrigin | ||
@ApiOperation("Get all holiday requests for requester") | ||
@GetMapping("/api/v1/request/requester/{id}") | ||
|
||
public List<RequestTO> getRequestByRequesterId(@PathVariable("id") Integer id) { | ||
return this.jdbcTemplate.query( | ||
" select request_start_date, request_report_date, request_status.req_status from requests inner join request_status on requests.request_status_id = request_status.request_status_id where requester_id =?", | ||
new Object[]{id}, | ||
new BeanPropertyRowMapper<>(RequestTO.class) | ||
); | ||
} | ||
|
||
@CrossOrigin | ||
@ApiOperation("Get all holiday requests") | ||
@GetMapping("/api/v1/requests") | ||
|
||
public List<RequestTO> getAllRequests() { | ||
return this.jdbcTemplate.query("select request_start_date, request_report_date, request_status.req_status from requests inner join request_status on requests.request_status_id = request_status.request_status_id", | ||
new BeanPropertyRowMapper<RequestTO>(RequestTO.class) | ||
|
||
); | ||
} | ||
|
||
@CrossOrigin | ||
@ApiOperation("Accept holiday request") | ||
@PutMapping("/api/v1/requests/approve/{id}") | ||
public void approveRequest(@PathVariable("id") Integer request_id) { | ||
this.jdbcTemplate.update("update requests set request_status_id = 3 where request_status_id = 1 and request_id = ?", request_id); | ||
} | ||
|
||
@CrossOrigin | ||
@ApiOperation("Decline holiday request") | ||
@PutMapping("/api/v1/requests/decline/{id}") | ||
public void declineRequest(@PathVariable("id") Integer request_id) { | ||
this.jdbcTemplate.update("update requests set request_status_id = 2 where request_status_id = 1 and request_id = ?", request_id); | ||
} | ||
|
||
@CrossOrigin | ||
@ApiOperation("validating employee with OIDC") | ||
@PostMapping("/validate") | ||
public Map<String, Object> checkToken(@RequestHeader("access-token") String token){ | ||
Map<String, Object> response = new HashMap<>(); | ||
|
||
Verifier verifier = RSAVerifier.newVerifier(Paths.get("public_key.pem")); | ||
try { | ||
// Verify and decode the encoded string JWT to a rich object | ||
JWT jwt = JWT.getDecoder().decode(token,verifier); | ||
response.put("success", true); | ||
response.put("decoded_token", jwt); | ||
return response; | ||
} catch (JWTException e) { | ||
e.getCause(); | ||
response.put("success", false); | ||
return response; | ||
} | ||
} | ||
|
||
@CrossOrigin | ||
@ApiOperation("Checking available email") | ||
@GetMapping("/verifymail/{email}") | ||
public Map<String, Object> check_employee_exits(@PathVariable("email") String email) { | ||
Map<String, Object> response = new HashMap<>(); | ||
|
||
response.put("response", this.jdbcTemplate.query("select * from employee where employee_email = ?", | ||
new Object[]{email}, | ||
BeanPropertyRowMapper.newInstance(Employee.class) | ||
) ); | ||
return response; | ||
} | ||
|
||
|
||
@CrossOrigin | ||
@ApiOperation("Checking available email") | ||
@PostMapping("/addemployee") | ||
public Map<String, Object> addemployeeDetails(@RequestBody Employee employeeDetails) { | ||
Map<String, Object> response = new HashMap<>(); | ||
|
||
SimpleJdbcInsert insertActor = new SimpleJdbcInsert(jdbcTemplate).withTableName("employee").usingGeneratedKeyColumns("employee_id"); | ||
Map<String, Object> insertEmployeeDetails = new HashMap<>(); | ||
insertEmployeeDetails.put("employee_firstname", employeeDetails.getEmployee_firstname()); | ||
insertEmployeeDetails.put("employee_lastname", employeeDetails.getEmployee_lastname()); | ||
insertEmployeeDetails.put("employee_email", employeeDetails.getEmployee_email()); | ||
|
||
Number Key = insertActor.executeAndReturnKey(insertEmployeeDetails); | ||
if (Key != null){ | ||
response.put("success",true); | ||
response.put("employee_id",Key.longValue()); | ||
}else { | ||
response.put("success",false); | ||
response.put("msg","Failed to add new employee, try again later"); | ||
} | ||
return response; | ||
} | ||
} | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you using a DAO for this? The controller uses the DAO, the DAO uses the JdbcTemplate.
This is fine if you're not using a DAO...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're not using DAO