Skip to content

Commit

Permalink
Merge pull request #12 from rainestormee/devHelp
Browse files Browse the repository at this point in the history
Really hacky barely works
  • Loading branch information
andreeaivancu authored Oct 25, 2020
2 parents 84bc92c + fa762a9 commit 31c9534
Show file tree
Hide file tree
Showing 38 changed files with 1,174 additions and 336 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ node_modules
resources/templates/css/**
resources/templates/js/**
resources/templates/fonts/**
dist
dist

.factorypath/
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# help-the-midlands
Submission for HackTheMidlands 5.0

## Categories
- Making IT Good For Society
- Supporting The Fight Against COVID-19
- Helping Your Local Community

## Concept

HelpTheMidlands is a web application designed to allow people to volunteer in their local communities by picking up shopping for those currently isolating due to coronavirus, or those who are older and may find it difficult to go to the shops.

This app has been designed with simplicity in mind, as we find that many online stores make it confusing for the elderly to place an order then setup a delivery slot.

Volunteers respond to requests made by supportees (*vulnerable people*) for food or other shopping.

## Usage

You can register as a **volunteer** or a **supportee** using your name, an email address and a password.

Once logged in, the supportee makes a request (shopping list) for each item of shopping they need, with a note of their budget and their preferred store. (Could be the local corner shop as opposed to be a chain).

A request is then sent out to nearby volunteers, who can then accept it and buy the shopping, delivering it to the vulnerable person.
107 changes: 57 additions & 50 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hackthemidlands.processblinders</groupId>
<artifactId>HackTheMidlands</artifactId>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.hackthemidlands.processblinders.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>com.hackthemidlands.processblinders.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hackthemidlands.processblinders</groupId>
<artifactId>HackTheMidlands</artifactId>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.hackthemidlands.processblinders.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>com.hackthemidlands.processblinders.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

137 changes: 52 additions & 85 deletions src/main/java/com/hackthemidlands/processblinders/Main.java
Original file line number Diff line number Diff line change
@@ -1,116 +1,83 @@
package com.hackthemidlands.processblinders;

import com.hackthemidlands.processblinders.api.Order;
import com.hackthemidlands.processblinders.api.OrderStatus;
import com.hackthemidlands.processblinders.api.User;
import lombok.Getter;
import com.hackthemidlands.processblinders.pages.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import spark.Filter;
import spark.Request;
import spark.Response;
import spark.ModelAndView;
import spark.Spark;
import spark.TemplateEngine;
import spark.template.thymeleaf.ThymeleafTemplateEngine;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static com.hackthemidlands.processblinders.util.OrderUtil.*;
import static com.hackthemidlands.processblinders.util.UserUtil.*;
import static spark.Spark.*;

public final class Main {

private static final Logger logger = LoggerFactory.getLogger(Main.class);
private static final Map<String, User> loggedInUsers = new HashMap<>();

@Getter
private static final List<User> allValidUsers = new ArrayList<>();

public static Filter setSession = (Request request, Response response) -> {
if (hasCookie(request)) {
String cookie = getCookie(request);
System.out.println(cookie);
User user = getUserFromEmail(cookie);
if (user != null) {
loggedInUsers.put(user.getEmail(), user);
} else {
response.redirect("/dev/fuck-off");
}
}
};

public static boolean addNewUserToDatabase(User user) {
if (findUserFromDatabase(user.getEmail()) != null) {
return false;
}
allValidUsers.add(user);
return true;
}

public static User findUserFromDatabase(String email) {
return allValidUsers.stream().filter(u -> u.getEmail().equalsIgnoreCase(email)).findFirst().orElse(null);
}

public static boolean isLoggedIn(User user) {
return loggedInUsers.containsValue(user);
}

public static void main(String[] args) {
Spark.exception(Exception.class, (exception, request, response) -> exception.printStackTrace()); // allow spark to internally handle exceptions
final TemplateEngine templateEngine = new ThymeleafTemplateEngine();
staticFileLocation("/public");
port(8080);

allValidUsers.add(new User());
allValidUsers.add(new User("test", "admin", "admin@admin.com", "pass"));

get("/test/test", new TestViewRoute(), new ThymeleafTemplateEngine());
get("/hello", (req, res) -> "Hello World");
get("/test", (req, res) -> "timer");
get("/goodbye/:name", (req, res) -> "See ya, " + req.params(":name"));
get("/thyme", new TestViewRoute(), new ThymeleafTemplateEngine());
get("/support", new SupportViewRoute(), new ThymeleafTemplateEngine());
get("/login/volunteer", new VolunteerViewRoute(), new ThymeleafTemplateEngine());
get("/login/makeAccount", new MakeAccountViewRoute(), new ThymeleafTemplateEngine());
path("/register", () -> {
post("", (re, rs) -> {
if (re.queryParams("validate").equalsIgnoreCase("Volunteer")) {
Random random = new Random();

getAllValidUsers().addAll(IntStream.range(0, 3).mapToObj(User::dummyVolunteer).collect(Collectors.toList())); // here i add the dummy volunteers 0, 1, 2
getAllValidUsers().addAll(IntStream.range(0, 3).mapToObj(User::dummyUser).collect(Collectors.toList())); // here i add the dummy users 0, 1, 2
getAllValidOrders().addAll(IntStream.range(0, 3)
.mapToObj(i -> Order.builder().shopList(new String[]{
(random.nextInt(10) + i) + " tins of beans", (random.nextInt(i + 1) + 1) + " loaves of bread", (random.nextInt(i + 4) + i) + " pints of milk"})
.id(++Order.maxId)
.user(getAllValidUsers().stream().filter(u -> !u.isVolunteer()).collect(Collectors.toList()).get(i))
.maxPrice(69d).status(OrderStatus.PENDING)
.build())
.collect(Collectors.toList()));

get("/error", (re, rs) -> new ModelAndView(new HashMap<>(), "error"), new ThymeleafTemplateEngine());

return "volunteer";
}
return "not volunteer";
});
get("/", new FrontPage(), templateEngine);

get("", (re, rs) -> "I got a GET request silly");
path("/orders", () -> {
ViewOrdersPage viewOrdersPage = new ViewOrdersPage();
get("/view", viewOrdersPage, templateEngine);

PlaceOrderPage placeOrderPage = new PlaceOrderPage();
post("/new", placeOrderPage.post);
get("/new", placeOrderPage, templateEngine);
});
path("/dev", () -> {
before("/protected", setSession);
get("/protected", (req, res) -> {
User u = getUserFromEmail(getCookie(req));
return "Your name is " + u.getFirstName() + " " + u.getLastName();
});
get("/fuck-off", (req, res) -> "You have been fucked off");
get("/login", (req, res) -> {
loggedInUsers.put(new User().getEmail(), new User());
System.err.println("YOU ARE SUPPOSED TO BE LOGGED IN HERE");
setCookie(res, new User());
return "You have been logged in.";
});

path("/commitTo", () -> {

});
}

public static void setCookie(Response response, User user) {
response.cookie("/", "email", user.getEmail(), -1, false);
}
path("/settings", () -> {
SettingsPage settingsPage = new SettingsPage();
get("", settingsPage, templateEngine);
post("", settingsPage.post);
});

public static boolean hasCookie(Request request) {
return request.cookie("email") != null;
}
path("/login", () -> {
LoginPage loginPage = new LoginPage();
get("", loginPage, templateEngine);
post("", loginPage.post);
});

public static String getCookie(Request request) {
return request.cookie("email");
}
path("/register", () -> {
RegisterPage registerPage = new RegisterPage();
post("", registerPage.post);
get("", registerPage, templateEngine);
});

public static User getUserFromEmail(String email) {
return findUserFromDatabase(email);
path("/dev", new DevPage().getRoutes);
}

}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 31c9534

Please sign in to comment.