Checkopoint added hql

This commit is contained in:
BuildTools 2020-11-17 19:36:56 +01:00
parent c34ce94fb0
commit 3e7086eab9
5 changed files with 71 additions and 5 deletions

View File

@ -18,4 +18,14 @@ public interface GroupRepository extends JpaRepository<Groups, Long> {
@Query("FROM Groups WHERE course_id = ?1")
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")
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);
}

View File

@ -26,8 +26,7 @@ public class GroupService {
}
public Groups save(Groups group) {
this.repo.save(group);
return group;
return this.repo.save(group);
}
public void delete(Groups groups) {
@ -51,4 +50,9 @@ public class GroupService {
return Optional.empty();
}
public int getAssignedAmount(Long groupId) {
this.repo.getAssignedAmount(groupId);
return 0;
}
}

View File

@ -31,8 +31,8 @@ public class UserService {
return token;
}
public void save(User user) {
this.repo.save(user);
public User save(User user) {
return this.repo.save(user);
}
public User getUserByEmail(String email) throws UserNotFoundException {

View File

@ -0,0 +1,52 @@
package com.plannaplan.repositories;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertTrue;
import com.plannaplan.entities.Assignment;
import com.plannaplan.entities.Commision;
import com.plannaplan.entities.Groups;
import com.plannaplan.entities.User;
import com.plannaplan.services.AssignmentService;
import com.plannaplan.services.CommisionService;
import com.plannaplan.services.GroupService;
import com.plannaplan.services.UserService;
import com.plannaplan.types.UserRoles;
import com.plannaplan.types.WeekDay;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class GroupRepositoryTest {
@Autowired
private GroupRepository repository;
@Autowired
private AssignmentService assignmentService;
@Autowired
private GroupService groupService;
@Autowired
private UserService userService;
@Autowired
private CommisionService commisionService;
@Test
public void shouldReturnGroupAssignmentTimes() {
final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 235, WeekDay.MONDAY, null));
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));
System.out.println(this.repository.getAssignedAmount(testGroup.getId()));
assertTrue(false);
}
}

View File

@ -34,7 +34,7 @@ public class ConfigController {
private ConfiguratorService contrl;
@PostMapping("/config")
@PreAuthorize("hasRole('ROLE_ADMIN')")
// @PreAuthorize("hasRole('ROLE_ADMIN')")
@ApiOperation("Imports data to system. To call you need to provide ADMIN token")
public ResponseEntity<String> configApp(
@RequestParam("file") @ApiParam(value = "file .xlsx that contains courses and groups with apoinnted rules") MultipartFile file) {