Skip to content

Commit

Permalink
Merge branch 'develop' into issue209
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyoung234 authored Jul 13, 2024
2 parents 0639198 + e9cbc31 commit f3dabf4
Show file tree
Hide file tree
Showing 120 changed files with 2,410 additions and 1,134 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/sonar-cloud-analysis-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ jobs:
name: sonar analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Install dependencies
run: npm install
- name: install sonarqube-scanner
run: npm install sonarqube-scanner -D
- name : run sonar
run: npm run sonar
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"build-storybook": "build-storybook -s public",
"pretty": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json}\"",
"predeploy": "npm run build && cp build/index.html build/404.html",
"deploy": "gh-pages -d build",
"sonar": "node sonar-project.js"
"deploy": "gh-pages -d build"
},
"eslintConfig": {
"extends": [
Expand Down
10 changes: 0 additions & 10 deletions sonar-project.js

This file was deleted.

21 changes: 13 additions & 8 deletions src/api/bookmark/fetchBookmarkList.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import type { BookmarkStore } from "types/common/bookmarkTypes";
import { BookmarkStore, BookmarkStoreServerResponse } from "types/common";

import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";
import { MESSAGES } from "constants/messages";

import axiosInstance from "api/axiosInstance";

const fetchBookmarkList = async () => {
const fetchBookmarkList = async (): Promise<BookmarkStore[] | undefined> => {
const accessToken = window.sessionStorage.getItem(ACCESS_TOKEN);

if (!accessToken) {
window.sessionStorage.removeItem(ACCESS_TOKEN);
window.alert("다시 로그인 해주세요");
window.location.href = "/";
return;
throw new Error(MESSAGES.LOGIN_REQUIRED);
}

const { data } = await axiosInstance.get<BookmarkStore[]>(
const { data } = await axiosInstance.get<BookmarkStoreServerResponse[]>(
ENDPOINTS.BOOKMARKS,
{
headers: {
Expand All @@ -23,7 +21,14 @@ const fetchBookmarkList = async () => {
}
);

return data;
const formattedData: BookmarkStore[] = data.map((bookmarkStore) => {
return {
...bookmarkStore,
thumbnailUrl: bookmarkStore.imageUrl,
};
});

return formattedData;
};

export default fetchBookmarkList;
7 changes: 3 additions & 4 deletions src/api/bookmark/sendBookmarkDeleteRequest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";
import { MESSAGES } from "constants/messages";

import axiosInstance from "api/axiosInstance";

const sendBookmarkDeleteRequest = (restaurantId: number) => () => {
const sendBookmarkDeleteRequest = (restaurantId: number) => {
const accessToken = window.sessionStorage.getItem(ACCESS_TOKEN);

if (!accessToken) {
window.sessionStorage.removeItem(ACCESS_TOKEN);
window.alert("로그인 해주세요");
window.location.reload();
throw new Error(MESSAGES.LOGIN_REQUIRED);
}

return axiosInstance.delete(ENDPOINTS.BOOKMARK_STORE(restaurantId), {
Expand Down
7 changes: 3 additions & 4 deletions src/api/bookmark/sendBookmarkPostRequest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";
import { MESSAGES } from "constants/messages";

import axiosInstance from "api/axiosInstance";

const sendBookmarkPostRequest = (restaurantId: number) => () => {
const sendBookmarkPostRequest = (restaurantId: number) => {
const accessToken = window.sessionStorage.getItem(ACCESS_TOKEN);

if (!accessToken) {
window.sessionStorage.removeItem(ACCESS_TOKEN);
window.alert("로그인 해주세요");
window.location.reload();
throw new Error(MESSAGES.LOGIN_REQUIRED);
}

return axiosInstance.post(ENDPOINTS.BOOKMARK_STORE(restaurantId), null, {
Expand Down
6 changes: 3 additions & 3 deletions src/api/image/sendImageUploadPostRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AxiosResponse } from "axios";

import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";
import { MESSAGES } from "constants/messages";

import axiosInstance from "api/axiosInstance";

Expand All @@ -13,9 +14,8 @@ const sendImageUploadPostRequest = async (imageFile: FormData) => {

if (!accessToken) {
window.sessionStorage.removeItem(ACCESS_TOKEN);
window.alert("다시 로그인 해주세요");
window.location.reload();
throw new Error("엑세스토큰이 유효하지 않습니다");

throw new Error(MESSAGES.LOGIN_REQUIRED);
}

const response: AxiosResponse<ImageUploadResponse> = await axiosInstance.post(
Expand Down
6 changes: 2 additions & 4 deletions src/api/mypage/fetchUserProfile.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import type { UserProfileInformation } from "types/common";

import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";
import { MESSAGES } from "constants/messages";

import axiosInstance from "api/axiosInstance";

const fetchUserProfile = async () => {
const accessToken = window.sessionStorage.getItem(ACCESS_TOKEN);

if (!accessToken) {
window.sessionStorage.removeItem(ACCESS_TOKEN);
window.alert("다시 로그인 해주세요");
window.location.href = "/";
return;
throw new Error(MESSAGES.LOGIN_REQUIRED);
}

const { data } = await axiosInstance.get<UserProfileInformation>(
Expand Down
34 changes: 27 additions & 7 deletions src/api/mypage/fetchUserReviewList.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import { FetchParamProps } from "types/apiTypes";
import type { UserReview } from "types/common";
import { UserReview, UserReviewServerResponse } from "types/common";

import { ACCESS_TOKEN, ENDPOINTS, SIZE } from "constants/api";
import { MESSAGES } from "constants/messages";

import axiosInstance from "api/axiosInstance";

interface UserReviewResponse {
hasNext: boolean;
reviews: UserReviewServerResponse[];
}

interface FetchUserReviewListResult {
hasNext: boolean;
nextPageParam: number;
reviews: UserReview[];
}

const fetchUserReviewList = async ({ pageParam = 0 }: FetchParamProps) => {
const fetchUserReviewList = async ({
pageParam = 0,
}: FetchParamProps): Promise<FetchUserReviewListResult> => {
const accessToken = window.sessionStorage.getItem(ACCESS_TOKEN);

if (!accessToken) {
window.sessionStorage.removeItem(ACCESS_TOKEN);
window.alert("다시 로그인 해주세요");
window.location.href = "/";
throw new Error("엑세스토큰이 유효하지 않습니다");
throw new Error(MESSAGES.LOGIN_REQUIRED);
}

const { data } = await axiosInstance.get<UserReviewResponse>(
Expand All @@ -30,7 +36,21 @@ const fetchUserReviewList = async ({ pageParam = 0 }: FetchParamProps) => {
}
);

return { ...data, nextPageParam: pageParam + 1 };
const formattedReviews = data.reviews.map((review) => {
return {
...review,
restaurant: {
...review.restaurant,
thumbnailUrl: review.restaurant.imageUrl,
},
};
});

return {
reviews: formattedReviews,
hasNext: data.hasNext,
nextPageParam: pageParam + 1,
};
};

export default fetchUserReviewList;
6 changes: 2 additions & 4 deletions src/api/review/deleteReviewItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AxiosResponse } from "axios";

import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";
import { MESSAGES } from "constants/messages";

import axiosInstance from "api/axiosInstance";

Expand All @@ -15,10 +16,7 @@ const deleteReviewItem = async ({
}: DeleteReviewItemProp) => {
const accessToken = window.sessionStorage.getItem(ACCESS_TOKEN);
if (!accessToken) {
window.sessionStorage.removeItem(ACCESS_TOKEN);
window.alert("다시 로그인 해주세요");
window.location.reload();
return;
throw new Error(MESSAGES.LOGIN_REQUIRED);
}

const { data } = await axiosInstance.delete<AxiosResponse>(
Expand Down
11 changes: 6 additions & 5 deletions src/api/review/sendReviewItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { AxiosResponse } from "axios";

import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";
import { MESSAGES } from "constants/messages";

import axiosInstance from "api/axiosInstance";

interface SendReviewItemProps {
export interface SendReviewItemProps {
restaurantId: string;
articleId: string;
content: string;
rating: number;
menu: string;
imageUrl: string;
}

const sendReviewItem = async ({
Expand All @@ -18,20 +20,19 @@ const sendReviewItem = async ({
content,
rating,
menu,
imageUrl,
}: SendReviewItemProps) => {
const accessToken = window.sessionStorage.getItem(ACCESS_TOKEN);
if (!accessToken) {
window.sessionStorage.removeItem(ACCESS_TOKEN);
window.alert("다시 로그인 해주세요");
window.location.reload();
return;
throw new Error(MESSAGES.LOGIN_REQUIRED);
}
const { data } = await axiosInstance.put<AxiosResponse>(
ENDPOINTS.UPDATE_REVIEW_ITEM(restaurantId, articleId),
{
content: content,
rating: rating,
menu: menu,
imageUrl,
},
{
headers: {
Expand Down
6 changes: 2 additions & 4 deletions src/api/review/sendReviewPostRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { ReviewInputShape } from "types/common";

import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";
import { MESSAGES } from "constants/messages";

import axiosInstance from "api/axiosInstance";

const sendReviewPostRequest =
(restaurantId: string) => (newReview: ReviewInputShape) => {
const accessToken = window.sessionStorage.getItem(ACCESS_TOKEN);
if (!accessToken) {
window.sessionStorage.removeItem(ACCESS_TOKEN);
window.alert("다시 로그인 해주세요");
window.location.reload();
throw new Error("엑세스토큰이 유효하지 않습니다");
throw new Error(MESSAGES.LOGIN_REQUIRED);
}
return axiosInstance.post(ENDPOINTS.REVIEWS(restaurantId), newReview, {
headers: {
Expand Down
31 changes: 31 additions & 0 deletions src/api/store/fetchAutoCompleteStoreList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { CampusId, AutoCompleteOption } from "types/common";

import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";

import axiosInstance from "api/axiosInstance";

interface AutoCompleteStoreGetResponse {
restaurants: AutoCompleteOption[];
}

const fetchAutoCompleteStoreList = async (
campusId: CampusId,
keyword: string
) => {
const accessToken = sessionStorage.getItem(ACCESS_TOKEN);

const userFetchOptions = {
headers: {
Authorization: `Bearer ${accessToken}`,
},
};

const { data } = await axiosInstance.get<AutoCompleteStoreGetResponse>(
ENDPOINTS.AUTO_COMPLETE_STORES(campusId, keyword),
accessToken ? userFetchOptions : undefined
);

return data.restaurants;
};

export default fetchAutoCompleteStoreList;
22 changes: 18 additions & 4 deletions src/api/store/fetchRandomStoreList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { CampusId, Store } from "types/common";
import {
CampusId,
StoreItemWithHeart,
StoreServerResponse,
} from "types/common";

import { ACCESS_TOKEN, ENDPOINTS } from "constants/api";

import axiosInstance from "api/axiosInstance";

const fetchRandomStoreList = async (campusId: CampusId, size: number) => {
const fetchRandomStoreList = async (
campusId: CampusId,
size: number
): Promise<StoreItemWithHeart[]> => {
const accessToken = sessionStorage.getItem(ACCESS_TOKEN);

const userFetchOptions = {
Expand All @@ -13,12 +20,19 @@ const fetchRandomStoreList = async (campusId: CampusId, size: number) => {
},
};

const { data } = await axiosInstance.get<Store[]>(
const { data } = await axiosInstance.get<StoreServerResponse[]>(
ENDPOINTS.RANDOM_STORES(campusId, size),
accessToken ? userFetchOptions : undefined
);

return data;
const formattedData: StoreItemWithHeart[] = data.map((store) => {
return {
...store,
thumbnailUrl: store.imageUrl,
};
});

return formattedData;
};

export default fetchRandomStoreList;
Loading

0 comments on commit f3dabf4

Please sign in to comment.