Skip to content

Commit

Permalink
Merge pull request #128 from yennanliu/ShoppingCart-dev-003-fix-wishlist
Browse files Browse the repository at this point in the history
ShoppingCart-dev-003-fix-wishlist-  Fix show wishlist, add wishlist
  • Loading branch information
yennanliu authored Dec 8, 2023
2 parents 6da1fc8 + bd0df1f commit debed1e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class WishList {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;


@OneToOne(targetEntity = User.class, fetch = FetchType.EAGER)
@JoinColumn(nullable = false, name = "user_id")
private User user;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.yen.ShoppingCart.model.WishList;

import java.util.List;
import java.util.stream.Collectors;
import javax.transaction.Transactional;

import com.yen.ShoppingCart.repository.WishListRepository;
Expand All @@ -24,7 +25,16 @@ public void createWishlist(WishList wishList) {
}

public List<WishList> readWishList(Integer userId) {
return wishListRepository.findAllByUserIdOrderByCreatedDateDesc(userId);

//return wishListRepository.findAllByUserIdOrderByCreatedDateDesc(userId);
//return wishListRepository.findAll();

// get all item in wishlist with given userid
List<WishList> items = wishListRepository.findAll()
.stream().filter(x -> x.getUser().getId() == userId)
.collect(Collectors.toList());

return items;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
id="wishlist-button"
class="btn mr-3 p-1 py-0"
:class="{ product_added_wishlist: isAddedToWishlist }"
@click="addToWishList(this.id)"
@click="addToWishList()"
>
{{ wishlistString }}
</button>
Expand Down Expand Up @@ -87,7 +87,8 @@ export default {
},
props: ["baseURL", "products", "categories"],
methods: {
addToWishList(productId) {
addToWishList() {
//console.log("productId = " + productId);
if (!this.token) {
swal({
text: "Please log in first!",
Expand All @@ -97,7 +98,7 @@ export default {
}
axios
.post(`${this.baseURL}wishlist/add?token=${this.token}`, {
id: productId,
id: this.$route.params.id, //productId, // TODO : fix get id from input param (use this.id approach for now)
})
.then(
(response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</template>

<script>
var axios = require("axios");
import ProductBox from "../../components/Product/ProductBox";
import axios from "axios";
export default {
data() {
return {
Expand All @@ -42,7 +42,6 @@ export default {
},
mounted() {
this.token = localStorage.getItem("token");
console.log("this.token = " + this.token)
this.fetchWishlist();
},
};
Expand All @@ -54,4 +53,4 @@ h4 {
color: #484848;
font-weight: 700;
}
</style>
</style>

0 comments on commit debed1e

Please sign in to comment.