-
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.
Adding school, repo, service and annotation for it
- Loading branch information
1 parent
37bb580
commit cbbc218
Showing
9 changed files
with
188 additions
and
3 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/pmgkn/pescores/pescores/domain/dto/binding/SchoolAddBindingDto.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,37 @@ | ||
package pmgkn.pescores.pescores.domain.dto.binding; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import pmgkn.pescores.pescores.validation.common.UniqueSchoolName; | ||
|
||
import static pmgkn.pescores.pescores.domain.entity.constants.ValidationErrorMessages.*; | ||
|
||
public class SchoolAddBindingDto { | ||
|
||
@NotEmpty(message = SCHOOL_NAME_REQUIRED) | ||
@UniqueSchoolName | ||
private String name; | ||
|
||
@NotEmpty(message = CITY_NAME_REQUIRED) | ||
private String city; | ||
|
||
public SchoolAddBindingDto() { | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public SchoolAddBindingDto setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public SchoolAddBindingDto setCity(String city) { | ||
this.city = city; | ||
return this; | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/pmgkn/pescores/pescores/domain/entity/SchoolEntity.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,77 @@ | ||
package pmgkn.pescores.pescores.domain.entity; | ||
|
||
import jakarta.persistence.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Table(name = "schools") | ||
@Entity | ||
public class SchoolEntity extends BaseEntity { | ||
|
||
@Column(nullable = false, unique = true) | ||
private String name; | ||
|
||
@Column(nullable = false) | ||
private String city; | ||
|
||
@OneToMany(cascade = CascadeType.ALL) | ||
private List<ClassEntity> classes; | ||
|
||
@OneToMany(cascade = CascadeType.ALL) | ||
private List<StudentEntity> students; | ||
|
||
@OneToMany(cascade = CascadeType.ALL) | ||
private List<UserEntity> users; | ||
|
||
public SchoolEntity() { | ||
this.classes = new ArrayList<>(); | ||
this.users = new ArrayList<>(); | ||
this.students = new ArrayList<>(); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public SchoolEntity setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public SchoolEntity setCity(String city) { | ||
this.city = city; | ||
return this; | ||
} | ||
|
||
public List<ClassEntity> getClasses() { | ||
return classes; | ||
} | ||
|
||
public SchoolEntity setClasses(List<ClassEntity> classes) { | ||
this.classes = classes; | ||
return this; | ||
} | ||
|
||
public List<StudentEntity> getStudents() { | ||
return students; | ||
} | ||
|
||
public SchoolEntity setStudents(List<StudentEntity> students) { | ||
this.students = students; | ||
return this; | ||
} | ||
|
||
public List<UserEntity> getUsers() { | ||
return users; | ||
} | ||
|
||
public SchoolEntity setUsers(List<UserEntity> users) { | ||
this.users = users; | ||
return this; | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/main/java/pmgkn/pescores/pescores/domain/enums/UserRoleEnum.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package pmgkn.pescores.pescores.domain.enums; | ||
|
||
public enum UserRoleEnum { | ||
USER, ADMIN | ||
USER, ADMIN, SUPERADMIN | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/pmgkn/pescores/pescores/repositories/SchoolRepository.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,15 @@ | ||
package pmgkn.pescores.pescores.repositories; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
import pmgkn.pescores.pescores.domain.entity.SchoolEntity; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Repository | ||
public interface SchoolRepository extends JpaRepository<SchoolEntity, UUID> { | ||
|
||
Optional<SchoolEntity> findByName(String name); | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/pmgkn/pescores/pescores/service/SchoolService.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,7 @@ | ||
package pmgkn.pescores.pescores.service; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class SchoolService { | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/pmgkn/pescores/pescores/validation/common/UniqueSchoolName.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,23 @@ | ||
package pmgkn.pescores.pescores.validation.common; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import static pmgkn.pescores.pescores.domain.entity.constants.ValidationErrorMessages.UNIQUE_SCHOOL_NAME; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
@Constraint(validatedBy = UniqueSchoolNameValidator.class) | ||
public @interface UniqueSchoolName { | ||
|
||
String message() default UNIQUE_SCHOOL_NAME; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/pmgkn/pescores/pescores/validation/common/UniqueSchoolNameValidator.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,23 @@ | ||
package pmgkn.pescores.pescores.validation.common; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import pmgkn.pescores.pescores.repositories.SchoolRepository; | ||
|
||
public class UniqueSchoolNameValidator implements ConstraintValidator<UniqueSchoolName, String> { | ||
|
||
private final SchoolRepository schoolRepository; | ||
|
||
public UniqueSchoolNameValidator(SchoolRepository schoolRepository) { | ||
this.schoolRepository = schoolRepository; | ||
} | ||
|
||
@Override | ||
public boolean isValid(String schoolName, | ||
ConstraintValidatorContext context) { | ||
|
||
return this.schoolRepository | ||
.findByName(schoolName) | ||
.isEmpty(); | ||
} | ||
} |
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