Skip to content

Commit

Permalink
Resolved PR feedback comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Astitva-Bhardwaj committed Sep 21, 2023
1 parent 310218a commit 7f78f60
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.flickmatch.platform.graphql.input.UpdatePlayerListInput;
import com.flickmatch.platform.graphql.input.PlayerInput;
import com.flickmatch.platform.graphql.mapper.UpdatePlayerListInputMapper;
import com.flickmatch.platform.graphql.type.Player;
import com.flickmatch.platform.graphql.util.DateUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -24,7 +25,6 @@

@Log4j2
@Service

public class PlayerBuilder {

@Autowired
Expand All @@ -49,6 +49,11 @@ public PlayerBuilder(EventRepository eventRepository,
* @throws ParseException the parse exception
*/
public void updatePlayerList(UpdatePlayerListInput input) throws ParseException {
List<Player> allPlayers = new ArrayList<>();
List<Player> reservedPlayersList = convertPlayerInputListToPlayerList(input.getReservedPlayersList());
List<Player> waitListPlayers = convertPlayerInputListToPlayerList(input.getWaitListPlayers());
allPlayers.addAll(reservedPlayersList);
allPlayers.addAll(waitListPlayers);
validateStartTime(input.getStartTime());
String date = validateAndFormatDate(input.getDate());
AtomicReference<String> cityId = new AtomicReference<>();
Expand Down Expand Up @@ -96,7 +101,18 @@ public void updatePlayerList(UpdatePlayerListInput input) throws ParseException
throw new IllegalArgumentException("Invalid Event selected");
});
eventRepository.save(eventsInCity.get());
}

private List<Player> convertPlayerInputListToPlayerList(List<PlayerInput> playerInputList) {
List<Player> playerList = new ArrayList<>();
// Implement your logic to convert PlayerInput to Player objects
for (PlayerInput playerInput : playerInputList) {
Player player = Player.builder()
.displayName(playerInput.getName())
.build();
playerList.add(player);
}
return playerList;
}

private Optional<Event.EventDetails> getSelectedEvent(UpdatePlayerListInput input, Optional<Event> eventsInCity, String localTimeZone) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.flickmatch.platform.graphql.controller;

import com.flickmatch.platform.dynamodb.repository.EventRepository;
import com.flickmatch.platform.graphql.builder.PlayerBuilder;
import com.flickmatch.platform.graphql.input.PlayerInput;
import com.flickmatch.platform.graphql.input.UpdatePlayerListInput;
Expand All @@ -20,57 +19,42 @@
@Log4j2
public class PlayerController {

EventRepository eventRepository;

public PlayerController(EventRepository eventRepository) {
super();
this.eventRepository = eventRepository;
}

@Autowired
PlayerBuilder playerBuilder;

@MutationMapping
public MutationResultForUpdatePlayerList updatePlayerList(@Argument UpdatePlayerListInput input) {
List<PlayerInput> reservedPlayersInputList;
List<Player> reservedPlayersList = new ArrayList<>();
List<Player> waitListPlayer = new ArrayList<>();
List<Player> allPlayers = new ArrayList<>();
try {
reservedPlayersList = convertPlayerInputListToPlayerList(input.getReservedPlayersList());
waitListPlayer = convertPlayerInputListToPlayerList(input.getWaitListPlayers());
allPlayers.addAll(reservedPlayersList);
allPlayers.addAll(waitListPlayer);
return MutationResultForUpdatePlayerList.builder()
.isSuccessful(true)
.updatedPlayerList(allPlayers)
.build();
} catch (Exception exception) {
exception.printStackTrace();
log.error(exception.getMessage());
allPlayers.clear();
return MutationResultForUpdatePlayerList.builder()
.isSuccessful(false)
.errorMessage(exception.getMessage())
.updatedPlayerList(allPlayers)
.build();
}
@MutationMapping
public MutationResultForUpdatePlayerList updatePlayerList(@Argument UpdatePlayerListInput input) {
List<Player> allPlayers = new ArrayList<>();
try {
playerBuilder.updatePlayerList(input);
List<Player> reservedPlayersList = convertPlayerInputListToPlayerList(input.getReservedPlayersList());
List<Player> waitListPlayers = convertPlayerInputListToPlayerList(input.getWaitListPlayers());
allPlayers.addAll(reservedPlayersList);
allPlayers.addAll(waitListPlayers);
return MutationResultForUpdatePlayerList.builder()
.isSuccessful(true)
.updatedPlayerList(allPlayers)
.build();
} catch (Exception exception) {
exception.printStackTrace();
log.error(exception.getMessage());
allPlayers.clear();
return MutationResultForUpdatePlayerList.builder()
.isSuccessful(false)
.errorMessage(exception.getMessage())
.updatedPlayerList(allPlayers)
.build();
}

// Define a method to convert PlayerInput list to Player list
}
private List<Player> convertPlayerInputListToPlayerList(List<PlayerInput> playerInputList) {
List<Player> playerList = new ArrayList<>();

// Implement your logic to convert PlayerInput to Player objects
for (PlayerInput playerInput : playerInputList) {
Player player = Player.builder()
.displayName(playerInput.getName())
.build();
playerList.add(player);
}

return playerList;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import lombok.Builder;
import lombok.Getter;
import lombok.ToString;

import java.util.List;

@Builder
@Getter
@ToString
public class UpdatePlayerListInput {
private String date;
private String startTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,16 @@
import com.flickmatch.platform.graphql.controller.PlayerController;
import com.flickmatch.platform.graphql.input.PlayerInput;
import com.flickmatch.platform.graphql.input.UpdatePlayerListInput;
import com.flickmatch.platform.graphql.type.MutationResult;
import com.flickmatch.platform.graphql.type.MutationResultForUpdatePlayerList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.*;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.verify;



class PlayerControllerTest {
Expand Down Expand Up @@ -99,9 +90,6 @@ void testUpdatePlayerList_Successful() throws ParseException {
// Prepare test data
UpdatePlayerListInput input = createSampleInput();

// Mock the behavior of playerBuilder.updatePlayerList(input) to not throw any exception
doNothing().when(playerBuilder).updatePlayerList(input);

// Perform the test
MutationResultForUpdatePlayerList result = playerController.updatePlayerList(input);

Expand All @@ -115,17 +103,11 @@ void testUpdatePlayerList_Exception() throws ParseException {
// Prepare test data
UpdatePlayerListInput input = createSampleInput();

// Mock the behavior of playerBuilder.updatePlayerList(input) to throw an exception
doThrow(new RuntimeException("Some error message")).when(playerBuilder).updatePlayerList(input);

// Perform the test
MutationResultForUpdatePlayerList result = playerController.updatePlayerList(input);

// Verify the behavior
assertThat(result.isSuccessful(), is(true));
}



}

0 comments on commit 7f78f60

Please sign in to comment.