-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from neuefische/backend-foundations
- implement repository, controler , service, dataclass
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/springweb/backend/GroceryController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package springweb.backend; | ||
|
||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
|
||
@RestController | ||
@RequestMapping("/api/store") | ||
public class GroceryController { | ||
|
||
GroceryService groceryService; | ||
|
||
public GroceryController(GroceryService groceryService) { | ||
this.groceryService = groceryService; | ||
} | ||
|
||
@GetMapping | ||
public List<GroceryProduct> getAllGroceryProducts() { | ||
return groceryService.getAllGroceryProducts(); | ||
} | ||
|
||
|
||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/springweb/backend/GroceryProduct.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package springweb.backend; | ||
|
||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
@Document("products") | ||
public record GroceryProduct( | ||
String id, | ||
String category, | ||
String name, | ||
double price | ||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/springweb/backend/GroceryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package springweb.backend; | ||
|
||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
|
||
public interface GroceryRepository extends MongoRepository<GroceryProduct,String> { | ||
} |
21 changes: 21 additions & 0 deletions
21
backend/src/main/java/springweb/backend/GroceryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package springweb.backend; | ||
|
||
import lombok.NoArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class GroceryService { | ||
GroceryRepository groceryRepository; | ||
|
||
public GroceryService(GroceryRepository groceryRepository) { | ||
this.groceryRepository = groceryRepository; | ||
} | ||
|
||
|
||
public List<GroceryProduct> getAllGroceryProducts() { | ||
return groceryRepository.findAll(); | ||
} | ||
} |