Skip to content

Commit

Permalink
Adding all schools and managing access to the pages
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoleNG18 committed Apr 9, 2024
1 parent fd5a925 commit fbe7e85
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity) throws
// Allow anyone to see the home page, the registration page and the login form
.requestMatchers("/users/login"
, "/users/register",
"/users/login-error","schools/**").permitAll()
"/users/login-error").permitAll()
.requestMatchers("/tasks",
"/classes/**", "/classes/edit/**", "/classes/delete/**"
, "/students/**",
"/denseBall", "/jump", "/thirty", "/twoHundred", "/tTest").authenticated()
.requestMatchers("/").anonymous()
.requestMatchers("/schools/**").hasRole(UserRoleEnum.SUPERADMIN.name())
// all other requests are authenticated.
.anyRequest().authenticated()
).formLogin(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package pmgkn.pescores.pescores.domain.dto.view;

import pmgkn.pescores.pescores.domain.entity.ClassEntity;
import pmgkn.pescores.pescores.domain.entity.StudentEntity;
import pmgkn.pescores.pescores.domain.entity.UserEntity;

import java.util.List;
import java.util.UUID;

public class SchoolViewDto {

private UUID id;

private String schoolName;

private String city;

// private String schoolAdmin;


private List<ClassEntity> classes;

private List<StudentEntity> students;

private List<UserEntity> teachers;

public SchoolViewDto() {
}

public UUID getId() {
return id;
}

public SchoolViewDto setId(UUID id) {
this.id = id;
return this;
}

public String getSchoolName() {
return schoolName;
}

public SchoolViewDto setSchoolName(String schoolName) {
this.schoolName = schoolName;
return this;
}

public String getCity() {
return city;
}

public SchoolViewDto setCity(String city) {
this.city = city;
return this;
}

public List<ClassEntity> getClasses() {
return classes;
}

public SchoolViewDto setClasses(List<ClassEntity> classes) {
this.classes = classes;
return this;
}

public List<StudentEntity> getStudents() {
return students;
}

public SchoolViewDto setStudents(List<StudentEntity> students) {
this.students = students;
return this;
}

public List<UserEntity> getTeachers() {
return teachers;
}

public SchoolViewDto setTeachers(List<UserEntity> teachers) {
this.teachers = teachers;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public class SchoolEntity extends BaseEntity {
private List<StudentEntity> students;

@OneToMany(cascade = CascadeType.ALL)
private List<UserEntity> users;
private List<UserEntity> teachers;

public SchoolEntity() {
this.classes = new ArrayList<>();
this.users = new ArrayList<>();
this.teachers = new ArrayList<>();
this.students = new ArrayList<>();
}

Expand Down Expand Up @@ -78,12 +78,12 @@ public SchoolEntity setStudents(List<StudentEntity> students) {
return this;
}

public List<UserEntity> getUsers() {
return users;
public List<UserEntity> getTeachers() {
return teachers;
}

public SchoolEntity setUsers(List<UserEntity> users) {
this.users = users;
public SchoolEntity setTeachers(List<UserEntity> teachers) {
this.teachers = teachers;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.stereotype.Repository;
import pmgkn.pescores.pescores.domain.entity.SchoolEntity;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

Expand All @@ -12,4 +13,6 @@ public interface SchoolRepository extends JpaRepository<SchoolEntity, UUID> {

Optional<SchoolEntity> findBySchoolName(String name);

List<SchoolEntity> findAll();

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ public DbInitService(UserRoleRepository userRoleRepository,

@PostConstruct
public void init() {
initSuperAdmin();
initRoles();
initSuperAdmin();
initDenseBall();
initJump();
initTTest();
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/pmgkn/pescores/pescores/service/SchoolService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import org.springframework.stereotype.Service;
import pmgkn.pescores.pescores.domain.dto.binding.ClassAddBindingDto;
import pmgkn.pescores.pescores.domain.dto.binding.SchoolAddBindingDto;
import pmgkn.pescores.pescores.domain.dto.view.SchoolViewDto;
import pmgkn.pescores.pescores.domain.entity.ClassEntity;
import pmgkn.pescores.pescores.domain.entity.SchoolEntity;
import pmgkn.pescores.pescores.repositories.SchoolRepository;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class SchoolService {

Expand All @@ -23,14 +27,17 @@ public SchoolService(SchoolRepository schoolRepository,

public void saveSchool(SchoolAddBindingDto schoolAddBindingDto) {

SchoolEntity schoolToSave=mapToSchoolEntity(schoolAddBindingDto);
SchoolEntity schoolToSave = mapToSchoolEntity(schoolAddBindingDto);

this.schoolRepository.saveAndFlush(schoolToSave);
}

private SchoolEntity mapToSchoolEntity(SchoolAddBindingDto schoolAddBindingDto) {

return this.modelMapper.map(schoolAddBindingDto,SchoolEntity.class);
return this.modelMapper.map(schoolAddBindingDto, SchoolEntity.class);
}

public List<SchoolViewDto> getAllSchools() {
return this.schoolRepository.findAll().stream().map(s -> this.modelMapper.map(s, SchoolViewDto.class)).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
Expand Down Expand Up @@ -53,7 +54,10 @@ public String postAddSchool(@Valid SchoolAddBindingDto schoolAddDto,
}

@GetMapping("/all")
public String getAllSchools() {
public String getAllSchools(Model model) {

model.addAttribute("schools",this.schoolService.getAllSchools());

return "all-schools";
}

Expand Down
147 changes: 147 additions & 0 deletions src/main/resources/static/css/all-schools.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
.main-section-schools {
padding: 5em;
display: flex;
background-color: #5d54c3;
justify-content: center;
min-height: 600px;
}

.buttons {
display: flex;
flex-direction: column;
gap: 0.5em;
}

.all-schools h2 {
font-weight: 700;
margin-bottom: 1em;
margin-top: 1.5em;
color: #5d54c3;
}

.all-schools {
width: 35%;
background-color: #d8d7fe;
text-align: center;
border-radius: 1em;
box-shadow: -4px -3px 45px 21px rgba(0, 0, 0, 0.35);
}

.all-schools ul {
list-style: none;
color: #5d54c3;
margin-bottom: 0.5em;
display: flex;
flex-direction: row;
gap: 2em;
justify-content: center;
padding-bottom: 1em;
border-bottom: 2px solid #5d54c3;
}

.all-schools li {
margin-top: 1em;
font-weight: 600;
text-align: center;
justify-content: center;
}

.className {
text-decoration: none;
font-size: 20px;
padding: 0.2em 2em;
color: #5d54c3;
border: 0.5px solid #5d54c3;
border-radius: 5px;
}

.className:hover {
color: #d8d7fe;
background-color: #5d54c3;
border-radius: 5px;
}

.edit {
color: #d8d7fe;
background-color: #5d54c3;
border-radius: 5px;
padding: 0.5em 1em;
text-decoration: none;
font-size: 16px;
font-weight: 500;
border: 1px solid #5d54c3;
}

.delete {
color: #d8d7fe;
background-color: #5d54c3;
border-radius: 5px;
padding: 0.5em 1em;
text-decoration: none;
font-size: 15px;
font-weight: 500;
border-color: #5d54c3;
}

form {
justify-content: center;
}

.edit:hover {
color: #5d54c3;
background-color: #d8d7fe;
}

.delete:hover {
color: #5d54c3;
background-color: #d8d7fe;
border-color: #d8d7fe;
}


/*.classes-table{*/
/* width: 80%;*/
/* background-color: #d8d7fe;*/
/* border-radius:1em;*/
/* box-shadow: -4px -3px 45px 21px rgba(0,0,0,0.35);*/
/*}*/

/*.classes-table h2{*/
/* font-weight: 700;*/
/* margin-bottom: 1em;*/
/* margin-top: 1.5em;*/
/* color: #5d54c3;*/
/* text-align: center;*/
/*}*/

/*.classes-table table{*/
/* border: 3px solid #5d54c3;*/
/* margin: 0 auto;*/
/* border-collapse: collapse;*/
/* width: 90%;*/
/*}*/

/*.classes-table thead th{*/
/* padding: 0.5em;*/
/* font-weight: 400;*/
/* color: #5d54c3;*/
/* text-align: center;*/
/* border-bottom: 2px solid #5d54c3;*/
/* border-right: 2px solid #5d54c3;*/
/*}*/

/*.classes-table tbody td{*/
/* padding: 0.5em;*/
/* border-bottom: 2px solid #5d54c3;*/
/* border-right: 2px solid #5d54c3;*/
/*}*/

/*.classes-table tbody td input{*/
/* width: 98%;*/
/* background-color: #d8d7fe;*/
/* border: none;*/
/* outline: none;*/
/* font-weight: 400;*/
/* color: #5d54c3;*/
/* text-align: left;*/
/*}*/
Loading

0 comments on commit fbe7e85

Please sign in to comment.