Skip to content

Commit

Permalink
News-Editing
Browse files Browse the repository at this point in the history
  • Loading branch information
commel committed Mar 26, 2024
1 parent c309361 commit 3e155ea
Show file tree
Hide file tree
Showing 14 changed files with 321 additions and 25 deletions.
4 changes: 3 additions & 1 deletion src/main/java/de/holarse/backend/db/Article.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@Table(name = "articles")
@Entity
public class Article extends Base {
public class Article extends Base implements Node {

private static final long serialVersionUID = 2L;

Expand Down Expand Up @@ -44,10 +44,12 @@ public class Article extends Base {
@JoinColumn(name="nodeid", insertable=false, nullable=false, updatable = false, referencedColumnName = "nodeid")
private Set<NodeSlug> nodeSlugs = new HashSet<>();

@Override
public int getNodeId() {
return nodeId;
}

@Override
public void setNodeId(int nodeId) {
this.nodeId = nodeId;
}
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/de/holarse/backend/db/News.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Table(name = "news")
@Entity
public class News extends Base {
public class News extends Base implements Node {

private static final long serialVersionUID = 2L;

Expand All @@ -24,7 +24,7 @@ public class News extends Base {

@OneToOne
@JoinColumn(name = "revisionid", referencedColumnName = "id")
private NewsRevision newsRevision;
private NewsRevision nodeRevision;

@Column(name = "drupalid")
private Integer drupalId;
Expand All @@ -48,10 +48,12 @@ public class News extends Base {
@JoinColumn(name="nodeid", referencedColumnName = "nodeid")
private Set<NodeSlug> nodeSlugz = new HashSet<>();

@Override
public int getNodeId() {
return nodeId;
}

@Override
public void setNodeId(int nodeId) {
this.nodeId = nodeId;
}
Expand All @@ -64,12 +66,12 @@ public void setDrupalId(Integer drupalId) {
this.drupalId = drupalId;
}

public NewsRevision getNewsRevision() {
return newsRevision;
public NewsRevision getNodeRevision() {
return nodeRevision;
}

public void setNewsRevision(NewsRevision articleRevision) {
this.newsRevision = newsRevision;
public void setNodeRevision(NewsRevision nodeRevision) {
this.nodeRevision = nodeRevision;
}

public NodeStatus getNodeStatus() {
Expand Down Expand Up @@ -100,7 +102,7 @@ public void setNodeSlugz(Set<NodeSlug> nodeSlugz) {
public String toString() {
return "News{" +
"nodeId=" + nodeId +
", newsRevision=" + newsRevision +
", nodeRevision=" + nodeRevision +
", drupalId=" + drupalId +
", nodeStatus=" + nodeStatus +
", tags=" + tags +
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/de/holarse/backend/db/Node.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package de.holarse.backend.db;

/**
*
* @author comrad
*/
public interface Node {

int getNodeId();
void setNodeId(int nodeId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
@Repository
public interface ArticleRepository extends JpaRepository<Article, Integer>, NodeAwareRepository {

@Query(value = "SELECT nr.nodeId, sl.name as slug, null as nodeType, nr.title1 as title, nr.teaser FROM Article n " +
@Query(value = "SELECT nr.nodeId, sl.name as slug, null as nodeType, nr.title1 as title, nr.teaser, concat('wiki/', sl.name) as url FROM Article n " +
"JOIN n.nodeRevision as nr " +
"JOIN n.nodeStatus as ns " +
"JOIN n.nodeSlugs as sl " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.holarse.backend.db.repositories;

import de.holarse.backend.db.Article;
import de.holarse.backend.db.News;
import de.holarse.backend.view.FrontpageItemView;
import org.springframework.data.domain.Pageable;
Expand All @@ -8,14 +9,27 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;
import org.springframework.data.repository.query.Param;

@Repository
public interface NewsRepository extends JpaRepository<News, Integer>, NodeAwareRepository {

@Query(value = "SELECT nr.nodeId, sl.name as slug, 'news' as nodeType, nr.title as title, nr.teaser FROM News n "
+ "JOIN n.newsRevision nr "
@Query(value = "SELECT nr.nodeId, sl.name as slug, 'news' as nodeType, nr.title as title, nr.teaser, concat('news/', sl.name) as url FROM News n "
+ "JOIN n.nodeRevision nr "
+ "JOIN n.nodeStatus as ns "
+ "JOIN n.nodeSlugz as sl "
+ "WHERE ns.published and NOT ns.deleted and sl.id = (SELECT max(_sl.id) FROM NodeSlug _sl where _sl.nodeId = n.nodeId)")
List<FrontpageItemView> findFrontpageItems(final Pageable pageable);

@Query(value = "FROM News n " +
"JOIN FETCH n.nodeRevision nr " +
"JOIN FETCH n.nodeStatus as ns " +
"JOIN n.nodeSlugz as sl " +
"LEFT JOIN FETCH n.tags " +
"WHERE ns.published and NOT ns.deleted " +
"AND sl.name = :slug")
Optional<News> findBySlug(@Param("slug") final String slug);

Optional<News> findByNodeId(final Integer nodeId);
}
3 changes: 1 addition & 2 deletions src/main/java/de/holarse/backend/view/FrontpageItemView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ public interface FrontpageItemView {
Integer getNodeId();
String getSlug();
NodeType getNodeType();

String getTitle();

String getTeaser();
String getUrl();

}
103 changes: 103 additions & 0 deletions src/main/java/de/holarse/backend/view/NewsView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package de.holarse.backend.view;

import de.holarse.backend.db.NewsCategory;
import de.holarse.backend.db.NewsRevision;
import de.holarse.backend.db.NodeSlug;
import java.util.ArrayList;
import java.util.List;

/**
*
* @author comrad
*/
public class NewsView {

private String title;
private String teaser;
private String content;
private NewsCategory newsCategory;
private Integer nodeId;

private String url;

private List<AttachmentView> websiteLinks = new ArrayList<>();
private List<YoutubeView> youtubeVideos = new ArrayList<>();

public static NewsView of(final NewsRevision newsRevision, final NodeSlug slug) {
final NewsView nv = new NewsView();
nv.title = newsRevision.getTitle();
nv.teaser = newsRevision.getTeaser();
nv.content = newsRevision.getContent();
nv.newsCategory = newsRevision.getNewsCategory();
nv.nodeId = newsRevision.getNodeId();

nv.setUrl(String.format("/news/%s", slug.getName()));

return nv;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getTeaser() {
return teaser;
}

public void setTeaser(String teaser) {
this.teaser = teaser;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}

public NewsCategory getNewsCategory() {
return newsCategory;
}

public void setNewsCategory(NewsCategory newsCategory) {
this.newsCategory = newsCategory;
}

public Integer getNodeId() {
return nodeId;
}

public void setNodeId(Integer nodeId) {
this.nodeId = nodeId;
}

public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}

public List<AttachmentView> getWebsiteLinks() {
return websiteLinks;
}

public void setWebsiteLinks(List<AttachmentView> websiteLinks) {
this.websiteLinks = websiteLinks;
}

public List<YoutubeView> getYoutubeVideos() {
return youtubeVideos;
}

public void setYoutubeVideos(List<YoutubeView> youtubeVideos) {
this.youtubeVideos = youtubeVideos;
}

}
Loading

0 comments on commit 3e155ea

Please sign in to comment.