Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pantry refactor #123

Merged
merged 102 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
334a2d4
Merge pull request #117 from COS301-SE-2023/PantryRefactor
SkulderLock Sep 7, 2023
ef99e5c
🚧 Adding barcode scanner
SkulderLock Sep 7, 2023
6c81c19
✨ Frontend barcode functionality
SkulderLock Sep 7, 2023
a409bcc
🐛 Bug fix and Barcode frontend components
SkulderLock Sep 7, 2023
3a88027
✨ Added Dynamic collections for products
SkulderLock Sep 8, 2023
ecbea60
🚧 Added methods to choose store
SkulderLock Sep 8, 2023
5379238
🚧 Webscraper code added
SkulderLock Sep 9, 2023
292f8dd
🚧 Get sitemap links Checkers
SkulderLock Sep 9, 2023
69b7cfc
🚧 Logic to process links
SkulderLock Sep 9, 2023
0930af5
🚧 Method to handle category links
SkulderLock Sep 10, 2023
294fd6b
🚧
SkulderLock Sep 10, 2023
b433ecc
🚧 Method to handle product link
SkulderLock Sep 10, 2023
3a0741f
♻️ Change to use constructors instead of autowired
SkulderLock Sep 10, 2023
9418dfd
🚧 Scraping scheduling
SkulderLock Sep 10, 2023
74fc509
🗃️ Added index
SkulderLock Sep 11, 2023
8512585
🐛 small fixes and extended timeout duration
SkulderLock Sep 11, 2023
90d8a6b
✨ Checkers Scraper + logs
SkulderLock Sep 12, 2023
7c22dba
✨ Price shown in modal
SkulderLock Sep 15, 2023
13177e2
✨ Total Price showing on shopping list
SkulderLock Sep 15, 2023
96eb0c5
🐛 bug fixes
SkulderLock Sep 15, 2023
7eab97f
➖ remove confilicting dependencies
SkulderLock Sep 17, 2023
ee491a8
Update home.page.ts
theodorleroux Sep 18, 2023
f64233c
images fixed
theodorleroux Sep 19, 2023
38fec0f
more css fixed
theodorleroux Sep 19, 2023
7b0d431
Create HydrationService.java
theodorleroux Sep 19, 2023
5f156c2
Create TriggerService.java
theodorleroux Sep 19, 2023
225c5ee
Create RecommendationService.java
theodorleroux Sep 19, 2023
f46224a
Update daily-meals.component.scss
theodorleroux Sep 21, 2023
affd637
Create LogEntryModel.java
theodorleroux Sep 21, 2023
b33082f
Update RecommendationService.java
theodorleroux Sep 21, 2023
df3bb9a
Relationship over new nodes
theodorleroux Sep 21, 2023
18615f6
Update HasLogEntry.java
theodorleroux Sep 21, 2023
bd64707
added relationships to user
theodorleroux Sep 21, 2023
8e14a74
removed empty constructor
theodorleroux Sep 21, 2023
f5c9872
mb gang
theodorleroux Sep 21, 2023
a449e08
Update MealManagementController.java
theodorleroux Sep 21, 2023
a72c55e
Create LogService.java
theodorleroux Sep 21, 2023
ffac33e
added findbymealNameFor logservice
theodorleroux Sep 21, 2023
be387d6
logging of meals added
theodorleroux Sep 21, 2023
bd5d27c
regen logged
theodorleroux Sep 21, 2023
9d10ca9
Logging Functional
theodorleroux Sep 21, 2023
173c8ac
cleanup
theodorleroux Sep 21, 2023
9a3b7e2
poll user list and set if processed.
theodorleroux Sep 21, 2023
19771b3
Tweaked poll rate
theodorleroux Sep 21, 2023
8d1c23e
Create ViewModel.java
theodorleroux Sep 21, 2023
55eb4ff
moved to correct folder
theodorleroux Sep 21, 2023
7b4b5d9
updated models to support view
theodorleroux Sep 21, 2023
84eb71c
ensure hashmap exists
theodorleroux Sep 21, 2023
7f688fe
added ability to find a users unprocessed log entries
theodorleroux Sep 21, 2023
fa0bedf
update view model and efficient processing
theodorleroux Sep 21, 2023
79c8ba9
data procesing and normalisation for hashmap
theodorleroux Sep 21, 2023
79739c0
cleanup
theodorleroux Sep 21, 2023
4d403de
flesh out hydration system, i take break now
theodorleroux Sep 21, 2023
8a72332
View Creation
theodorleroux Sep 21, 2023
c6a3c3a
Delete TriggerService.java
theodorleroux Sep 21, 2023
aeaefec
done for the day i cant think
theodorleroux Sep 21, 2023
fd32144
i lied, save request mapped, now im done
theodorleroux Sep 21, 2023
ddcfba9
fixed build error
theodorleroux Sep 22, 2023
9a2f03d
score tweaks
theodorleroux Sep 22, 2023
e8e27ad
enabled scheduliung and lowered polling rate
theodorleroux Sep 22, 2023
6da0b3d
many fixes
theodorleroux Sep 22, 2023
0286084
working now, lottta fixes
theodorleroux Sep 22, 2023
f8396c5
Update HydrationService.java
theodorleroux Sep 22, 2023
d1bf894
✨ New exception handler
SkulderLock Sep 23, 2023
c7e05b2
actually fixed now
theodorleroux Sep 23, 2023
10d979f
value tweaks
theodorleroux Sep 23, 2023
a79b84b
mapped out recommendation
theodorleroux Sep 23, 2023
60527bb
function to get certain values added
theodorleroux Sep 23, 2023
0e6d09e
Update ViewModel.java
theodorleroux Sep 23, 2023
0b7463a
pantry list function
theodorleroux Sep 23, 2023
b473f54
✨ qol changes
SkulderLock Sep 23, 2023
7762403
Common items Function added
theodorleroux Sep 23, 2023
378339a
Update RecommendationService.java
theodorleroux Sep 23, 2023
fad123f
ingredient testing on regen
theodorleroux Sep 23, 2023
1b55836
Forgot @servvice smh
theodorleroux Sep 23, 2023
9001bb1
add meal passing for mealgenerationservice
theodorleroux Sep 23, 2023
05b7fa0
generateFromIngredients added
theodorleroux Sep 23, 2023
cbf9584
Added overloaded Functions to include Liked Ingredeints
theodorleroux Sep 23, 2023
1430eaf
gpt now gets queried with liked meals, not tested
theodorleroux Sep 23, 2023
34ac446
forgot to change
theodorleroux Sep 23, 2023
3810575
all implemented except for checking the database for valid meals
theodorleroux Sep 23, 2023
82b966a
to lower case trim to ensure less duplicates
theodorleroux Sep 23, 2023
6e86bba
to lower case for comparisons
theodorleroux Sep 23, 2023
fc0cfcd
better trimming
theodorleroux Sep 23, 2023
95e7a38
cleanup and better regex matching
theodorleroux Sep 23, 2023
92fa9d6
cleanup and trimming whitespace on list creation
theodorleroux Sep 23, 2023
59171e6
cleanup
theodorleroux Sep 23, 2023
909a7ed
added function and variable to find a meal in the database the user c…
theodorleroux Sep 23, 2023
908d597
done, time for testing
theodorleroux Sep 23, 2023
4c8db1a
fixed some dumb logic error of mine
theodorleroux Sep 23, 2023
8678128
🐛 minor change
SkulderLock Sep 23, 2023
50eca20
🍱 App Icon
SkulderLock Sep 23, 2023
53c2f3a
Optimise view model
theodorleroux Sep 24, 2023
2963c84
cleanup
theodorleroux Sep 24, 2023
7517c03
last tweak for the day
theodorleroux Sep 24, 2023
241288f
Merge pull request #126 from COS301-SE-2023/hydration-system-PantryRe…
SkulderLock Sep 24, 2023
9f9ce1d
🐛 fix for building
SkulderLock Sep 24, 2023
ddeb485
Merge branch 'PantryRefactor' into Web-Scraper
SkulderLock Sep 24, 2023
94568d8
🐛 merge conflict fix
SkulderLock Sep 24, 2023
3310357
Merge pull request #127 from COS301-SE-2023/Web-Scraper
SkulderLock Sep 24, 2023
ae0182a
✅ update tests
SkulderLock Sep 24, 2023
afda8ea
Merge branch 'development' into PantryRefactor
SkulderLock Sep 24, 2023
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
3 changes: 2 additions & 1 deletion android/app/capacitor.build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ android {

apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
implementation project(':capacitor-mlkit-barcode-scanning')
implementation project(':capacitor-app')
implementation project(':capacitor-haptics')
implementation project(':capacitor-http')
implementation project(':capacitor-keyboard')
implementation project(':capacitor-status-bar')

implementation "androidx.webkit:webkit:1.4.0"
}


