Skip to content
Snippets Groups Projects
Commit 2d19a2d6 authored by Anders Austlid's avatar Anders Austlid
Browse files

Added endpoint to get group level by groupId

parent 79b3c43b
No related branches found
No related tags found
No related merge requests found
......@@ -59,4 +59,17 @@ public class GroupController {
}
return ResponseEntity.ok(groupService.createGroup(group));
}
/**
* Gets the level of a group
*
* @param groupId the id of the group
* @return a ResponseEntity containing the level of the group if it exists, or a 404 if it doesn't
*/
@GetMapping("/group/{groupId}/level")
public ResponseEntity<Integer> getGroupLevel(@PathVariable("groupId") long groupId) {
return groupService.getGroupById(groupId)
.map(group -> ResponseEntity.ok(group.getLevel()))
.orElseGet(() -> ResponseEntity.notFound().build());
}
}
......@@ -11,10 +11,15 @@ import java.util.Optional;
* Repository for groups
*
* @author Stian Lyng, Anders Austlid
* @version 1.2
* @since 21.04.2023
* @version 1.3
* @since 24.04.2023
*/
public interface GroupRepository extends JpaRepository<Group, Long> {
/**
* Finds a group by group name
* @param name the name of the group
* @return the group with the given name if it exists
*/
Optional<Group> findByGroupName(String name);
/**
......@@ -23,4 +28,12 @@ public interface GroupRepository extends JpaRepository<Group, Long> {
* @return list of groups with the given achievement
*/
List<Group> findAllByAchievementsAchievementName(String achievementName);
/**
* Gets group level by group id
*
* @param id the id of the group
* @return the level of the group
*/
int getLevelByGroupId(long id);
}
......@@ -53,4 +53,14 @@ public class GroupService {
throw new IllegalArgumentException("Group already exists");
return groupRepository.save(group);
}
/**
* Gets the level of a group
*
* @param id the id of the group
* @return the level of the group
*/
public int getLevelByGroupId(long id) {
return groupRepository.getLevelByGroupId(id);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment