Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e7608f6
Setting up GitHub Classroom Feedback
github-classroom[bot] Oct 10, 2023
bf9fde6
add deadline
github-classroom[bot] Oct 10, 2023
1825578
test complete for get methods for user details.
chellacodes Nov 2, 2023
d902d3b
getter and setters method and tests. all passed.
chellacodes Nov 4, 2023
829295f
toString method added and tested
chellacodes Nov 4, 2023
483123b
couldnt test method but added them
chellacodes Nov 5, 2023
5d1ef6c
update , display and delete methods not working
chellacodes Nov 6, 2023
d481d43
tweaking
chellacodes Nov 6, 2023
00eef5e
changed userID from string to UUID
chellacodes Nov 8, 2023
1408b65
made interface better. NOW WORK ON API!
chellacodes Nov 9, 2023
79d7383
json data added, finish service class methods
chellacodes Nov 13, 2023
ce9316f
json file added
chellacodes Nov 13, 2023
adfa41d
implement methods from SAF to Service class
chellacodes Nov 14, 2023
422ae7a
keep maven
chellacodes Nov 14, 2023
a11aa51
1 step forward 10 steps back
chellacodes Nov 14, 2023
e4fa0db
api service complete? finish controller. and test
chellacodes Nov 15, 2023
f335224
trying to test api , merge create new branch
chellacodes Nov 16, 2023
ef7f766
testing
chellacodes Nov 16, 2023
e454bb7
api is retreiving json file !!! finish requests
chellacodes Nov 16, 2023
6c6bb8a
switch to different brach, implement post and get
chellacodes Nov 17, 2023
99c2a8e
two get request complete. post :/
chellacodes Nov 18, 2023
96ab51a
POSTMAPPING request working but not saving2json
chellacodes Nov 18, 2023
380f39a
working get request and post mapping
chellacodes Nov 18, 2023
0994cfb
success message added to @PostMapping req
chellacodes Nov 18, 2023
fec52f9
success mesage returning on all requests
chellacodes Nov 19, 2023
c3b61a9
update methodi is now working
chellacodes Nov 19, 2023
87d4eaf
both controllers working, all requests working
chellacodes Nov 19, 2023
0759248
algorithm inputted, push all to main
chellacodes Nov 19, 2023
333aa24
Merge pull request #7 from cbfacademy/implementing_api
chellacodes Nov 19, 2023
ea0875e
Testing programme functions class
chellacodes Nov 19, 2023
4b0c816
tests mostly complete for programme functions
chellacodes Nov 19, 2023
efbfeb1
Create README2.md
chellacodes Nov 19, 2023
2de6d72
Update README2.md
chellacodes Nov 19, 2023
c02be70
Update README2.md
chellacodes Nov 19, 2023
f3a75a3
FINAL COMMIT GOOD LUCK
chellacodes Nov 19, 2023
854c193
Merge branch 'main' of https://github.com/cbfacademy/java-rest-api-as…
chellacodes Nov 19, 2023
021bec2
Update README2.md
chellacodes Nov 19, 2023
1d1777a
last last
chellacodes Nov 19, 2023
f09cc8f
Merge branch 'main' of https://github.com/cbfacademy/java-rest-api-as…
chellacodes Nov 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed .github/.keep
Empty file.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-24ddc0f5d75046c5622901739e7c5dd533143b0c8e959d652212380cedb1ea36.svg)](https://classroom.github.com/a/iDPpP-d0)
# **Java API Assessment**

## **Introduction**
Expand Down
61 changes: 61 additions & 0 deletions README2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Activities of Daily Living Self Assessment

A Spring Boot API for managing self assessment user details and returning useful information based on the input.

## Description

The SelfAssessmentAPI is an API that provides a platform for users to perform self-assessments based on a set of questions. The project includes classes for managing user details, a service for program functions, and controllers for handling HTTP requests. The API allows users to perform CRUD operations on self-assessment data. It includes features like user creation, updating, and retrieving useful information based on results.

## Class structure

### Getters and Setters

SelfAssessmentUserDetails.java

This class represents the details of a user performing a self-assessment. It includes attributes such as userID, name, yearOfBirth, contactNumber, and answers to specific assessment questions. The class also provides methods for retrieving and updating user details.

Question.java

This class represents a set of predefined questions for a self-assessment. It serves as a container for questions related to various aspects of an individual's physical care and accessibility. Each question is encapsulated as a private field with corresponding getter and setter methods.

### Functions

SelfAssessmentUserProgrammeFunctions.java

This class contains methods for program functions related to the Self Assessment Programme. It handles the storage and retrieval of self-assessment questions and user details using JSON files. The class includes methods for adding, updating, and deleting user details.

### Controllers

SelfAssessmentController.java

This class is a REST controller that handles HTTP requests related to self-assessment questions and user details. It includes endpoints for retrieving questions, retrieving user details, adding a new user assessment, updating user details, and deleting user details.

SelfAssessmentResultsController.java

The SelfAssessmentResultsController class is another REST controller responsible for handling requests related to self-assessment results. It includes an endpoint for retrieving results based on a user's ID and a specialized endpoint for obtaining the count of users over 65 who answered a specific question.

### Service

SelfAssessmentServiceForAPI.java

This class serves as the service layer for the SelfAssessmentAPI, containing methods utilized by the controller class. It orchestrates the communication between the controller, program functions, and the searching algorithm.

### Algorithm

SearchingAlgorithm.java

This class provides a method to count the number of users over the age of 65 who answered a specific question negatively. This class is designed to work with a list of SelfAssessmentUserDetails objects. The countOver65sReturningFalseToAnswer1 takes a list of user details as input, uses Java streams to filter users born in or before 1957 who answered a specific question (answer1) with false. The method then returns the count of matching users.

### Programme

SelfAssessmentUserProgramme.java

This class serves as the entry point for the SelfAssessmentAPI application. It uses the Spring Boot @SpringBootApplication annotation to bootstrap the application, making it executable. The class also includes the main method (public static void main(String[] args)) responsible for launching the Spring Boot application.

### Link to published PostMan Documentation

[PostMan Documentation](https://documenter.getpostman.com/view/31214081/2s9Ye8fuov#97f450c0-bbdb-4c7e-b719-cf71bc4944f3)

### Acknowledgments

Thank you Coding Black Females for giving me the knowledge and inspiration to complete this project
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.4</version>
<version>3.1.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cbfacademy</groupId>
Expand Down Expand Up @@ -33,7 +33,13 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
22 changes: 0 additions & 22 deletions src/main/java/com/cbfacademy/apiassessment/App.java

This file was deleted.

65 changes: 65 additions & 0 deletions src/main/java/com/cbfacademy/apiassessment/Question.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.cbfacademy.apiassessment;

public class Question {

private String question1 = "Do you need physical care and support due to difficulties managing with any of the following; personal care, accessing the community, getting in and out of bed, drink and meal prep?";
private String question2 = "Do you have any difficulties ascending and / or descending the stairs?";
private String question3 = "Do you have any difficulties accessing your bathing facilities?";
private String question4 = "Do you have difficulties accessing your property?";
private String question5 = "Do you have difficulties transferring on and off the bed, chair, toilet, sofa?";


public Question() {
this.question1 = "Do you need physical care and support due to difficulties managing with any of the following; personal care, accessing the community, getting in and out of bed, drink and meal prep?";
this.question2 = "Do you have any difficulties ascending and / or descending the stairs? ";
this.question3 = "Do you have any difficulties accessing your bathing facilities?";
this.question4 = "Do you have difficulties accessing your property? ";
this.question5 = "Do you have difficulties transferring on and off the bed, chair, toilet, sofa?";
}

public String getQuestion1() {
return this.question1;
}

public void setQuestion1(String question1) {
this.question1 = question1;
}

public String getQuestion2() {
return this.question2;
}

public void setQuestion2(String question2) {
this.question2 = question2;
}

public String getQuestion3() {
return this.question3;
}

public void setQuestion3(String question3) {
this.question3 = question3;
}

public String getQuestion4() {
return this.question4;
}

public void setQuestion4(String question4) {
this.question4 = question4;
}

public String getQuestion5() {
return this.question5;
}

public void setQuestion5(String question5) {
this.question5 = question5;
}






}
20 changes: 20 additions & 0 deletions src/main/java/com/cbfacademy/apiassessment/SearchingAlgorithm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.cbfacademy.apiassessment;

import java.util.List;

import org.springframework.stereotype.Component;

// method is taking in a list of SelfAssessmentUserDetails as input and using Java streams to filter users born <= 1957 and return false
// count function used to count matching users

@Component
public class SearchingAlgorithm {

public long countOver65sReturningFalseToAnswer1 (List<SelfAssessmentUserDetails> userDetailsList) {
return userDetailsList.stream()
.filter(user -> user.getYearOfBirth() <= 1957).
filter(user -> !user.getAnswer1())
.count();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.cbfacademy.apiassessment;

import java.util.LinkedList;
// import java.util.UUID;

// import javax.swing.RepaintManager;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpStatus;
// import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
// import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
// import org.springframework.web.bind.annotation.PathVariable;
// import org.springframework.web.bind.annotation.PostMapping;
// import org.springframework.web.bind.annotation.PutMapping;
// import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@SpringBootApplication
@RestController
@RequestMapping("/api")

public class SelfAssessmentController {

// end points @GetMapping
SelfAssessmentServiceForAPI selfAssessmentService;
public SelfAssessmentController(SelfAssessmentServiceForAPI selfAssessmentService) {
this.selfAssessmentService = selfAssessmentService;
}

//

// sends a request to retreieve the json file with the self assessment questions
@GetMapping("/selfAssessmentQuestions")
public ResponseEntity <LinkedList<Question>> retrieveSelfAssessmentQuestions(){
LinkedList<Question> selfAssessmentQuestions = selfAssessmentService.retrieveQuestions();
return ResponseEntity.ok(selfAssessmentQuestions);
}

// sends request to retreive the json file with self assessment data
@GetMapping("/selfAssessmentData")
public ResponseEntity <LinkedList<SelfAssessmentUserDetails>> retrieveSelfAssessmentData(){
LinkedList<SelfAssessmentUserDetails> selfAssessment = selfAssessmentService.retrieveSelfAssessment();
return ResponseEntity.ok(selfAssessment);
}

// sends request to create a user self assessment following input into body
@PostMapping("/selfAssessmentData/addUser")
public ResponseEntity<String> createUserDetails(@RequestBody SelfAssessmentUserDetails userDetails) {
selfAssessmentService.createUserSelfAssessment(userDetails);
String successMessage = "Self Assessment added successfully";
return ResponseEntity.status(HttpStatus.CREATED).body(successMessage);
}

// request to update user, takes in param userID , update json file in body
@PutMapping("/selfAssessmentData/userDetails/{userID}")
public ResponseEntity<String> updateUserDetails(@PathVariable String userID, @RequestBody SelfAssessmentUserDetails userDetails) {
boolean updated = selfAssessmentService.updateUserSelfAssessment(userID, userDetails);
if (updated) {
String successMessage = "Self Assessment updated successfully";
return ResponseEntity.ok(successMessage);
} else {
String errorMessage = "Self Assessment not found for userID: " + userID;
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorMessage);
}
}

// request to delete user, takes in param userID , updates json file in body
@DeleteMapping("/selfAssessmentData/userDetails/{userID}")
public ResponseEntity<String> deleteUserDetails(@PathVariable String userID) {
boolean deleted = selfAssessmentService.deleteUserSelfAssessment(userID);
if (deleted) {
String successMessage = "Self Assessment deleted successfully";
return ResponseEntity.ok(successMessage);
} else {
String errorMessage = "Self Assessment not found for userID: " + userID;
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(errorMessage);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SelfAssessment Results</title>
</head>
<body>
<h1>Useful Information based on your answers </h1>

<!-- JavaScript to dynamically update content based on user answers -->
<script>
var userAnswers = {
answer1: false,
answer2: false,
answer3: false,
answer4: false,
answer5: false
// ... other answers
};

// Function to generate content based on answers
function generateContent(answers) {
// Logic to map answers to content
// Example: If answer1 is false, show a link
if (!answers.answer1) {
document.write('<p>Here is a useful link if you need physical care and support: <a href="https://www.gov.uk/apply-needs-assessment-social-services"> Find your local council to access Adult Social Care</a></p>');
}
if (!answers.answer2) {
document.write('<p>Here is a useful link if you are struggling with getting up and down the stairs (You can also try fitting a second stair rail): <a href="https://www.mobilitycompare.co.uk/stairlifts/?show-form=true&msclkid=0cd3dda3797b131283eab8fa099456b0&utm_source=bing&utm_medium=cpc&utm_campaign=Stairlifts%20Generic&utm_term=stairlifts%20uk&utm_content=Core"> Stair lift comparison website</a></p>');
}
if (!answers.answer3) {
document.write('<p>Here is a useful link if you are struggling with accessing your bathing facilities: <a href="https://www.careco.co.uk/bathroom/"> Link to bathroom aids</a></p>');
}
if (!answers.answer4) {
document.write('<p>Here is a useful link if you are struggling with accessing your property in any way: <a href="https://livingmadeeasy.org.uk/dlf-factsheets/adapting-your-home-access-into-and-around-your-home"> How to ensure safe access link</a></p>');
}
if (!answers.answer5) {
document.write('<p>Here is a useful link if you are struggling with getting on and off your; bed, chair, toilet (Explore the bed rails , raisers and toileting equipment section): <a href="https://www.careco.co.uk/furniture/furniture-accessories/furniture-raisers/">Care Co link</a></p>');
}
}

generateContent(userAnswers);
</script>
</body>
</html>
Loading