1
0
forked from PGL/Clyde

moved portective method to Static ProtectiveService

This commit is contained in:
2024-03-17 03:06:19 +01:00
parent d855bbe911
commit f7df234312
5 changed files with 59 additions and 48 deletions

View File

@@ -1,10 +1,7 @@
package ovh.herisson.Clyde.Services;
import org.springframework.stereotype.Service;
import ovh.herisson.Clyde.Tables.InscriptionRequest;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.Token;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.*;
import java.util.Date;
import java.util.HashMap;
@@ -53,25 +50,5 @@ public class AuthenticatorService {
}
return true;
}
/** return user's data except password
* @param user the user to return
* @return all the user data without the password
*/
public HashMap<String,Object> userWithoutPassword(User user){
HashMap<String,Object> toReturn = new HashMap<>();
toReturn.put("regNo",user.getRegNo());
toReturn.put("lastName",user.getLastName());
toReturn.put("firstName",user.getFirstName());
toReturn.put("email", user.getEmail());
toReturn.put("address",user.getAddress());
toReturn.put("birthDate",user.getBirthDate());
toReturn.put("country",user.getCountry());
toReturn.put("profilePictureUrl",user.getProfilePictureUrl());
toReturn.put("role",user.getRole());
return toReturn;
}
}

View File

@@ -36,11 +36,11 @@ public class CurriculumCourseService {
return null;
HashMap<String ,Object> toReturn = new HashMap<>();
ArrayList<Course> courses = new ArrayList<>();
ArrayList<Map<String ,Object>> courses = new ArrayList<>();
Iterable<Course> foundCourses = curriculumCourseRepo.findCoursesByCurriculum(curriculum);
for (Course c: foundCourses){
courses.add(c);
courses.add(ProtectionService.courseWithoutPassword(c));
}
toReturn.put("courses",courses);
toReturn.put("curriculumId", curriculum.getCurriculumId());
@@ -89,6 +89,5 @@ public class CurriculumCourseService {
curriculumCourseRepo.save(new CurriculumCourse(curriculum,course));
}
return true;
}
}

View File

@@ -0,0 +1,38 @@
package ovh.herisson.Clyde.Services;
import ovh.herisson.Clyde.Tables.Course;
import ovh.herisson.Clyde.Tables.User;
import java.util.HashMap;
public class ProtectionService {
/** return user's data except password
* @param user the user to return
* @return all the user data without the password
*/
public static HashMap<String,Object> userWithoutPassword(User user){
HashMap<String,Object> toReturn = new HashMap<>();
toReturn.put("regNo",user.getRegNo());
toReturn.put("lastName",user.getLastName());
toReturn.put("firstName",user.getFirstName());
toReturn.put("email", user.getEmail());
toReturn.put("address",user.getAddress());
toReturn.put("birthDate",user.getBirthDate());
toReturn.put("country",user.getCountry());
toReturn.put("profilePictureUrl",user.getProfilePictureUrl());
toReturn.put("role",user.getRole());
return toReturn;
}
public static HashMap<String,Object> courseWithoutPassword(Course course){
HashMap<String ,Object> toReturn = new HashMap<>();
toReturn.put("courseId",course.getCourseID());
toReturn.put("credits",course.getCredits());
toReturn.put("title", course.getTitle());
toReturn.put("owner", userWithoutPassword(course.getOwner()));
return toReturn;
}
}