Skip to content

Commit

Permalink
FIXED SOME ERROR
Browse files Browse the repository at this point in the history
  • Loading branch information
sayeedajmal committed Feb 8, 2024
1 parent c0dd950 commit 47dc80f
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 39 deletions.
5 changes: 3 additions & 2 deletions Senario.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Donor Entity:
# Donor Entity

Purpose: Represents information about blood donors.
Attributes:
donorId: Unique identifier for each donor.
firstName and lastName: First and last names of the donor.
dateOfBirth: Date of birth of the donor.
bloodGroup: Blood group of the donor (using a BloodType enum).
BloodType: Blood group of the donor (using a BloodType enum).
contactNumber: Contact number of the donor.
email: Email address of the donor.
address: Address of the donor.
Expand Down
5 changes: 2 additions & 3 deletions Web/Appointment.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Donor Form</title>
<title>Appointment Form</title>
</head>

<body>
<form action="http://localhost:8080/api/v1/appointment/createAppointment?donorId=202" method="post" style="
<form action="http://localhost:8080/api/v1/appointment/createAppointment?donorId=2" method="post" style="
font-size: 2.5rem;
text-align: center;
align-items: center;
Expand All @@ -18,7 +18,6 @@
<!-- Other fields for the Appointment object -->
<input type="date" placeholder="appointmentDate" name="appointmentDate" /><br />
<input type="time" placeholder="appointmentTime" name="appointmentTime" /><br />
<input type="text" placeholder="location" name="location" /><br />

<button type="clear">Clear</button>
<button type="submit">Submit</button>
Expand Down
55 changes: 55 additions & 0 deletions Web/donation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">

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

<body>
<form id="donationForm" style="
font-size: 2.5rem;
text-align: center;
align-items: center;
padding:0;margin: 0;
align-content: center;
">
<label for="donationStatus">Donation Status:</label>
<select id="donationStatus" name="donationStatus" required><br>
<option value="PENDING">Pending</option>
<option value="COMPLETED">Completed</option>
</select><br>


<label for="quantity">Quantity (in ml):</label>
<input type="number" id="quantity" name="quantity" required><br>

<button type="submit">Submit</button>
</form>

<div id="response"></div>

<script>
document.getElementById("donationForm").addEventListener("submit", function (event) {
event.preventDefault();
var form = event.target;
var formData = new FormData(form);

fetch('http://localhost:8080/api/v1/Donation/createDonation?donorId=2', {
method: 'POST',
body: formData
})
.then(response => response.text())
.then(data => {
document.getElementById("response").innerText = data;
})
.catch(error => {
console.error('Error:', error);
document.getElementById("response").innerText = 'An error occurred while processing your request.';
});
});
</script>
</body>

</html>
29 changes: 14 additions & 15 deletions Web/donor.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
</head>

<body>
<form id="donorForm" style="font-size: 2.5rem; text-align: center; align-items: center; align-content: center;">
<form style="font-size: 2.5rem; text-align: center; align-items: center; align-content: center;">
<input type="text" placeholder="firstName" id="firstName"><br>
<input type="text" placeholder="lastName" id="lastName"><br>
<input type="date" placeholder="dob" id="dob"><br>
<input type="text" placeholder="BloodGroup" id="bloodGroup"><br>
<input type="text" placeholder="bloodType" id="bloodType"><br>
<input type="text" placeholder="contactNumber" id="contactNumber"><br>
<input type="email" placeholder="email" id="email"><br>
<input type="text" placeholder="address" id="address"><br>
<input type="date" placeholder="lastDonationDate" id="lastDonationDate"><br>
<button type="button" onclick="submitForm()">Submit</button>
</form>
<h2 style="text-align: center;" id="response"></h2>
</body>
<style>
input {
Expand All @@ -34,34 +35,32 @@
firstName: document.getElementById("firstName").value,
lastName: document.getElementById("lastName").value,
dob: document.getElementById("dob").value,
bloodGroup: document.getElementById("bloodGroup").value,
bloodType: document.getElementById("bloodType").value,
contactNumber: document.getElementById("contactNumber").value,
email: document.getElementById("email").value,
address: document.getElementById("address").value,
lastDonationDate: document.getElementById("lastDonationDate").value
};

