Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit 4f12871

Browse files
committed
Fixed bugs with updating blog posts
1 parent f485e21 commit 4f12871

File tree

2 files changed

+46
-0
lines changed
  • admin-panel/src/main/java/net/cryptic_game/backend/admin/service/website/impl
  • java-dto/src/main/java/net/cryptic_game/backend/dto/website

2 files changed

+46
-0
lines changed

admin-panel/src/main/java/net/cryptic_game/backend/admin/service/website/impl/BlogServiceImpl.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
import net.cryptic_game.backend.dto.website.BlogPost;
1313
import net.cryptic_game.backend.dto.website.BlogPost.Id;
1414
import net.cryptic_game.backend.dto.website.BlogPostSmall;
15+
import net.getnova.framework.core.exception.NotFoundException;
1516
import net.getnova.framework.core.service.AbstractSmallIdCrudService;
17+
import net.getnova.framework.core.utils.ValidationUtils;
1618
import org.springframework.stereotype.Service;
1719
import org.springframework.transaction.annotation.Transactional;
1820

21+
import java.time.OffsetDateTime;
1922
import java.util.List;
2023
import java.util.stream.Collectors;
2124

@@ -42,4 +45,39 @@ public List<BlogPostSmall> findPosts(final String language) {
4245
.map(this.smallConverter::toDto)
4346
.collect(Collectors.toList());
4447
}
48+
49+
@Override
50+
public BlogPost save(final Id id, final BlogPost dto) {
51+
ValidationUtils.validate(dto);
52+
53+
final IdModel idModel = this.idConverter.toModel(id);
54+
55+
final BlogPostModel model = this.repository.findById(idModel)
56+
.orElseThrow(() -> new NotFoundException(this.name));
57+
58+
final boolean published = model.isPublished();
59+
60+
this.converter.override(model, dto);
61+
62+
if (published) {
63+
model.setUpdated(OffsetDateTime.now());
64+
}
65+
66+
return this.converter.toDto(model);
67+
}
68+
69+
@Override
70+
public BlogPost save(final BlogPost dto) {
71+
return super.save(new BlogPost(
72+
dto.getId(),
73+
dto.getTitle(),
74+
dto.getImage(),
75+
OffsetDateTime.now(),
76+
null,
77+
false,
78+
dto.getDescription(),
79+
dto.getContent(),
80+
dto.getLanguages()
81+
));
82+
}
4583
}

java-dto/src/main/java/net/cryptic_game/backend/dto/website/BlogPost.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ public void validate() throws ValidationException {
7878
throw new ValidationException("image", "MATCH_REGEX");
7979
}
8080

81+
if (this.created == null) {
82+
throw new ValidationException("created", "NOT_NULL");
83+
}
84+
85+
if (this.updated == null) {
86+
throw new ValidationException("updated", "NOT_NULL");
87+
}
88+
8189
if (this.published == null) {
8290
throw new ValidationException("published", "NOT_NULL");
8391
}

0 commit comments

Comments
 (0)