-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
809 additions
and
0 deletions.
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,104 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.quicksilver.healthTracker</groupId> | ||
<artifactId>Health-Tracker</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
|
||
<name>HealthTracker</name> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.1.7.RELEASE</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>jstl</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>bootstrap</artifactId> | ||
<version>3.3.6</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>bootstrap-datepicker</artifactId> | ||
<version>1.0.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>jquery</artifactId> | ||
<version>1.9.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-tomcat</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.tomcat.embed</groupId> | ||
<artifactId>tomcat-embed-jasper</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-security</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
|
||
</project> |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/quicksilver/healthTracker/Application.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,34 @@ | ||
package com.quicksilver.healthTracker; | ||
|
||
import com.quicksilver.healthTracker.model.Patient; | ||
import com.quicksilver.healthTracker.repository.PatientRepository; | ||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
@SpringBootApplication | ||
@EnableAutoConfiguration | ||
@ComponentScan(basePackages={"com.quicksilver.healthTracker"}) | ||
@EnableJpaRepositories(basePackages="com.quicksilver.healthTracker.repository") | ||
public class Application extends SpringBootServletInitializer { | ||
@Autowired | ||
private PatientRepository repository; | ||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
@Bean | ||
InitializingBean seedData() { | ||
return () -> { | ||
repository.save(new Patient("Sheldon", "Cooper", "[email protected]", "Fever", 8L)); | ||
repository.save(new Patient("Amy","Fowler","[email protected]", "Headache", 3L)); | ||
repository.save(new Patient("Meg","March","[email protected]","Cold", 5L)); | ||
|
||
}; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/quicksilver/healthTracker/controller/ErrorController.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,24 @@ | ||
package com.quicksilver.healthTracker.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.servlet.ModelAndView; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
@Controller("error") | ||
public class ErrorController { | ||
|
||
@ExceptionHandler(Exception.class) | ||
public ModelAndView handleException | ||
(HttpServletRequest request, Exception ex){ | ||
ModelAndView mv = new ModelAndView(); | ||
|
||
mv.addObject("exception", ex.getLocalizedMessage()); | ||
mv.addObject("url", request.getRequestURL()); | ||
|
||
mv.setViewName("error"); | ||
return mv; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/quicksilver/healthTracker/controller/LogoutController.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,30 @@ | ||
package com.quicksilver.healthTracker.controller; | ||
|
||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
@Controller | ||
public class LogoutController { | ||
|
||
@RequestMapping(value = "/logout", method = RequestMethod.GET) | ||
public String logout(HttpServletRequest request, | ||
HttpServletResponse response) { | ||
|
||
Authentication authentication = SecurityContextHolder.getContext() | ||
.getAuthentication(); | ||
|
||
if (authentication != null) { | ||
new SecurityContextLogoutHandler().logout(request, response, | ||
authentication); | ||
} | ||
|
||
return "redirect:/"; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/quicksilver/healthTracker/controller/PatientController.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,80 @@ | ||
package com.quicksilver.healthTracker.controller; | ||
|
||
import com.quicksilver.healthTracker.model.Patient; | ||
import com.quicksilver.healthTracker.service.PatientService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import javax.validation.Valid; | ||
|
||
@Controller | ||
public class PatientController { | ||
|
||
private PatientService service; | ||
|
||
@Autowired | ||
public PatientController(PatientService service) { | ||
this.service = service; | ||
} | ||
|
||
@GetMapping("/list-patients") | ||
public String showAllPatients(Model model) { | ||
model.addAttribute("patients", service.findAll()); | ||
return "patients"; | ||
} | ||
|
||
@GetMapping("/new-patient") | ||
public String showPatientCreationForm(Model model) { | ||
model.addAttribute("patient", new Patient()); | ||
return "new-patient"; | ||
} | ||
|
||
@PostMapping(value = "/add", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) | ||
public String addNewPatient(@Valid @ModelAttribute Patient patient, BindingResult result, Model model) { | ||
if (result.hasErrors()) { | ||
return "new-patient"; | ||
} | ||
service.save(patient); | ||
return "redirect:/list-patients"; | ||
} | ||
|
||
@GetMapping("/{id}") | ||
public String showPatientById(@PathVariable Long id, Model model) { | ||
Patient patient = service.findById(id) | ||
.orElseThrow(() -> new IllegalArgumentException("Invalid patient Id:" + id)); | ||
model.addAttribute("patient", patient); | ||
return "edit-patient"; | ||
} | ||
|
||
@PostMapping("/{id}/update") | ||
public String updatePatient(@PathVariable Long id, @Valid @ModelAttribute Patient patient, BindingResult result, Model model) { | ||
if (result.hasErrors()) { | ||
return "edit-patient"; | ||
} | ||
service.findById(id) | ||
.orElseThrow(() -> new IllegalArgumentException("Invalid patient Id:" + id)); | ||
service.save(patient); | ||
return "redirect:/list-patients"; | ||
} | ||
|
||
@PostMapping("/{id}/delete") | ||
public String deletePatient(@PathVariable Long id, Model model) { | ||
service.findById(id) | ||
.orElseThrow(() -> new IllegalArgumentException("Invalid patient Id:" + id)); | ||
service.deleteById(id); | ||
return "redirect:/list-patients"; | ||
} | ||
@GetMapping("/{id}/bar") | ||
public String showBar(@PathVariable Long id, Model model) { | ||
Patient patient = service.findById(id) | ||
.orElseThrow(() -> new IllegalArgumentException("Invalid patient Id:" + id)); | ||
//todo conver it to json/gson | ||
model.addAttribute("patient", patient); | ||
return "bar"; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/com/quicksilver/healthTracker/controller/WelcomeController.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,30 @@ | ||
package com.quicksilver.healthTracker.controller; | ||
|
||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
@Controller | ||
public class WelcomeController { | ||
|
||
@RequestMapping(value = "/", method = RequestMethod.GET) | ||
public String showWelcomePage(ModelMap model) { | ||
model.put("name", getLoggedinUserName()); | ||
return "welcome"; | ||
} | ||
|
||
private String getLoggedinUserName() { | ||
Object principal = SecurityContextHolder.getContext() | ||
.getAuthentication().getPrincipal(); | ||
|
||
if (principal instanceof UserDetails) { | ||
return ((UserDetails) principal).getUsername(); | ||
} | ||
|
||
return principal.toString(); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/com/quicksilver/healthTracker/model/Disease.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,48 @@ | ||
package com.quicksilver.healthTracker.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.validation.constraints.NotBlank; | ||
|
||
@Entity | ||
public class Disease { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private long id; | ||
|
||
@NotBlank(message = "Disease is mandatory") | ||
private String disease; | ||
|
||
public Disease() {} | ||
|
||
public Disease(String disease) { | ||
this.disease = disease; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getDisease() { | ||
return disease; | ||
} | ||
|
||
public void setDisease(String disease) { | ||
this.disease = disease; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "disease: {" + | ||
"id=" + id + | ||
", disease='" + disease + '\'' + | ||
'}'; | ||
} | ||
} |
Oops, something went wrong.