-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GET users/{userId} endpoint implemented.(User Profile & bookmark reci…
…pe related infos.)
- Loading branch information
1 parent
adf4ebb
commit 9b15a89
Showing
4 changed files
with
55 additions
and
18 deletions.
There are no files selected for viewing
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
15 changes: 15 additions & 0 deletions
15
backend/src/main/java/com/group1/cuisines/dto/CuisineDetailsDto.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,15 @@ | ||
package com.group1.cuisines.dto; | ||
import lombok.*; | ||
|
||
import java.util.List; | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class CuisineDetailsDto { | ||
private String id; | ||
private String name; | ||
// private String description; | ||
//private String image; | ||
// private Boolean isSelfFollowing; | ||
private List<DishDto> dishes; | ||
} |
37 changes: 28 additions & 9 deletions
37
backend/src/main/java/com/group1/cuisines/services/CuisineService.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 |
---|---|---|
@@ -1,24 +1,43 @@ | ||
package com.group1.cuisines.services; | ||
|
||
import com.group1.cuisines.dto.CuisineDetailsDto; | ||
import com.group1.cuisines.dto.DishDto; | ||
import com.group1.cuisines.entities.Cuisine; | ||
import com.group1.cuisines.entities.Dish; | ||
import com.group1.cuisines.repositories.CuisineRepository; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class CuisineService { | ||
|
||
@Autowired | ||
private CuisineRepository cuisineRepository; | ||
|
||
public Cuisine getCuisineById(String cuisineId, boolean includeDishes) { | ||
return cuisineRepository.findById(cuisineId) | ||
.map(cuisine -> { | ||
if (!includeDishes) { | ||
cuisine.setDishes(null); // Clear the dishes if not required | ||
} | ||
return cuisine; | ||
}) | ||
.orElse(null); | ||
public CuisineDetailsDto getCuisineById(String cuisineId, boolean includeDishes) { | ||
Cuisine cuisine = cuisineRepository.findById(cuisineId) | ||
.orElseThrow(() -> new EntityNotFoundException("Cuisine not found")); | ||
|
||
CuisineDetailsDto detailsDto = new CuisineDetailsDto( | ||
cuisine.getId(), | ||
cuisine.getName(), | ||
// cuisine.getDescription(), | ||
|
||
|
||
includeDishes ? convertDishes(cuisine.getDishes()) : new ArrayList<>() | ||
); | ||
return detailsDto; | ||
} | ||
|
||
private List<DishDto> convertDishes(Set<Dish> dishes) { | ||
return dishes.stream() | ||
.map(dish -> new DishDto(dish.getId(), dish.getName(),dish.getImage())) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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