Skip to content

Commit f3c0fc4

Browse files
committed
Auflistung der News-Beiträge unter /news
1 parent 6028ce7 commit f3c0fc4

File tree

6 files changed

+78
-0
lines changed

6 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package de.holarse.backend.db.datasets;
2+
3+
public interface CurrentNews {
4+
5+
int getNodeId();
6+
int getRevisionId();
7+
String getTitle();
8+
String getSlug();
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
package de.holarse.backend.db.repositories;
22

33
import de.holarse.backend.db.News;
4+
import de.holarse.backend.db.NewsRevision;
5+
import de.holarse.backend.db.datasets.CurrentArticle;
6+
import de.holarse.backend.db.datasets.CurrentNews;
7+
import org.springframework.data.domain.Pageable;
48
import org.springframework.data.jpa.repository.JpaRepository;
9+
import org.springframework.data.jpa.repository.Query;
510
import org.springframework.stereotype.Repository;
611

12+
import java.util.List;
13+
14+
715
@Repository
816
public interface NewsRepository extends JpaRepository<News, Integer>, NodeAwareRepository {
17+
18+
@Query(value = "SELECT e.nodeId as nodeId, rev.id as revisionId, rev.title as title, sl.name as slug from News e " +
19+
"INNER JOIN e.newsRevision as rev " +
20+
"INNER JOIN NodeStatus ns on ns.nodeId = e.nodeId " +
21+
"INNER JOIN NodeSlug sl on sl.nodeId = e.nodeId " +
22+
"WHERE ns.published and not ns.deleted and sl.id = (SELECT max(_sl.id) FROM NodeSlug _sl where _sl.nodeId = e.nodeId)")
23+
List<CurrentNews> listCurrent(final Pageable pageable);
924
}

src/main/java/de/holarse/config/MultipleHttpSecurityConfig.java

+2
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,15 @@ public SecurityFilterChain webFormSecurityFilterChain(final HttpSecurity http, f
131131
.authorizeHttpRequests((requests) -> requests.requestMatchers(antMatcher("/profile"),
132132
antMatcher("/workspace/**"),
133133
antMatcher("/wiki/*/edit"),
134+
antMatcher("/news/*/edit"),
134135
antMatcher("/logout")).authenticated())
135136

136137
// Normale Webseite, auch als Gast nutzbar
137138
.authorizeHttpRequests((requests) -> requests.requestMatchers(antMatcher("/"),
138139
antMatcher("/search/**"),
139140
antMatcher("/tags/**"),
140141
antMatcher("/wiki/**"),
142+
antMatcher("/news/**"),
141143
antMatcher("/help/**"),
142144
antMatcher("/spielefinder/**"),
143145
antMatcher("/category/*/*"), // Legacy-Tag-URLs
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package de.holarse.web.controller;
2+
3+
import de.holarse.backend.db.repositories.NewsRepository;
4+
import de.holarse.web.defines.WebDefines;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.data.domain.Pageable;
7+
import org.springframework.data.web.PageableDefault;
8+
import org.springframework.stereotype.Controller;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.servlet.ModelAndView;
12+
13+
import static de.holarse.web.defines.WebDefines.NEWS_ARTICLES_DEFAULT_PAGE_SIZE;
14+
15+
@Controller
16+
@RequestMapping(value = {"/news", "/news/" })
17+
public class NewsController {
18+
19+
@Autowired
20+
private NewsRepository newsRepository;
21+
22+
@GetMapping
23+
public ModelAndView index(@PageableDefault(sort = {"title"}, value = NEWS_ARTICLES_DEFAULT_PAGE_SIZE) final Pageable pageable, final ModelAndView mv) {
24+
mv.setViewName("layouts/bare");
25+
mv.addObject("title", "Die Linuxspiele-Seite für Linuxspieler");
26+
mv.addObject(WebDefines.DEFAULT_VIEW_ATTRIBUTE_NAME, "sites/news/index");
27+
28+
// TODO: Wieder entfernen, nur zum Testen
29+
mv.addObject("items", newsRepository.listCurrent(pageable));
30+
return mv;
31+
}
32+
}

src/main/java/de/holarse/web/defines/WebDefines.java

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class WebDefines {
77
public static final int DEFAULT_LIST_SIZE = 25;
88
public static final int ADMIN_USERS_DEFAULT_PAGE_SIZE = DEFAULT_LIST_SIZE;
99
public static final int WIKI_ARTICLES_DEFAULT_PAGE_SIZE = 50;
10+
public static final int NEWS_ARTICLES_DEFAULT_PAGE_SIZE = 50;
1011
public static final int REVISION_DEFAULT_PAGE_SIZE = 10;
1112

1213
public static final String TAG_DELIMITER = "@@@";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- Login -->
2+
<div class="row justify-content-center">
3+
<div class="col-sm-8 col-lg-5">
4+
<div class="u-shadow-v21 g-bg-white rounded g-py-40 g-px-30">
5+
<header class="text-center mb-4">
6+
<h2 class="h2 g-color-black g-font-weight-600">Die News-Beiträge</h2>
7+
</header>
8+
9+
<ul data-th-each="item : ${items}">
10+
<li><a href="#" data-th-href="@{/news/{slug}(slug=${news.slug})}" data-th-text="${news.title}"></a></li>
11+
</ul>
12+
13+
</div>
14+
</div>
15+
</div>
16+
<!-- End Login -->
17+
18+

0 commit comments

Comments
 (0)