From a681496e1569c0f152d881b17f341127287462fb Mon Sep 17 00:00:00 2001 From: realtradam Date: Mon, 8 Jul 2024 22:24:20 -0400 Subject: few basic pages --- pom.xml | 4 + .../blog/web/controllers/ArticleController.java | 33 +++ src/main/java/com/blog/web/dto/ArticleDto.java | 27 ++ src/main/java/com/blog/web/models/Article.java | 30 ++ .../com/blog/web/repository/ArticleRepository.java | 8 + .../java/com/blog/web/services/ArticleService.java | 9 + .../blog/web/services/impl/ArticleServiceImpl.java | 36 +++ src/main/resources/templates/articles-list.html | 16 ++ src/main/resources/templates/articles/new.html | 68 +++++ src/main/resources/templates/index.html | 224 +++++++++++++++ src/main/resources/templates/layout.html | 81 ++++++ src/main/resources/templates/post.html | 315 +++++++++++++++++++++ 12 files changed, 851 insertions(+) create mode 100644 src/main/java/com/blog/web/controllers/ArticleController.java create mode 100644 src/main/java/com/blog/web/dto/ArticleDto.java create mode 100644 src/main/java/com/blog/web/models/Article.java create mode 100644 src/main/java/com/blog/web/repository/ArticleRepository.java create mode 100644 src/main/java/com/blog/web/services/ArticleService.java create mode 100644 src/main/java/com/blog/web/services/impl/ArticleServiceImpl.java create mode 100644 src/main/resources/templates/articles-list.html create mode 100644 src/main/resources/templates/articles/new.html create mode 100644 src/main/resources/templates/index.html create mode 100644 src/main/resources/templates/layout.html create mode 100644 src/main/resources/templates/post.html diff --git a/pom.xml b/pom.xml index 2a2996c..de71b39 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,10 @@ org.springframework.boot spring-boot-starter-thymeleaf + + nz.net.ultraq.thymeleaf + thymeleaf-layout-dialect + org.springframework.boot spring-boot-starter-web diff --git a/src/main/java/com/blog/web/controllers/ArticleController.java b/src/main/java/com/blog/web/controllers/ArticleController.java new file mode 100644 index 0000000..3c86ea3 --- /dev/null +++ b/src/main/java/com/blog/web/controllers/ArticleController.java @@ -0,0 +1,33 @@ +package com.blog.web.controllers; + +import com.blog.web.dto.ArticleDto; +import com.blog.web.models.Article; +import com.blog.web.services.ArticleService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +import java.util.List; + +@Controller +public class ArticleController { + private ArticleService articleService; + + public ArticleController(ArticleService articleService) { + this.articleService = articleService; + } + + @GetMapping("/") + public String listArticles(Model model) { + List articles = articleService.findAllArticles(); + model.addAttribute("articles", articles); + return "index"; + } + + @GetMapping("/articles/new") + public String createArticleForm(Model model) { + Article article = new Article(); + model.addAttribute("article", article); + return "articles/new"; + } +} diff --git a/src/main/java/com/blog/web/dto/ArticleDto.java b/src/main/java/com/blog/web/dto/ArticleDto.java new file mode 100644 index 0000000..ffe7926 --- /dev/null +++ b/src/main/java/com/blog/web/dto/ArticleDto.java @@ -0,0 +1,27 @@ +package com.blog.web.dto; + +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.Builder; +import lombok.Data; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import java.time.LocalDateTime; + +@Data +@Builder +public class ArticleDto { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String title; + private String photoUrl; + private String content; + @CreationTimestamp + private LocalDateTime createdOn; + @UpdateTimestamp + private LocalDateTime updatedOn; + +} diff --git a/src/main/java/com/blog/web/models/Article.java b/src/main/java/com/blog/web/models/Article.java new file mode 100644 index 0000000..5d4566f --- /dev/null +++ b/src/main/java/com/blog/web/models/Article.java @@ -0,0 +1,30 @@ +package com.blog.web.models; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import jakarta.persistence.*; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import java.time.LocalDateTime; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +public class Article { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String title; + private String photoUrl; + private String content; + @CreationTimestamp + private LocalDateTime createdOn; + @UpdateTimestamp + private LocalDateTime updatedOn; +} diff --git a/src/main/java/com/blog/web/repository/ArticleRepository.java b/src/main/java/com/blog/web/repository/ArticleRepository.java new file mode 100644 index 0000000..c7e8c04 --- /dev/null +++ b/src/main/java/com/blog/web/repository/ArticleRepository.java @@ -0,0 +1,8 @@ +package com.blog.web.repository; + +import com.blog.web.models.Article; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ArticleRepository extends JpaRepository { + +} diff --git a/src/main/java/com/blog/web/services/ArticleService.java b/src/main/java/com/blog/web/services/ArticleService.java new file mode 100644 index 0000000..c1b28e6 --- /dev/null +++ b/src/main/java/com/blog/web/services/ArticleService.java @@ -0,0 +1,9 @@ +package com.blog.web.services; + +import com.blog.web.dto.ArticleDto; + +import java.util.List; + +public interface ArticleService { + List findAllArticles(); +} diff --git a/src/main/java/com/blog/web/services/impl/ArticleServiceImpl.java b/src/main/java/com/blog/web/services/impl/ArticleServiceImpl.java new file mode 100644 index 0000000..2d3f253 --- /dev/null +++ b/src/main/java/com/blog/web/services/impl/ArticleServiceImpl.java @@ -0,0 +1,36 @@ +package com.blog.web.services.impl; + +import com.blog.web.dto.ArticleDto; +import com.blog.web.models.Article; +import com.blog.web.repository.ArticleRepository; +import com.blog.web.services.ArticleService; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class ArticleServiceImpl implements ArticleService { + public ArticleServiceImpl(com.blog.web.repository.ArticleRepository articleRepository) { + this.articleRepository = articleRepository; + } + + private ArticleRepository articleRepository; + + @Override + public List findAllArticles() { + List
articles = articleRepository.findAll(); + return articles.stream().map(this::mapToArticleDto).collect(Collectors.toList()); + } + + private ArticleDto mapToArticleDto(Article article) { + return ArticleDto.builder() + .id(article.getId()) + .title(article.getTitle()) + .photoUrl(article.getPhotoUrl()) + .content(article.getContent()) + .createdOn(article.getCreatedOn()) + .updatedOn(article.getUpdatedOn()) + .build(); + } +} diff --git a/src/main/resources/templates/articles-list.html b/src/main/resources/templates/articles-list.html new file mode 100644 index 0000000..799c751 --- /dev/null +++ b/src/main/resources/templates/articles-list.html @@ -0,0 +1,16 @@ + + + + + Title + + +

