Checkpoint: ownedGroups.contains(groupId) and tests
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
e24938dfce
commit
c7feb10997
@ -3,6 +3,8 @@ package com.plannaplan.controllers;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.plannaplan.App;
|
import com.plannaplan.App;
|
||||||
import com.plannaplan.entities.Assignment;
|
import com.plannaplan.entities.Assignment;
|
||||||
@ -37,12 +39,6 @@ import io.swagger.annotations.ApiOperation;
|
|||||||
@Api(tags = { "Exchange" }, value = "Exchange", description = "Endpoint to exchange with accepted assignments.")
|
@Api(tags = { "Exchange" }, value = "Exchange", description = "Endpoint to exchange with accepted assignments.")
|
||||||
public class ExchangeController extends TokenBasedController{
|
public class ExchangeController extends TokenBasedController{
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Endpoint do wylistowania exchangow użytkownika
|
|
||||||
* Endpoint do usuwania exchanga
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private GroupService groupService;
|
private GroupService groupService;
|
||||||
|
|
||||||
@ -61,6 +57,11 @@ public class ExchangeController extends TokenBasedController{
|
|||||||
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
.orElseThrow(() -> new UserNotFoundException("Invalid token"));
|
||||||
final Long assignmentId = exchangeRequest.get("assignment");
|
final Long assignmentId = exchangeRequest.get("assignment");
|
||||||
final Long groupId = exchangeRequest.get("group");
|
final Long groupId = exchangeRequest.get("group");
|
||||||
|
final List<Long> ownedGroups = asker.getStudentRegisteredGrups().stream().map(Groups::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
if(ownedGroups.contains(groupId)){
|
||||||
|
return new ResponseEntity<>("User has already got this group.", HttpStatus.BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
if(assignmentId == null || groupId == null ){
|
if(assignmentId == null || groupId == null ){
|
||||||
return new ResponseEntity<>("Some of values are missing", HttpStatus.BAD_REQUEST);
|
return new ResponseEntity<>("Some of values are missing", HttpStatus.BAD_REQUEST);
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
package com.plannaplan.controllers;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import javax.validation.constraints.AssertTrue;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
@ContextConfiguration
|
||||||
|
public class ExchangeControllerTest extends AbstractControllerTest{
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldGetAllUsersExchanges(){
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailGettingExchange(){
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailPostDueToExchangeNoFound(){
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldInsertExchange(){
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDenyExchangeDueToAssigmentOverlapping(){
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDenyPostDueToAssignmentNotAccepted(){
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDeleteDueToWrongPermissions(){
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFailDeleteDueToExchangeNoFound(){
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void shouldFailPostDueToGroupAlreadyAccepted(){
|
||||||
|
assertTrue(false);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user