16
16
import com .apporelbotna .gameserver .stubs .User ;
17
17
import com .apporelbotna .gameserver .stubs .UserWrapper ;
18
18
19
- public class GameDAO {
19
+ public class GameDAO
20
+ {
20
21
public static final String SERVER_URL = "http://localhost:8082/" ;
21
22
RestTemplate restTemplate = new RestTemplate ();
22
23
23
- public GameDAO () {
24
+ public GameDAO ()
25
+ {
24
26
25
27
}
26
28
27
- public boolean finishMatch (Match ... matches ) {
29
+ public boolean finishMatch (Match ... matches )
30
+ {
28
31
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
+ {
32
38
return false ;
33
39
}
34
40
}
35
41
36
42
return true ;
37
43
}
38
44
39
- public boolean isUserLoggeable (String email , String tokenString ) {
45
+ public boolean isUserLoggeable (String email , String tokenString )
46
+ {
40
47
41
48
UserWrapper wrapper = new UserWrapper (new User (email ), new Token (tokenString ));
42
49
43
- ResponseEntity <?> response = restTemplate .postForEntity (SERVER_URL + "/auth" , wrapper , null );
50
+ ResponseEntity <?> response = restTemplate .postForEntity (SERVER_URL + "/auth" , wrapper ,
51
+ null );
44
52
45
53
return (response .getStatusCode ().equals (HttpStatus .OK ));
46
54
}
47
55
48
- public User validateUser (String email , String tokenString ) {
56
+ public User validateUser (String email , String tokenString )
57
+ {
49
58
return isUserLoggeable (email , tokenString ) ? getUserInformation (email ) : null ;
50
59
}
51
60
52
- public Token login (String email , String password ) {
61
+ public Token login (String email , String password )
62
+ {
53
63
54
64
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 );
56
67
}
57
68
58
69
// saca todos los juegos de un usuario
59
- public List <Game > findAllGamesByUser (User user ) {
70
+ public List <Game > findAllGamesByUser (User user )
71
+ {
60
72
String userEmail = user .getId ();
61
73
62
74
RestTemplate restTemplate = new RestTemplate ();
63
75
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
+ {
66
80
});
67
81
68
82
return responseWS .getBody ();
69
83
}
70
84
71
- public boolean createUser (User user , String password ) {
85
+ public boolean createUser (User user , String password )
86
+ {
72
87
RegisterUser userToRegister = new RegisterUser (user , password );
73
88
74
- ResponseEntity <?> response = restTemplate .postForEntity (SERVER_URL + "/user/" , userToRegister , null );
89
+ ResponseEntity <?> response = restTemplate .postForEntity (SERVER_URL + "/user/" ,
90
+ userToRegister , null );
75
91
76
92
return (response .getStatusCode ().equals (HttpStatus .CREATED ));
77
93
}
78
94
79
- public User getUserInformation (String email ) {
95
+ public User getUserInformation (String email )
96
+ {
80
97
return restTemplate .getForObject (SERVER_URL + "/user/" + email , User .class );
81
98
}
82
99
@@ -86,14 +103,19 @@ public User getUserInformation(String email) {
86
103
* @param gameID
87
104
* @return time in miliseconds
88
105
*/
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 );
91
110
}
92
111
93
- public List <RankingPointsTO > getRankingPointsByGameAndUser (int gameId ) {
112
+ public List <RankingPointsTO > getRankingPointsByGameAndUser (int gameId )
113
+ {
94
114
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
+ {
97
119
});
98
120
99
121
return responseWS .getBody ();
0 commit comments