Skip to content

Commit fc00526

Browse files
committed
Merge branch 'master' of
https://github.com/java-game-server/ws-java-client.git Conflicts: build.gradle src/main/java/com/apporelbotna/gameserver/persistencewsclient/properties/ApplicationProperties.java src/main/java/com/apporelbotna/gameserver/persistencewsclient/properties/application.properties
2 parents 253e04a + 416cca0 commit fc00526

5 files changed

Lines changed: 44 additions & 30 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# ws-java-client
2+
A java client for persistence-ws
3+
4+
[![](https://jitpack.io/v/java-game-server/ws-java-client.svg)](https://jitpack.io/#java-game-server/ws-java-client)
5+
6+
#How to build
7+
https://jitpack.io/#java-game-server/ws-java-client/3.0.0

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ dependencies {
2525

2626
// https://mvnrepository.com/artifact/org.springframework.hateoas/spring-hateoas
2727
compileOnly 'org.springframework.hateoas:spring-hateoas:0.24.0.RELEASE'
28-
28+
29+
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web
30+
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.0.RELEASE'
31+
2932
// PersistenceWS Stubs
3033
compile 'com.github.java-game-server:stubs:0.6.2'
3134

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

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@
99
import org.springframework.web.client.RestTemplate;
1010

1111
import com.apporelbotna.gameserver.stubs.Game;
12+
import com.apporelbotna.gameserver.stubs.Match;
1213
import com.apporelbotna.gameserver.stubs.RankingPointsTO;
1314
import com.apporelbotna.gameserver.stubs.RegisterUser;
1415
import com.apporelbotna.gameserver.stubs.Token;
1516
import com.apporelbotna.gameserver.stubs.User;
1617
import com.apporelbotna.gameserver.stubs.UserWrapper;
1718

18-
//TODO los metodos devuelven un HttpStatus que es el code de segun si ha ido bien, mal, etc.
19-
//esto se podria hacer alguna clase que controlase los codigos que se mostraran en la applicacion
20-
//personalizados y en diferentes idiomas
21-
2219
public class GameDAO
2320
{
2421
public static final String SERVER_URL = "http://localhost:8082/";
@@ -29,30 +26,44 @@ public GameDAO()
2926

3027
}
3128

32-
public boolean isUserLoggeable(String email, String tokenString)
33-
{
34-
UserWrapper wrapper = new UserWrapper(new User(email), new
35-
Token(tokenString));
29+
public boolean finishMatch(Match... matches)
30+
{
31+
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+
{
38+
return false;
39+
}
40+
}
41+
42+
return true;
43+
}
44+
45+
public boolean isUserLoggeable(String email, String tokenString)
46+
{
47+
48+
UserWrapper wrapper = new UserWrapper(new User(email), new Token(tokenString));
3649

37-
HttpStatus response = restTemplate
38-
.getForObject(SERVER_URL + "/auth/" + email + "/" + tokenString,
39-
HttpStatus.class);
50+
ResponseEntity<?> response = restTemplate.postForEntity(SERVER_URL + "/auth", wrapper,
51+
null);
4052

41-
return (response.equals(HttpStatus.OK));
42-
}
53+
return (response.getStatusCode().equals(HttpStatus.OK));
54+
}
4355

4456
public User validateUser(String email, String tokenString)
4557
{
46-
//TODO implement
47-
return null;
58+
return isUserLoggeable(email, tokenString) ? getUserInformation(email) : null;
4859
}
4960

50-
public UserWrapper login(String email, String password)
61+
public Token login(String email, String password)
5162
{
5263

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

5869
// saca todos los juegos de un usuario
@@ -110,6 +121,4 @@ public List<RankingPointsTO> getRankingPointsByGameAndUser(int gameId)
110121
return responseWS.getBody();
111122
}
112123

113-
114-
115124
}

src/main/java/com/apporelbotna/gameserver/persistencewsclient/properties/ApplicationProperties.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22

33
import java.util.ResourceBundle;
44

5-
import org.slf4j.Logger;
6-
import org.slf4j.LoggerFactory;
7-
85
public final class ApplicationProperties
96
{
10-
private static final Logger logger = LoggerFactory.getLogger(ApplicationProperties.class);
11-
127
private static String version;
138
private static String name;
149

@@ -44,4 +39,4 @@ public static String getServerUrl()
4439
{
4540
return serverUrl;
4641
}
47-
}
42+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version=2.0.2
2-
name=PersistenceWSClient
3-
4-
server.url=http\://localhost\:8082/
1+
version=3.0.1
2+
name=PersistenceWSClient
3+
4+
server.url=http://localhost:8082/

0 commit comments

Comments
 (0)