add links to the bot list, and better name the template, and add a bot details viewing page

This commit is contained in:
Yvan 2025-01-29 11:45:21 +00:00
parent d64a9c75e8
commit bcaa6508f1
3 changed files with 45 additions and 10 deletions

View file

@ -3,6 +3,7 @@ package dev.activitypub.activitypubbot;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model; import org.springframework.ui.Model;
@ -10,7 +11,7 @@ import java.util.List;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
/** /**
* This handles requests relating to our bots (users) - so things like * This handles web requests relating to our bots (users) - so things like
* /@username and /users/username. * /@username and /users/username.
*/ */
@Controller @Controller
@ -22,17 +23,27 @@ public class BotController {
@GetMapping("/viewbot") @GetMapping("/viewbot")
public String listAll(Model model) { public String listAll(Model model) {
log.info("WebHandler::viewbot"); log.info("BotController::viewbot");
List<Bot> botlist = botServ.findAll(); List<Bot> botlist = botServ.findAll();
model.addAttribute("bots", botlist); model.addAttribute("bots", botlist);
return "listbots";
}
@GetMapping("/viewbot/{username}")
public String listAll(@PathVariable String username, Model model) {
log.info("BotController::viewbot/" + username);
Bot bot = botServ.getBotByUsername(username);
model.addAttribute("bot", bot);
return "viewbot"; return "viewbot";
} }
@GetMapping("/makebot") @GetMapping("/makebot")
public String makebotget(Model model) { public String makebotget(Model model) {
log.info("WebHandler::makebot"); log.info("BotController::makebot");
Bot bot = new Bot(); Bot bot = new Bot();
model.addAttribute("bot", bot); model.addAttribute("bot", bot);

View file

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>List Bot</title>
<style type="text/css">
span {
display: inline-block;
width: 200px;
text-align: left;
}
</style>
</head>
<body>
<div align="center">
<h2>Pick-a-Bot!</h2>
<ul th:if="${bots.empty}">
<li>No Bots!</li>
</ul>
<ul th:each="bot : ${bots}">
<li>Bot: <a th:href="@{/viewbot/} + ${bot.username}"><span th:text="${bot.username}">Bot</span></a></li>
</ul>
</div>
</body>
</html>

View file

@ -13,13 +13,12 @@
</head> </head>
<body> <body>
<div align="center"> <div align="center">
<h2>Pick-a-Bot!</h2> <h2>Bot:</h2>
<ul th:if="${bots.empty}"> <span>Username:</span><span th:text="${bot.username}"></span><br/>
<li>No Bots!</li> <span>Display Name:</span><span th:text="${bot.name}"></span><br/>
</ul> <span>Description:</span><span th:text="${bot.summary}"></span><br/>
<ul th:each="bot : ${bots}"> <span>Published:</span><span th:text="${bot.published}"></span><br/>
<li>Bot: <span th:text="${bot.username}"> Bot </span></li> <span>Type:</span><span th:text="${bot.type}"></span><br/>
</ul>
</div> </div>
</body> </body>
</html> </html>