Skip to content

Commit 1a23ba8

Browse files
test
1 parent 8c34994 commit 1a23ba8

File tree

2 files changed

+80
-47
lines changed

2 files changed

+80
-47
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies {
3030
compile 'org.springframework.hateoas:spring-hateoas:0.24.0.RELEASE'
3131

3232
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
33-
compileOnly group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.0.RELEASE'
33+
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.0.RELEASE'
3434

3535
// PersistenceWS Stubs
3636
compile 'com.github.java-game-server:stubs:1.0.2'

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

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

19-
public class GameDAO
20-
{
21-
public static final String SERVER_URL = "http://172.16.2.94:8082/";
19+
public class GameDAO {
20+
public static final String SERVER_URL = "http://172.16.2.94:8082/";
21+
// public static final String SERVER_URL = "http://localhost:8082/";
2222
RestTemplate restTemplate = new RestTemplate();
2323

24-
public GameDAO()
25-
{
24+
public GameDAO() {
2625

2726
}
2827

29-
public boolean finishMatch(Match... matches)
30-
{
28+
public boolean finishMatch(Match... matches) {
3129

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-
{
30+
for (Match match : matches) {
31+
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/match", match, null);
32+
if (!response.getStatusCode().equals(HttpStatus.CREATED)) {
3833
return false;
3934
}
4035
}
4136

4237
return true;
4338
}
4439

45-
public boolean isUserLoggeable(String email, String tokenString)
46-
{
40+
public boolean isUserLoggeable(String email, String tokenString) {
4741

4842
UserWrapper wrapper = new UserWrapper(new User(email), new Token(tokenString));
4943

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

5346
return (response.getStatusCode().equals(HttpStatus.OK));
5447
}
5548

56-
public User validateUser(String email, String tokenString)
57-
{
49+
public User validateUser(String email, String tokenString) {
5850
return isUserLoggeable(email, tokenString) ? getUserInformation(email) : null;
5951
}
6052

61-
public Token login(String email, String password)
62-
{
53+
public Token login(String email, String password) {
6354

6455
RestTemplate restTemplate = new RestTemplate();
65-
return restTemplate.getForObject(SERVER_URL + "/login/" + email + "/" + password,
66-
Token.class);
56+
return restTemplate.getForObject(SERVER_URL + "/login/" + email + "/" + password, Token.class);
6757
}
6858

6959
// saca todos los juegos de un usuario
70-
public List<Game> findAllGamesByUser(User user)
71-
{
60+
public List<Game> findAllGamesByUser(User user) {
7261
String userEmail = user.getId();
7362

7463
RestTemplate restTemplate = new RestTemplate();
7564

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

8269
return responseWS.getBody();
8370
}
8471

85-
public boolean createUser(User user, String password)
86-
{
72+
public boolean createUser(User user, String password) {
8773
RegisterUser userToRegister = new RegisterUser(user, password);
8874

89-
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/user/",
90-
userToRegister, null);
75+
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/user/", userToRegister, null);
76+
77+
if (response.getStatusCode().equals(HttpStatus.CREATED)) {
78+
return true;
79+
}
80+
return false;
9181

92-
return (response.getStatusCode().equals(HttpStatus.CREATED));
9382
}
9483

95-
public User getUserInformation(String email)
96-
{
84+
public User getUserInformation(String email) {
9785
return restTemplate.getForObject(SERVER_URL + "/user/" + email, User.class);
9886
}
9987

@@ -103,22 +91,67 @@ public User getUserInformation(String email)
10391
* @param gameID
10492
* @return time in miliseconds
10593
*/
106-
public float gameTimePlayedByGame(String email, int gameID)
107-
{
108-
return restTemplate.getForObject(
109-
SERVER_URL + "/user/" + email + "/game/" + gameID + "/time/", Float.class);
94+
public float gameTimePlayedByGame(String email, int gameID) {
95+
return restTemplate.getForObject(SERVER_URL + "/user/" + email + "/game/" + gameID + "/time/", Float.class);
11096
}
11197

112-
public List<RankingPointsTO> getRankingPointsByGameAndUser(int gameId)
113-
{
98+
public List<RankingPointsTO> getRankingPointsByGameAndUser(int gameId) {
11499

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

121104
return responseWS.getBody();
122105
}
123106

107+
public static void main(String[] args) {
108+
GameDAO dao = new GameDAO();
109+
110+
// Creating User
111+
// User user = new User("[email protected]", "rai");
112+
// String password = "1234";
113+
//
114+
// System.out.println(dao.createUser(user, password));
115+
116+
// Testing log in
117+
118+
String email = "[email protected]";
119+
String password = "1234";
120+
Token token = dao.login(email, password);
121+
System.out.println(token);
122+
123+
// Find all games by username
124+
// List<Game> games = dao.findAllGamesByUser(new User("[email protected]", "pp"));
125+
// for (Game game : games)
126+
// {
127+
// System.out.println(game);
128+
// }
129+
130+
// TEST USER INFORMATION
131+
132+
// User userInformatiton = dao.getUserInformation("[email protected]");
133+
// System.out.println(userInformatiton);
134+
135+
// GET TIME PLAYED IN GAME
136+
// String email = "[email protected]";
137+
// int game = 1;
138+
// System.out.println(dao.gameTimePlayedByGame(email, game));
139+
140+
// Test ranking
141+
// List<RankingPointsTO> ranking = dao.getRankingPointsByGameAndUser(1);
142+
// for (RankingPointsTO rankingPointsTO : ranking) {
143+
// System.out.println(rankingPointsTO);
144+
// }
145+
146+
// Auth
147+
// System.out.println(dao.validateUser("[email protected]",
148+
// "114e39264fd343e98e138837172a9e36"));
149+
150+
// Finish match
151+
// Match match1 = new Match("[email protected]", 1, 30000, 25);
152+
// Match match2 = new Match("[email protected]", 1, 30000, -25);
153+
// System.out.println(dao.finishMatch(match1, match2));
154+
155+
}
156+
124157
}

0 commit comments

Comments
 (0)