From f2d2d42c6b2b457825abff2407136b3614b1a8c7 Mon Sep 17 00:00:00 2001 From: Yuanmeng Liu Date: Wed, 26 Jun 2024 11:23:11 +0100 Subject: [PATCH 1/4] nothing to commit --- .../makersacademy/acebook/config/SecurityConfig.java | 2 +- .../acebook/controller/LoginController.java | 2 +- src/main/resources/templates/events/details.html | 1 + src/main/resources/templates/landingpage.html | 10 +++++----- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/makersacademy/acebook/config/SecurityConfig.java b/src/main/java/com/makersacademy/acebook/config/SecurityConfig.java index 7cc224a4..a47bfe85 100644 --- a/src/main/java/com/makersacademy/acebook/config/SecurityConfig.java +++ b/src/main/java/com/makersacademy/acebook/config/SecurityConfig.java @@ -32,7 +32,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .cors().and() .authorizeRequests(authorizeRequests -> authorizeRequests - .antMatchers("/", "/login", "/register","/images/**", "/users","/error/**", "/styles/**", "/search", "/events", "/oauth2/**", "/assets/**","/events/details/**").permitAll() + .antMatchers("/", "/login", "/register","/images/**", "/users","/error/**", "/styles/**", "/search", "/events", "/oauth2/**", "/assets/**","/events/details/**","/events/third-party-events").permitAll() .anyRequest().authenticated() ) .formLogin(formLogin -> diff --git a/src/main/java/com/makersacademy/acebook/controller/LoginController.java b/src/main/java/com/makersacademy/acebook/controller/LoginController.java index bd79cf2d..6ecfd1b2 100644 --- a/src/main/java/com/makersacademy/acebook/controller/LoginController.java +++ b/src/main/java/com/makersacademy/acebook/controller/LoginController.java @@ -13,6 +13,6 @@ public String login() { @GetMapping("/loginSuccess") public String loginSuccess() { - return "redirect:/ "; + return "/"; } } diff --git a/src/main/resources/templates/events/details.html b/src/main/resources/templates/events/details.html index 0c60cfae..e59db3f8 100644 --- a/src/main/resources/templates/events/details.html +++ b/src/main/resources/templates/events/details.html @@ -127,6 +127,7 @@

London Credit and Risk Di + diff --git a/src/main/resources/templates/landingpage.html b/src/main/resources/templates/landingpage.html index 49fb4253..6b22d872 100644 --- a/src/main/resources/templates/landingpage.html +++ b/src/main/resources/templates/landingpage.html @@ -39,11 +39,11 @@

Events

Date:
Time:
-
-

-
-

You are attending this event!

-

+ + + + + From 2b5dd5fc4788b1b73a12f75154da95f7d682950d Mon Sep 17 00:00:00 2001 From: Yuanmeng Liu Date: Wed, 26 Jun 2024 13:18:47 +0100 Subject: [PATCH 2/4] save my work --- .../controller/LandingPageController.java | 13 ++---- .../acebook/controller/LoginController.java | 2 +- .../acebook/controller/UserController.java | 6 +-- .../repository/AttendeesRepository.java | 3 +- .../acebook/repository/EventRepository.java | 8 ++-- .../acebook/repository/UserRepository.java | 3 -- .../resources/templates/fragments/navbar.html | 46 +++++++------------ src/main/resources/templates/landingpage.html | 17 +++++-- 8 files changed, 42 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/makersacademy/acebook/controller/LandingPageController.java b/src/main/java/com/makersacademy/acebook/controller/LandingPageController.java index d92cf261..d5050ad3 100644 --- a/src/main/java/com/makersacademy/acebook/controller/LandingPageController.java +++ b/src/main/java/com/makersacademy/acebook/controller/LandingPageController.java @@ -1,14 +1,15 @@ package com.makersacademy.acebook.controller; +import com.makersacademy.acebook.model.Attendee; import com.makersacademy.acebook.model.Event; import com.makersacademy.acebook.model.User; import com.makersacademy.acebook.repository.AttendeesRepository; import com.makersacademy.acebook.repository.EventRepository; import com.makersacademy.acebook.repository.UserRepository; +import com.makersacademy.acebook.service.AttendeesService; import com.makersacademy.acebook.service.SearchService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; -import org.springframework.security.core.Authentication; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.oauth2.core.user.OAuth2User; @@ -20,12 +21,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.view.RedirectView; -import com.makersacademy.acebook.model.Attendee; -import com.makersacademy.acebook.service.AttendeesService; - import java.util.Date; import java.util.List; -import java.util.Optional; @CrossOrigin @Controller @@ -74,14 +71,14 @@ public String userEvents(Model model, } else if (minScheduledDate != null && maxScheduledDate != null) { events = eventRepository.findByScheduledDateBetween(minScheduledDate, maxScheduledDate); } else { - events = eventRepository.findAllByOrderByScheduledDate(); + events = eventRepository.findAllByOrderByScheduledDateDesc(); } User user = userRepository.findByUsername(username); for (Event event: events) { event.setAttendees(attendeesRepository.countByEvent(event)); - Attendee userAttendee = attendeesRepository.findByUserAndEvent(user, event); - event.setUserAttending(userAttendee != null); + List userAttendees = attendeesRepository.findByUserAndEvent(user, event); + event.setUserAttending(!userAttendees.isEmpty()); } List users = userRepository.findAll(); diff --git a/src/main/java/com/makersacademy/acebook/controller/LoginController.java b/src/main/java/com/makersacademy/acebook/controller/LoginController.java index 6ecfd1b2..94080367 100644 --- a/src/main/java/com/makersacademy/acebook/controller/LoginController.java +++ b/src/main/java/com/makersacademy/acebook/controller/LoginController.java @@ -13,6 +13,6 @@ public String login() { @GetMapping("/loginSuccess") public String loginSuccess() { - return "/"; + return "redirect:/"; } } diff --git a/src/main/java/com/makersacademy/acebook/controller/UserController.java b/src/main/java/com/makersacademy/acebook/controller/UserController.java index b286cea2..80b8854d 100644 --- a/src/main/java/com/makersacademy/acebook/controller/UserController.java +++ b/src/main/java/com/makersacademy/acebook/controller/UserController.java @@ -25,25 +25,21 @@ public class UserController { @GetMapping public String accountPage(@AuthenticationPrincipal Object principal, Model model) { User user = null; -// boolean isAuthenticated = false; if (principal instanceof UserDetails) { UserDetails currentUser = (UserDetails) principal; user = userService.findByUsername(currentUser.getUsername()); -// isAuthenticated = true; } else if (principal instanceof OAuth2User) { OAuth2User oauthUser = (OAuth2User) principal; String email = oauthUser.getAttribute("email"); user = userService.findByEmail(email); -// isAuthenticated = true; } if (user != null) { model.addAttribute("user", user); -// model.addAttribute("isAuthenticated", isAuthenticated); return "/account"; } else { @@ -82,7 +78,7 @@ public String handleGoogleLogin(OAuth2AuthenticationToken token, RedirectAttribu } redirectAttributes.addFlashAttribute("message", "Logged in with Google successfully!"); - return "events/new"; + return ""; } } diff --git a/src/main/java/com/makersacademy/acebook/repository/AttendeesRepository.java b/src/main/java/com/makersacademy/acebook/repository/AttendeesRepository.java index e510e8c4..80a7b703 100644 --- a/src/main/java/com/makersacademy/acebook/repository/AttendeesRepository.java +++ b/src/main/java/com/makersacademy/acebook/repository/AttendeesRepository.java @@ -9,5 +9,6 @@ public interface AttendeesRepository extends CrudRepository { public Long countByEvent (Event event); - public Attendee findByUserAndEvent(User user, Event event); + // Modify this method to return a List of attendees + List findByUserAndEvent(User user, Event event); } diff --git a/src/main/java/com/makersacademy/acebook/repository/EventRepository.java b/src/main/java/com/makersacademy/acebook/repository/EventRepository.java index 1f7943d8..77dfa854 100644 --- a/src/main/java/com/makersacademy/acebook/repository/EventRepository.java +++ b/src/main/java/com/makersacademy/acebook/repository/EventRepository.java @@ -10,12 +10,12 @@ public interface EventRepository extends CrudRepository { - // Method to fetch all events ordered by scheduledDate - List findAllByOrderByScheduledDate(); + // Method to find events by a specific scheduledDate List findByScheduledDateBetween(Date minScheduledDate, Date maxScheduledDate); - + // Searching term @Query("SELECT e FROM Event e WHERE LOWER(e.title) LIKE LOWER(CONCAT('%', :keyword, '%')) OR LOWER(e.user.username) LIKE LOWER(CONCAT('%', :keyword, '%')) OR LOWER(e.location) LIKE LOWER(CONCAT('%', :keyword, '%'))") List searchEventsByTitleOrUsernameOrLocation(@Param("keyword") String keyword); -} + // Method to fetch all events ordered by scheduledDate in descending order + List findAllByOrderByScheduledDateDesc();} diff --git a/src/main/java/com/makersacademy/acebook/repository/UserRepository.java b/src/main/java/com/makersacademy/acebook/repository/UserRepository.java index 15300288..e466a452 100644 --- a/src/main/java/com/makersacademy/acebook/repository/UserRepository.java +++ b/src/main/java/com/makersacademy/acebook/repository/UserRepository.java @@ -4,13 +4,10 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import java.util.List; - @Repository public interface UserRepository extends JpaRepository { User findByUsername(String username); User findIdByUsername(String name); User findByEmail(String email); - List findByUsernameContaining(String username); } diff --git a/src/main/resources/templates/fragments/navbar.html b/src/main/resources/templates/fragments/navbar.html index fd54e380..90a4cf8c 100644 --- a/src/main/resources/templates/fragments/navbar.html +++ b/src/main/resources/templates/fragments/navbar.html @@ -1,5 +1,5 @@ - + @@ -17,7 +17,6 @@ } -
- - - @@ -41,32 +37,24 @@ Find events
-
- -
+ Account
- -
-
- - -
-
-
- - +
+
+ +
+
+
+ + +
diff --git a/src/main/resources/templates/landingpage.html b/src/main/resources/templates/landingpage.html index 6b22d872..a9e6e5a9 100644 --- a/src/main/resources/templates/landingpage.html +++ b/src/main/resources/templates/landingpage.html @@ -34,16 +34,23 @@

Events

  • +
    + Image: + Event Image + Default Event Image +
    Title:
    Description:
    Date:
    Time:
    - - - - - +
    + +
    +

    You are attending this event!

    +

  • From c71195fd69b75f1eed6f043bb56b61bc0b314ed2 Mon Sep 17 00:00:00 2001 From: EthanDunwiddie Date: Wed, 26 Jun 2024 15:50:26 +0100 Subject: [PATCH 3/4] updated user controller --- .../acebook/controller/UserController.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/makersacademy/acebook/controller/UserController.java b/src/main/java/com/makersacademy/acebook/controller/UserController.java index 2a549aaf..3c48e410 100644 --- a/src/main/java/com/makersacademy/acebook/controller/UserController.java +++ b/src/main/java/com/makersacademy/acebook/controller/UserController.java @@ -15,14 +15,13 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; @Controller -@RequestMapping("/account") public class UserController { @Autowired private UserService userService; - @GetMapping + @GetMapping("/account") public String accountPage(@AuthenticationPrincipal Object principal, Model model) { User user = null; @@ -42,7 +41,7 @@ public String accountPage(@AuthenticationPrincipal Object principal, Model model } } - @PostMapping + @PostMapping("/account") public String updateAccount(@AuthenticationPrincipal Object principal, User updatedUser, RedirectAttributes redirectAttributes) { User user = null; @@ -93,7 +92,7 @@ public String updateAccount(@AuthenticationPrincipal Object principal, User upda return "redirect:/account"; } - @GetMapping("/password") + @GetMapping("/account/password") public String passwordPage(@AuthenticationPrincipal Object principal, RedirectAttributes redirectAttributes, Model model) { User user = null; @@ -121,7 +120,7 @@ public String passwordPage(@AuthenticationPrincipal Object principal, RedirectAt return "updatePassword"; } - @PostMapping("/password") + @PostMapping("/account/password") public String changePassword(@AuthenticationPrincipal Object principal, String newPassword, String confirmPassword, RedirectAttributes redirectAttributes) { User user = null; @@ -155,7 +154,7 @@ public String changePassword(@AuthenticationPrincipal Object principal, String n return "redirect:/account"; } - @GetMapping("/login/oauth2/code/google") + @GetMapping("/account/login/oauth2/code/google") public String handleGoogleLogin(OAuth2AuthenticationToken token, RedirectAttributes redirectAttributes) { OAuth2User oauthUser = token.getPrincipal(); String email = oauthUser.getAttribute("email"); From bc3f9e0fa2305502384b330cf16d77cede6bd4f4 Mon Sep 17 00:00:00 2001 From: Yuanmeng Liu Date: Wed, 26 Jun 2024 16:00:25 +0100 Subject: [PATCH 4/4] add external links --- .../templates/fragments/dark-mode.html | 70 +++++++++++++++ .../resources/templates/fragments/loyout.html | 20 ++--- .../resources/templates/fragments/navbar.html | 6 +- src/main/resources/templates/landingpage.html | 88 +++++++++++++++++-- tailwind.config.js | 6 +- 5 files changed, 165 insertions(+), 25 deletions(-) create mode 100644 src/main/resources/templates/fragments/dark-mode.html diff --git a/src/main/resources/templates/fragments/dark-mode.html b/src/main/resources/templates/fragments/dark-mode.html new file mode 100644 index 00000000..1113866b --- /dev/null +++ b/src/main/resources/templates/fragments/dark-mode.html @@ -0,0 +1,70 @@ + + + + + + +
    + + + + + +
    + + diff --git a/src/main/resources/templates/fragments/loyout.html b/src/main/resources/templates/fragments/loyout.html index 4631f86a..5725b633 100644 --- a/src/main/resources/templates/fragments/loyout.html +++ b/src/main/resources/templates/fragments/loyout.html @@ -1,21 +1,15 @@ - - - My Application - + My Website + + + - - + +
    -

    Content goes here...

    -
    - - -
    - - + +
    - \ No newline at end of file + diff --git a/src/main/resources/templates/landingpage.html b/src/main/resources/templates/landingpage.html index e0d6bf09..22d5aba3 100644 --- a/src/main/resources/templates/landingpage.html +++ b/src/main/resources/templates/landingpage.html @@ -3,9 +3,13 @@ Website-Hosted Events - - + + + +
    + +
    @@ -16,25 +20,92 @@
    -
    -
    -
    + +
    +
    + +
    +
    -

    Events

    +

    Events

    + - \ No newline at end of file + diff --git a/tailwind.config.js b/tailwind.config.js index d10511c3..09da2ada 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -1,5 +1,6 @@ /** @type {import('tailwindcss').Config} */ module.exports = { + darkMode: 'class', // Enable class-based dark mode content: [ "./pages/**/*.{js,ts,jsx,tsx,mdx}", "./components/**/*.{js,ts,jsx,tsx,mdx}", @@ -10,11 +11,10 @@ module.exports = { extend: { backgroundImage: { "gradient-radial": "radial-gradient(var(--tw-gradient-stops))", - "gradient-conic": - "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))", + "gradient-conic": "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))", }, }, }, presets: [require("@relume_io/relume-tailwind")], plugins: [], -}; \ No newline at end of file +};