Skip to content

Commit

Permalink
position added
Browse files Browse the repository at this point in the history
  • Loading branch information
sayeedajmal committed Feb 10, 2024
1 parent 8462543 commit 0dac50c
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 38 deletions.
58 changes: 58 additions & 0 deletions Web/Position.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Position Form</title>
</head>

<body>
<h1 style="text-align: center;">Staff Position</h1>
<h3 style="text-align: center;" id="responseShow"></h3>

<form id="updateForm" style="font-size: 2.5rem;text-align: center;align-items: center;align-content: center;">

<input type="text" placeholder="position" name="position" /><br />
<input type="checkbox" placeholder="enabled" name="enabled" value="true">Enabled<br>

<button type="reset">Clear</button>
<button type="button" onclick="updateStaffPosition()">Submit</button>
</form>
</body>
<script>
function updateStaffPosition() {
var responseShow = document.getElementById("responseShow");

var formData = {
position: document.querySelector('input[name="position"]').value,
enabled: document.querySelector('input[name="enabled"]').checked
};

fetch('http://localhost:8080/api/v1/staff/updateStaffPosition?staffId=3', {
method: 'PATCH',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(formData)
}).then(response => response.json())
.then(data => {
if (typeof data === 'object') {
responseshow.innerText = JSON.stringify(data);
} else {
responseshow.innerText = data;
}
})
.catch(error => {
responseshow.innerText = 'Error ' + error;
});
}

</script>
<style>
input {
font-size: 1.5rem;
}
</style>

</html>
44 changes: 37 additions & 7 deletions Web/Staff.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,46 @@

