PUNKT-25 poprawki w tworzeniu grup

This commit is contained in:
yetju000 2019-12-07 23:33:28 +01:00
parent 9eb166274a
commit fa4d9a36fc
9 changed files with 29 additions and 29 deletions

View File

@ -50,12 +50,12 @@ public class GroupController {
}
@GetMapping("{group_id}/info")
public GroupInfoDto getGroupInfo(@PathVariable(required = true) Long group_id) {
public GroupInfoDto getGroupInfo(@PathVariable(required = true) Integer group_id) {
return this.groupService.getGroupInfo(group_id);
}
@DeleteMapping("/{group_id}/member/{user_id}")
public ResponseEntity deleteUserFromGroup(@PathVariable(required = true) Long group_id,
public ResponseEntity deleteUserFromGroup(@PathVariable(required = true) Integer group_id,
@PathVariable(required = true) Long user_id) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String currentPrincipalName = authentication.getName();
@ -67,12 +67,12 @@ public class GroupController {
}
@DeleteMapping("/{group_id}")
public ResponseEntity deleteGroup(@PathVariable(required = true) Long group_id) {
public ResponseEntity deleteGroup(@PathVariable(required = true) Integer group_id) {
return this.groupService.deleteGroup(group_id);
}
@GetMapping("/{group_id}/generate")
public ResponseEntity generateCode(@PathVariable(required = true) Long group_id) {
public ResponseEntity generateCode(@PathVariable(required = true) Integer group_id) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String currentPrincipalName = authentication.getName();
Long id = userRepository.findByUsername(currentPrincipalName).get().getId();
@ -178,12 +178,12 @@ public class GroupController {
}
@GetMapping("/{group_id}/leaderboard")
public ResponseEntity<?> getGroupLeaderboard(@PathVariable(required = true) Long group_id) {
public ResponseEntity<?> getGroupLeaderboard(@PathVariable(required = true) Integer group_id) {
return this.groupService.getGroupLeaderboard(group_id);
}
@GetMapping("/{group_id}/testleaderboard")
public ResponseEntity<?> getGroupTestLeaderboard(@PathVariable(required = true) Long group_id) {
public ResponseEntity<?> getGroupTestLeaderboard(@PathVariable(required = true) Integer group_id) {
return this.groupService.getGroupTestLeaderboard(group_id);
}
}

View File

@ -308,7 +308,7 @@ public class SetController {
SimpleSetDTO setDTO = modelMapper.map(set, SimpleSetDTO.class);
setDTO.setOwner(username);
if(set.getGroupId() != null)
setDTO.setGroup(groupRepository.findById((long)set.getGroupId()).orElse(null).getName());
setDTO.setGroup(groupRepository.findById(set.getGroupId()).orElse(null).getName());
setDTOs.add(setDTO);
}
return new ResponseEntity<List<SimpleSetDTO>>(setDTOs, HttpStatus.OK);

View File

@ -297,7 +297,7 @@ public class TestController {
SimpleTestDTO testDTO = modelMapper.map(test, SimpleTestDTO.class);
testDTO.setOwner(username);
if(test.getGroupId() != null)
testDTO.setGroup(groupRepository.findById((long)test.getGroupId()).orElse(null).getName());
testDTO.setGroup(groupRepository.findById(test.getGroupId()).orElse(null).getName());
testDTOs.add(testDTO);
}

View File

@ -171,7 +171,7 @@ public class UploadController {
materialDTO.setOwner(username);
if(material.getGroup() != null )
if((long)material.getGroup().getId() != 0 )
materialDTO.setGroup(groupRepository.findById((long)material.getGroup().getId()).orElse(null).getName());
materialDTO.setGroup(groupRepository.findById(material.getGroup().getId()).orElse(null).getName());
materialDTOs.add(materialDTO);
}
return new ResponseEntity<List<MaterialGetDTO>>(materialDTOs, HttpStatus.OK);

View File

@ -6,7 +6,7 @@ import studycave.studycaverestservice.model.studyGroup.StudyGroup;
import java.util.List;
import java.util.Optional;
public interface GroupRepository extends JpaRepository<StudyGroup, Long> {
public interface GroupRepository extends JpaRepository<StudyGroup, Integer> {
List<StudyGroup> findByName(String name);

View File

@ -118,11 +118,11 @@ public class GroupService {
return new ResponseEntity<GroupDto>(createdGroupDto, HttpStatus.OK);
}
public GroupInfoDto getGroupInfo(Long id) {
public GroupInfoDto getGroupInfo(Integer id) {
StudyGroup group = new StudyGroup();
group = this.groupRepository.findById(id).orElse(null);
GroupInfoDto groupInfo = new GroupInfoDto();
groupInfo.setId((long)group.getId());
groupInfo.setId(group.getId());
groupInfo.setName(group.getName());
groupInfo.setDescription(group.getDescription());
groupInfo.setGroupKey(group.getGroupKey());
@ -141,7 +141,7 @@ public class GroupService {
return groupInfo;
}
public ResponseEntity deleteUserFromGroup(Long gId, Long pId) {
public ResponseEntity deleteUserFromGroup(Integer gId, Long pId) {
StudyGroupMember user = new StudyGroupMember();
user = this.memberRepository.findUserInGroup(gId, pId);
this.memberRepository.delete(user);
@ -149,7 +149,7 @@ public class GroupService {
}
public ResponseEntity deleteGroup(Long id) {
public ResponseEntity deleteGroup(Integer id) {
StudyGroup group = new StudyGroup();
group = this.groupRepository.findById(id).orElse(null);
for (StudyGroupMember m : group.getMembers()) {
@ -159,7 +159,7 @@ public class GroupService {
return new ResponseEntity(HttpStatus.OK);
}
public ResponseEntity<?> generateCode(Long id) {
public ResponseEntity<?> generateCode(Integer id) {
StudyGroup group = new StudyGroup();
group = this.groupRepository.findById(id).orElse(null);
RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange('0', 'z')
@ -234,7 +234,7 @@ public class GroupService {
}
public ResponseEntity<?> addFlashcardSets(String groupId, @RequestBody List<AddSetDto> setIds) {
StudyGroup group = this.groupRepository.findById(Long.parseLong(groupId)).orElse(null);
StudyGroup group = this.groupRepository.findById(Integer.parseInt(groupId)).orElse(null);
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User user = userRepository.findByUsername(authentication.getName()).get();
@ -263,7 +263,7 @@ public class GroupService {
public ResponseEntity<?> addMaterials(String groupId, @RequestBody List<AddMaterialDto> materialIds) {
StudyGroup group = this.groupRepository.findById(Long.parseLong(groupId)).orElse(null);
StudyGroup group = this.groupRepository.findById(Integer.parseInt(groupId)).orElse(null);
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User user = userRepository.findByUsername(authentication.getName()).get();
@ -286,7 +286,7 @@ public class GroupService {
}
public ResponseEntity<?> addTests(String groupId, @RequestBody List<AddTestDto> testIds) {
StudyGroup group = this.groupRepository.findById(Long.parseLong(groupId)).orElse(null);
StudyGroup group = this.groupRepository.findById(Integer.parseInt(groupId)).orElse(null);
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User user = userRepository.findByUsername(authentication.getName()).get();
@ -440,7 +440,7 @@ public class GroupService {
}
public ResponseEntity<?> acceptTest(String groupId, String testId, VerifyDto dto) {
StudyGroup group = this.groupRepository.findById(Long.parseLong(groupId)).orElse(null);
StudyGroup group = this.groupRepository.findById(Integer.parseInt(groupId)).orElse(null);
if (group == null) {
return new ResponseEntity<>("Nie znaleziono grupy", HttpStatus.NOT_FOUND);
}
@ -458,7 +458,7 @@ public class GroupService {
}
public ResponseEntity<?> acceptSet(String groupId, String setId, VerifyDto dto) {
StudyGroup group = this.groupRepository.findById(Long.parseLong(groupId)).orElse(null);
StudyGroup group = this.groupRepository.findById(Integer.parseInt(groupId)).orElse(null);
if (group == null) {
return new ResponseEntity<>("Nie znaleziono grupy", HttpStatus.NOT_FOUND);
}
@ -479,7 +479,7 @@ public class GroupService {
}
public ResponseEntity<?> acceptMaterial(String groupId, String materialId, VerifyDto dto) {
StudyGroup group = this.groupRepository.findById(Long.parseLong(groupId)).orElse(null);
StudyGroup group = this.groupRepository.findById(Integer.parseInt(groupId)).orElse(null);
if (group == null) {
return new ResponseEntity<>("Nie znaleziono grupy", HttpStatus.NOT_FOUND);
}
@ -500,7 +500,7 @@ public class GroupService {
}
public ResponseEntity<?> rejectTest(String groupId, String testId, VerifyDto dto) {
StudyGroup group = this.groupRepository.findById(Long.parseLong(groupId)).orElse(null);
StudyGroup group = this.groupRepository.findById(Integer.parseInt(groupId)).orElse(null);
if (group == null) {
return new ResponseEntity<>("Nie znaleziono grupy", HttpStatus.NOT_FOUND);
}
@ -519,7 +519,7 @@ public class GroupService {
}
public ResponseEntity<?> rejectSet(String groupId, String setId, VerifyDto dto) {
StudyGroup group = this.groupRepository.findById(Long.parseLong(groupId)).orElse(null);
StudyGroup group = this.groupRepository.findById(Integer.parseInt(groupId)).orElse(null);
if (group == null) {
return new ResponseEntity<>("Nie znaleziono grupy", HttpStatus.NOT_FOUND);
}
@ -541,7 +541,7 @@ public class GroupService {
}
public ResponseEntity<?> rejectMaterial(String groupId, String materialId, VerifyDto dto) {
StudyGroup group = this.groupRepository.findById(Long.parseLong(groupId)).orElse(null);
StudyGroup group = this.groupRepository.findById(Integer.parseInt(groupId)).orElse(null);
if (group == null) {
return new ResponseEntity<>("Nie znaleziono grupy", HttpStatus.NOT_FOUND);
}
@ -629,7 +629,7 @@ public class GroupService {
}
}
public ResponseEntity<?> getGroupLeaderboard(Long group_id){
public ResponseEntity<?> getGroupLeaderboard(Integer group_id){
StudyGroup group = this.groupRepository.findById(group_id).orElse(null);
if (group == null) {
return new ResponseEntity<>("Nie znaleziono grupy", HttpStatus.NOT_FOUND);
@ -666,7 +666,7 @@ public class GroupService {
return new ResponseEntity<List<LeaderboardDTO>>(leaderboard,HttpStatus.OK);
}
public ResponseEntity<?> getGroupTestLeaderboard(Long group_id){
public ResponseEntity<?> getGroupTestLeaderboard(Integer group_id){
StudyGroup group = this.groupRepository.findById(group_id).orElse(null);
if (group == null) {
return new ResponseEntity<>("Nie znaleziono grupy", HttpStatus.NOT_FOUND);

View File

@ -12,7 +12,7 @@ import lombok.Setter;
@Getter
@Setter
public class GroupDto {
private Long id;
private Integer id;
private String owner;
private String name;
private String description;

View File

@ -14,7 +14,7 @@ import java.util.List;
@Getter
@Setter
public class GroupInfoDto {
private Long id;
private Integer id;
private String owner;
private String name;
private String description;

View File

@ -14,7 +14,7 @@ public interface StudyGroupMemberRepository extends JpaRepository<StudyGroupMemb
@Query("select t from StudyGroupMember t where (t.group.id = :g and t.user.id = :u)")
StudyGroupMember findUserInGroup(@Param("g") Long g, @Param("u") Long u);
StudyGroupMember findUserInGroup(@Param("g") Integer g, @Param("u") Long u);
Optional<StudyGroupMember> findByUserUsosUserUsosIdAndGroupUsosGroupId(String id, String groupId);
}