diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/Favourite.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/Favourite.java deleted file mode 100644 index 03f37e787763a595a0d12c23ac0bf70007ea03db..0000000000000000000000000000000000000000 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/entity/Favourite.java +++ /dev/null @@ -1,24 +0,0 @@ -package ntnu.idatt2016.v233.SmartMat.entity; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@NoArgsConstructor -@AllArgsConstructor -@Builder -@Entity(name = "favorite") -@Data -public class Favourite { - - @Id - @Column(name = "recipe_id") - long recipeId; - - @Column(name = "username") - String username; -} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/FavoriteRepository.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/FavoriteRepository.java deleted file mode 100644 index 7f266bf30ef18e5a7d59b34306dcf14f666c40ae..0000000000000000000000000000000000000000 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/repository/FavoriteRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -package ntnu.idatt2016.v233.SmartMat.repository; - -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; - -import ntnu.idatt2016.v233.SmartMat.entity.Favourite; - -public interface FavoriteRepository extends JpaRepository<Favourite, Long> { - - /** - * Gets all favorites by username - * - * @param id the username - * @return a list of all favorites if they exist - */ - List<Favourite> getAllByUsername(String name); - - /** - * Gets all favorites by recipe ID - * - * @param id the ID of the recipe - * @return a list of all favorites if they exist - */ - List<Favourite> getAllByRecipeId(long id); - -} diff --git a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/FavouriteService.java b/src/main/java/ntnu/idatt2016/v233/SmartMat/service/FavouriteService.java deleted file mode 100644 index f4e2d1a4064b82c9ae48d95154332b0881c288fe..0000000000000000000000000000000000000000 --- a/src/main/java/ntnu/idatt2016/v233/SmartMat/service/FavouriteService.java +++ /dev/null @@ -1,77 +0,0 @@ -package ntnu.idatt2016.v233.SmartMat.service; - -import java.util.List; -import java.util.Optional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import ntnu.idatt2016.v233.SmartMat.dto.request.FavoriteRequest; -import ntnu.idatt2016.v233.SmartMat.entity.Favourite; -import ntnu.idatt2016.v233.SmartMat.repository.FavoriteRepository; - -/** - * Service for the favorites enitity - * - * @author Stian Lyng - * @version 1.1 - */ -@Service -public class FavouriteService { - - @Autowired - FavoriteRepository favoriteRepository; - - /** - * Create and save a shopping list to the database - * @param shoppingList the shopping list to save - * @return the saved shopping list - */ - public Favourite addFav(FavoriteRequest request) { - Favourite favourite = new Favourite(); - favourite.setRecipeId(request.getRecipeId()); - favourite.setUsername(request.getUsername()); - return favoriteRepository.save(favourite); - } - - /** - * Gets all favorites - * - * @return a list of all favorites if they exist - */ - public List<Favourite> getAllFavorites() { - return favoriteRepository.findAll(); - } - - /** - * Gets all favorites by recipe ID - * - * @param id the ID of the recipe - * @return a list of all favorites if they exist - */ - public List<Favourite> getAllFavoritesByRecipeId(long id) { - return favoriteRepository.getAllByRecipeId(id); - } - - /** - * Gets all favorites by username - * - * @param id the username of the user - * @return a list of all favorites if they exist - */ - public List<Favourite> getAllFavoritesByUsername(String name) { - return favoriteRepository.getAllByUsername(name); - } - - /** - * Deletes a favorite by its ID - * - * @param id the ID of the favorite entry - */ - public void deleteFavoriteById(long id) { - Optional<Favourite> favorite = favoriteRepository.findById(id); - if (favorite.isPresent()) { - favoriteRepository.deleteById(id); - } - } -}