changes on auth service complete and secretary functios activated

This commit is contained in:
DECSEF Sistemas
2020-08-02 19:32:00 -05:00
parent ed939b9e63
commit e493387aa4
16 changed files with 152 additions and 10 deletions
+4
View File
@@ -63,6 +63,10 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
@@ -0,0 +1,12 @@
package com.unam.acatlan.coviserv.Entity;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Career {
@Id
private Long code;
private String name;
}
@@ -1,6 +1,7 @@
package com.unam.acatlan.coviserv.Entity;
import lombok.Data;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.CreationTimestamp;
import javax.persistence.*;
@@ -9,6 +10,7 @@ import java.time.LocalDateTime;
@Data
@Entity
@SuperBuilder
public class Evolution {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
@@ -29,7 +29,7 @@ public class Student {
private String email;
@NotBlank
private Integer codeCareer;
private Career codeCareer;
@NotBlank
@Size(min = 10)
@@ -0,0 +1,17 @@
package com.unam.acatlan.coviserv.Entity;
import lombok.Data;
import javax.persistence.*;
@Entity
@Data
public class StudentSubjects {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Long id;
@OneToOne
private Student student;
@OneToOne
private Subject subject;
}
@@ -0,0 +1,14 @@
package com.unam.acatlan.coviserv.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
public class Subject {
@Id
private Long id;
private String name;
@OneToOne
private Career career;
}
@@ -0,0 +1,7 @@
package com.unam.acatlan.coviserv.Repository;
import com.unam.acatlan.coviserv.Entity.Career;
import org.springframework.data.jpa.repository.JpaRepository;
public interface CareerRepository extends JpaRepository<Career,Long> {
}
@@ -0,0 +1,11 @@
package com.unam.acatlan.coviserv.Repository;
import com.unam.acatlan.coviserv.Entity.Student;
import com.unam.acatlan.coviserv.Entity.StudentSubjects;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
public interface StudentSubjectRepository extends JpaRepository<StudentSubjects,Long> {
List<StudentSubjects> findAllByStudent(Student student);
}
@@ -0,0 +1,6 @@
package com.unam.acatlan.coviserv.Repository;
import org.springframework.data.jpa.repository.JpaRepository;
public interface SubjectRepository extends JpaRepository<SubjectRepository,Long> {
}
@@ -1,9 +1,19 @@
package com.unam.acatlan.coviserv.Service;
import com.unam.acatlan.coviserv.Entity.Evolution;
import com.unam.acatlan.coviserv.Entity.Student;
import com.unam.acatlan.coviserv.Repository.EvolutionRepository;
import com.unam.acatlan.coviserv.Repository.StudentRepository;
import com.unam.acatlan.coviserv.Repository.SymptomsRepository;
import com.unam.acatlan.coviserv.auth.entity.AuthUser;
import com.unam.acatlan.coviserv.auth.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import static com.unam.acatlan.coviserv.RoleName.ROLE_SECRETARY;
@Service
public class SicknesService {
@@ -11,6 +21,35 @@ public class SicknesService {
private EvolutionRepository evolutionRepository;
@Autowired
private SymptomsRepository symptomsRepository;
@Autowired
private StudentRepository studentRepository;
@Autowired
private AuthService authService;
@Transactional
public Boolean insertSymptoms(Long[] symptoms, AuthUser user ){
Student student = studentRepository.findById(user.getId()).get();
if(symptoms.length>0){
for (int i=0;i<symptoms.length;i++){
if(symptomsRepository.existsById(symptoms[i])){
Evolution evolution = Evolution.builder()
.student(student)
.symptoms(symptomsRepository.findById(symptoms[i]).get().getDescription())
.build();
evolutionRepository.save(evolution);
}
}
return true;
}
return false;
}
public Boolean setStudentState(AuthUser user,String noCtaStudent ){
if(user.hasRole(ROLE_SECRETARY) && authService.userExists(noCtaStudent)){
Student student = studentRepository.findById(authService.getUser(noCtaStudent).getId()).get();
student.setInfected(true);
return true;
}
return false;
}
}
@@ -1,10 +1,14 @@
package com.unam.acatlan.coviserv.Service;
import com.unam.acatlan.coviserv.Entity.Career;
import com.unam.acatlan.coviserv.Entity.Student;
import com.unam.acatlan.coviserv.Entity.StudentSubjects;
import com.unam.acatlan.coviserv.Entity.Subject;
import com.unam.acatlan.coviserv.Payloads.SingUpUserRequest;
import com.unam.acatlan.coviserv.Repository.CareerRepository;
import com.unam.acatlan.coviserv.Repository.SecretaryRepository;
import com.unam.acatlan.coviserv.Repository.StudentRepository;
import com.unam.acatlan.coviserv.RoleName;
import com.unam.acatlan.coviserv.Repository.StudentSubjectRepository;
import com.unam.acatlan.coviserv.auth.entity.AuthUser;
import com.unam.acatlan.coviserv.auth.payload.CreateUserRequest;
import com.unam.acatlan.coviserv.auth.payload.CreateUserResponse;
@@ -14,6 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.List;
@Slf4j
@Service
@@ -28,6 +33,12 @@ public class UserService {
@Autowired
private SecretaryRepository secretaryRepository;
@Autowired
private CareerRepository careerRepository;
@Autowired
private StudentSubjectRepository studentSubjectRepository;
@Transactional
public CreateUserResponse create(SingUpUserRequest signUpRequest, String roleNames) {
CreateUserRequest createUserRequest = CreateUserRequest.builder()
@@ -43,7 +54,7 @@ public class UserService {
AuthUser authUser = authService.getUser(signUpRequest.getNoId());
Student student = Student.builder()
.user(authUser)
.codeCareer(signUpRequest.getCodeCareer())
.codeCareer(careerRepository.findById(Long.valueOf(signUpRequest.getCodeCareer())).get())
.email("test@test.com")
.phone("5555555555")
.build();
@@ -55,4 +66,15 @@ public class UserService {
return createUserResponse;
}
@Transactional
public List<StudentSubjects> newSubject(AuthUser user,Subject subject){
Student student = studentRepository.findById(user.getId()).get();
StudentSubjects studentSubject = new StudentSubjects();
studentSubject.setStudent(student);
studentSubject.setSubject(subject);
studentSubject = studentSubjectRepository.save(studentSubject);
return studentSubjectRepository.findAllByStudent(studentSubject.getStudent());
}
}
@@ -1,7 +1,6 @@
package com.unam.acatlan.coviserv.auth.filter;
import com.decsef.auth.manager.token.ITokenProvider;
import com.unam.acatlan.coviserv.auth.token.ITokenProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -1,8 +1,8 @@
package com.unam.acatlan.coviserv.auth.payload;
import com.decsef.auth.manager.entity.AuthUser;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.unam.acatlan.coviserv.auth.entity.AuthUser;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -3,8 +3,7 @@ package com.unam.acatlan.coviserv.auth.service;
import com.unam.acatlan.coviserv.auth.AuthManagerConfig;
import com.unam.acatlan.coviserv.auth.entity.AuthRole;
import com.unam.acatlan.coviserv.auth.entity.AuthUser;
import com.unam.acatlan.coviserv.auth.payload.CreateUserRequest;
import com.unam.acatlan.coviserv.auth.payload.CreateUserResponse;
import com.unam.acatlan.coviserv.auth.payload.*;
import com.unam.acatlan.coviserv.auth.repository.AuthRoleRepository;
import com.unam.acatlan.coviserv.auth.repository.AuthUserRepository;
import com.unam.acatlan.coviserv.auth.token.ITokenProvider;
@@ -1,6 +1,6 @@
package com.unam.acatlan.coviserv.auth.token;
import com.decsef.auth.manager.AuthManagerConfig;
import com.unam.acatlan.coviserv.auth.AuthManagerConfig;
import io.jsonwebtoken.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
+12 -2
View File
@@ -1,5 +1,6 @@
# The secret key for encode all tokens.
auth.manager.secret-key = $AUTH-SECRET-KEY$
#Auth Manager properties#
auth.manager.secret-key = covid-secret-encription-tokens-don't-hack
# If is true, auth.manager.secret-key property is ignored and a random secret-key is generated on each system startup.
auth.manager.secret-key.random = false
@@ -11,4 +12,13 @@ auth.manager.token-header.prefix = Bearer
# If is true, the token will be searched in the query of each request.
auth.manager.token-query = true
auth.manager.token-query.name = token
auth.manager.token-query.prefix =
#Server properties
server.port=9707
#Database properties
spring.datasource.url=jdbc:postgresql://localhost:5432/coviData
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect