Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

Commit

Permalink
Merge pull request #66 from Kerosene-Labs/add-introductions
Browse files Browse the repository at this point in the history
Add introductions
  • Loading branch information
hlafaille authored Dec 16, 2024
2 parents a0f44cc + d825e01 commit cf6e65b
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(confirmedUserInterceptor)
.addPathPatterns("/home/**"); // Apply to specific routes
.addPathPatterns("/home/**")
.addPathPatterns("/settings/**");
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
package com.kerosenelabs.billtracker.controller;

import java.time.LocalDate;
import java.util.Date;

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

import com.kerosenelabs.billtracker.entity.UserEntity;
import com.kerosenelabs.billtracker.service.UserService;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HomeController {
private final UserService userService;

public HomeController(UserService userService) {
this.userService = userService;
}

@GetMapping("/home")
public String getHome(UserEntity user) {
public String getHome(UserEntity user, Model model) {
// if the user has completed their introductory settings, hide that card on the
// home screen
if (user.getFirstName() != null) {
model.addAttribute("showIntroduction", false);
}
return "pages/home";
}

Expand All @@ -17,4 +36,13 @@ public String getConfirmAccount() {
return "pages/welcomeNextSteps";
}

@PostMapping("/home")
public String handleEditIntroductions(UserEntity user, @RequestParam String firstName,
@RequestParam String lastName,
@RequestParam LocalDate birthday) {

userService.setIntroductorySettings(user, firstName, lastName, birthday);
return "redirect:/home";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kerosenelabs.billtracker.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class SettingsController {
@GetMapping("/settings")
public String getSettings() {
return "pages/settings";
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.kerosenelabs.billtracker.entity;

import java.time.LocalDate;
import java.util.Date;
import java.util.UUID;

import jakarta.persistence.Column;
Expand All @@ -22,6 +24,7 @@ public class UserEntity {

private String firstName = null;
private String lastName = null;
private LocalDate birthday = null;

@Column(nullable = false, unique = true)
private String emailAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.kerosenelabs.billtracker.service;

import java.time.LocalDate;
import java.util.Date;
import java.util.UUID;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
Expand Down Expand Up @@ -86,4 +88,14 @@ public UserEntity getUserById(UUID id) throws AuthException {
public void establishSession(HttpSession httpSession, UserEntity userEntity) {
httpSession.setAttribute("userId", userEntity.getId());
}

/**
* Sets introductory settings such as the users first and last name
*/
public void setIntroductorySettings(UserEntity userEntity, String firstName, String lastName, LocalDate birthday) {
userEntity.setFirstName(firstName);
userEntity.setLastName(lastName);
userEntity.setBirthday(birthday);
userRepository.save(userEntity);
}
}
15 changes: 11 additions & 4 deletions src/main/resources/templates/error.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:replace="~{fragments/common :: head('Error')}"></head>
<head th:replace="~{fragments/common :: head('Home')}"></head>

<body class="flex items-center justify-center flex-col gap-2">
<p>An internal error occurred.</p>
<a th:replace="~{tk/buttons :: link('Go Home', '/home')}"></a>
<body th:replace="~{fragments/common :: body(~{::content})}">
<div th:fragment="content" class="flex w-full justify-center">
<div class="flex flex-col gap-6 w-full lg:w-1/4 items-center justify-center">
<div
th:replace="~{tk/cards :: simpleCard('Oops', 'An error occurred while processing your request.', ~{::errorContent})}">
<div th:fragment="errorContent" class="flex">
<a th:replace="~{tk/buttons :: link('Go Home', '/home')}"></a>
</div>
</div>
</div>
</body>

</html>
32 changes: 22 additions & 10 deletions src/main/resources/templates/pages/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,33 @@
<div
th:replace="~{tk/cards :: simpleCard('Welcome to BillTracker', 'This thing\'s still in the oven, apologies for the bugs and lack of polish.', ~{::reportBugsContent})}">
<div th:fragment="reportBugsContent" class="flex flex-col gap-4 lg:flex-row lg:items-end w-full">
<a th:replace="~{tk/buttons :: link('Report Bug', '/bugReport')}"></a>
<a
th:replace="~{tk/buttons :: link('Report Bug', 'https://github.com/Kerosene-Labs/billtracker/issues')}"></a>
<a th:replace="~{tk/buttons :: link('Settings', '/settings')}"></a>
<a th:replace="~{tk/buttons :: link('Logout', '/logout')}"></a>
</div>
</div>
<div
th:replace="~{tk/cards :: simpleCard('Introductions', 'Tell us a bit more about yourself.', ~{::introductionsContent})}">
<div th:fragment="introductionsContent" class="flex flex-col gap-4 lg:flex-row lg:items-end w-full">
<input th:replace="~{tk/inputs :: text('firstName', 'First Name')}">
<input th:replace="~{tk/inputs :: text('firstName', 'Last Name')}">
<input th:replace="~{tk/inputs :: date('birthday', 'Birthday')}">
<div class="max-w-full">
<button th:replace="~{tk/buttons :: button('Save')}"></button>
</div>
<!-- Introductions -->
<div th:if="${showIntroduction}">
<div
th:replace="~{tk/cards :: simpleCard('Introductions', 'Tell us a bit more about yourself.', ~{::introductionsContent})}">
<form th:fragment="introductionsContent" class="flex flex-col gap-4 lg:flex-row lg:items-end w-full"
method="post">
<input th:replace="~{tk/inputs :: text('firstName', 'First Name')}">
<input th:replace="~{tk/inputs :: text('lastName', 'Last Name')}">
<input th:replace="~{tk/inputs :: date('birthday', 'Birthday')}">
<div class="max-w-full">
<button th:replace="~{tk/buttons :: button('Save')}"></button>
</div>
</form>
</div>
</div>
<div th:unless="${showIntroduction}">
<div
th:replace="~{tk/cards :: simpleCard('Introductions', 'Thanks for giving us some more information. You can expect your experience to be tailored further, just for you.', null)}">
</div>
</div>
<!-- Expenses -->
<div
th:replace="~{tk/cards :: simpleCard('Expenses', 'Where\'s that cheddar going?', ~{::expensesContent})}">
<div th:fragment="expensesContent">
Expand All @@ -33,6 +44,7 @@
</div>
</div>
</div>
<!-- Income -->
<div th:replace="~{tk/cards :: simpleCard('Income', 'Aww yeah baby, it\'s pay day!', ~{::incomeContent})}">
<div th:fragment="incomeContent">
<div class="w-full flex">
Expand Down
12 changes: 12 additions & 0 deletions src/main/resources/templates/pages/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:replace="~{fragments/common :: head('Home')}"></head>

<body th:replace="~{fragments/common :: body(~{::content})}">
<div th:fragment="content" class="flex w-full justify-center">
<div th:replace="~{tk/cards :: simpleCard('Settings', '', null)}"></div>
</div>
</body>

</html>

0 comments on commit cf6e65b

Please sign in to comment.