var response = document.getElementById("response");
fetch('http://localhost:8080/api/v1/donor/createDonor', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(donorData)
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
}).then(response => response.json())
.then(data => {
console.log('Success:', data);
// Handle success response from server
if (typeof data === 'object') {
response.innerText = JSON.stringify(data);
} else {
response.innerText = data;
}
})
.catch(error => {
console.error('Error:', error);
// Handle error response from server
response.innerText = 'Error ' + error;
});


}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ public ResponseEntity<String> updateAppointment(@RequestBody Appointment updated
if (existAppoint != null) {
existAppoint.setAppointmentDate(updatedAppointment.getAppointmentDate());
existAppoint.setAppointmentTime(updatedAppointment.getAppointmentTime());
existAppoint.setLocation(updatedAppointment.getLocation());
existAppoint.setStatus(updatedAppointment.getStatus());

appointService.updateAppointment(existAppoint);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.strong.BloodDonation.Controller;

import java.time.LocalDate;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -18,7 +19,9 @@

import com.strong.BloodDonation.Email.MailService;
import com.strong.BloodDonation.Model.Donation;
import com.strong.BloodDonation.Model.Donor;
import com.strong.BloodDonation.Service.DonationService;
import com.strong.BloodDonation.Service.DonorService;
import com.strong.BloodDonation.Utils.BloodException;

import jakarta.transaction.Transactional;
Expand All @@ -33,6 +36,9 @@ public class DonationController {
@Autowired
private DonationService donationService;

@Autowired
private DonorService donorService;

/**
*
* POST endpoint to create a new Donation.
Expand All @@ -43,12 +49,17 @@ public class DonationController {
* @return A response indicating the success or failure of the operation.
*/
@PostMapping("createDonation")
public ResponseEntity<String> createDonation(@ModelAttribute Donation donation) throws BloodException {
public ResponseEntity<String> createDonation(@ModelAttribute Donation donation,
@RequestParam Integer donorId) throws BloodException {

Donor byId = donorService.findById(donorId);
donation.setDonor(byId);
donation.setDonationDate(LocalDate.now());
donationService.saveDonation(donation);
mailService.sendDonationConfirmation(donation.getDonor().getEmail(),
donation.getDonor().getFirstName() + " " + donation.getDonor().getLastName(),
donation.getQuantity(),
donation.getBloodType());
byId.getBloodType());
return new ResponseEntity<>("Created Successfully", HttpStatus.CREATED);
}

Expand Down Expand Up @@ -104,9 +115,7 @@ public ResponseEntity<String> updateDonation(@RequestBody Donation updatedDonati
@RequestParam("donationId") Integer donationId) throws BloodException {
Donation existDonation = donationService.findById(donationId);
if (existDonation != null) {
existDonation.setBloodType(updatedDonation.getBloodType());
existDonation.setDonationDate(updatedDonation.getDonationDate());
existDonation.setDonationLocation(updatedDonation.getDonationLocation());
existDonation.setDonationStatus(updatedDonation.getDonationStatus());
existDonation.setQuantity(updatedDonation.getQuantity());
donationService.updateDonation(existDonation);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/strong/BloodDonation/Email/MailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ public void sendAppointmentNotification(String fullName, String to, LocalDate ap
+ ".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; }"
+ ".heart { color: #e74c3c; font-size: 2em; margin-right: 5px; }"
+ ".info { list-style: none; padding: 0; }"
+ ".info li { margin-bottom: 10px; }"
+ ".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>Your Lifesaving Appointment is Set!</h1>"
+ "<h1> <span class='heart'>&hearts;</span> Your Lifesaving Appointment is Set!</h1>"
+ "<p>Dear <b>" + fullName + "</b>,</p>"
+ "<p>We're pleased to confirm your appointment for blood donation.</p>"
+ "<p>Here are the details:</p>"
Expand Down Expand Up @@ -155,6 +156,8 @@ public void sendDonationConfirmation(String to, String donorName, Double quantit
+ "p { line-height: 1.5; color: #666; }"
+ ".heart { color: #e74c3c; font-size: 2em; margin-right: 5px; }"
+ ".blood-details { font-weight: bold; }"
+ ".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> Thank You for Donating Blood!</h1>"
Expand All @@ -169,7 +172,7 @@ public void sendDonationConfirmation(String to, String donorName, Double quantit
+ "</ul>"
+ "<p>Your blood donation will be used to help patients in need of medical treatment. You have truly made a lifesaving contribution.</p>"
+ "<p>In the coming days, you will receive a notification regarding your blood test results. You can also access your donor profile and donation history on our website: "
+ OrganisationWebsite + "</p>"
+ "<a href='" + OrganisationWebsite + "' class='button'>" + "</p>"
+ "<p>Thank you again for your kindness and compassion. We encourage you to continue donating blood in the future.</p>"
+ "<p>Sincerely,<br/>" + OrganisationName + " Team</p>"
+ "</div>"
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/strong/BloodDonation/Model/Appointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ public class Appointment {
@Check(constraints = "appointment_time >= '09:00:00' AND appointment_time <= '17:00:00'")
private LocalTime appointmentTime;

@NotNull
private String location;

@Enumerated(EnumType.STRING)
@NotNull
private AppointmentStatus status;
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/strong/BloodDonation/Model/Donation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.LocalDate;

import com.strong.BloodDonation.Utils.BloodType;
import com.strong.BloodDonation.Utils.DonationStatus;

import jakarta.persistence.Column;
Expand Down Expand Up @@ -34,17 +33,10 @@ public class Donation {
@Column(nullable = false)
private LocalDate donationDate;

@Column(nullable = false)
private String donationLocation;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private DonationStatus donationStatus;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private BloodType bloodType;

@Column(nullable = false)
private Double quantity;
}
6 changes: 5 additions & 1 deletion src/main/java/com/strong/BloodDonation/Model/Donor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import java.util.List;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.strong.BloodDonation.Utils.BloodType;

import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand Down Expand Up @@ -42,7 +45,8 @@ public class Donor {
private Date DOB;

@Column(nullable = false)
private String bloodGroup;
@Enumerated(EnumType.STRING)
private BloodType BloodType;

@Column(nullable = false)
private String contactNumber;
Expand Down

0 comments on commit 47dc80f

Please sign in to comment.