From accbd2fd5f67d64d9c5c9dba040e15039540b584 Mon Sep 17 00:00:00 2001 From: Anders Austlid <andemau@ntnu.no> Date: Fri, 21 Apr 2023 09:52:37 +0200 Subject: [PATCH] Small corrections in shoppinglist endpoint, changed cors origin --- pom.xml | 6 ++++++ .../idatt2016/v233/SmartMat/config/CorsConfig.java | 2 +- .../SmartMat/controller/ShoppingListController.java | 10 +++++----- src/main/resources/application.properties | 3 +++ target/classes/application.properties | 9 ++++++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 2b3ff05d..2d824c62 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,12 @@ <artifactId>spring-boot-starter-oauth2-resource-server</artifactId> </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <optional>true</optional> + </dependency> + <dependency> <groupId>org.postgresql</groupId> <artifactId>postgresql</artifactId> diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/config/CorsConfig.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/config/CorsConfig.java index a5342e55..1046085e 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/config/CorsConfig.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/config/CorsConfig.java @@ -38,7 +38,7 @@ public class CorsConfig { public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins(domainProperty.domain()) - .allowedOrigins("http://localhost:5173") + .allowedOrigins("https://smartmat.app") .allowedMethods(Arrays.asList( HttpMethod.GET.name(), HttpMethod.POST.name(), diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java index 04f97f18..3623fbbb 100644 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java +++ b/src/main/java/ntnu/idatt2016/v233/SmartMat/controller/ShoppingListController.java @@ -41,12 +41,12 @@ public class ShoppingListController { /** * Gets a shopping list by its ID * - * @param request the request containing the shopping list ID + * @param id the shopping list ID * @return the shopping list, or an error if the ID is invalid */ - @GetMapping("/{id}") - public ResponseEntity<ShoppingList> getShoppingListById(@RequestBody ShoppingListRequest request) { - Optional<ShoppingList> shoppingList = shoppingListService.getShoppingListById(request.getGroupID()); + @GetMapping("shoppinglist/{id}") + public ResponseEntity<ShoppingList> getShoppingListById(@PathVariable("id") long id) { + Optional<ShoppingList> shoppingList = shoppingListService.getShoppingListById(id); return shoppingList.map(list -> ResponseEntity.status(HttpStatus.OK).body(list)) .orElseGet(() -> ResponseEntity.status(HttpStatus.NOT_FOUND).build()); } @@ -57,7 +57,7 @@ public class ShoppingListController { * @param request the request containing the group ID * @return the shopping list, or an error if the ID is invalid */ - @GetMapping("/group/{id}") + @GetMapping("/group/shoppinglist") public ResponseEntity<ShoppingList> getAllShoppingListsByGroupId(@RequestBody ShoppingListRequest request) { Optional<ShoppingList> shoppingList = shoppingListService.getShoppingListByGroupId(request.getGroupID()); return shoppingList.map(list -> ResponseEntity.status(HttpStatus.OK).body(list)) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index bef07f68..c142e573 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -14,6 +14,9 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialec # Hibernate ddl auto (create, create-drop, validate, update) spring.jpa.hibernate.ddl-auto = update +# Set CORS configuration origin address +domain.domain=https://smartmat.app + ## info # Hostname: dpg-cgv5710dh87i4q0fd1b0-a diff --git a/target/classes/application.properties b/target/classes/application.properties index ba7e37ce..dad35a77 100644 --- a/target/classes/application.properties +++ b/target/classes/application.properties @@ -14,6 +14,8 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialec # Hibernate ddl auto (create, create-drop, validate, update) spring.jpa.hibernate.ddl-auto = update + + ## info # Hostname: dpg-cgv5710dh87i4q0fd1b0-a @@ -23,4 +25,9 @@ spring.jpa.hibernate.ddl-auto = update # Password: Eyhs1OJxyZC56NQCrV7yAolEk9AkLAsC # Internal Database URl (from render): postgres://smartmat_user:Eyhs1OJxyZC56NQCrV7yAolEk9AkLAsC@dpg-cgv5710dh87i4q0fd1b0-a/smartmat # External Database URL: postgres://smartmat_user:Eyhs1OJxyZC56NQCrV7yAolEk9AkLAsC@dpg-cgv5710dh87i4q0fd1b0-a.frankfurt-postgres.render.com/smartmat -# PSQL Command: PGPASSWORD=Eyhs1OJxyZC56NQCrV7yAolEk9AkLAsC psql -h dpg-cgv5710dh87i4q0fd1b0-a.frankfurt-postgres.render.com -U smartmat_user smartmat \ No newline at end of file +# PSQL Command: PGPASSWORD=Eyhs1OJxyZC56NQCrV7yAolEk9AkLAsC psql -h dpg-cgv5710dh87i4q0fd1b0-a.frankfurt-postgres.render.com -U smartmat_user smartmat + +# Run spring boot locally/network-wide +# Uncomment to run network-wide. +#server.address=0.0.0.0 +#server.port=8080 \ No newline at end of file -- GitLab