Presentations
This commit is contained in:
parent
722a71d1af
commit
17789f2c51
@ -1,43 +0,0 @@
|
||||
package edu.amu.pl.demo;
|
||||
|
||||
import edu.amu.pl.demo.risk.entity.Client;
|
||||
import edu.amu.pl.demo.risk.entity.Illness;
|
||||
import edu.amu.pl.demo.risk.repository.ClientRepository;
|
||||
import edu.amu.pl.demo.risk.repository.IllnessRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoJakartaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoJakartaApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner populate(
|
||||
@Autowired IllnessRepository illnessRepository, @Autowired ClientRepository repository) {
|
||||
return (args) -> {
|
||||
// Hypothetical conditions with corresponding risk factors
|
||||
var hypertension = illnessRepository.save(new Illness(null, "Nadciśnienie", 0.7d));
|
||||
var liverCancer = illnessRepository.save(new Illness(null, "Rak wątroby", 0.95d));
|
||||
var obesity = illnessRepository.save(new Illness(null, "Otyłość", 0.6d));
|
||||
var stupidity = illnessRepository.save(new Illness(null, "Głupota", 0.8d));
|
||||
|
||||
// Clients with their conditions
|
||||
repository.save(new Client(null, Set.of(hypertension, obesity, stupidity)));
|
||||
repository.save(new Client(null, Set.of(liverCancer, obesity)));
|
||||
repository.save(new Client(null, Set.of()));
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
package edu.amu.pl.demo.risk.dto;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Setter
|
||||
@Getter
|
||||
@ToString
|
||||
public class RiskFactorDTO {
|
||||
|
||||
Long clientId;
|
||||
Double riskFactor;
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package edu.amu.pl.demo.risk.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Entity(name = "client")
|
||||
@Table(name = "client")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class Client {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "client_id")
|
||||
private Long id;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
name = "client_illness",
|
||||
joinColumns = @JoinColumn(name = "client_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "illness_id")
|
||||
)
|
||||
private Set<Illness> conditions;
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package edu.amu.pl.demo.risk.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.*;
|
||||
|
||||
@Entity(name = "illness")
|
||||
@Table(name = "illness")
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode
|
||||
@ToString
|
||||
public class Illness {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
@Column(name = "illness_id")
|
||||
private Long id;
|
||||
|
||||
@Column(name = "illness_name", nullable = false, unique = true)
|
||||
private String name;
|
||||
|
||||
@Column(name = "illness_risk_factor", nullable = false)
|
||||
private Double riskFactor;
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package edu.amu.pl.demo.risk.repository;
|
||||
|
||||
import edu.amu.pl.demo.risk.entity.Client;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ClientRepository extends CrudRepository<Client, Long> {
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package edu.amu.pl.demo.risk.repository;
|
||||
|
||||
import edu.amu.pl.demo.risk.entity.Illness;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface IllnessRepository extends CrudRepository<Illness, Long> {
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package edu.amu.pl.demo.risk.service;
|
||||
|
||||
import edu.amu.pl.demo.risk.dto.RiskFactorDTO;
|
||||
import edu.amu.pl.demo.risk.entity.Illness;
|
||||
import edu.amu.pl.demo.risk.repository.ClientRepository;
|
||||
import lombok.val;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RiskService {
|
||||
|
||||
@Autowired
|
||||
private ClientRepository repository;
|
||||
|
||||
public RiskFactorDTO calculateRiskFactor(Long clientId) {
|
||||
if (!repository.existsById(clientId)) {
|
||||
return new RiskFactorDTO(clientId, -1.0d);
|
||||
}
|
||||
val client = repository.findById(clientId).orElseThrow();
|
||||
if (client.getConditions().size() == 0) {
|
||||
return new RiskFactorDTO(clientId, 0d);
|
||||
} else {
|
||||
val maxRisk = client.getConditions().stream()
|
||||
.map(Illness::getRiskFactor)
|
||||
.max(Double::compare)
|
||||
.orElseThrow();
|
||||
return new RiskFactorDTO(clientId, maxRisk);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package edu.amu.pl.demo.risk.web;
|
||||
|
||||
import edu.amu.pl.demo.risk.dto.RiskFactorDTO;
|
||||
import edu.amu.pl.demo.risk.service.RiskService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController("/risk")
|
||||
public class RiskController {
|
||||
|
||||
@Autowired
|
||||
private RiskService service;
|
||||
|
||||
@GetMapping("/risk/{clientId}")
|
||||
public RiskFactorDTO getRiskForClient(@PathVariable Long clientId) {
|
||||
return service.calculateRiskFactor(clientId);
|
||||
}
|
||||
|
||||
}
|
@ -1 +0,0 @@
|
||||
server.port=8088
|
@ -1,13 +0,0 @@
|
||||
package edu.amu.pl.demo;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class DemojakartaApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
BIN
prezentacje/05-06-orm-spring-rest.pdf
Normal file
BIN
prezentacje/05-06-orm-spring-rest.pdf
Normal file
Binary file not shown.
BIN
prezentacje/07-application-servers.pdf
Normal file
BIN
prezentacje/07-application-servers.pdf
Normal file
Binary file not shown.
BIN
prezentacje/08-user-interface.pdf
Normal file
BIN
prezentacje/08-user-interface.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user