Skip to content

Commit

Permalink
Merge pull request #26 from The-Socialites/feature/landingPage
Browse files Browse the repository at this point in the history
Feature/landing page
  • Loading branch information
EthanDunwiddie committed Jun 26, 2024
2 parents c71195f + bc3f9e0 commit ee8ebc8
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.springframework.security.web.SecurityFilterChain;

@EnableWebSecurity


@Configuration
public class SecurityConfig {

Expand All @@ -30,7 +32,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.cors().and()
.authorizeRequests(authorizeRequests ->
authorizeRequests
.antMatchers("/", "/login", "/register","/images/**", "/users","/error/**", "/styles/**", "/search", "/events", "/events/attend/**", "/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 ->
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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<Attendee> userAttendees = attendeesRepository.findByUserAndEvent(user, event);
event.setUserAttending(!userAttendees.isEmpty());
}

List<User> users = userRepository.findAll();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public String login() {

@GetMapping("/loginSuccess")
public String loginSuccess() {
return "redirect:/ ";
return "redirect:/";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,26 @@ public class UserController {
@GetMapping("/account")
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 {
return "redirect:/login";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@

public interface AttendeesRepository extends CrudRepository<Attendee, Long> {
public Long countByEvent (Event event);
public Attendee findByUserAndEvent(User user, Event event);
// Modify this method to return a List of attendees
List<Attendee> findByUserAndEvent(User user, Event event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

public interface EventRepository extends CrudRepository<Event, Long> {

// Method to fetch all events ordered by scheduledDate
List<Event> findAllByOrderByScheduledDate();


// Method to find events by a specific scheduledDate
List<Event> 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<Event> searchEventsByTitleOrUsernameOrLocation(@Param("keyword") String keyword);
}
// Method to fetch all events ordered by scheduledDate in descending order
List<Event> findAllByOrderByScheduledDateDesc();}
Original file line number Diff line number Diff line change
Expand Up @@ -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, Long> {
User findByUsername(String username);
User findIdByUsername(String name);
User findByEmail(String email);
List<User> findByUsernameContaining(String username);

}
12 changes: 0 additions & 12 deletions src/main/resources/templates/events/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,7 @@ <h1>Event Details</h1>
<strong>Host:</strong> <span th:text="${event.user.username}"></span>
</div>

<form action="#" th:action="@{/events/details/{id}/comments/new(id=${{event.id}})}" th:object="${comment}" method="post">
<p>Comment: <input type="text" th:field="*{content}" /></p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>

<h5 th:text="${comments.isEmpty}? 'No comments yet' : 'Comments'"></h5>
<ul>
<li th:each="comment : ${comments}">
<p th:text="${comment.user.username}"></p>
<p th:text="${comment.formattedCreatedAt}"></p>
<p th:text="${comment.content}"></p>
</li>
</ul>


</body>
Expand Down
70 changes: 70 additions & 0 deletions src/main/resources/templates/fragments/dark-mode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<style>
/* Light Mode Styles */
.light-mode {
background-color: #f7fafc; /* Tailwind light mode bg-gray-100 */
color: #1a202c; /* Tailwind light mode text-gray-900 */
}

/* Dark Mode Styles */
.dark-mode {
background-color: #1a202c; /* Tailwind dark mode bg-gray-900 */
color: #cbd5e0; /* Tailwind dark mode text-gray-300 */
}

/* Additional Styles for Body Element */
body.light-mode {
background-color: #f7fafc;
color: #1a202c;
}

body.dark-mode {
background-color: #1a202c;
color: #cbd5e0;
}
</style>
</head>
<body>
<div th:fragment="dark-mode">
<!-- Dark Mode Toggle Button -->
<button id="dark-mode-toggle" class="p-2 bg-gray-200 dark:bg-gray-800 rounded ml-4 text-gray-800 dark:text-gray-200">
<i id="dark-mode-icon" class="fas fa-moon"></i>
</button>

<!-- Dark Mode Script -->
<script>
document.addEventListener("DOMContentLoaded", function() {
const toggleButton = document.getElementById('dark-mode-toggle');
const darkModeIcon = document.getElementById('dark-mode-icon');
const bodyElement = document.body;
const currentTheme = localStorage.getItem('theme');

if (currentTheme === 'dark') {
bodyElement.classList.remove('light-mode');
bodyElement.classList.add('dark-mode');
darkModeIcon.classList.remove('fa-moon');
darkModeIcon.classList.add('fa-sun');
}

toggleButton.addEventListener('click', function() {
if (bodyElement.classList.contains('dark-mode')) {
bodyElement.classList.remove('dark-mode');
bodyElement.classList.add('light-mode');
localStorage.setItem('theme', 'light');
darkModeIcon.classList.remove('fa-sun');
darkModeIcon.classList.add('fa-moon');
} else {
bodyElement.classList.remove('light-mode');
bodyElement.classList.add('dark-mode');
localStorage.setItem('theme', 'dark');
darkModeIcon.classList.remove('fa-moon');
darkModeIcon.classList.add('fa-sun');
}
});
});
</script>
</div>
</body>
</html>
20 changes: 7 additions & 13 deletions src/main/resources/templates/fragments/loyout.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Application</title>
<link rel="stylesheet" th:href="@{/css/styles.css}">
<title th:fragment="title">My Website</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>
</head>
<body>
<!-- Navigation Bar -->
<body class="light-mode">
<!-- Include Navbar -->
<div th:replace="fragments/navbar :: navbar"></div>

<!-- Main Content -->
<div th:fragment="content">
<p>Content goes here...</p>
</div>

<!-- Footer -->
<div th:replace="fragments/footer :: footer"></div>
</body>
</html>
<!-- Page-specific content
7 changes: 5 additions & 2 deletions src/main/resources/templates/fragments/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<head>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://kit.fontawesome.com/a076d05399.js" crossorigin="anonymous"></script>

<style>
.rounded-circle {
border-radius: 9999px;
Expand All @@ -17,7 +19,6 @@
}
</style>
</head>

<body>
<div th:fragment="navbar">
<nav class="flex w-full items-center border-b border-border-primary bg-background-primary lg:min-h-18 lg:px-[5%]">
Expand Down Expand Up @@ -56,10 +57,12 @@
<a href="/register" class="block py-3 text-md focus-visible:outline-none lg:px-4 lg:py-2 lg:text-base">Signup</a>
</button>
</div>
<!-- Include Dark Mode Fragment -->
<div th:replace="fragments/dark-mode :: dark-mode"></div>
</div>
</div>
</div>
</nav>
</div>
</body>
</html>
</html>
Loading

0 comments on commit ee8ebc8

Please sign in to comment.