Skip to content

Commit 5b8e863

Browse files
bukajsytlosBrutus5000
authored andcommitted
Closes FAForever#652 Add replay rating to the replay search
1 parent 111383e commit 5b8e863

9 files changed

Lines changed: 64 additions & 2 deletions

File tree

‎src/inttest/java/com/faforever/api/config/MainDbTestContainers.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
@Configuration
2222
public class MainDbTestContainers {
2323
private static final MariaDBContainer<?> fafDBContainer = new MariaDBContainer<>("mariadb:10.6");
24-
private static final GenericContainer<?> flywayMigrationsContainer = new GenericContainer<>("faforever/faf-db-migrations:v127");
24+
private static final GenericContainer<?> flywayMigrationsContainer = new GenericContainer<>("faforever/faf-db-migrations:v128");
2525
private static final Network sharedNetwork = Network.newNetwork();
2626

2727
@Bean

‎src/inttest/java/com/faforever/api/data/GameElideTest.java‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,27 @@ public void filterNonExistingGameByVictoryCondition() throws Exception {
4141
.andExpect(status().isOk())
4242
.andExpect(jsonPath("$.data[*]", hasSize(0)));
4343
}
44+
45+
@Test
46+
@WithAnonymousUser
47+
public void filterExistingGameReviewsSummaryAverageScore() throws Exception {
48+
mockMvc.perform(
49+
get("/data/game")
50+
.queryParam("filter", "reviewsSummary.averageScore=gt=3.333")
51+
)
52+
.andExpect(status().isOk())
53+
.andExpect(jsonPath("$.data[*]", hasSize(1)));
54+
}
55+
56+
@Test
57+
@WithAnonymousUser
58+
public void filterNonExistingGameReviewsSummaryAverageScore() throws Exception {
59+
mockMvc.perform(
60+
get("/data/game")
61+
.queryParam("filter", "reviewsSummary.averageScore=gt=3.334")
62+
)
63+
.andExpect(status().isOk())
64+
.andExpect(jsonPath("$.data[*]", hasSize(0)));
65+
}
4466
}
4567

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
INSERT INTO game_stats (id, startTime, gameName, gameType, gameMod, `host`, mapId, validity, replay_available)
22
VALUES (1, NOW(), 'Test game', '0', 6, 1, 1, 0, false);
3+
4+
insert into game_review (id, text, user_id, score, game_id) VALUES (1, 'Awesome', 1, 5, 1);
5+
insert into game_review (id, text, user_id, score, game_id) VALUES (2, 'Nice', 2, 3, 1);
6+
insert into game_review (id, text, user_id, score, game_id) VALUES (3, 'Meh', 3, 2, 1);

‎src/main/java/com/faforever/api/data/domain/GameReviewsSummary.java‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.hibernate.annotations.BatchSize;
66
import org.hibernate.annotations.Immutable;
77

8+
import jakarta.annotation.Nullable;
89
import jakarta.persistence.Column;
910
import jakarta.persistence.Entity;
1011
import jakarta.persistence.Id;
@@ -23,6 +24,8 @@ public class GameReviewsSummary {
2324
private float score;
2425
private int reviews;
2526
private float lowerBound;
27+
@Nullable
28+
private Float averageScore;
2629
private Game game;
2730

2831
@Id
@@ -56,6 +59,11 @@ public float getLowerBound() {
5659
return lowerBound;
5760
}
5861

62+
@Column(name = "average_score")
63+
public float getAverageScore() {
64+
return averageScore;
65+
}
66+
5967
@OneToOne(mappedBy = "reviewsSummary")
6068
@BatchSize(size = 1000)
6169
public Game getGame() {

‎src/main/java/com/faforever/api/data/domain/MapReviewsSummary.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class MapReviewsSummary {
2727
private int reviews;
2828
@Nullable
2929
private Float lowerBound;
30+
@Nullable
31+
private Float averageScore;
3032
private Map map;
3133

3234
@Id
@@ -61,6 +63,11 @@ public Float getLowerBound() {
6163
return lowerBound;
6264
}
6365

66+
@Column(name = "average_score")
67+
public float getAverageScore() {
68+
return averageScore;
69+
}
70+
6471
@OneToOne(fetch = FetchType.LAZY)
6572
@JoinColumn(name = "map_id", insertable = false, updatable = false)
6673
@BatchSize(size = 1000)

‎src/main/java/com/faforever/api/data/domain/MapVersionReviewsSummary.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class MapVersionReviewsSummary {
2727
private int reviews;
2828
@Nullable
2929
private Float lowerBound;
30+
@Nullable
31+
private Float averageScore;
3032
private MapVersion mapVersion;
3133

3234
@Id
@@ -61,6 +63,11 @@ public Float getLowerBound() {
6163
return lowerBound;
6264
}
6365

66+
@Column(name = "average_score")
67+
public float getAverageScore() {
68+
return averageScore;
69+
}
70+
6471
@OneToOne(fetch = FetchType.LAZY)
6572
@JoinColumn(name = "map_version_id", insertable = false, updatable = false)
6673
@BatchSize(size = 1000)

‎src/main/java/com/faforever/api/data/domain/ModReviewsSummary.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class ModReviewsSummary {
2727
private int reviews;
2828
@Nullable
2929
private Float lowerBound;
30+
@Nullable
31+
private Float averageScore;
3032
private Mod mod;
3133

3234
@Id
@@ -61,6 +63,11 @@ public Float getLowerBound() {
6163
return lowerBound;
6264
}
6365

66+
@Column(name = "average_score")
67+
public float getAverageScore() {
68+
return averageScore;
69+
}
70+
6471
@OneToOne(fetch = FetchType.LAZY)
6572
@JoinColumn(name = "mod_id", insertable = false, updatable = false)
6673
@BatchSize(size = 1000)

‎src/main/java/com/faforever/api/data/domain/ModVersionReviewsSummary.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class ModVersionReviewsSummary {
2727
private int reviews;
2828
@Nullable
2929
private Float lowerBound;
30+
@Nullable
31+
private Float averageScore;
3032
private ModVersion modVersion;
3133

3234
@Id
@@ -61,6 +63,11 @@ public float getLowerBound() {
6163
return lowerBound;
6264
}
6365

66+
@Column(name = "average_score")
67+
public float getAverageScore() {
68+
return averageScore;
69+
}
70+
6471
@OneToOne(fetch = FetchType.LAZY)
6572
@JoinColumn(name = "mod_version_id", insertable = false, updatable = false)
6673
@BatchSize(size = 1000)

‎src/main/resources/config/application.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ faf-api:
1818
hmac-secret: ${CLOUDFLARE_HMAC_SECRET}
1919
hmac-param: ${CLOUDFLARE_HMAC_PARAM:verify}
2020
database:
21-
schema-version: ${DATABASE_SCHEMA_VERSION:127}
21+
schema-version: ${DATABASE_SCHEMA_VERSION:128}
2222
deployment:
2323
forged-alliance-exe-path: ${FORGED_ALLIANCE_EXE_PATH:/content/legacy-featured-mod-files/updates_faf_files/ForgedAlliance.exe}
2424
repositories-directory: ${REPOSITORIES_DIRECTORY:/repositories}

0 commit comments

Comments
 (0)