-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c07170d
commit d302b43
Showing
9 changed files
with
171 additions
and
32 deletions.
There are no files selected for viewing
16 changes: 0 additions & 16 deletions
16
src/main/java/com/baloise/platformplanedemoapp/DemoController.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/com/baloise/platformplanedemoapp/todo/ThymeleafTodoController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.baloise.platformplanedemoapp.todo; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.context.SecurityContext; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.validation.BindingResult; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
|
||
import java.util.Collection; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class ThymeleafTodoController { | ||
|
||
private final TodoRepository todoRepository; | ||
|
||
@GetMapping("/todos") | ||
public String todos(final Model model) { | ||
SecurityContext context = SecurityContextHolder.getContext(); | ||
if(context.getAuthentication().getPrincipal() instanceof DefaultOidcUser user) { | ||
String userName = user.getName(); | ||
String mail = user.getPreferredUsername(); | ||
model.addAttribute("currentUser", userName + " (" + mail + ")"); | ||
Collection<? extends GrantedAuthority> authorities = user.getAuthorities(); | ||
model.addAttribute("role", authorities.iterator().next()); | ||
model.addAttribute("issuer", "Azure EntraID"); | ||
model.addAttribute("mail", mail); | ||
model.addAttribute("name", userName); | ||
} else { | ||
model.addAttribute("currentUser", "Anonymous"); | ||
} | ||
model.addAttribute("todos", todoRepository.findAll()); | ||
model.addAttribute("todo", new Todo(null, null, false)); | ||
return "todos"; | ||
} | ||
|
||
@PostMapping("/addtodo") | ||
public String addTodo(@Valid Todo todo, BindingResult result, Model model) { | ||
if (result.hasErrors()) { | ||
return "todos"; | ||
} | ||
todoRepository.save(todo); | ||
return "redirect:/todos"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
DROP TABLE IF EXISTS todo; | ||
CREATE TABLE todo (id SERIAL PRIMARY KEY, description VARCHAR(255), details VARCHAR(4096), done BOOLEAN); | ||
CREATE TABLE IF NOT EXISTS todo (id SERIAL PRIMARY KEY, description VARCHAR(255), details VARCHAR(4096), done BOOLEAN); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!DOCTYPE html> | ||
<html xmlns:th="http://www.thymeleaf.org" lang="de-CH"> | ||
<head th:replace="~{header :: jscssinclude}"><title>Control Plane Demo</title></head> | ||
<body> | ||
<bal-app class="has-sticky-footer"> | ||
<header> | ||
<div th:insert="~{navbar :: navbar}"></div> | ||
</header> | ||
<main> | ||
<div class="container is-compact"> | ||
<bal-content> | ||
<div th:switch="${todos}"> | ||
<bal-heading th:case="null">No todos yet!</bal-heading> | ||
<bal-card style="margin-top: 40px;"> | ||
<bal-card-content> | ||
<form id="todoForm" action="#" th:action="@{/addtodo}" th:object="${todo}" method="post"> | ||
<bal-form-grid> | ||
<bal-form-col size="half"> | ||
<bal-field required="true"> | ||
<bal-field-label required="true">Description</bal-field-label> | ||
<bal-field-control> | ||
<bal-input th:field="*{description}" id="description" name="description" placeholder="Enter description" required="true"></bal-input> | ||
</bal-field-control> | ||
</bal-field> | ||
</bal-form-col> | ||
|
||
<bal-form-col size="half"> | ||
<bal-field required="true"> | ||
<bal-field-label required="true">Details</bal-field-label> | ||
<bal-field-control> | ||
<bal-input th:field="*{details}" id="details" name="details" placeholder="Enter details"></bal-input> | ||
</bal-field-control> | ||
</bal-field> | ||
</bal-form-col> | ||
</bal-form-grid> | ||
</form> | ||
</bal-card-content> | ||
<bal-card-actions position="right"> | ||
<button class="button is-primary" form="todoForm" type="submit">Add todo</button> | ||
</bal-card-actions> | ||
</bal-card> | ||
<bal-card style="margin-top: 40px;"> | ||
<bal-card-content> | ||
<div th:case="*"> | ||
<bal-heading level="h2">Todos</bal-heading> | ||
<table class="table w-full is-striped is-hoverable p-none"> | ||
<thead> | ||
<tr> | ||
<th>Description</th> | ||
<th>Details</th> | ||
<th>Done</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr th:each="todo : ${todos}"> | ||
<td th:text="${todo.description}"></td> | ||
<td th:text="${todo.details}"></td> | ||
<td th:text="${todo.done}"></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
</bal-card-content> | ||
</bal-card> | ||
</div> | ||
</bal-content> | ||
</div> | ||
</main> | ||
<bal-footer hide-links hide-language-selection/> | ||
</bal-app> | ||
</body> | ||
</html> |