Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
doc. Ing. Jaroslav Porubän PhD.
gamestudio2020
Commits
d8aeef23
Commit
d8aeef23
authored
Apr 05, 2020
by
doc. Ing. Jaroslav Porubän PhD.
Browse files
8. prednaska
parent
fcbcf3a9
Changes
5
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
d8aeef23
...
...
@@ -29,6 +29,11 @@
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-jpa
</artifactId>
...
...
src/main/java/sk/tuke/gamestudio/SpringClient.java
View file @
d8aeef23
...
...
@@ -2,20 +2,28 @@ package sk.tuke.gamestudio;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.WebApplicationType
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.FilterType
;
import
sk.tuke.gamestudio.game.mines.consoleui.ConsoleUI
;
import
sk.tuke.gamestudio.game.mines.core.Field
;
import
sk.tuke.gamestudio.service.ScoreService
;
import
sk.tuke.gamestudio.service.ScoreServiceJDBC
;
import
sk.tuke.gamestudio.service.ScoreServiceJPA
;
import
sk.tuke.gamestudio.service.ScoreServiceRestClient
;
@SpringBootApplication
@Configuration
@ComponentScan
(
excludeFilters
=
@ComponentScan
.
Filter
(
type
=
FilterType
.
REGEX
,
pattern
=
"sk.tuke.gamestudio.server.*"
))
public
class
SpringClient
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
SpringClient
.
class
,
args
);
new
SpringApplicationBuilder
(
SpringClient
.
class
).
web
(
WebApplicationType
.
NONE
).
run
(
args
);
//SpringApplication.run(SpringClient.class, args);
}
@Bean
...
...
@@ -36,6 +44,7 @@ public class SpringClient {
@Bean
public
ScoreService
scoreService
()
{
//return new ScoreServiceJDBC();
return
new
ScoreServiceJPA
();
//return new ScoreServiceJPA();
return
new
ScoreServiceRestClient
();
}
}
\ No newline at end of file
src/main/java/sk/tuke/gamestudio/server/GameStudioServer.java
0 → 100644
View file @
d8aeef23
package
sk.tuke.gamestudio.server
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.domain.EntityScan
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
sk.tuke.gamestudio.service.ScoreService
;
import
sk.tuke.gamestudio.service.ScoreServiceJPA
;
@SpringBootApplication
@Configuration
@EntityScan
({
"sk.tuke.gamestudio.entity"
})
public
class
GameStudioServer
{
public
static
void
main
(
String
[]
args
)
{
SpringApplication
.
run
(
GameStudioServer
.
class
,
args
);
}
@Bean
public
ScoreService
scoreService
()
{
//return new ScoreServiceJDBC();
return
new
ScoreServiceJPA
();
}
}
src/main/java/sk/tuke/gamestudio/server/webservice/ScoreRestService.java
0 → 100644
View file @
d8aeef23
package
sk.tuke.gamestudio.server.webservice
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
sk.tuke.gamestudio.entity.Score
;
import
sk.tuke.gamestudio.service.ScoreService
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/api/score"
)
//http://localhost:8080/api/score/mines
public
class
ScoreRestService
{
@Autowired
private
ScoreService
scoreService
;
@GetMapping
(
"/{game}"
)
public
List
<
Score
>
getTopScores
(
@PathVariable
String
game
)
{
return
scoreService
.
getTopScores
(
game
);
}
@PostMapping
public
void
addScore
(
@RequestBody
Score
score
)
{
scoreService
.
addScore
(
score
);
}
}
src/main/java/sk/tuke/gamestudio/service/ScoreServiceRestClient.java
0 → 100644
View file @
d8aeef23
package
sk.tuke.gamestudio.service
;
import
org.springframework.web.client.RestTemplate
;
import
sk.tuke.gamestudio.entity.Score
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
ScoreServiceRestClient
implements
ScoreService
{
private
static
final
String
URL
=
"http://localhost:8080/api/score"
;
private
RestTemplate
restTemplate
=
new
RestTemplate
();
@Override
public
void
addScore
(
Score
score
)
{
restTemplate
.
postForEntity
(
URL
,
score
,
Score
.
class
);
}
@Override
public
List
<
Score
>
getTopScores
(
String
gameName
)
{
return
Arrays
.
asList
(
restTemplate
.
getForEntity
(
URL
+
"/"
+
gameName
,
Score
[].
class
).
getBody
());
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment