Search in sources :

Example 1 with MapVersion

use of com.faforever.client.api.dto.MapVersion in project downlords-faf-client by FAForever.

the class FafServiceImpl method saveMapVersionReview.

@Override
@Async
public CompletableFuture<Void> saveMapVersionReview(Review review, String mapVersionId) {
    MapVersionReview mapVersionReview = (MapVersionReview) new MapVersionReview().setScore(review.getScore().byteValue()).setText(review.getText());
    if (review.getId() == null) {
        Assert.notNull(review.getPlayer(), "Player ID must be set");
        MapVersionReview updatedReview = fafApiAccessor.createMapVersionReview((MapVersionReview) mapVersionReview.setMapVersion(new MapVersion().setId(mapVersionId)).setId(String.valueOf(review.getId())).setPlayer(new com.faforever.client.api.dto.Player().setId(String.valueOf(review.getPlayer().getId()))));
        review.setId(updatedReview.getId());
    } else {
        fafApiAccessor.updateMapVersionReview((MapVersionReview) mapVersionReview.setId(String.valueOf(review.getId())));
    }
    return CompletableFuture.completedFuture(null);
}
Also used : Player(com.faforever.client.player.Player) MapVersionReview(com.faforever.client.api.dto.MapVersionReview) MapVersion(com.faforever.client.api.dto.MapVersion) Async(org.springframework.scheduling.annotation.Async)

Example 2 with MapVersion

use of com.faforever.client.api.dto.MapVersion in project downlords-faf-client by FAForever.

the class FafApiAccessorImplTest method testCreateMapVersionReview.

@Test
public void testCreateMapVersionReview() {
    MapVersionReview mapVersionReview = new MapVersionReview().setMapVersion(new MapVersion().setId("5"));
    when(restOperations.postForEntity(eq("/data/mapVersion/5/reviews"), eq(mapVersionReview), eq(MapVersionReview.class))).thenReturn(new ResponseEntity<>(HttpStatus.OK));
    instance.createMapVersionReview(mapVersionReview);
    ArgumentCaptor<MapVersionReview> captor = ArgumentCaptor.forClass(MapVersionReview.class);
    verify(restOperations).postForEntity(eq("/data/mapVersion/5/reviews"), captor.capture(), eq(MapVersionReview.class));
    MapVersionReview review = captor.getValue();
    assertThat(review, is(mapVersionReview));
}
Also used : MapVersionReview(com.faforever.client.api.dto.MapVersionReview) MapVersion(com.faforever.client.api.dto.MapVersion) Test(org.junit.Test)

Example 3 with MapVersion

use of com.faforever.client.api.dto.MapVersion in project downlords-faf-client by FAForever.

the class MapBean method fromMapDto.

public static MapBean fromMapDto(com.faforever.client.api.dto.Map map) {
    MapVersion mapVersion = map.getLatestVersion();
    MapBean mapBean = new MapBean();
    Optional.ofNullable(map.getAuthor()).ifPresent(author -> mapBean.setAuthor(author.getLogin()));
    mapBean.setDescription(mapVersion.getDescription());
    mapBean.setDisplayName(map.getDisplayName());
    mapBean.setFolderName(mapVersion.getFolderName());
    mapBean.setSize(MapSize.valueOf(mapVersion.getWidth(), mapVersion.getHeight()));
    mapBean.setDownloads(map.getStatistics().getDownloads());
    mapBean.setId(mapVersion.getId());
    mapBean.setPlayers(mapVersion.getMaxPlayers());
    mapBean.setVersion(mapVersion.getVersion());
    mapBean.setDownloadUrl(mapVersion.getDownloadUrl());
    mapBean.setSmallThumbnailUrl(mapVersion.getThumbnailUrlSmall());
    mapBean.setLargeThumbnailUrl(mapVersion.getThumbnailUrlLarge());
    mapBean.setCreateTime(mapVersion.getCreateTime().toLocalDateTime());
    mapBean.setNumberOfPlays(map.getStatistics().getPlays());
    mapBean.getReviews().setAll(map.getVersions().stream().filter(v -> v.getReviews() != null).flatMap(v -> v.getReviews().parallelStream()).map(Review::fromDto).collect(Collectors.toList()));
    return mapBean;
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) MapVersion(com.faforever.client.api.dto.MapVersion) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) URL(java.net.URL) LocalDateTime(java.time.LocalDateTime) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) Observable(javafx.beans.Observable) SimpleListProperty(javafx.beans.property.SimpleListProperty) IntegerProperty(javafx.beans.property.IntegerProperty) Collectors(java.util.stream.Collectors) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Map(java.util.Map) Optional(java.util.Optional) ComparableVersion(org.apache.maven.artifact.versioning.ComparableVersion) ObservableList(javafx.collections.ObservableList) ListProperty(javafx.beans.property.ListProperty) StringProperty(javafx.beans.property.StringProperty) NotNull(org.jetbrains.annotations.NotNull) Review(com.faforever.client.vault.review.Review) MapVersion(com.faforever.client.api.dto.MapVersion) Review(com.faforever.client.vault.review.Review)

Aggregations

MapVersion (com.faforever.client.api.dto.MapVersion)3 MapVersionReview (com.faforever.client.api.dto.MapVersionReview)2 Player (com.faforever.client.player.Player)1 Review (com.faforever.client.vault.review.Review)1 URL (java.net.URL)1 LocalDateTime (java.time.LocalDateTime)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Observable (javafx.beans.Observable)1 IntegerProperty (javafx.beans.property.IntegerProperty)1 ListProperty (javafx.beans.property.ListProperty)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)1 SimpleListProperty (javafx.beans.property.SimpleListProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 StringProperty (javafx.beans.property.StringProperty)1 FXCollections (javafx.collections.FXCollections)1