Skip to content

Commit f3f23d0

Browse files
authored
Merge pull request #313 from COS301-SE-2023/dev
User Release
2 parents b2954ea + 6435e90 commit f3f23d0

File tree

264 files changed

+9523
-7910
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

264 files changed

+9523
-7910
lines changed

.github/workflows/cd-dev.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ jobs:
4141
printf "${{ secrets.ENV_FILE }}" > .env
4242
shell: bash
4343

44+
- name: Setup NX
45+
run: npm install nx@latest
46+
4447
- name: Install Dependencies
4548
run: npm install
4649

@@ -88,12 +91,6 @@ jobs:
8891
- name: Setup NX
8992
run: npm install nx@latest
9093

91-
- name: Setup Enviroment Files
92-
run: |
93-
printf "${{ secrets.API_APPLICATION_PROPERTIES }}" > apps/api/src/main/resources/application.properties
94-
cat apps/api/src/main/resources/application.properties
95-
shell: bash
96-
9794
- name: Build API
9895
run: npm run build:api
9996

.github/workflows/ci-dev.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ jobs:
3838
- name: Install Dependencies
3939
run: npm install
4040

41-
- name: Setup Enviroment Files
42-
run: |
43-
printf "${{ secrets.API_APPLICATION_PROPERTIES }}" > apps/api/src/main/resources/application.properties
44-
cat apps/api/src/main/resources/application.properties
45-
shell: bash
46-
4741
- name: Lint App
4842
run: npx nx run app:lint
4943

@@ -57,11 +51,11 @@ jobs:
5751
with:
5852
files: coverage/lcov.info
5953

60-
- name: e2e Test App
61-
run: npm run e2e:app:test
62-
6354
- name: Build App
6455
run: npm run build:app:dev
56+
57+
- name: e2e Test App
58+
run: npm run e2e:app:test
6559

6660
- name: Build API
6761
run: npm run build:api

.github/workflows/ci-prod.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ jobs:
3434
- name: Install Dependencies
3535
run: npm install
3636

37-
- name: Setup Enviroment Files
38-
run: |
39-
printf "${{ secrets.API_APPLICATION_PROPERTIES }}" > apps/api/src/main/resources/application.properties
40-
cat apps/api/src/main/resources/application.properties
41-
shell: bash
42-
4337
- name: Lint App
4438
run: npx nx run app:lint
4539

@@ -52,12 +46,12 @@ jobs:
5246
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
5347
with:
5448
files: coverage/lcov.info
55-
56-
- name: e2e Test App
57-
run: npm run e2e:app:test
5849

5950
- name: Build App
6051
run: npm run build:app:prod
52+
53+
- name: e2e Test App
54+
run: npm run e2e:app:test
6155

6256
- name: Build API
6357
run: npm run build:api

apps/api/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ dependencies {
1919
implementation 'org.projectlombok:lombok:1.18.20'
2020
annotationProcessor 'org.projectlombok:lombok:1.18.20'
2121
implementation 'org.springframework.boot:spring-boot-starter-graphql'
22+
implementation 'nl.martijndwars:web-push:5.1.1'
23+
implementation 'name.neuhalfen.projects.crypto.bouncycastle.openpgp:bouncy-gpg:2.3.0'
24+
implementation 'org.springframework.boot:spring-boot-starter-websocket'
25+
testImplementation 'org.awaitility:awaitility:3.1.2'
2226
}
2327

