package com.rtlabs.training.blog;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class ArticleController {

    @PostMapping("/preview")
    public String previewArticle(@RequestParam("body") String body, Model model) {
        if (body == null || body.isBlank()) {
            model.addAttribute("preview", "<em>Черновик пуст</em>");
        } else {
            model.addAttribute("preview", body);
        }
        return "preview";
    }
}

/*
 preview.html
 -----------------------------------------
 <section class="preview" th:utext="${preview}"></section>
 */
