Skip to content

Commit

Permalink
modification and acquisition of sprints now require the context of a …
Browse files Browse the repository at this point in the history
…project and user
  • Loading branch information
Igor Kedzierawski committed Dec 17, 2023
1 parent 495e684 commit ae8572b
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public class SprintControllerImpl implements SprintController {

@Override
@PostMapping(value = ADD_SPRINT)
public SprintResponse addNewSprint(@RequestBody SprintRequest sprintRequest) {
public SprintResponse addNewSprint(@RequestBody SprintRequest sprintRequest, @JwtAuthed User user) {
return sprintService.addNewSprint(sprintRequest.name(), sprintRequest.startDate(),
sprintRequest.endDate(), sprintRequest.description());
sprintRequest.endDate(), sprintRequest.description(), user);
}

@Override
Expand All @@ -51,38 +51,38 @@ public SprintResponse getSprintById(@RequestParam long sprintId, @JwtAuthed User

@Override
@GetMapping(value = GET_SPRINTS_ON_PAGE)
public List<SprintResponse> getSprintsOnPage(@RequestParam int page, @JwtAuthed User user) {
return sprintService.getSprintsOnPage(page, user);
public List<SprintResponse> getSprintsOnPage(@RequestParam int page, @RequestParam long projectId, @JwtAuthed User user) {
return sprintService.getSprintsOnPage(page, projectId, user);
}

@Override
@PatchMapping(value = UPDATE_SPRINTS_NAME)
public SprintResponse updateSprintsName(@RequestParam String name, @RequestParam long sprintId) {
return sprintService.updateSprintsName(name, sprintId);
public SprintResponse updateSprintsName(@RequestParam String name, @RequestParam long sprintId, @JwtAuthed User user) {
return sprintService.updateSprintsName(name, sprintId, user);
}

@Override
@PatchMapping(value = UPDATE_SPRINTS_DESCRIPTION)
public SprintResponse updateSprintsDescription(@RequestParam String description, @RequestParam long sprintId) {
return sprintService.updateSprintsDescription(description, sprintId);
public SprintResponse updateSprintsDescription(@RequestParam String description, @RequestParam long sprintId, @JwtAuthed User user) {
return sprintService.updateSprintsDescription(description, sprintId, user);
}

@Override
@PatchMapping(value = UPDATE_SPRINTS_START_DATE)
public SprintResponse updateSprintsStartDate(@RequestParam LocalDate startDate, @RequestParam long sprintId) {
return sprintService.updateSprintsStartDate(startDate, sprintId);
public SprintResponse updateSprintsStartDate(@RequestParam LocalDate startDate, @RequestParam long sprintId, @JwtAuthed User user) {
return sprintService.updateSprintsStartDate(startDate, sprintId, user);
}

@Override
@PatchMapping(value = UPDATE_SPRINTS_END_DATE)
public SprintResponse updateSprintsEndDate(@RequestParam LocalDate endDate, @RequestParam long sprintId) {
return sprintService.updateSprintsEndDate(endDate, sprintId);
public SprintResponse updateSprintsEndDate(@RequestParam LocalDate endDate, @RequestParam long sprintId, @JwtAuthed User user) {
return sprintService.updateSprintsEndDate(endDate, sprintId, user);
}

@Override
@DeleteMapping(value = DELETE_SPRINT)
public SprintResponse deleteSprint(@RequestParam long sprintId) {
return sprintService.deleteSprint(sprintId);
public SprintResponse deleteSprint(@RequestParam long sprintId, @JwtAuthed User user) {
return sprintService.deleteSprint(sprintId, user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public class SprintServiceImpl implements SprintService {
private final SprintMapper sprintMapper;

@Override
public final SprintResponse addNewSprint(String name, LocalDate startDate, LocalDate endDate, String description) {
public final SprintResponse addNewSprint(String name, LocalDate startDate, LocalDate endDate, String description, User user) {

//auth user

Sprint sprint = Sprint
.builder()
.sprintName(name)
Expand All @@ -50,6 +53,8 @@ public final SprintResponse addNewSprint(String name, LocalDate startDate, Local
public final SprintResponse getSprintById(long sprintId, User user) {
log.info("Getting sprint with id: {} for user: {}", sprintId, user);

//auth user

Sprint sprint = sprintRepository.findById(sprintId)
.orElseThrow(() -> new SprintDoesNotExistException(sprintId));
log.info("Sprint found : {}", sprint);
Expand All @@ -58,20 +63,24 @@ public final SprintResponse getSprintById(long sprintId, User user) {
}

@Override
public final List<SprintResponse> getSprintsOnPage(int page, User user) {
log.info("Getting sprints on page: {} for user: {}", page, user);
public final List<SprintResponse> getSprintsOnPage(int page, long projectId, User user) {
log.info("Getting sprints in project {} on page: {} for user: {}", projectId, page, user);

//auth user

Pageable pageable = PageRequest.of(page, SPRINTS_PER_PAGE);
Page<Sprint> sprints = sprintRepository.findAllByOwnerOrderByName(user, pageable);
Page<Sprint> sprints = sprintRepository.findAllByProjectId(projectId, pageable);
log.info("Sprints found on page : {}", sprints.getTotalElements());

return sprints.map(sprintMapper::toSprintResponse).toList();
}

@Override
public final SprintResponse updateSprintsName(String name, long sprintId) {
public final SprintResponse updateSprintsName(String name, long sprintId, User user) {
log.info("Updating sprint with id: {} name to: {}", sprintId, name);

//auth user

Sprint sprintToUpdate = sprintRepository.findById(sprintId)
.orElseThrow(() -> new SprintDoesNotExistException(sprintId));
log.info("Found sprint to update: {}", sprintToUpdate);
Expand All @@ -84,9 +93,11 @@ public final SprintResponse updateSprintsName(String name, long sprintId) {
}

@Override
public final SprintResponse updateSprintsDescription(String description, long sprintId) {
public final SprintResponse updateSprintsDescription(String description, long sprintId, User user) {
log.info("Updating sprint with id: {} description to: {}", sprintId, description);

//auth user

Sprint sprintToUpdate = sprintRepository.findById(sprintId)
.orElseThrow(() -> new SprintDoesNotExistException(sprintId));
log.info("Found sprint to update: {}", sprintToUpdate);
Expand All @@ -99,9 +110,11 @@ public final SprintResponse updateSprintsDescription(String description, long sp
}

@Override
public final SprintResponse updateSprintsStartDate(LocalDate startDate, long sprintId) {
public final SprintResponse updateSprintsStartDate(LocalDate startDate, long sprintId, User user) {
log.info("Updating sprint with id: {} startDate to: {}", sprintId, startDate);

//auth user

Sprint sprintToUpdate = sprintRepository.findById(sprintId)
.orElseThrow(() -> new SprintDoesNotExistException(sprintId));
log.info("Found sprint to update: {}", sprintToUpdate);
Expand All @@ -118,9 +131,11 @@ public final SprintResponse updateSprintsStartDate(LocalDate startDate, long spr
}

@Override
public final SprintResponse updateSprintsEndDate(LocalDate endDate, long sprintId) {
public final SprintResponse updateSprintsEndDate(LocalDate endDate, long sprintId, User user) {
log.info("Updating sprint with id: {} endDate to: {}", sprintId, endDate);

//auth user

Sprint sprintToUpdate = sprintRepository.findById(sprintId)
.orElseThrow(() -> new SprintDoesNotExistException(sprintId));
log.info("Found sprint to update: {}", sprintToUpdate);
Expand All @@ -137,9 +152,11 @@ public final SprintResponse updateSprintsEndDate(LocalDate endDate, long sprintI
}

@Override
public final SprintResponse deleteSprint(long sprintId) {
public final SprintResponse deleteSprint(long sprintId, User user) {
log.info("Deleting sprint with id: {}", sprintId);

//auth user

Sprint sprintToDelete = sprintRepository.findById(sprintId)
.orElseThrow(() -> new SprintDoesNotExistException(sprintId));
log.info("Found sprint to delete: {}", sprintToDelete);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,28 @@

import dev.corn.cornbackend.api.sprint.data.SprintRequest;
import dev.corn.cornbackend.api.sprint.data.SprintResponse;
import dev.corn.cornbackend.entities.project.Project;
import dev.corn.cornbackend.entities.user.User;

import java.time.LocalDate;
import java.util.List;

public interface SprintController {

SprintResponse addNewSprint(SprintRequest sprintRequest);
SprintResponse addNewSprint(SprintRequest sprintRequest, User user);

SprintResponse getSprintById(long sprintId, User user);

List<SprintResponse> getSprintsOnPage(int page, User user);
List<SprintResponse> getSprintsOnPage(int page, long projectId, User user);

SprintResponse updateSprintsName(String name, long sprintId);
SprintResponse updateSprintsName(String name, long sprintId, User user);

SprintResponse updateSprintsDescription(String description, long sprintId);
SprintResponse updateSprintsDescription(String description, long sprintId, User user);

SprintResponse updateSprintsStartDate(LocalDate startDate, long sprintId);
SprintResponse updateSprintsStartDate(LocalDate startDate, long sprintId, User user);

SprintResponse updateSprintsEndDate(LocalDate endDate, long sprintId);
SprintResponse updateSprintsEndDate(LocalDate endDate, long sprintId, User user);

SprintResponse deleteSprint(long sprintId);
SprintResponse deleteSprint(long sprintId, User user);

}
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package dev.corn.cornbackend.api.sprint.interfaces;

import dev.corn.cornbackend.api.sprint.data.SprintResponse;
import dev.corn.cornbackend.entities.project.Project;
import dev.corn.cornbackend.entities.user.User;

import java.time.LocalDate;
import java.util.List;

public interface SprintService {

SprintResponse addNewSprint(String name, LocalDate startDate, LocalDate endDate, String description);
SprintResponse addNewSprint(String name, LocalDate startDate, LocalDate endDate, String description, User user);

SprintResponse getSprintById(long sprintId, User user);

List<SprintResponse> getSprintsOnPage(int page, User user);
List<SprintResponse> getSprintsOnPage(int page, long projectId, User user);

SprintResponse updateSprintsName(String name, long sprintId);
SprintResponse updateSprintsName(String name, long sprintId, User user);

SprintResponse updateSprintsDescription(String description, long sprintId);
SprintResponse updateSprintsDescription(String description, long sprintId, User user);

SprintResponse updateSprintsStartDate(LocalDate startDate, long sprintId);
SprintResponse updateSprintsStartDate(LocalDate startDate, long sprintId, User user);

SprintResponse updateSprintsEndDate(LocalDate endDate, long sprintId);
SprintResponse updateSprintsEndDate(LocalDate endDate, long sprintId, User user);

SprintResponse deleteSprint(long sprintId);
SprintResponse deleteSprint(long sprintId, User user);

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package dev.corn.cornbackend.entities.sprint.interfaces;

import dev.corn.cornbackend.entities.sprint.Sprint;
import dev.corn.cornbackend.entities.user.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface SprintRepository extends JpaRepository<Sprint, Long> {

Page<Sprint> findAllByOwnerOrderByName(User owner, Pageable pageable);

}
@Query("SELECT s FROM Sprint s WHERE s.project.projectId = ?1")
Page<Sprint> findAllByProjectId(long projectId, Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ final void test_addNewSprint_shouldAddNewSprint() {

// when
when(sprintService.addNewSprint(ADD_SPRINT_DATA.name(), ADD_SPRINT_DATA.startDate(),
ADD_SPRINT_DATA.endDate(), ADD_SPRINT_DATA.description()))
ADD_SPRINT_DATA.endDate(), ADD_SPRINT_DATA.description(), ADD_SPRINT_DATA.project().getOwner()))
.thenReturn(expected);

SprintResponse actual = sprintController.addNewSprint(ADD_SPRINT_DATA.asSprintRequest());
SprintResponse actual = sprintController.addNewSprint(ADD_SPRINT_DATA.asSprintRequest(), ADD_SPRINT_DATA.project().getOwner());

// then
assertEquals(expected, actual, SPRINT_RESPONSE_SHOULD_BE_EQUAL_TO_EXPECTED);
Expand Down Expand Up @@ -70,10 +70,12 @@ final void test_getSprintsOnPage_shouldGetSprints() {
int page = 0;

// when
when(sprintService.getSprintsOnPage(page, ADD_SPRINT_DATA.project().getOwner()))
when(sprintService.getSprintsOnPage(page, ADD_SPRINT_DATA.project().getProjectId(),
ADD_SPRINT_DATA.project().getOwner()))
.thenReturn(expected);

List<SprintResponse> actual = sprintController.getSprintsOnPage(page, ADD_SPRINT_DATA.project().getOwner());
List<SprintResponse> actual = sprintController.getSprintsOnPage(page, ADD_SPRINT_DATA.project().getProjectId(),
ADD_SPRINT_DATA.project().getOwner());

// then
assertEquals(expected, actual, SPRINT_RESPONSE_SHOULD_BE_EQUAL_TO_EXPECTED);
Expand All @@ -85,10 +87,12 @@ final void test_updateSprintsName_shouldUpdateName() {
SprintResponse expected = MAPPER.toSprintResponse(ADD_SPRINT_DATA.asSprint());

// when
when(sprintService.updateSprintsName(ADD_SPRINT_DATA.name(), ADD_SPRINT_DATA.asSprint().getSprintId()))
when(sprintService.updateSprintsName(ADD_SPRINT_DATA.name(),
ADD_SPRINT_DATA.asSprint().getSprintId(), ADD_SPRINT_DATA.project().getOwner()))
.thenReturn(expected);

SprintResponse actual = sprintController.updateSprintsName(ADD_SPRINT_DATA.name(), ADD_SPRINT_DATA.asSprint().getSprintId());
SprintResponse actual = sprintController.updateSprintsName(ADD_SPRINT_DATA.name(),
ADD_SPRINT_DATA.asSprint().getSprintId(), ADD_SPRINT_DATA.project().getOwner());

// then
assertEquals(expected, actual, SPRINT_RESPONSE_SHOULD_BE_EQUAL_TO_EXPECTED);
Expand All @@ -100,10 +104,12 @@ final void test_updateSprintsDescription_shouldUpdateDescription() {
SprintResponse expected = MAPPER.toSprintResponse(ADD_SPRINT_DATA.asSprint());

// when
when(sprintService.updateSprintsDescription(ADD_SPRINT_DATA.description(), ADD_SPRINT_DATA.asSprint().getSprintId()))
when(sprintService.updateSprintsDescription(ADD_SPRINT_DATA.description(),
ADD_SPRINT_DATA.asSprint().getSprintId(), ADD_SPRINT_DATA.project().getOwner()))
.thenReturn(expected);

SprintResponse actual = sprintController.updateSprintsDescription(ADD_SPRINT_DATA.description(), ADD_SPRINT_DATA.asSprint().getSprintId());
SprintResponse actual = sprintController.updateSprintsDescription(ADD_SPRINT_DATA.description(),
ADD_SPRINT_DATA.asSprint().getSprintId(), ADD_SPRINT_DATA.project().getOwner());

// then
assertEquals(expected, actual, SPRINT_RESPONSE_SHOULD_BE_EQUAL_TO_EXPECTED);
Expand All @@ -115,10 +121,12 @@ final void test_updateSprintsStartDate_shouldUpdateStartDate() {
SprintResponse expected = MAPPER.toSprintResponse(ADD_SPRINT_DATA.asSprint());

// when
when(sprintService.updateSprintsStartDate(ADD_SPRINT_DATA.startDate(), ADD_SPRINT_DATA.asSprint().getSprintId()))
when(sprintService.updateSprintsStartDate(ADD_SPRINT_DATA.startDate(),
ADD_SPRINT_DATA.asSprint().getSprintId(), ADD_SPRINT_DATA.project().getOwner()))
.thenReturn(expected);

SprintResponse actual = sprintController.updateSprintsStartDate(ADD_SPRINT_DATA.startDate(), ADD_SPRINT_DATA.asSprint().getSprintId());
SprintResponse actual = sprintController.updateSprintsStartDate(ADD_SPRINT_DATA.startDate(),
ADD_SPRINT_DATA.asSprint().getSprintId(), ADD_SPRINT_DATA.project().getOwner());

// then
assertEquals(expected, actual, SPRINT_RESPONSE_SHOULD_BE_EQUAL_TO_EXPECTED);
Expand All @@ -130,10 +138,12 @@ final void test_updateSprintsEndDate_shouldUpdateEndDate() {
SprintResponse expected = MAPPER.toSprintResponse(ADD_SPRINT_DATA.asSprint());

// when
when(sprintService.updateSprintsEndDate(ADD_SPRINT_DATA.endDate(), ADD_SPRINT_DATA.asSprint().getSprintId()))
when(sprintService.updateSprintsEndDate(ADD_SPRINT_DATA.endDate(),
ADD_SPRINT_DATA.asSprint().getSprintId(), ADD_SPRINT_DATA.project().getOwner()))
.thenReturn(expected);

SprintResponse actual = sprintController.updateSprintsEndDate(ADD_SPRINT_DATA.endDate(), ADD_SPRINT_DATA.asSprint().getSprintId());
SprintResponse actual = sprintController.updateSprintsEndDate(ADD_SPRINT_DATA.endDate(),
ADD_SPRINT_DATA.asSprint().getSprintId(), ADD_SPRINT_DATA.project().getOwner());

// then
assertEquals(expected, actual, SPRINT_RESPONSE_SHOULD_BE_EQUAL_TO_EXPECTED);
Expand All @@ -146,10 +156,10 @@ final void test_deleteSprint_shouldDeleteSprint() {
long sprintId = ADD_SPRINT_DATA.asSprint().getSprintId();

// when
when(sprintService.deleteSprint(sprintId))
when(sprintService.deleteSprint(sprintId, ADD_SPRINT_DATA.project().getOwner()))
.thenReturn(expected);

SprintResponse actual = sprintController.deleteSprint(sprintId);
SprintResponse actual = sprintController.deleteSprint(sprintId, ADD_SPRINT_DATA.project().getOwner());

// then
assertEquals(expected, actual, SPRINT_RESPONSE_SHOULD_BE_EQUAL_TO_EXPECTED);
Expand Down
Loading

0 comments on commit ae8572b

Please sign in to comment.