2428
tasks.named('test') {
@@ -27,4 +31,4 @@ tasks.named('test') {
2731

2832
jar {
2933
enabled = false
30-
}
34+
}

apps/api/src/main/java/com/fridgetoplate/api/ApiApplication.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import org.springframework.boot.web.client.RestTemplateBuilder;
66
import org.springframework.context.annotation.Bean;
77
import org.springframework.context.annotation.ComponentScan;
8+
import org.springframework.scheduling.annotation.EnableScheduling;
89
import org.springframework.web.client.RestTemplate;
910

11+
@EnableScheduling
1012
@SpringBootApplication
1113
@ComponentScan("com.fridgetoplate")
1214
public class ApiApplication {
@@ -15,8 +17,8 @@ public static void main(String[] args) {
1517
SpringApplication.run(ApiApplication.class, args);
1618
}
1719

18-
@Bean
19-
public RestTemplate restTemplate(RestTemplateBuilder builder) {
20+
@Bean
21+
RestTemplate restTemplate(RestTemplateBuilder builder) {
2022
return builder.build();
2123
}
2224

apps/api/src/main/java/com/fridgetoplate/config/DynamoDBConfiguration.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
88
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
99
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
10+
import com.amazonaws.services.dynamodbv2.document.DynamoDB;
11+
1012
import org.springframework.beans.factory.annotation.Value;
1113
import org.springframework.context.annotation.Bean;
1214
import org.springframework.context.annotation.Configuration;
@@ -28,6 +30,11 @@ public DynamoDBMapper dynamoDBMapper() {
2830
return new DynamoDBMapper(buildAmazonDynamoDB());
2931
}
3032

33+
@Bean
34+
public DynamoDB dynamodb(){
35+
return new DynamoDB(buildAmazonDynamoDB());
36+
}
37+
3138
private AmazonDynamoDB buildAmazonDynamoDB() {
3239
return AmazonDynamoDBClientBuilder
3340
.standard()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.fridgetoplate.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
5+
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
6+
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
7+
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
8+
9+
@Configuration
10+
@EnableWebSocketMessageBroker
11+
12+
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
13+
14+
@Override
15+
public void configureMessageBroker(MessageBrokerRegistry config) {
16+
config.enableSimpleBroker("/all", "/specific");
17+
config.setApplicationDestinationPrefixes("/app");
18+
}
19+
20+
@Override
21+
public void registerStompEndpoints(StompEndpointRegistry registry) {
22+
registry.addEndpoint("/push-notifications").setAllowedOrigins("*");
23+
registry.addEndpoint("/push-notifications").setAllowedOrigins("*").withSockJS();
24+
}
25+
26+
}

apps/api/src/main/java/com/fridgetoplate/controller/ExploreController.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,27 @@
88

99
import org.springframework.beans.factory.annotation.Autowired;
1010
import org.springframework.web.bind.annotation.CrossOrigin;
11-
import org.springframework.web.bind.annotation.DeleteMapping;
12-
import org.springframework.web.bind.annotation.GetMapping;
13-
import org.springframework.web.bind.annotation.PathVariable;
1411
import org.springframework.web.bind.annotation.PostMapping;
15-
import org.springframework.web.bind.annotation.PutMapping;
1612
import org.springframework.web.bind.annotation.RequestBody;
1713
import org.springframework.web.bind.annotation.RequestMapping;
1814
import org.springframework.web.bind.annotation.RequestMethod;
1915
import org.springframework.web.bind.annotation.RestController;
2016

21-
import com.fridgetoplate.frontendmodels.RecipeFrontendModel;
2217
import com.fridgetoplate.interfaces.Explore;
23-
import com.fridgetoplate.interfaces.Recipe;
24-
import com.fridgetoplate.model.Ingredient;
25-
import com.fridgetoplate.model.MealPlanModel;
26-
import com.fridgetoplate.model.ProfileModel;
27-
import com.fridgetoplate.repository.ExploreRepository;
28-
// import com.fridgetoplate.repository.IngredientRepository;
29-
import com.fridgetoplate.repository.MealPlanRepository;
30-
18+
import com.fridgetoplate.interfaces.RecipeDesc;
19+
import com.fridgetoplate.service.ExploreService;
3120
@RestController
3221
@CrossOrigin(origins = "*", allowedHeaders = "*", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE })
3322
@RequestMapping("/explore")
3423

3524
public class ExploreController {
3625

3726
@Autowired
38-
private ExploreRepository exploreRepository;
39-
40-
41-
@GetMapping
42-
public List<RecipeFrontendModel> findAll() {
43-
return exploreRepository.findAll();
44-
}
27+
private ExploreService exploreService;
4528

4629
@PostMapping("/search")
47-
public List<RecipeFrontendModel> findBySearch(@RequestBody Explore search) {
48-
return exploreRepository.findBySearch(search);
30+
public List<RecipeDesc> findBySearch(@RequestBody Explore search) {
31+
return exploreService.findBySearch(search);
4932
}
5033

5134
}

apps/api/src/main/java/com/fridgetoplate/controller/MealPlanController.java

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import org.springframework.web.bind.annotation.GetMapping;
88
import org.springframework.web.bind.annotation.PathVariable;
99
import org.springframework.web.bind.annotation.PostMapping;
10-
import org.springframework.web.bind.annotation.PutMapping;
1110
import org.springframework.web.bind.annotation.RequestBody;
1211
import org.springframework.web.bind.annotation.RequestMapping;
1312
import org.springframework.web.bind.annotation.RestController;
1413
import org.springframework.web.bind.annotation.RequestMethod;
1514

1615
import com.fridgetoplate.frontendmodels.MealPlanFrontendModel;
16+
import com.fridgetoplate.model.Ingredient;
1717
import com.fridgetoplate.model.MealPlanModel;
18-
import com.fridgetoplate.repository.MealPlanRepository;
18+
import com.fridgetoplate.service.MealPlanService;
1919

2020
@RestController
2121
@CrossOrigin(origins = "*", allowedHeaders = "*", methods = { RequestMethod.GET, RequestMethod.POST, RequestMethod.PUT, RequestMethod.DELETE })
@@ -24,54 +24,22 @@
2424
public class MealPlanController {
2525

2626
@Autowired
27-
private MealPlanRepository mealPlanRepository;
27+
private MealPlanService mealPlanService;
28+
2829

2930
@PostMapping("/save")
3031
public MealPlanFrontendModel save(@RequestBody MealPlanFrontendModel mealPlan) {
31-
32-
MealPlanModel plan = new MealPlanModel();
33-
34-
35-
36-
if(mealPlan.getBreakfast() != null) {
37-
plan.setBreakfastId(mealPlan.getBreakfast().getRecipeId());
38-
}
39-
else {
40-
plan.setBreakfastId("");
41-
}
42-
if(mealPlan.getLunch() != null) {
43-
plan.setLunchId(mealPlan.getLunch().getRecipeId());
44-
}
45-
else {
46-
plan.setLunchId("");
47-
}
48-
49-
if(mealPlan.getDinner() != null) {
50-
plan.setDinnerId(mealPlan.getDinner().getRecipeId());
51-
}
52-
else {
53-
plan.setDinnerId("");
54-
}
55-
if(mealPlan.getSnack() != null) {
56-
plan.setSnackId(mealPlan.getSnack().getRecipeId());
57-
}
58-
else {
59-
plan.setSnackId("");
60-
}
61-
62-
plan.setUsername(mealPlan.getUsername());
63-
plan.setDate(mealPlan.getDate());
64-
return mealPlanRepository.save(plan);
32+
return this.mealPlanService.save(mealPlan);
6533
}
6634

67-
@GetMapping
68-
public List<MealPlanModel> findAll() {
69-
return mealPlanRepository.findAll();
35+
@GetMapping("/{username}/{date}")
36+
public MealPlanFrontendModel findByUsernameAndDate(@PathVariable(value = "username") String username, @PathVariable(value = "date") String date) {
37+
return this.mealPlanService.findMealPlan(username, date);
7038
}
7139

72-
@GetMapping("/{username}")
73-
public MealPlanModel findByUsername(@PathVariable(value = "username") String username) {
74-
return mealPlanRepository.findByUsername(username);
40+
@PostMapping("/ingredients")
41+
public List<Ingredient> getIngredients(@RequestBody MealPlanFrontendModel mealPlan){
42+
return this.mealPlanService.findMealPlanIngredients(mealPlan);
7543
}
7644

7745
}
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.fridgetoplate.controller;
22

3-
import java.util.List;
43

54
import org.springframework.beans.factory.annotation.Autowired;
5+
66
import org.springframework.web.bind.annotation.CrossOrigin;
77
import org.springframework.web.bind.annotation.DeleteMapping;
88
import org.springframework.web.bind.annotation.GetMapping;
@@ -12,36 +12,30 @@
1212
import org.springframework.web.bind.annotation.RestController;
1313

1414
import com.fridgetoplate.frontendmodels.NotificationsResponseModel;
15-
import com.fridgetoplate.repository.NotificationsRepository;
15+
import com.fridgetoplate.service.NotificationService;
1616

1717
@RestController
1818
@CrossOrigin(origins = "*", allowedHeaders = "*", methods = { RequestMethod.GET, RequestMethod.DELETE })
1919
@RequestMapping("/notifications")
2020

2121
public class NotificationController {
22-
22+
2323
@Autowired
24-
private NotificationsRepository notificationsRepository;
24+
private NotificationService notificationService;
2525

2626
@GetMapping("/{userId}")
2727
public NotificationsResponseModel findAll(@PathVariable(value = "userId") String userId){
28-
return notificationsRepository.findAll(userId);
29-
}
30-
31-
@DeleteMapping("/{notificationId}")
32-
public String delete(@PathVariable(value = "notificationId") String notificationId){
33-
return notificationsRepository.delete(notificationId);
28+
return notificationService.findAllNotifications(userId);
3429
}
3530

3631
@DeleteMapping("/clear/{userId}")
3732
public String clearNotifications(@PathVariable(value = "userId") String userId){
38-
return notificationsRepository.clearNotifications(userId);
33+
return notificationService.clearNotifications(userId);
3934
}
4035

4136
@DeleteMapping("/clear/{userId}/{notificationType}")
4237
public String clearAllNotificationsOfType(@PathVariable(value = "userId") String userId, @PathVariable(value = "notificationType") String type){
43-
return notificationsRepository.clearAllNotificationOfType(userId, type);
38+
return notificationService.clearAllNotificationOfType(userId, type);
4439
}
4540

46-
4741
}

0 commit comments

Comments
 (0)