<body>
<h1 style="text-align: center;">Staff SignUp</h1>
<form action="https://localhost:443/api/v1/Staff/createStaff" method="post"
style="font-size: 2.5rem; text-align: center; align-items: center; align-content: center;">
<input type="text" placeholder="staffName" name="staffName"><br>
<input type="tel" placeholder="contactNumber" name="contactNumber"><br>
<input type="password" placeholder="password" name="password"><br>
<input type="email" placeholder="email" name="email"><br>
<form style="font-size: 2.5rem; text-align: center; align-items: center; align-content: center;">
<input type="text" placeholder="staffName" id="staffName"><br>
<input type="tel" placeholder="contactNumber" id="contactNumber"><br>
<input type="password" placeholder="password" id="password"><br>
<input type="email" placeholder="email" id="email"><br>
<input type="text" placeholder="address" id="address"><br>
<button type="clear">Clear</button>
<button type="submit">Submit</button>
<button type="button" onclick="submitForm()">Submit</button>
</form>
<h2 style="text-align: center;" id="response"></h2>
</body>
<script>
function submitForm() {
var staffData = {
staffName: document.getElementById("staffName").value,
contactNumber: document.getElementById("contactNumber").value,
password: document.getElementById("password").value,
email: document.getElementById("email").value,
address: document.getElementById("address").value,
};
var responseshow = document.getElementById("response");
fetch('http://localhost:8080/api/v1/staff/createStaff', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(staffData)
}).then(response => response.json())
.then(data => {
if (typeof data === 'object') {
responseshow.innerText = JSON.stringify(data);
} else {
responseshow.innerText = data;
}
})
.catch(error => {
responseshow.innerText = 'Error ' + error;
});
}
</script>
<style>
input {
font-size: 1.5rem;
Expand Down
10 changes: 5 additions & 5 deletions Web/donor.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<title>Donor Form</title>
</head>

<body>
<body>
<h1 style="text-align: center;">Donor SignUp</h1>
<form style="font-size: 2.5rem; text-align: center; align-items: center; align-content: center;">
<input type="text" placeholder="firstName" id="firstName"><br>
Expand Down Expand Up @@ -42,7 +42,7 @@ <h2 style="text-align: center;" id="response"></h2>
address: document.getElementById("address").value,
lastDonationDate: document.getElementById("lastDonationDate").value
};
var response = document.getElementById("response");
var responseshow = document.getElementById("response");
fetch('http://localhost:8080/api/v1/donor/createDonor', {
method: 'POST',
headers: {
Expand All @@ -52,13 +52,13 @@ <h2 style="text-align: center;" id="response"></h2>
}).then(response => response.json())
.then(data => {
if (typeof data === 'object') {
response.innerText = JSON.stringify(data);
responseshow.innerText = JSON.stringify(data);
} else {
response.innerText = data;
responseshow.innerText = data;
}
})
.catch(error => {
response.innerText = 'Error ' + error;
responseshow.innerText = 'Error ' + error;
});


Expand Down
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ CREATE TABLE IF NOT EXISTS staff (
-- Insert an initial admin into the staff table
INSERT INTO staff (staff_id, staff_name, position, contact_number, email, address, password, enabled, created_at, updated_at)
VALUES (3,'test','Manager','0000000000','test@gmail.com','AdminAddress','$2a$12$zn5nIdsS5llI26.vwXSJne27fqC9AkJhgrBPtkkT5Q3gFXfYiJMlu', true, NOW(), null);
VALUES (1,'Admin','Manager','0000000000','Admin@gmail.com','AdminAddress','$2a$12$zn5nIdsS5llI26.vwXSJne27fqC9AkJhgrBPtkkT5Q3gFXfYiJMlu', true, NOW(), null);
END_SQL

# Restart MySQL service to apply changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import jakarta.transaction.Transactional;

@RestController
@RequestMapping("/api/v1/BloodBank")
@RequestMapping("/api/v1/bloodBank")
public class BloodBankController {
@Autowired
private BloodBankService bloodBankService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import jakarta.transaction.Transactional;

@RestController
@RequestMapping("/api/v1/Donation")
@RequestMapping("/api/v1/donation")
public class DonationController {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
package com.strong.BloodDonation.Controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.strong.BloodDonation.Email.MailService;
import com.strong.BloodDonation.Model.Staff;
import com.strong.BloodDonation.Service.StaffService;
import com.strong.BloodDonation.Utils.BloodException;
import jakarta.transaction.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import jakarta.transaction.Transactional;

/**
* StaffController class handles HTTP requests related to staff operations.
Expand Down Expand Up @@ -99,19 +109,24 @@ public ResponseEntity<String> updateStaff(@RequestBody Staff updatedStaff) throw
/**
* PATCH endpoint to update Position of an existing staff member.
*
* @param updatedStaff The updated staff member object.
* @param staffId The unique identifier of the staff member to be
* positioned.
* @param position The position to be assigned.
* @param enabled The staff will be enabled or disabled from here.
* @return A response indicating the success or failure of the operation.
*/
@Transactional
@PatchMapping("updateStaffPosition")
public ResponseEntity<String> positionStaff(@RequestBody Staff updatedStaff) throws BloodException {
Staff byId = staffService.findById(updatedStaff.getStaffId());

byId.setPosition(updatedStaff.getPosition());
byId.setEnabled(updatedStaff.isEnabled());
public ResponseEntity<String> positionStaff(@RequestParam("staffId") Integer staffId,
@RequestParam String position,
@RequestParam Boolean enabled) throws BloodException {
Staff byId = staffService.findById(staffId);

staffService.updateStaff(updatedStaff);
mailService.sendStaffPositionNotification(updatedStaff);
byId.setPosition(position);
byId.setEnabled(enabled);

staffService.updateStaff(byId);
mailService.sendStaffPositionNotification(byId);
return new ResponseEntity<>("Updated Successfully", HttpStatus.OK);
}
}
18 changes: 10 additions & 8 deletions src/main/java/com/strong/BloodDonation/Email/MailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void sendDonorSignUpEmail(Donor donor) {
+ "</style></head><body>"
+ "<div class='container'>"
+ "<h1><span class='heart'>&hearts;</span> You're a Lifesaver!</h1>"
+ "<p>Dear <b>" + donor.getFirstName() + "" + donor.getLastName() + "</b>, Your ID : <b>" + donor.getDonorId()
+ "<p>Dear <b>" + donor.getFirstName() + " " + donor.getLastName() + "</b>, Your ID : <b>" + donor.getDonorId()
+ "</b>,</p>"
+ "<p>From the bottom of our hearts, thank you for choosing to donate blood! Your generous act will touch the lives of countless individuals in need.</p>"
+ "<p>Your decision doesn't just fill a vial, it fills their hope, their laughter, and their second chances. You are a true hero!</p>"
Expand Down Expand Up @@ -237,16 +237,17 @@ public void sendStaffWelcomeEmail(Staff staff) {
+ ".container { background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); }"
+ "h1 { text-align: center; font-size: 24px; color: #333; }"
+ "p { line-height: 1.5; color: #666; }"
+ "h4 {text-align: center; font-size: 18px; color: #0663440}"
+ ".heart { color: #e74c3c; font-size: 2em; margin-right: 5px; }"
+ ".button { display: block; background-color: #e74c3c; color: #fff; padding: 10px 20px; border: none; border-radius: 5px; text-align: center; cursor: pointer; margin-top: 20px; text-decoration: none; }"
+ ".button:hover { background-color: #c0392b; }"
+ "</style></head><body>"
+ "<div class='container'>"
+ "<h1><span class='heart'>&hearts;</span> Welcome to Our Team, " + staff.getStaffName() + " ID: "
+ staff.getStaffId() + "!</h1>"
+ "<h1><span class='heart'>&hearts;</span> Welcome to Our Team, " + staff.getStaffName() + "!</h1><br>"
+ " <h2>Your Id is:- " + staff.getStaffId() + "</h2>"
+ "<p>We are thrilled to have you on board. Your account has been successfully created.</p>"
+ "<p>Feel free to explore our platform and reach out if you have any questions or need assistance.</p>"
+ "<p> <b>We've notified you about your position, please wait for further instructions.</b></p>"
+ "<h4> <b> We've notified you about your position, please wait for further instructions.</b></h4>"
+ "<p>Best regards,</p>"
+ "<p>The " + OrganisationName + " Manager.</p>"
+ "</div>"
Expand All @@ -263,17 +264,18 @@ public void sendStaffPositionNotification(Staff staff) {
+ ".container { background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); }"
+ "h1 { text-align: center; font-size: 24px; color: #333; }"
+ "p { line-height: 1.5; color: #666; }"
+ "h4 {text-align: center; font-size: 18px; color: #0663440}"
+ ".heart { color: #e74c3c; font-size: 2em; margin-right: 5px; }"
+ ".button { display: block; background-color: #e74c3c; color: #fff; padding: 10px 20px; border: none; border-radius: 5px; text-align: center; cursor: pointer; margin-top: 20px; text-decoration: none; }"
+ ".button:hover { background-color: #c0392b; }"
+ "</style></head><body>"
+ "<div class='container'>"
+ "<h1><span class='heart'>&hearts;</span> Staff Position Updated Successfully!</h1>"
+ "<p>Dear " + staff.getStaffName() + " ID: " + staff.getStaffId() + ",</p>"
+ "<p>We're delighted to inform you that you've been assigned the position of <b>" + staff.getPosition()
+ "</b>.</p>"
+ "<h4>We're delighted to inform you that you've been assigned the position of <b>" + staff.getPosition()
+ "</b>.</h4>"
+ "<p>Thank you for your dedication and commitment to our team. We believe you'll excel in your new role!</p>"
+ "<p>Your position has been successfully updated. You are now <b><i>" + staff.isEnabled() + "</i></b>.</p>"
+ "<h4>Your position has been successfully updated. You are now <b><i>" + staff.isEnabled() + "</i></b>.</h4>"
+ "<p>Best regards,</p>"
+ "<p>The " + OrganisationName + " Manager</p>"
+ "</div>"
Expand All @@ -297,7 +299,7 @@ public void sendDonationConfirmation(Donation donation) {
+ "</style></head><body>"
+ "<div class='container'>"
+ "<h1><span class='heart'>&hearts;</span> Thank You for Donating Blood!</h1>"
+ "<p>Dear <b>" + donation.getDonor().getFirstName() + "" + donation.getDonor().getLastName() + "</b>,</p>"
+ "<p>Dear <b>" + donation.getDonor().getFirstName() + " " + donation.getDonor().getLastName() + "</b>,</p>"
+ "<p>We are writing to express our sincere gratitude for your recent blood donation. Your generosity will make a real difference in the lives of others.</p>"
+ "<p>Here are the details of your donation:</p>"
+ "<ul class='blood-details'>"
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/strong/BloodDonation/Model/Staff.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class Staff {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer staffId;

@Column(nullable = false)
Expand Down

0 comments on commit 0dac50c

Please sign in to comment.