Skip to content

Commit 504ee62

Browse files
Cleaning repo
1 parent bdd11bd commit 504ee62

File tree

1 file changed

+44
-22
lines changed
  • src/main/java/com/apporelbotna/gameserver/persistencewsclient

1 file changed

+44
-22
lines changed

src/main/java/com/apporelbotna/gameserver/persistencewsclient/GameDAO.java

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,67 +16,84 @@
1616
import com.apporelbotna.gameserver.stubs.User;
1717
import com.apporelbotna.gameserver.stubs.UserWrapper;
1818

19-
public class GameDAO {
19+
public class GameDAO
20+
{
2021
public static final String SERVER_URL = "http://localhost:8082/";
2122
RestTemplate restTemplate = new RestTemplate();
2223

23-
public GameDAO() {
24+
public GameDAO()
25+
{
2426

2527
}
2628

27-
public boolean finishMatch(Match... matches) {
29+
public boolean finishMatch(Match... matches)
30+
{
2831

29-
for (Match match : matches) {
30-
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/match", match, null);
31-
if (!response.getStatusCode().equals(HttpStatus.CREATED)) {
32+
for (Match match : matches)
33+
{
34+
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/match", match,
35+
null);
36+
if (!response.getStatusCode().equals(HttpStatus.CREATED))
37+
{
3238
return false;
3339
}
3440
}
3541

3642
return true;
3743
}
3844

39-
public boolean isUserLoggeable(String email, String tokenString) {
45+
public boolean isUserLoggeable(String email, String tokenString)
46+
{
4047

4148
UserWrapper wrapper = new UserWrapper(new User(email), new Token(tokenString));
4249

43-
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/auth", wrapper, null);
50+
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/auth", wrapper,
51+
null);
4452

4553
return (response.getStatusCode().equals(HttpStatus.OK));
4654
}
4755

48-
public User validateUser(String email, String tokenString) {
56+
public User validateUser(String email, String tokenString)
57+
{
4958
return isUserLoggeable(email, tokenString) ? getUserInformation(email) : null;
5059
}
5160

52-
public Token login(String email, String password) {
61+
public Token login(String email, String password)
62+
{
5363

5464
RestTemplate restTemplate = new RestTemplate();
55-
return restTemplate.getForObject(SERVER_URL + "/login/" + email + "/" + password, Token.class);
65+
return restTemplate.getForObject(SERVER_URL + "/login/" + email + "/" + password,
66+
Token.class);
5667
}
5768

5869
// saca todos los juegos de un usuario
59-
public List<Game> findAllGamesByUser(User user) {
70+
public List<Game> findAllGamesByUser(User user)
71+
{
6072
String userEmail = user.getId();
6173

6274
RestTemplate restTemplate = new RestTemplate();
6375

64-
ResponseEntity<List<Game>> responseWS = restTemplate.exchange(SERVER_URL + "/user/game/" + userEmail,
65-
HttpMethod.GET, null, new ParameterizedTypeReference<List<Game>>() {
76+
ResponseEntity<List<Game>> responseWS = restTemplate.exchange(
77+
SERVER_URL + "/user/game/" + userEmail, HttpMethod.GET, null,
78+
new ParameterizedTypeReference<List<Game>>()
79+
{
6680
});
6781

6882
return responseWS.getBody();
6983
}
7084

71-
public boolean createUser(User user, String password) {
85+
public boolean createUser(User user, String password)
86+
{
7287
RegisterUser userToRegister = new RegisterUser(user, password);
7388

74-
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/user/", userToRegister, null);
89+
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/user/",
90+
userToRegister, null);
7591

7692
return (response.getStatusCode().equals(HttpStatus.CREATED));
7793
}
7894

79-
public User getUserInformation(String email) {
95+
public User getUserInformation(String email)
96+
{
8097
return restTemplate.getForObject(SERVER_URL + "/user/" + email, User.class);
8198
}
8299

@@ -86,14 +103,19 @@ public User getUserInformation(String email) {
86103
* @param gameID
87104
* @return time in miliseconds
88105
*/
89-
public float gameTimePlayedByGame(String email, int gameID) {
90-
return restTemplate.getForObject(SERVER_URL + "/user/" + email + "/game/" + gameID + "/time/", Float.class);
106+
public float gameTimePlayedByGame(String email, int gameID)
107+
{
108+
return restTemplate.getForObject(
109+
SERVER_URL + "/user/" + email + "/game/" + gameID + "/time/", Float.class);
91110
}
92111

93-
public List<RankingPointsTO> getRankingPointsByGameAndUser(int gameId) {
112+
public List<RankingPointsTO> getRankingPointsByGameAndUser(int gameId)
113+
{
94114

95-
ResponseEntity<List<RankingPointsTO>> responseWS = restTemplate.exchange(SERVER_URL + "/ranking/" + gameId,
96-
HttpMethod.GET, null, new ParameterizedTypeReference<List<RankingPointsTO>>() {
115+
ResponseEntity<List<RankingPointsTO>> responseWS = restTemplate.exchange(
116+
SERVER_URL + "/ranking/" + gameId, HttpMethod.GET, null,
117+
new ParameterizedTypeReference<List<RankingPointsTO>>()
118+
{
97119
});
98120

99121
return responseWS.getBody();

0 commit comments

Comments
 (0)