Skip to content

Commit

Permalink
Merge pull request #89 from szymonpoltorak/devel
Browse files Browse the repository at this point in the history
Sprint 9 - update
  • Loading branch information
szymonpoltorak authored Apr 7, 2024
2 parents 67d5596 + 7f6f930 commit cb49bd6
Show file tree
Hide file tree
Showing 67 changed files with 1,638 additions and 651 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_ADD_MAPPING;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_API_MAPPING;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_DELETE_MAPPING;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_GET_ALL_WITHOUT_SPRINT_MAPPING;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_GET_BY_PROJECT_MAPPING;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_GET_BY_SPRINT_MAPPING;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_GET_DETAILS_MAPPING;
Expand Down Expand Up @@ -67,9 +66,12 @@ public final BacklogItemResponse create(@RequestBody BacklogItemRequest backlogI

@Override
@GetMapping(BACKLOG_ITEM_GET_BY_SPRINT_MAPPING)
public final List<BacklogItemResponse> getBySprintId(@RequestParam long sprintId,
public final BacklogItemResponseList getBySprintId(@RequestParam long sprintId,
@RequestParam int pageNumber,
@RequestParam String sortBy,
@RequestParam String order,
@JwtAuthed User user) {
return backlogItemService.getBySprintId(sprintId, user);
return backlogItemService.getBySprintId(sprintId, pageNumber, sortBy, order, user);
}

@Override
Expand All @@ -88,4 +90,13 @@ public final BacklogItemDetails getDetailsById(@RequestParam long id,
@JwtAuthed User user) {
return backlogItemService.getDetailsById(id, user);
}
@Override
@GetMapping(BACKLOG_ITEM_GET_ALL_WITHOUT_SPRINT_MAPPING)
public final BacklogItemResponseList getAllWithoutSprint(@RequestParam long projectId,
@RequestParam int pageNumber,
@RequestParam String sortBy,
@RequestParam String order,
@JwtAuthed User user) {
return backlogItemService.getAllWithoutSprint(projectId, pageNumber, sortBy, order, user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.BACKLOG_ITEM;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.BACKLOG_ITEM_NOT_FOUND_MESSAGE;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.BACKLOG_ITEM_PAGE_SIZE;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.CREATING_PAGEABLE_FOR;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.GETTING_BACKLOG_ITEMS_WITH_PAGEABLE;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.GETTING_BY_ID;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.GETTING_BY_PROJECT;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.PROJECT;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.PROJECT_MEMBER;
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemServiceConstants.PROJECT_MEMBER_NOT_FOUND_MESSAGE;
Expand Down Expand Up @@ -132,55 +133,42 @@ public BacklogItemResponse create(BacklogItemRequest backlogItemRequest, User us
}

@Override
public List<BacklogItemResponse> getBySprintId(long sprintId, User user) {
public BacklogItemResponseList getBySprintId(long sprintId, int pageNumber, String sortBy, String order, User user) {
Pageable pageable = createPageableForBacklogItems(pageNumber, sortBy, order);

log.info(GETTING_BY_ID, SPRINT, sprintId);

Sprint sprint = sprintRepository.findByIdWithProjectMember(sprintId, user)
.orElseThrow(() -> new SprintNotFoundException(SPRINT_NOT_FOUND_MESSAGE));

log.info("Getting backlog items for sprint: {}", sprint);

List<BacklogItem> items = backlogItemRepository.getBySprint(sprint);
log.info(GETTING_BACKLOG_ITEMS_WITH_PAGEABLE, SPRINT, sprint, pageable);
Page<BacklogItem> items = backlogItemRepository.getBySprint(sprint, pageable);

log.info(RETURNING_BACKLOG_ITEMS_OF_QUANTITY, items.size());
log.info(RETURNING_BACKLOG_ITEMS_OF_QUANTITY, items.getNumberOfElements());

return items.stream()
.map(backlogItemMapper::backlogItemToBacklogItemResponse)
.toList();
return BacklogItemResponseList.builder()
.backlogItemResponseList(items.stream()
.map(backlogItemMapper::backlogItemToBacklogItemResponse)
.toList())
.totalNumber(items.getTotalElements())
.build();
}

@Override
public BacklogItemResponseList getByProjectId(long projectId, int pageNumber, String sortBy,
String order, User user) {
if(pageNumber < 0) {
throw new WrongPageNumberException(pageNumber);
}
String order, User user) {
Pageable pageable = createPageableForBacklogItems(pageNumber, sortBy, order);

BacklogItemSortBy sort = BacklogItemSortBy.of(sortBy);
Sort.Direction direction = Sort.Direction.DESC.name().equalsIgnoreCase(order) ?
Sort.Direction.DESC : Sort.DEFAULT_DIRECTION;

return getByProjectId(projectId, pageNumber, sort, direction, user);
}

private BacklogItemResponseList getByProjectId(long projectId, int pageNumber, BacklogItemSortBy sortBy,
Sort.Direction order, User user) {
log.info(GETTING_BY_ID, PROJECT, projectId);

Project project = projectRepository.findByIdWithProjectMember(projectId, user)
.orElseThrow(() -> new ProjectDoesNotExistException(PROJECT_NOT_FOUND_MESSAGE));

Pageable pageRequest;

if(sortBy == BacklogItemSortBy.ASSIGNEE) {
pageRequest = getPageableForAssignee(pageNumber, order);
} else {
pageRequest = PageRequest.of(pageNumber, BACKLOG_ITEM_PAGE_SIZE, Sort.by(order,
sortBy.getValue()));
}
log.info(GETTING_BACKLOG_ITEMS_WITH_PAGEABLE, PROJECT, project, pageable);
Page<BacklogItem> items = backlogItemRepository.getByProject(project, pageable);

log.info(GETTING_BY_PROJECT, project, sortBy.getValue(), order);
Page<BacklogItem> items = backlogItemRepository.getByProject(project, pageRequest);
log.info(RETURNING_BACKLOG_ITEMS_OF_QUANTITY, items.getNumberOfElements());

return BacklogItemResponseList.builder()
.backlogItemResponseList(items.stream()
Expand All @@ -202,6 +190,30 @@ public BacklogItemDetails getDetailsById(long id, User user) {
return backlogItemMapper.backlogItemToBacklogItemDetails(backlogItem);
}

@Override
public BacklogItemResponseList getAllWithoutSprint(long projectId, int pageNumber, String sortBy,
String order, User user) {
Pageable pageable = createPageableForBacklogItems(pageNumber, sortBy, order);

log.info(GETTING_BY_ID, PROJECT, projectId);

Project project = projectRepository.findByIdWithProjectMember(projectId, user)
.orElseThrow(() -> new ProjectDoesNotExistException(PROJECT_NOT_FOUND_MESSAGE));

log.info("Getting backlog items that aren't assigned to any sprint for project: {}, pageable: {}",
project, pageable);
Page<BacklogItem> items = backlogItemRepository.findByProjectAndSprintIsNull(project, pageable);

log.info(RETURNING_BACKLOG_ITEMS_OF_QUANTITY, items.getNumberOfElements());

return BacklogItemResponseList.builder()
.backlogItemResponseList(items.stream()
.map(backlogItemMapper::backlogItemToBacklogItemResponse)
.toList())
.totalNumber(items.getTotalElements())
.build();
}

private record BacklogItemBuilderDto(Sprint sprint, Project project, ProjectMember assignee) {
}

Expand All @@ -211,15 +223,23 @@ private BacklogItemBuilderDto prepareDataForBacklogItemCreation(BacklogItemReque
Project project = projectRepository.findByIdWithProjectMember(backlogItemRequest.projectId(), user)
.orElseThrow(() -> new ProjectDoesNotExistException(PROJECT_NOT_FOUND_MESSAGE));

log.info(GETTING_BY_ID, PROJECT_MEMBER, backlogItemRequest.projectMemberId());
ProjectMember assignee = null;

ProjectMember assignee = projectMemberRepository.findByProjectMemberIdAndProject(backlogItemRequest.projectMemberId(), project)
.orElseThrow(() -> new ProjectMemberDoesNotExistException(PROJECT_MEMBER_NOT_FOUND_MESSAGE));
if(backlogItemRequest.projectMemberId() != -1L) {
log.info(GETTING_BY_ID, PROJECT_MEMBER, backlogItemRequest.projectMemberId());

log.info(GETTING_BY_ID, SPRINT, backlogItemRequest.sprintId());
assignee = projectMemberRepository.findByProjectMemberIdAndProject(backlogItemRequest.projectMemberId(), project)
.orElseThrow(() -> new ProjectMemberDoesNotExistException(PROJECT_MEMBER_NOT_FOUND_MESSAGE));
}

Sprint sprint = sprintRepository.findBySprintIdAndProject(backlogItemRequest.sprintId(), project)
.orElseThrow(() -> new SprintNotFoundException(SPRINT_NOT_FOUND_MESSAGE));
Sprint sprint = null;

if(backlogItemRequest.sprintId() != -1L) {
log.info(GETTING_BY_ID, SPRINT, backlogItemRequest.sprintId());

sprint = sprintRepository.findBySprintIdAndProject(backlogItemRequest.sprintId(), project)
.orElseThrow(() -> new SprintNotFoundException(SPRINT_NOT_FOUND_MESSAGE));
}

return new BacklogItemBuilderDto(sprint, project, assignee);
}
Expand Down Expand Up @@ -270,4 +290,25 @@ private Pageable getPageableForAssignee(int pageNumber, Sort.Direction direction
return PageRequest.of(pageNumber, BACKLOG_ITEM_PAGE_SIZE, sorting);

}

private Pageable createPageableForBacklogItems(int pageNumber, String sortBy, String order) {
log.info(CREATING_PAGEABLE_FOR, pageNumber, sortBy, order);
if(pageNumber < 0) {
throw new WrongPageNumberException(pageNumber);
}

BacklogItemSortBy sort = BacklogItemSortBy.of(sortBy);
Sort.Direction direction = Sort.Direction.DESC.name().equalsIgnoreCase(order) ?
Sort.Direction.DESC : Sort.DEFAULT_DIRECTION;
Pageable pageable;

if(sort == BacklogItemSortBy.ASSIGNEE) {
pageable = getPageableForAssignee(pageNumber, direction);
} else {
pageable = PageRequest.of(pageNumber, BACKLOG_ITEM_PAGE_SIZE, Sort.by(direction, sort.getValue()));
}

log.info("Returning pageable: {}", pageable);
return pageable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class BacklogItemMappings {

public static final String BACKLOG_ITEM_GET_DETAILS_MAPPING = "/getDetails";

public static final String BACKLOG_ITEM_GET_ALL_WITHOUT_SPRINT_MAPPING = "/getAllWithoutSprint";

private BacklogItemMappings() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public final class BacklogItemServiceConstants {
public static final String PROJECT = "Project";
public static final String RETURNING_BACKLOG_ITEMS_OF_QUANTITY = "Returning backlog items of quantity: {}";
public static final String SAVING_AND_RETURNING_RESPONSE_OF = "Saving and returning response of: {}";
public static final String GETTING_BY_PROJECT = "Getting backlog items for project: {}, sorting by: {}, order: {}";
public static final String GETTING_BACKLOG_ITEMS_WITH_PAGEABLE = "Getting backlog items for {}: {}, pageable: {}";
public static final String CREATING_PAGEABLE_FOR = "Creating pageable for pageNumber: {}, sortBy: {}, order{}";

public static final int BACKLOG_ITEM_PAGE_SIZE = 30;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import dev.corn.cornbackend.api.backlog.item.data.BacklogItemResponseList;
import dev.corn.cornbackend.entities.user.User;

import java.util.List;

/**
* Interface for the BacklogItemController
*/
Expand Down Expand Up @@ -50,19 +48,24 @@ public interface BacklogItemController {
BacklogItemResponse create(BacklogItemRequest backlogItemRequest, User user);

/**
* Get backlog items by sprint id on given page
* Get backlog items by sprint id on given page and sort by given field in given order
*
* @param sprintId id of the sprint
* @param pageNumber number of page
* @param sortBy name of field to sort backlog items by
* @param order order of sort ("ASC" or "DESC")
* @param user user to get the backlog items for
* @return the backlog items
*/
List<BacklogItemResponse> getBySprintId(long sprintId, User user);
BacklogItemResponseList getBySprintId(long sprintId, int pageNumber, String sortBy, String order, User user);

/**
* Get backlog items by project id
* Get backlog items by project id on given page and sort by given field in given order
*
* @param projectId id of the project
* @param pageNumber number of page
* @param sortBy name of field to sort backlog items by
* @param order order of sort ("ASC" or "DESC")
* @param user user to get the backlog items for
* @return the backlog items
*/
Expand All @@ -76,4 +79,16 @@ public interface BacklogItemController {
* @return the backlog item details
*/
BacklogItemDetails getDetailsById(long id, User user);

/**
* Get all backlog items that aren't assigned to any sprint
* @param projectId id of the project
* @param pageNumber number of page
* @param sortBy name of field to sort backlog items by
* @param order order of sort ("ASC" or "DESC")
* @param user user to get the backlog items for
* @return the backlog items
*/

BacklogItemResponseList getAllWithoutSprint(long projectId, int pageNumber, String sortBy, String order, User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import dev.corn.cornbackend.api.backlog.item.data.BacklogItemResponseList;
import dev.corn.cornbackend.entities.user.User;

import java.util.List;

/**
* Service for backlog items
*/
Expand Down Expand Up @@ -56,7 +54,7 @@ public interface BacklogItemService {
* @param sprintId id of the sprint
* @return response with the list of backlog items
*/
List<BacklogItemResponse> getBySprintId(long sprintId, User user);
BacklogItemResponseList getBySprintId(long sprintId, int pageNumber, String sortBy, String order, User user);

/**
* Get all backlog items by project id
Expand All @@ -75,4 +73,6 @@ public interface BacklogItemService {
* @return response with the backlog item details
*/
BacklogItemDetails getDetailsById(long id, User user);

BacklogItemResponseList getAllWithoutSprint(long projectId, int pageNumber, String sortBy, String order, User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;

import static dev.corn.cornbackend.api.sprint.constants.SprintMappings.ADD_SPRINT;
import static dev.corn.cornbackend.api.sprint.constants.SprintMappings.CURRENT_AND_FUTURE_SPRINTS;
import static dev.corn.cornbackend.api.sprint.constants.SprintMappings.DELETE_SPRINT;
import static dev.corn.cornbackend.api.sprint.constants.SprintMappings.GET_SPRINTS_ON_PAGE;
import static dev.corn.cornbackend.api.sprint.constants.SprintMappings.GET_SPRINT_BY_ID;
Expand Down Expand Up @@ -90,4 +91,11 @@ public final SprintResponse updateSprintsEndDate(@RequestParam LocalDate endDate
public final SprintResponse deleteSprint(@RequestParam long sprintId, @JwtAuthed User user) {
return sprintService.deleteSprint(sprintId, user);
}

@Override
@GetMapping(value = CURRENT_AND_FUTURE_SPRINTS)
public List<SprintResponse> getCurrentAndFutureSprints(@RequestParam long projectId,
@JwtAuthed User user) {
return sprintService.getCurrentAndFutureSprints(projectId, user);
}
}
Loading

0 comments on commit cb49bd6

Please sign in to comment.