Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/workspace.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/example/maphub/Consts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.maphub;

import java.time.LocalDateTime;

public class Consts {
public static final LocalDateTime SERVER_START_TIME = LocalDateTime.of(2020, 3,29,22,37);
public static final int TOTAL_UK_BUILDINGS = 30000000;
public static final int MILLIS_IN_DAY = 86400000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
"/images/**",
"/favicon.ico",
"/ForgotPassword.html",
"/building/**"
"/building/**",
"/map/**",
"/stats/homePage/**",
"/stats/homePage"
).permitAll()
.requestMatchers("/user/me","/Profile.html").authenticated()
.anyRequest().authenticated()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.example.maphub;
package com.example.maphub.controllers;
import com.example.maphub.PasswordUtil;
import com.example.maphub.entities.*;
import com.example.maphub.entities.otc.NewOTCRequest;
import com.example.maphub.entities.otc.OTCResetPasswordRequest;
import com.example.maphub.entities.otc.VerificationResponse;
import com.example.maphub.services.OTCService;
import com.example.maphub.services.PasswordValidationService;
import com.example.maphub.services.ProxyAPIService;
Expand All @@ -8,11 +12,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;

import javax.swing.plaf.synth.SynthTabbedPaneUI;
import java.security.Principal;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -81,7 +82,7 @@ public ResponseEntity<?> register(@RequestBody LoginUser user) {
return ResponseEntity.badRequest().body(passwordErrors);
}
userService.deleteByUuid(uuid);
userService.register(uuid,PasswordUtil.hash(user.password));
userService.register(uuid, PasswordUtil.hash(user.password));
otcService.createOneTimeCode(uuid,"REGISTER");//should be a const in the future
return ResponseEntity.ok("OTC Created");
}
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/com/example/maphub/controllers/MapController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.maphub.controllers;

import com.example.maphub.entities.MapBounds;
import com.example.maphub.entities.buildings.BuildingGridItem;
import com.example.maphub.entities.buildings.BuildingGridRequest;
import com.example.maphub.entities.mapResponses.CloseUpResponse;
import com.example.maphub.entities.mapResponses.OverviewResponse;
import com.example.maphub.services.BuildingService;
import com.example.maphub.services.HeatmapService;
import com.example.maphub.services.ProxyAPIService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.List;

@RestController
@RequestMapping("/map")
public class MapController {

private final BuildingService buildingService;
private final HeatmapService heatmapService;
private final ProxyAPIService proxyAPIService;
public MapController(BuildingService buildingService, HeatmapService heatmapService, ProxyAPIService proxyAPIService){
this.buildingService = buildingService;
this.heatmapService = heatmapService;
this.proxyAPIService = proxyAPIService;
}

@PostMapping("/overview")
public ResponseEntity<?> getOverview(@RequestBody BuildingGridRequest req, Principal principal){
List<BuildingGridItem> buildings = buildingService.getGridCount(req,principal);
OverviewResponse resp = new OverviewResponse();
resp.heatmap = heatmapService.getHeatmap(buildings, buildingService.getTotalCount());
resp.buildings = buildingService.getGroupedGridCounts(buildings);
return ResponseEntity.ok(resp);
}
@PostMapping("/closeUp")
public ResponseEntity<?> getCloseUp(@RequestBody MapBounds req, Principal principal){
CloseUpResponse resp = new CloseUpResponse();
resp.buildings = buildingService.getAllBuildings(req,principal);
return ResponseEntity.ok(resp);
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/example/maphub/controllers/StatsController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.example.maphub.controllers;


import com.example.maphub.entities.stats.HomeStatsResp;
import com.example.maphub.entities.stats.StatsFilters;
import com.example.maphub.services.StatsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

@RestController
@RequestMapping("/stats")
public class StatsController {

private final StatsService statsService;
public StatsController(StatsService statsService){
this.statsService = statsService;
}
@GetMapping("/homePage")
public ResponseEntity<?> getHomePageStats(){
HomeStatsResp resp = statsService.getHomepageStats();
return ResponseEntity.ok(resp);
}
@GetMapping("/profile")
public ResponseEntity<?> getProfileStats(Principal principal){
if (principal == null){
return ResponseEntity.status(401).body("User not logged in");
}
return ResponseEntity.ok(statsService.getProfileStats(principal.getName()));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub;
package com.example.maphub.controllers;
import com.example.maphub.entities.DeleteAccountRequest;
import com.example.maphub.entities.PasswordChangeObject;
import com.example.maphub.services.PasswordValidationService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub.entities;
package com.example.maphub.entities.buildings;

import java.time.LocalDateTime;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub.entities;
package com.example.maphub.entities.buildings;

public record BuildingDTO(
int buildingId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.example.maphub.entities;
package com.example.maphub.entities.buildings;

public class BuildingGridItem {
public double lat;
public double lon;
public int count;
public int row;
public int col;
public double minLat;
public double minLon;
public double maxLat;
public double maxLon;

public int count() {
return count;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub.entities;
package com.example.maphub.entities.buildings;

public record BuildingGridRequest (
double minLat,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub.entities;
package com.example.maphub.entities.buildings;

public record BuildingGridRespItem(double lat, double lon, int count) {}

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.maphub.entities.mapResponses;

import com.example.maphub.entities.buildings.Building;

import java.util.List;

public class CloseUpResponse {
public List<Building> buildings;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.maphub.entities.mapResponses;

public class HeatmapRespItem {
public double maxLat;
public double minLat;
public double maxLon;
public double minLon;
public int magnitude;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.maphub.entities.mapResponses;

import com.example.maphub.entities.buildings.BuildingGridRespItem;

import java.util.List;

public class OverviewResponse {
public List<BuildingGridRespItem> buildings;
public List<HeatmapRespItem> heatmap;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub.entities;
package com.example.maphub.entities.otc;

public class NewOTCRequest {
public String purpose;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub.entities;
package com.example.maphub.entities.otc;

public class OTCResetPasswordRequest {
public String username;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub.entities;
package com.example.maphub.entities.otc;

import jakarta.persistence.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub.entities;
package com.example.maphub.entities.otc;

public class VerificationResponse {
public String username;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.maphub.entities;
package com.example.maphub.entities.otc;

public class VerificationResult {
public String username;
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/example/maphub/entities/stats/HomeStatsResp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.maphub.entities.stats;

import java.time.LocalDateTime;

public class HomeStatsResp {
public int buildings;
public double percentage;
public int buildingsRecent; //buildings in the last month?
public LocalDateTime estimatedFinishDate;
public int previousRecentBuildings;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.maphub.entities.stats;

public class PlayerBaseStats {
public int buildings;
public int tplls;
public int timePlayed;
public int messagesSent;
public int reviewsCompleted;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.maphub.entities.stats;

public class ProfileStatsResp {
public int buildings;
public int tplls;
public float timeNonAFK;
public String productivity;
public int messagesSent;
public int reviewsCompleted;
}
10 changes: 10 additions & 0 deletions src/main/java/com/example/maphub/entities/stats/StatsFilters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.maphub.entities.stats;

import java.time.LocalDateTime;
import java.util.List;

public class StatsFilters {
public List<String> playeruuid;
public LocalDateTime timeStart;
public LocalDateTime timeEnd;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.maphub.entities.stats;

public class TotalBaseStats {
public int buildings;
public int recentBuildings;
public int previousRecentBuildings;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.maphub.repositories;

import com.example.maphub.entities.OneTimeCode;
import com.example.maphub.entities.otc.OneTimeCode;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;
Expand Down
Loading