blah blah

+
+
my aga article
+

+ ... +

+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/articles/new.html b/src/main/resources/templates/articles/new.html new file mode 100644 index 0000000..d288e91 --- /dev/null +++ b/src/main/resources/templates/articles/new.html @@ -0,0 +1,68 @@ + + + + +
+
+
+
+ + +

Please fill out this field.

+
+
+ + +
+
+
+
+ + +

Make it as long and as crazy as you'd like

+
+
+
+
+ + +
+
+ +
+ +
+ +
+
+
+
+ + +
+
+
+
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html new file mode 100644 index 0000000..611ef92 --- /dev/null +++ b/src/main/resources/templates/index.html @@ -0,0 +1,224 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/layout.html b/src/main/resources/templates/layout.html new file mode 100644 index 0000000..3a93a87 --- /dev/null +++ b/src/main/resources/templates/layout.html @@ -0,0 +1,81 @@ + + + + + + Title Layout + + + + + + + + + + + + + + + + + + + +
+
+ +

+ ๐Ÿ‘ป Ghostwind CSS +

+

Welcome to my Blog

+
+
+ +
+ + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/post.html b/src/main/resources/templates/post.html new file mode 100644 index 0000000..bf86f96 --- /dev/null +++ b/src/main/resources/templates/post.html @@ -0,0 +1,315 @@ + + + + + + + Tailwind Starter Template - Ghostwind CSS : Tailwind Toolbox + + + + + + + + + + + + + + + + + +
+

04 JULY 2023 / GETTING STARTED

+

Welcome to Ghostwind CSS

+
+ + +
+ + +
+ +
+ +
+ + + + + +

+ ๐Ÿ‘‹ Welcome fellow Tailwind CSS and Ghost fan. This starter template is an attempt to replicate the default Ghost theme "Casper" using Tailwind CSS and vanilla Javascript. +

+ +

The basic blog page layout is available and all using the default Tailwind CSS classes (although there are a few hardcoded style tags). If you are going to use this in your project, you will want to convert the classes into components.

+ +

Sed dignissim lectus ut tincidunt vulputate. Fusce tincidunt lacus purus, in mattis tortor sollicitudin pretium. Phasellus at diam posuere, scelerisque nisl sit amet, tincidunt urna. Cras nisi diam, pulvinar ut molestie eget, eleifend ac magna. Sed at lorem condimentum, dignissim lorem eu, blandit massa. Phasellus eleifend turpis vel erat bibendum scelerisque. Maecenas id risus dictum, rhoncus odio vitae, maximus purus. Etiam efficitur dolor in dolor molestie ornare. Aenean pulvinar diam nec neque tincidunt, vitae molestie quam fermentum. Donec ac pretium diam. Suspendisse sed odio risus. Nunc nec luctus nisi. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis nec nulla eget sem dictum elementum.

+ +
    +
  1. Maecenas accumsan lacus sit amet elementum porta. Aliquam eu libero lectus. Fusce vehicula dictum mi. In non dolor at sem ullamcorper venenatis ut sed dui. Ut ut est quam. Suspendisse quam quam, commodo sit amet placerat in, interdum a ipsum. Morbi sit amet tellus scelerisque tortor semper posuere.
  2. +
  3. Morbi varius posuere blandit. Praesent gravida bibendum neque eget commodo. Duis auctor ornare mauris, eu accumsan odio viverra in. Proin sagittis maximus pharetra. Nullam lorem mauris, faucibus ut odio tempus, ultrices aliquet ex. Nam id quam eget ipsum luctus hendrerit. Ut eros magna, eleifend ac ornare vulputate, pretium nec felis.
  4. +
  5. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nunc vitae pretium elit. Cras leo mauris, tristique in risus ac, tristique rutrum velit. Mauris accumsan tempor felis vitae gravida. Cras egestas convallis malesuada. Etiam ac ante id tortor vulputate pretium. Maecenas vel sapien suscipit, elementum odio et, consequat tellus.
  6. +
+ +
Example of blockquote - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam at ipsum eu nunc commodo posuere et sit amet ligula.
+ +

Example code block:

+
+					
+<header class="site-header outer">
+  <div class="inner">
+    {{> "site-nav"}}
+  </div>
+</header>
+					
+				
+ + + + +
+ + + +
+

Subscribe to Ghostwind CSS

+

Get the latest posts delivered right to your inbox

+
+
+
+ + +
+
+
+
+ + + + +
+ Avatar of Author +
+

Ghostwind CSS

+

Tailwind CSS version of Ghost's Casper theme by TailwindToolbox.com

+
+
+ +
+ + +
+ + +
+ +
+ + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3