Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ public class BlogDetailResponse {
private String authorRole;
private OffsetDateTime createdAt;


private Boolean isPublished;

public Boolean getIsPublished() {
return isPublished;
}
public void setIsPublished(Boolean isPublished) {
this.isPublished = isPublished;
}

public String getTitle() {
return title;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ public class BlogListResponse {
private Long id;


private Boolean isPublished;

public Boolean getIsPublished() {
return isPublished;
}
public void setIsPublished(Boolean isPublished) {
this.isPublished = isPublished;
}


public String getAuthorName() {
return authorName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void createBlog(BlogCreateRequest request) {
blog.setAuthorName(request.getAuthorName());
blog.setAuthorRole(request.getAuthorRole());
blog.setStatus(BlogStatus.DRAFT);
// Removed setCreatedAt and setUpdatedAt as they are handled automatically by your Entity

blogRepository.save(blog);
}
Expand Down Expand Up @@ -84,12 +85,17 @@ public List<BlogListResponse> getPublishedBlogs() {

for (Blog b : blogs) {
BlogListResponse dto = new BlogListResponse();
dto.setId(b.getId());
dto.setTitle(b.getTitle());
dto.setSlug(b.getSlug());
dto.setExcerpt(b.getExcerpt());
dto.setAuthorName(b.getAuthorName());
dto.setAuthorRole(b.getAuthorRole());
dto.setCreatedAt(b.getCreatedAt());

// ✅ Set published to true for this list
dto.setIsPublished(true);

response.add(dto);
}

Expand All @@ -110,18 +116,20 @@ public BlogDetailResponse getBlogBySlug(String slug) {
res.setAuthorRole(blog.getAuthorRole());
res.setCreatedAt(blog.getCreatedAt());

// ✅ Set published status
res.setIsPublished(true);

return res;
}

// ---------- SLUG GENERATOR ----------
private String generateSlug(String input) {
String slug = Normalizer.normalize(input, Normalizer.Form.NFD)
if (input == null) return "";
return Normalizer.normalize(input, Normalizer.Form.NFD)
.replaceAll("[^\\w\\s-]", "")
.trim()
.replaceAll("\\s+", "-")
.toLowerCase(Locale.ENGLISH);

return slug;
}

@Override
Expand All @@ -132,13 +140,18 @@ public List<BlogListResponse> getAllBlogsForAdmin() {

for (Blog b : blogs) {
BlogListResponse dto = new BlogListResponse();
dto.setId(b.getId()); // ⭐ THIS WAS MISSING
dto.setId(b.getId());
dto.setTitle(b.getTitle());
dto.setSlug(b.getSlug());
dto.setExcerpt(b.getExcerpt());
dto.setAuthorName(b.getAuthorName());
dto.setAuthorRole(b.getAuthorRole());
dto.setCreatedAt(b.getCreatedAt());

// ✅ CRITICAL FIX: Map the status to the boolean field
// This ensures the frontend sees correct status!
dto.setIsPublished(b.getStatus() == BlogStatus.PUBLISHED);

response.add(dto);
}

Expand All @@ -159,8 +172,10 @@ public BlogDetailResponse getBlogByIdForAdmin(Long id) {
res.setAuthorRole(blog.getAuthorRole());
res.setCreatedAt(blog.getCreatedAt());

// ✅ CRITICAL FIX: Map the status here as well
res.setIsPublished(blog.getStatus() == BlogStatus.PUBLISHED);

return res;
}


}
}