Added tests and service
This commit is contained in:
parent
3e7086eab9
commit
b4bb13f2dd
@ -18,14 +18,7 @@ public interface GroupRepository extends JpaRepository<Groups, Long> {
|
|||||||
@Query("FROM Groups WHERE course_id = ?1")
|
@Query("FROM Groups WHERE course_id = ?1")
|
||||||
List<Groups> getByCourse(@Param("id") Long id);
|
List<Groups> getByCourse(@Param("id") Long id);
|
||||||
|
|
||||||
// SELECT group_id, COUNT(*) AS assinged_times FROM assignment WHERE
|
|
||||||
// is_past_assignment=0 GROUP BY group_id HAVING group_id=7;
|
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) AS assinged_times FROM Assignment WHERE isPastAssignment=false GROUP BY group HAVING group_id=?1")
|
@Query("SELECT COUNT(*) AS assinged_times FROM Assignment WHERE isPastAssignment=false GROUP BY group HAVING group_id=?1")
|
||||||
Number getAssignedAmount(Long groupId);
|
Optional<Number> getAssignedAmount(Long groupId);
|
||||||
|
|
||||||
// @Query("SELECT group_id, COUNT(*) AS assinged_times FROM assignment WHERE
|
|
||||||
// is_past_assignment=0 GROUP BY group_id HAVING group_id=7;")
|
|
||||||
// Number getTmpSqlAssignedAmount(Long groupId);
|
|
||||||
|
|
||||||
}
|
}
|
@ -52,7 +52,6 @@ public class GroupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getAssignedAmount(Long groupId) {
|
public int getAssignedAmount(Long groupId) {
|
||||||
this.repo.getAssignedAmount(groupId);
|
return this.repo.getAssignedAmount(groupId).orElse(Integer.valueOf(0)).intValue();
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -39,14 +39,41 @@ public class GroupRepositoryTest {
|
|||||||
private CommisionService commisionService;
|
private CommisionService commisionService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnGroupAssignmentTimes() {
|
public void shouldReturnGroupAssignmentTimes() throws InterruptedException {
|
||||||
final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 235, WeekDay.MONDAY, null));
|
final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 235, WeekDay.MONDAY, null));
|
||||||
final User user = this.userService.save(
|
int startGroupAmmount = this.repository.getAssignedAmount(testGroup.getId()).orElse(Integer.valueOf(0))
|
||||||
new User("Luis", "Vita", "shouldReturnGroupAssignmentTimes@grouprepository.test", UserRoles.STUDENT));
|
.intValue();
|
||||||
final Commision commision = this.commisionService.save(new Commision(user));
|
|
||||||
this.assignmentService.save(new Assignment(testGroup, commision));
|
final User user = this.userService.save(new User("Luis", "Vita",
|
||||||
|
"shouldReturnGroupAssignmentTimes@grouprepository.test", UserRoles.STUDENT));
|
||||||
|
final Commision commision = this.commisionService.save(new Commision(user));
|
||||||
|
|
||||||
|
this.assignmentService.save(new Assignment(testGroup, commision));
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
int afterAssignedGroupAmmount = this.repository.getAssignedAmount(testGroup.getId())
|
||||||
|
.orElse(Integer.valueOf(0)).intValue();
|
||||||
|
|
||||||
|
assertTrue(afterAssignedGroupAmmount > startGroupAmmount);
|
||||||
|
|
||||||
|
final Commision recommision = this.commisionService.save(new Commision(user));
|
||||||
|
this.assignmentService.save(new Assignment(testGroup, recommision));
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
int afterreAssignedGroupAmmount = this.repository.getAssignedAmount(testGroup.getId())
|
||||||
|
.orElse(Integer.valueOf(0)).intValue();
|
||||||
|
|
||||||
|
assertTrue(afterAssignedGroupAmmount == afterreAssignedGroupAmmount);
|
||||||
|
|
||||||
|
this.commisionService.save(new Commision(user));
|
||||||
|
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
int afterdeAssignedGroupAmmount = this.repository.getAssignedAmount(testGroup.getId())
|
||||||
|
.orElse(Integer.valueOf(0)).intValue();
|
||||||
|
|
||||||
|
assertTrue(afterdeAssignedGroupAmmount < afterreAssignedGroupAmmount);
|
||||||
|
|
||||||
System.out.println(this.repository.getAssignedAmount(testGroup.getId()));
|
|
||||||
assertTrue(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public class ConfigController {
|
|||||||
private ConfiguratorService contrl;
|
private ConfiguratorService contrl;
|
||||||
|
|
||||||
@PostMapping("/config")
|
@PostMapping("/config")
|
||||||
// @PreAuthorize("hasRole('ROLE_ADMIN')")
|
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||||
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
|
||||||
public ResponseEntity<String> configApp(
|
public ResponseEntity<String> configApp(
|
||||||
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) {
|
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) {
|
||||||
|
Loading…
Reference in New Issue
Block a user