From 2828dabd2a9031d91e0453a0dbeaa21280677d09 Mon Sep 17 00:00:00 2001 From: euije Date: Tue, 23 Aug 2022 17:36:23 +0900 Subject: [PATCH 1/5] feat: Update constant of API --- src/common/Constant/API.js | 118 ++++++++++++++++++++++++++++--------- 1 file changed, 89 insertions(+), 29 deletions(-) diff --git a/src/common/Constant/API.js b/src/common/Constant/API.js index f246046..e71d30a 100644 --- a/src/common/Constant/API.js +++ b/src/common/Constant/API.js @@ -1,47 +1,107 @@ -import { TARGET_URL } from "@api/."; +/**------------------------ Common ----------------------------- */ +export const GET_HEADER_OPTION = { + withCredenitals: true, +}; + +const TARGET_URL = "http://localhost:3000"; + +/** ------------------------ Albums ----------------------------- */ +export const GET_ALBUM_URL = (familyId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums`; +export const CREATE_ALBUM_URL = (familyId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums`; -/**------------------------ Archives ----------------------------- */ export const GET_ALBUM_DETAIL_URL = (familyId, albumId) => -`${TARGET_URL}/api/v1/families/${familyId}/albums/?album=${albumId}` + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}`; + +export const PUT_ALBUM_URL = (familyId, albumId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}`; + +export const DELETE_ALBUM_URL = (familyId, albumId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}`; + +/** ------------------------ Families ----------------------------- */ + +export const CREATE_FAMILY_URL = () => `${TARGET_URL}/api/v1/families`; + +export const GET_FAMILY_VALIDATE_URL = (familyId) => + `${TARGET_URL}/api/v1/families/${familyId}/validate`; + +export const PATCH_FAMILY_INFO_URL = (familyId) => + `${TARGET_URL}/api/v1/families/${familyId}/validate`; + +export const GET_FAMILY_URL = (familyId) => + `${TARGET_URL}/api/v1/families/${familyId}`; + +export const DELETE_FAMILY_URL = (familyId) => + `${TARGET_URL}/api/v1/families/${familyId}`; + +export const PUT_FAMILY_URL = (familyId) => + `${TARGET_URL}/api/v1/families/${familyId}`; -export const GET_ALBUM_URL = (familyId) => -`${TARGET_URL}/api/v1/families/${familyId}/albums` +/** ------------------------ Photo ----------------------------- */ -export const DELETE_ALBUM_URL = (familyId, albumId) => -`${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}` +export const DELETE_PHOTO_URL = (familyId, albumId, photoId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}/photos/${photoId}`; -export const PUT_ALBUM_URL = (familyId, albumId) => -`${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}` +export const GET_PHOTO_URL = (familyId) => + `${TARGET_URL}/api/v1/families/${familyId}/photo`; -export const CREATE_ALBUM_URL = (familyId) => -`${TARGET_URL}/api/v1/families/${familyId}/albums` +/** ------------------------ User ----------------------------- */ -export const POST_LIKE_URL = (familyId, albumId, photoId) => -`${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}/likes/${photoId}` +export const POST_USER_URL = () => `${TARGET_URL}/api/v1/users`; -export const DELETE_LIKE_URL = (familyId, albumId, photoId) => -`${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}/likes/${photoId}` +export const GET_USER_URL = (userId) => `${TARGET_URL}/api/v1/users/${userId}`; + +export const DELETE_USER_URL = (userId) => + `${TARGET_URL}/api/v1/users/${userId}`; + +export const PUT_USER_URL = (userId) => `${TARGET_URL}/api/v1/users/${userId}`; + +export const LOGIN_USER_URL = (userId) => + `${TARGET_URL}/api/v1/users/${userId}`; + +export const LOGOUT_USER_URL = (userId) => + `${TARGET_URL}/api/v1/users/${userId}`; + +/** ------------------------ Like ----------------------------- */ + +export const POST_LIKE_URL = (familyId, albumId, photoId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}/likes/${photoId}`; + +export const DELETE_LIKE_URL = (familyId, albumId, photoId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}/likes/${photoId}`; + +/**------------------------ Comment ----------------------------- */ export const POST_COMMENT_URL = (familyId, photoId) => -`${TARGET_URL}/api/v1/families/${familyId}/photos/${photoId}` + `${TARGET_URL}/api/v1/families/${familyId}/photos/${photoId}`; -export const DELETE_COMMNET_URL = (familyId, photoId, commentId) => `${TARGET_URL}/api/v1/families/${familyId}/photos/${photoId}/comments/${commentId}` +export const PUT_COMMNET_URL = (familyId, photoId, commentId) => + `${TARGET_URL}/api/v1/families/${familyId}/photos/${photoId}/comments/${commentId}`; -export const UPDATE_COMMNET_URL = (familyId, photoId, commentId) => `${TARGET_URL}/api/v1/families/${familyId}/photos/${photoId}/comments/${commentId}` +export const DELETE_COMMNET_URL = (familyId, photoId, commentId) => + `${TARGET_URL}/api/v1/families/${familyId}/photos/${photoId}/comments/${commentId}`; +export const GET_COMMNET_URL = (familyId, photoId) => + `${TARGET_URL}/api/v1/families/${familyId}/photos/${photoId}/comments`; -/**------------------------ Family ----------------------------- */ -export const CREATE_FAMILY_URL = `${TARGET_URL}/api/v1/familes` +/**------------------------ Bookmark ----------------------------- */ -export const POST_FAMILY_URL = (familyId) => `${TARGET_URL}/api/v1/familes/${familyId}/register` -export const UPDATE_FAMILY_INFO_URL = (familyId) => `${TARGET_URL}/api/v1/familes/${familyId}/register` -export const GET_FAMILY_URL = (familyId) => `${TARGET_URL}/api/v1/families/${familyId}` -export const DELETE_FAMILY_URL = (familyId) => `${TARGET_URL}/api/v1/families/${familyId}` -export const PUT_FAMILY_URL = (familyId) => `${TARGET_URL}/api/v1/families/${familyId}` +export const POST_BOOKMARK_URL = (familyId, albumId, photoId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}/bookmarks/${photoId}`; +export const DELETE_BOOKMARK_URL = (familyId, albumId, photoId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}/bookmarks/${photoId}`; -/**------------------------ Common ----------------------------- */ -export const GET_HEADER_OPTION = { - "withCredenitals" : true, -}; \ No newline at end of file +export const GET_BOOKMARK_URL = (familyId, userId) => + `${TARGET_URL}/api/v1/families/${familyId}/bookmarks/${userId}`; + +/**------------------------ Tag ----------------------------- */ + +export const POST_TAG_URL = (familyId, albumId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}/tags`; + +export const DELETE_TAG_URL = (familyId, albumId, tagId) => + `${TARGET_URL}/api/v1/families/${familyId}/albums/${albumId}/tags/${tagId}`; \ No newline at end of file From d663cb7428924c0ed19742b6cf9e44a5a2bf4961 Mon Sep 17 00:00:00 2001 From: euije Date: Wed, 24 Aug 2022 03:48:42 +0900 Subject: [PATCH 2/5] style: Update comments of API function --- src/api/Family/index.js | 157 ++++++++++++++++++++++++++-------------- 1 file changed, 101 insertions(+), 56 deletions(-) diff --git a/src/api/Family/index.js b/src/api/Family/index.js index 54f643e..2f7a2bb 100644 --- a/src/api/Family/index.js +++ b/src/api/Family/index.js @@ -1,64 +1,109 @@ import { - POST_FAMILY_URL, - UPDATE_FAMILY_INFO_URL, - GET_FAMILY_URL, - DELETE_FAMILY_URL, - PUT_FAMILY_URL -} from "@Constant/API" + POST_FAMILY_URL, + GET_FAMILY_VALIDATE_URL, + PATCH_FAMILY_INFO_URL, + GET_FAMILY_URL, + DELETE_FAMILY_URL, + PUT_FAMILY_URL, +} from "../../common/Constant/API"; import axios from "axios"; -import { GET_HEADER_OPTION } from "../../common/Constant/API"; -// 가족 참여 성공시에 유저 정보 업데이트 -export const updateFamilyInfo = async ( - familyId, body -) => { - const {data} = await axios.patch( - UPDATE_FAMILY_INFO_URL(familyId), - body - ); - return data -} +/** + * axios 'withCredentials' property is set to true as a default + * + * import { GET_HEADER_OPTION } from "../../common/Constant/API"; + */ +axios.defaults.withCredentials = true; -// 가족 생성 -export const postFamily = async ( - familyId, body -) => { - const { data } = await axios.post( - POST_FAMILY_URL(familyId), - body - ); - return data -} +/** + * ### 가족 생성 + * - POST + * - creates family with request body + * - returns created data of family with @familyId and request body + * - sessionId cookie needed + * + * @body {family_name, cover_image, bio, password} + * @data {id, family_name, cover_image, bio, password, created_at, updated_at} + */ +export const postFamily = async (body) => { + const { data } = await axios.post(POST_FAMILY_URL(), body); + return data; +}; -// 가족 조회 -export const getFamily = async ( - familyId -) => { - const { data } = await axios.get( - GET_FAMILY_URL(familyId), - GET_HEADER_OPTION - ); - return data -} +/** + * ### 가족 참여 전 가족 정보 보여주기 + * - GET + * - returns data of family with @familyId + * - NO sessionId cookie needed + * + * @familyId + * @data {family_name, cover_image, bio, members} + */ +export const getValidateFamily = async (familyId) => { + const { data } = await axios.get(GET_FAMILY_VALIDATE_URL(familyId)); + return data; +}; -// 가족 정보 삭제 -export const deleteFamily = async ( - familyId -) => { - const { data } = await axios.delete( - DELETE_FAMILY_URL(familyId) - ) - return data; -} +/** + * ### 가족 비밀번호 검증 및 유저 정보 업데이트 + * - PATCH + * - update data of family with @familyId + * - if password is correct, "is_participant" is set to true + * - returns true if password is correct + * - sessionId cookie needed + * + * @familyId + * @body {password} + * @data + */ +export const updateFamilyInfo = async (familyId, body) => { + const { data } = await axios.patch(PATCH_FAMILY_INFO_URL(familyId), body); + return data; +}; -// 가족 정보 수정 -export const putFamily = async ( - familyId, body - ) => { - const { data } = await axios.put( - PUT_FAMILY_URL(familyId), - body - ); - return data - } \ No newline at end of file +/** + * ### 가족 조회 + * - GET + * - returns data of family with @familyId + * - sessionId cookie needed + * + * @familyId + * @data {family_name, cover_image, bio, members} + */ +export const getFamily = async (familyId) => { + const { data } = await axios.get(GET_FAMILY_URL(familyId)); + return data; +}; + +/** + * ### 가족 삭제 + * - DELETE + * - deletes family with @familyId + * - returns true if deletion is success + * - sessionId cookie needed + * + * @familyId + * @data + */ +export const deleteFamily = async (familyId) => { + const { data } = await axios.delete(DELETE_FAMILY_URL(familyId)); + return data; +}; + +/** + * ### 가족 수정 + * - PUT + * - edits data of family with @familyId + * - returns data of album that is edited + * - password returned is hashed with *bcrypt* + * - sessionId cookie needed + * + * @familyId + * @body {family_id, family_name, cover_image, bio, password} + * @data {family_id, family_name, cover_image, bio, password} + */ +export const putFamily = async (familyId, body) => { + const { data } = await axios.put(PUT_FAMILY_URL(familyId), body); + return data; +}; From 8c1645be6b4b6312eda9179601d1ba8a7c464bf7 Mon Sep 17 00:00:00 2001 From: euije Date: Wed, 24 Aug 2022 03:49:41 +0900 Subject: [PATCH 3/5] style: Update comments of Album API function --- src/api/Album/index.js | 94 +++++++++++++++++++++++++++++++ src/api/Archive/index.js | 116 --------------------------------------- 2 files changed, 94 insertions(+), 116 deletions(-) create mode 100644 src/api/Album/index.js delete mode 100644 src/api/Archive/index.js diff --git a/src/api/Album/index.js b/src/api/Album/index.js new file mode 100644 index 0000000..0b89996 --- /dev/null +++ b/src/api/Album/index.js @@ -0,0 +1,94 @@ +import { + POST_ALBUM_URL, + GET_ALBUM_URL, + GET_ALBUM_DETAIL_URL, + PUT_ALBUM_URL, + DELETE_ALBUM_URL, +} from "../../common/Constant/API"; + +import axios from "axios"; + +/** + * axios 'withCredentials' property is set to true as a default + * + * import { GET_HEADER_OPTION } from "../../common/Constant/API"; + */ +axios.defaults.withCredentials = true; + +/** + * ### 앨범 조회 + * - GET + * - returns lists of albums with @familyId + * - sessionId cookie needed + * + * @familyId + * @data {id, family_id, user_id, title, album_image, like_count, comment_count, tag_set_all, created_at, updated_at} + */ +export const getAlbum = async (familyId) => { + const { data } = await axios.get(GET_ALBUM_URL(familyId)); + return data; +}; + +/** + * ### 앨범 생성 + * - POST + * - creates album with @familyId + * - returns data of album that is created + * - sessionId cookie needed + * + * @familyId + * @body {title, cover_image, album_image, tag_set_all} + * @data {id, title, user_id, family_id, cover_image, created_at, updated_at} + */ +export const postAlbum = async (familyId, body) => { + const { data } = await axios.post(POST_ALBUM_URL(familyId), body); + return data; +}; + +/** + * ### 앨범 상세 조회 + * - GET + * - returns data of photos with @familyID @albumId + * - sessionId cookie needed + * + * @familyId + * @albumId + * @data [{id, album_id, family_id, photo_image, like_count, comment_count, created_at, updated_at, my_like, my_bookmark}] + */ +export const getAlbumDetail = async (familyId, albumId) => { + const { data } = await axios.get(GET_ALBUM_DETAIL_URL(familyId, albumId)); + return data; +}; + +/** + * ### 앨범 전체 내용 수정 + * - PUT + * - edits 'title' of album with @familyId @albumId + * - returns data of album that is edited + * - sessionId cookie needed + * + * @familyId + * @albumId + * @body {title} + * @data {new_title} + */ +export const updateAlbum = async (familyId, albumId, body) => { + const { data } = await axios.update(PUT_ALBUM_URL(familyId, albumId), body); + return data; +}; + +/** + * ### 앨범 삭제 + * - DELETE + * - deletes album with @familyId @albumId + * - returns data of album that is deleted + * - sessionId cookie needed + * + * @familyId + * @albumId + * @data + */ +export const deleteAlbum = async (familyId, albumId) => { + const { data } = await axios.delete(DELETE_ALBUM_URL(familyId, albumId)); + return data; +}; diff --git a/src/api/Archive/index.js b/src/api/Archive/index.js deleted file mode 100644 index 2cc15a3..0000000 --- a/src/api/Archive/index.js +++ /dev/null @@ -1,116 +0,0 @@ -import { - GET_ALBUM_DETAIL_URL, - GET_ALBUM_URL, - DELETE_ALBUM_URL, - PUT_ALBUM_URL, - CREATE_ALBUM_URL, - POST_LIKE_URL, - DELETE_LIKE_URL, - POST_COMMENT_URL, - DELETE_COMMNET_URL, - UPDATE_COMMNET_URL -} from "@Constant/API" - -import axios from "axios"; -import { GET_HEADER_OPTION } from "../../common/Constant/API"; - -// 앨범 생성 -export const postAlbum = async ( - body, familyId -) => { - const { data } = await axios.post( - CREATE_ALBUM_URL(familyId), - body, - ); - return data -} -// 앨범 수정 -export const updateAlbum = async ( - body, familyId, albumId -) => { - const { data } = await axios.update( - PUT_ALBUM_URL(familyId, albumId), - body - ); - return data -} -// 앨범 상세 조회 -export const getAlbumDetail = async (familyId, albumId) => { - const { data } = await axios.get( - GET_ALBUM_DETAIL_URL(familyId, albumId), - GET_HEADER_OPTION - ); - return data -} - -// 앨범 전체 조회 -export const getAlbum = async ( - familyId - ) => { - const { data } = await axios.get( - GET_ALBUM_URL(familyId), - GET_HEADER_OPTION - ); - return data -} - -// 앨범 삭제 -export const deleteAlbum = async ( - familyId, albumId -) => { - const { data } = await axios.delete( - DELETE_ALBUM_URL(familyId, albumId) - ); - return data -} - -// 좋아요 -export const postLike = async ( - familyId, albumId, photoId -) => { - const { data } = await axios.post( - POST_LIKE_URL(familyId, albumId, photoId) - ); - return data -} - -// 좋아요 취소 -export const deleteLike = async ( - familyId, albumId, photoId -) => { - const { data } = await axios.delete( - DELETE_LIKE_URL(familyId, albumId, photoId) - ) - return data -} - -// 댓글 작성 -export const postComment = async ( - body -) => { - const { data } = await axios.post( - POST_COMMENT_URL - ); - return data -} -// 댓글 수정 - -export const updateComment = async ( - familyId, photoId, commentId, body -) => { - const { data } = await axios.put( - UPDATE_COMMNET_URL(familyId, photoId, commentId), - body - ); - return data -} - -// 댓글 삭제 -export const deleteComment = async ( - familyId, albumId -) => { - const { data } = await axios.delete( - DELETE_COMMNET_URL(familyId, albumId) - ); - return data -} From 009ce3fd709b5daa3a3c84847dec6c8011ceb76e Mon Sep 17 00:00:00 2001 From: euije Date: Fri, 26 Aug 2022 21:06:21 +0900 Subject: [PATCH 4/5] feat: Add 'User' API file --- src/api/User/index.js | 110 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 src/api/User/index.js diff --git a/src/api/User/index.js b/src/api/User/index.js new file mode 100644 index 0000000..c034425 --- /dev/null +++ b/src/api/User/index.js @@ -0,0 +1,110 @@ +import { + POST_USER_URL, + GET_USER_URL, + DELETE_USER_URL, + PUT_USER_URL, + LOGIN_USER_URL, + LOGOUT_USER_URL, +} from "../../common/Constant/API"; + +import axios from "axios"; + +/** + * axios 'withCredentials' property is set to true as a default + * + * import { GET_HEADER_OPTION } from "../../common/Constant/API"; + */ +axios.defaults.withCredentials = true; + +/** + * ### 회원 가입 + * - POST + * - creates user with request body + * - returns created data of user without "password" + * - NO sessionId cookie needed + * + * @body {username, password, name, birth, bio, avatar, nickname, is_participant} + * @data {id, username, name, birth, bio, avatar, nickname, is_participant} + */ +export const postSignUpUser = (body) => { + const data = axios.post(POST_USER_URL(), body); + return data; +}; + +/** + * ### 유저 조회 + * - GET + * - returns data of user without "password" + * - NO sessionId cookie needed + * + * @userId + * @data {id, username, name, birth, bio, avatar, nickname, is_participant} + */ +export const getUser = (userId) => { + const data = axios.get(GET_USER_URL(userId)); + return data; +}; + +/** + * ### 유저 삭제 + * - DELETE + * - deletes user with @userId + * - returns deleted data of user without "password" + * - NO sessionId cookie needed + * + * @userId + * @data {id, username, name, birth, bio, avatar, nickname, is_participant} + */ +export const deleteUser = async (userId) => { + const data = await axios.delete(DELETE_USER_URL(userId)); + return data; +}; + +/** + * ### 유저 수정 + * - PUT + * - edits user with @userId + * - NOT ALLOWED TO EDIT "password", "is_participant" + * - returns deleted data of user without "password" + * - NO sessionId cookie needed + * + * @userId + * @body {id, username, name, birth, bio, avatar, nickname} + * @data {id, username, name, birth, bio, avatar, nickname} + */ +export const putUser = async (userId, body) => { + const data = await axios.put(PUT_USER_URL(userId), body); + return data; +}; + +/** + * ### 로그인 + * - POST + * - do login with @body + * - returns logined data of user + * - and sessionId + * - NO sessionId cookie needed + * + * @body {username, password} + * @data {id, username, name, birth, bio, avatar, nickname, is_participant} + */ +export const loginUser = async (body) => { + const data = await axios.post(LOGIN_USER_URL(), body); + return data; +}; + +/** + * ### 로그아웃 + * - POST + * - do logout with @body + * > ***Remove the authenticated user's ID from the request and flush their session data.*** + * - returns success if logout is success + * - sessionId cookie needed + * + * @body None + * @data + */ +export const logoutUser = async (body) => { + const data = await axios.post(LOGOUT_USER_URL(), body); + return data; +}; From 4fd29291f7282b56a2113c2db398646810f65b1f Mon Sep 17 00:00:00 2001 From: euije Date: Sun, 28 Aug 2022 23:35:07 +0900 Subject: [PATCH 5/5] docs: Update participants --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5db0765..5d9eb93 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ # OSDS-client - +`Online space for family` ## 👨‍👩‍👧‍👦 Participants 👨‍👩‍👧‍👦 | name | 역할 | |-------|----------| +| [unanchoi](https://github.com/unanchoi)| Develop / Review / Deploy | | [euije](https://github.com/euije)| Develop | @@ -33,7 +34,7 @@ npm run start | chore | 기본 세팅 및 settings.py 관련, 패키지 관리 | ## Deploy -|*|status| +|Site|Status| |-|-| |[main](https://mrmr-likelion.netlify.app/)|[![Netlify Status](https://api.netlify.com/api/v1/badges/117d3837-aeb8-4618-8713-0b55db770d50/deploy-status)](https://app.netlify.com/sites/mrmr-likelion/deploys)| |[github-page](http://www.osds-client.kro.kr/)|![example workflow](https://img.shields.io/badge/Github-success-%236E9972)| \ No newline at end of file