Skip to content
Snippets Groups Projects
Commit a1956127 authored by nahyun's avatar nahyun
Browse files

finish

parent 68de4d38
No related branches found
No related tags found
No related merge requests found
Pipeline #8432 passed
...@@ -34,7 +34,45 @@ export default function App() { ...@@ -34,7 +34,45 @@ export default function App() {
// } // }
// }; // };
//버전2 //버전2 - 돌아가긴 함. (최종 버전 spring 병합이 안됌)
// const handleOnLike = (item) => {
// let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId);
// if (favoriteItem) {
// // item.like = false;
// //favorite & search 둘다 삭제
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// item.like = false;
// }
// let b = favorites.filter((it) => it.collectionId !== item.collectionId);
// setFavorites(b);
// }
// else {
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// item.like = true;
// }
// setFavorites([...favorites, item]);
// //setFavorites([...favorites, { ...item, like: true }]);
// //좋아요 아이템 spring 서버로 보내기
// axios.post('/likes', {
// collectionId: item.collectionId,
// collectionType: item.collectionType,
// artistId: item.artistId
// }
// )
// .then((response) => {
// console.log(response.data);
// })
// .catch((error) => {
// console.error('Error:', error);
// });
// }
//버전3 - 연결시키기 위해 노력
const handleOnLike = (item) => { const handleOnLike = (item) => {
let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId); let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId);
...@@ -47,9 +85,18 @@ export default function App() { ...@@ -47,9 +85,18 @@ export default function App() {
} }
let b = favorites.filter((it) => it.collectionId !== item.collectionId); let b = favorites.filter((it) => it.collectionId !== item.collectionId);
setFavorites(b); setFavorites(b);
axios.delete(`/likes/${item.collectionId}`)
.then((response) => {
console.log(response.data);
})
.catch((error) => {
console.error('Error: ', error);
})
} }
else { else {
let a = searchResult.find((it) => it.collectionId === item.collectionId); let a = searchResult.find((it) => it.collectionId !== item.collectionId);
if (a) { if (a) {
item.like = true; item.like = true;
} }
...@@ -58,9 +105,15 @@ export default function App() { ...@@ -58,9 +105,15 @@ export default function App() {
//setFavorites([...favorites, { ...item, like: true }]); //setFavorites([...favorites, { ...item, like: true }]);
//좋아요 아이템 spring 서버로 보내기 //좋아요 아이템 spring 서버로 보내기
axios.post('/likes', { collectionId: item.collectionId }, axios.post('/likes', {
{ collectionType: item.collectionType }, collectionId: item.collectionId,
{ artistId: item.artistId } collectionType: item.collectionType,
artistId: item.artistId,
artistName: item.artistName,
artistViewUrl: item.artistViewUrl,
collectionName: item.collectionName,
collectionViewUrl: item.collectionViewUrl
}
) )
.then((response) => { .then((response) => {
console.log(response.data); console.log(response.data);
...@@ -70,6 +123,52 @@ export default function App() { ...@@ -70,6 +123,52 @@ export default function App() {
}); });
} }
// const handleOnLike = (item) => {
// let favoriteItem = favorites.find((it) => it.collectionId === item.collectionId);
// if (favoriteItem) {
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// item.like = false;
// }
// let updatedFavorites = favorites.filter((it) => it.collectionId !== item.collectionId);
// setFavorites(updatedFavorites);
// // 좋아요 아이템 spring 서버로 보내기
// axios.post('/likes', {
// collectionId: item.collectionId,
// collectionType: item.collectionType,
// artistId: item.artistId
// })
// .then((response) => {
// console.log(response.data);
// })
// .catch((error) => {
// console.error('Error:', error);
// });
// } else {
// let a = searchResult.find((it) => it.collectionId === item.collectionId);
// if (a) {
// item.like = true;
// }
// setFavorites([...favorites, item]);
// // 좋아요 아이템 spring 서버로 보내기
// axios.post('/likes', {
// collectionId: item.collectionId,
// collectionType: item.collectionType,
// artistId: item.artistId
// })
// .then((response) => {
// console.log(response.data);
// })
// .catch((error) => {
// console.error('Error:', error);
// });
// }
// };
// const updatedSearchResult = searchResult.map((it) => // const updatedSearchResult = searchResult.map((it) =>
// it.collectionId === item.collectionId ? { ...it, like: !favoriteItem } : it // it.collectionId === item.collectionId ? { ...it, like: !favoriteItem } : it
// ); // );
......
...@@ -33,7 +33,7 @@ export default function SearchPage({ list, onSearch, onLike }) { ...@@ -33,7 +33,7 @@ export default function SearchPage({ list, onSearch, onLike }) {
// console.error('Error:', error); // console.error('Error:', error);
// }); // });
fetch(`/musicSearch/${encodeURIComponent(searchWord)}`, { fetch(`/musicSearch/${(searchWord)}`, {
method: 'GET', // HTTP 메서드는 GET입니다. method: 'GET', // HTTP 메서드는 GET입니다.
headers: {}, headers: {},
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment