Skip to content

Commit

Permalink
Merge pull request #2 from neuefische/backend-foundations
Browse files Browse the repository at this point in the history
- implement repository, controler , service, dataclass
  • Loading branch information
NrdnKrmt authored Nov 12, 2024
2 parents fefb47b + 56352ea commit 7225119
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
28 changes: 28 additions & 0 deletions backend/src/main/java/springweb/backend/GroceryController.java
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 backend/src/main/java/springweb/backend/GroceryProduct.java
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
) {
}
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 backend/src/main/java/springweb/backend/GroceryService.java
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();
}
}

0 comments on commit 7225119

Please sign in to comment.