Expand Down
8 changes: 8 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">

<meta-data android:name="com.google.mlkit.vision.DEPENDENCIES" android:value="barcode-ui" />

<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name=".MainActivity"
Expand Down Expand Up @@ -38,4 +40,10 @@
<!-- Permissions -->

<uses-permission android:name="android.permission.INTERNET" />

<!-- To get access to the camera -->
<uses-permission android:name="android.permission.CAMERA" />

<!-- To get access to the flashlight -->
<uses-permission android:name="android.permission.FLASHLIGHT" />
</manifest>
3 changes: 3 additions & 0 deletions android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')

include ':capacitor-mlkit-barcode-scanning'
project(':capacitor-mlkit-barcode-scanning').projectDir = new File('../node_modules/@capacitor-mlkit/barcode-scanning/android')

include ':capacitor-app'
project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/android')

Expand Down
2 changes: 2 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-neo4j'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-logging'
implementation 'org.jsoup:jsoup:1.16.1'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package fellowship.mealmaestro;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.fasterxml.jackson.core.JsonProcessingException;


@SpringBootApplication
@EnableScheduling
public class MealmaestroApplication {

public static void main(String[] args) throws JsonProcessingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
Expand Down Expand Up @@ -45,4 +47,13 @@ public PasswordEncoder passwordEncoder() {
public AuthenticationManager authenticationManager(AuthenticationConfiguration config) throws Exception {
return config.getAuthenticationManager();
}

@Bean
public TaskScheduler taskScheduler() {
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(6);
scheduler.initialize();
return scheduler;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import fellowship.mealmaestro.config.exceptions.UserNotFoundException;

@RestControllerAdvice
public class GlobalExceptionHandler {

// @ExceptionHandler(RuntimeException.class)
// public ResponseEntity<String> handleUserNotFoundException(RuntimeException e)
// {
// return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
// }
@ExceptionHandler(UserNotFoundException.class)
public ResponseEntity<String> handleUserNotFoundException(UserNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Driver neo4jDriver() {
username = "No DB Username Found";
password = "No DB Password Found";
}

return GraphDatabase.driver(uri, AuthTokens.basic(username, password));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,31 @@ public class SecurityConfig {

private final AuthenticationProvider authenticationProvider;

public SecurityConfig(JwtAuthenticationFilter jwtAuthFilter, AuthenticationProvider authenticationProvider){
public SecurityConfig(JwtAuthenticationFilter jwtAuthFilter, AuthenticationProvider authenticationProvider) {
this.jwtAuthFilter = jwtAuthFilter;
this.authenticationProvider = authenticationProvider;
}

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception{
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(authReq -> authReq
.requestMatchers("/register", "/authenticate")
.permitAll()
.anyRequest()
.authenticated()
)
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
)
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);

.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.csrf(csrf -> csrf.disable())
.authorizeHttpRequests(authReq -> authReq
.requestMatchers("/register", "/authenticate", "/hello")
.permitAll()
.anyRequest()
.authenticated())
.sessionManagement(session -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);

http.authenticationProvider(authenticationProvider);
return http.build();
}

@Bean
CorsConfigurationSource corsConfigurationSource(){
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration corsConfig = new CorsConfiguration();
corsConfig.setAllowedOrigins(Arrays.asList("*"));
corsConfig.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package fellowship.mealmaestro.config.exceptions;

public class UserNotFoundException extends RuntimeException {
public UserNotFoundException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -15,8 +14,11 @@
@RestController
public class BrowseController {

@Autowired
private BrowseService browseService;
private final BrowseService browseService;

public BrowseController(BrowseService browseService) {
this.browseService = browseService;
}

@GetMapping("/getPopularMeals")
public ResponseEntity<List<MealModel>> getPopularMeals(@RequestHeader("Authorization") String token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -19,16 +18,28 @@
import fellowship.mealmaestro.models.RegenerateMealRequest;
import fellowship.mealmaestro.models.neo4j.DateModel;
import fellowship.mealmaestro.models.neo4j.MealModel;
import fellowship.mealmaestro.services.LogService;
import fellowship.mealmaestro.services.MealDatabaseService;
import fellowship.mealmaestro.services.MealManagementService;
import fellowship.mealmaestro.services.RecommendationService;
import jakarta.validation.Valid;

@RestController
public class MealManagementController {
@Autowired
private MealManagementService mealManagementService;
@Autowired
private MealDatabaseService mealDatabaseService;

private final MealManagementService mealManagementService;
private final MealDatabaseService mealDatabaseService;
private final RecommendationService recommendationService;
private final LogService logService;

public MealManagementController(MealManagementService mealManagementService,
MealDatabaseService mealDatabaseService, RecommendationService recommendationService,
LogService logService) {
this.mealManagementService = mealManagementService;
this.mealDatabaseService = mealDatabaseService;
this.recommendationService = recommendationService;
this.logService = logService;
}

@PostMapping("/getMealPlanForDay")
public ResponseEntity<List<MealModel>> dailyMeals(@Valid @RequestBody DateModel request,
Expand Down Expand Up @@ -120,13 +131,26 @@ public ResponseEntity<MealModel> regenerate(@RequestBody RegenerateMealRequest r
@RequestHeader("Authorization") String token)
throws JsonMappingException, JsonProcessingException {

token = token.substring(7);
logService.logMeal(token, request.getMeal(), "regenerate");
MealModel recoMeal = null;
try {
recoMeal = recommendationService.getRecommendedMeal(request.getMeal().getType(), token);
} catch (Exception e) {
System.out.println(e);
}

// Try find an appropriate meal in the database
Optional<MealModel> replacementMeal = mealDatabaseService.findMealTypeForUser(request.getMeal().getType(),
token);
Optional<MealModel> replacementMeal = null;
MealModel returnedMeal = null;

if (recoMeal != null) {
replacementMeal = Optional.ofNullable(recoMeal);
} else {
token = token.substring(7);

// Try find an appropriate meal in the database
replacementMeal = mealDatabaseService.findMealTypeForUser(request.getMeal().getType(), token);
}

if (replacementMeal.isPresent()) {
returnedMeal = mealDatabaseService.replaceMeal(request, replacementMeal.get(), token);
} else {
Expand All @@ -138,16 +162,4 @@ public ResponseEntity<MealModel> regenerate(@RequestBody RegenerateMealRequest r
return ResponseEntity.ok(returnedMeal);
}

// @GetMapping("/getPopularMeals")
// public String popularMeals() throws JsonMappingException,
// JsonProcessingException{
// return mealManagementService.generatePopularMeals();
// }

// @GetMapping("/getSearchedMeals")
// public String searchedMeals(@RequestParam String query) throws
// JsonMappingException, JsonProcessingException {
// // Call the mealManagementService to search meals based on the query
// return mealManagementService.generateSearchedMeals(query);
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -17,8 +16,11 @@
@RestController
public class PantryController {

@Autowired
private PantryService pantryService;
private final PantryService pantryService;

public PantryController(PantryService pantryService) {
this.pantryService = pantryService;
}

@PostMapping("/addToPantry")
public ResponseEntity<FoodModel> addToPantry(@Valid @RequestBody FoodModel request,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package fellowship.mealmaestro.controllers;

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.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

import fellowship.mealmaestro.models.mongo.findBarcodeRequest;
import fellowship.mealmaestro.models.mongo.FoodModelM;
import fellowship.mealmaestro.services.BarcodeService;

@RestController
public class ProductController {

private final BarcodeService barcodeService;

public ProductController(BarcodeService barcodeService) {
this.barcodeService = barcodeService;
}

@PostMapping("/findProduct")
public ResponseEntity<FoodModelM> findProduct(@RequestBody findBarcodeRequest request,
@RequestHeader("Authorization") String token) {
if (token == null || token.isEmpty()) {
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(barcodeService.findProduct(request));
}

@PostMapping("/addProduct")
public ResponseEntity<FoodModelM> addProduct(@RequestBody FoodModelM product,
@RequestHeader("Authorization") String token) {
if (token == null || token.isEmpty()) {
return ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(barcodeService.addProduct(product));
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package fellowship.mealmaestro.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import fellowship.mealmaestro.models.neo4j.MealModel;
import fellowship.mealmaestro.services.LogService;
import fellowship.mealmaestro.services.RecipeBookService;
import jakarta.validation.Valid;

import java.util.List;

@RestController
public class RecipeBookController {

@Autowired
private LogService logService;
private final RecipeBookService recipeBookService;

public RecipeBookController(RecipeBookService recipeBookService) {
Expand All @@ -25,6 +28,8 @@ public ResponseEntity<MealModel> addRecipe(@Valid @RequestBody MealModel request
return ResponseEntity.badRequest().build();
}

logService.logMeal(token, request, "save");

String authToken = token.substring(7);
return ResponseEntity.ok(recipeBookService.addRecipe(request, authToken));
}
Expand Down
Loading
Loading