fix null content handling in user posts

This commit is contained in:
Tim
2025-07-10 00:11:13 +08:00
parent 3dbb1c26bb
commit 6351f329cd

View File

@@ -175,11 +175,14 @@ public class UserController {
PostMetaDto dto = new PostMetaDto(); PostMetaDto dto = new PostMetaDto();
dto.setId(post.getId()); dto.setId(post.getId());
dto.setTitle(post.getTitle()); dto.setTitle(post.getTitle());
String content = post.getContent();
if (content == null) {
content = "";
}
if (snippetLength >= 0) { if (snippetLength >= 0) {
String c = post.getContent(); dto.setSnippet(content.length() > snippetLength ? content.substring(0, snippetLength) : content);
dto.setSnippet(c.length() > snippetLength ? c.substring(0, snippetLength) : c);
} else { } else {
dto.setSnippet(post.getContent()); dto.setSnippet(content);
} }
dto.setCreatedAt(post.getCreatedAt()); dto.setCreatedAt(post.getCreatedAt());
dto.setCategory(post.getCategory().getName()); dto.setCategory(post.getCategory().getName());