Skip to content
Snippets Groups Projects
Commit fcd6e19c authored by Pedro Pablo Cardona Arroyave's avatar Pedro Pablo Cardona Arroyave
Browse files

Comments for the methods were added

parent 79645afa
No related branches found
No related tags found
No related merge requests found
......@@ -72,18 +72,32 @@ public class GroupController {
.map(group -> ResponseEntity.ok(group.getLevel()))
.orElseGet(() -> ResponseEntity.notFound().build());
}
/**
* Sets the level of the group identified by the given ID to the level corresponding to the given experience points.
* Returns a ResponseEntity containing the new level of the group, or a 404 Not Found response if no Group with the given ID was found.
*
* @param groupId the ID of the group to update
* @param exp the new experience points of the group
* @return a ResponseEntity containing the new level of the group, or a 404 Not Found response if no Group with the given ID was found
*/
@PutMapping("/group/{groupId}/newLevel/{exp}")
public ResponseEntity<Long> setNewLevel(@PathVariable("groupId") long groupId, @PathVariable("exp") long exp){
return groupService.setLevelByGroupId(groupId,exp)
public ResponseEntity<Long> setNewLevel(@PathVariable("groupId") long groupId, @PathVariable("exp") long exp) {
return groupService.setLevelByGroupId(groupId, exp)
.map(group -> ResponseEntity.ok(group.getLevel()))
.orElseGet(()->ResponseEntity.notFound().build());
.orElseGet(() -> ResponseEntity.notFound().build());
}
/**
* Returns the progress of the level for the group identified by the given ID.
* Returns a ResponseEntity containing the progress of the current level as a percentage, or a 404 Not Found response if no Group with the given ID was found.
*
* @param groupId the ID of the group to query
* @return a ResponseEntity containing the progress of the current level as a percentage, or a 404 Not Found response if no Group with the given ID was found
*/
@GetMapping("/group/{groupId}/progress")
public ResponseEntity<Integer> getProgressOfLevel(@PathVariable("groupId") long groupId){
public ResponseEntity<Integer> getProgressOfLevel(@PathVariable("groupId") long groupId) {
return groupService.getProgressOfLevel(groupId)
.map(ResponseEntity::ok)
.orElseGet(()->ResponseEntity.notFound().build());
.orElseGet(() -> ResponseEntity.notFound().build());
}
}
......@@ -41,5 +41,10 @@ public interface GroupRepository extends JpaRepository<Group, Long> {
*/
Optional<Long> getLevelByGroupId(long id);
/**
* Finds a group by group id
* @param id the id of the group
* @return the group with the given id if it exists
*/
Optional<Group> findByGroupId(long id);
}
......@@ -65,9 +65,16 @@ public class GroupService {
return groupRepository.getLevelByGroupId(id);
}
public Optional<Group> setLevelByGroupId(long id, long exp){
/**
* Sets the level of the group identified by the given ID to the level corresponding to the given experience points.
*
* @param id the ID of the group to update
* @param exp the new experience points of the group
* @return an Optional containing the updated Group, or an empty Optional if no Group with the given ID was found
*/
public Optional<Group> setLevelByGroupId(long id, long exp) {
Optional<Group> answer = groupRepository.findByGroupId(id);
if(answer.isPresent()){
if (answer.isPresent()) {
Group realGroup = answer.get();
realGroup.setPoints(exp);
realGroup.setLevel(LevelUtil.getLevel(exp));
......@@ -76,9 +83,15 @@ public class GroupService {
return Optional.empty();
}
public Optional<Integer> getProgressOfLevel(long id){
/**
* Returns the progress of the level for the group identified by the given ID.
*
* @param id the ID of the group to query
* @return an Optional containing the progress of the current level as a percentage, or an empty Optional if no Group with the given ID was found
*/
public Optional<Integer> getProgressOfLevel(long id) {
Optional<Group> answer = groupRepository.findByGroupId(id);
if(answer.isPresent()){
if (answer.isPresent()) {
Group realGroup = answer.get();
return Optional.of(LevelUtil.getProgressOfLevel(realGroup.getPoints()));
}
......
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