Skip to content

Commit

Permalink
feat: follow 조회 #132
Browse files Browse the repository at this point in the history
  • Loading branch information
seoyeoneel02 committed Oct 19, 2024
1 parent b7e008f commit 33336de
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/domains/search/search.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { response } from "../../config/response.js";
import { status } from "../../config/response.status.js";
import { getSearch, getCloth, getSearchResult, getSearchBrand, getMyCloth, getMyWish } from "./search.provider.js";
import { getSearch, getCloth, getSearchResult, getSearchBrand, getMyCloth, getMyWish, getMyFollow } from "./search.provider.js";
import { addMyCloth, addMyWish, delMyWish, addMyFollow, delMyFollow } from "./search.service.js";

export const searchPreview = async (req, res, next) => {
Expand Down Expand Up @@ -63,4 +63,10 @@ export const delFollow = async (req, res, next) => {
console.log("팔로우 취소를 요청하였습니다!");
const userId = res.locals.uuid;
res.send(response(status.SUCCESS, await delMyFollow(userId, req.params.clothId)));
}

export const getFollow = async (req, res, next) => {
console.log("팔로우 조회를 요청하였습니다!");
const userId = res.locals.uuid;
res.send(response(status.SUCCESS, await getMyFollow(userId, req.params.clothId)));
}
14 changes: 14 additions & 0 deletions src/domains/search/search.dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,20 @@ export const delFollowDAO = async (userId, clothId) => {
}
await pool.query(delFollowSQL, [userId, to_user[0][0].uuid]);
const follow = await pool.query(getFollowSQL, [userId, to_user[0][0].uuid]);
conn.release();
return follow;
}catch (err) {
throw new BaseError(status.PARAMETER_IS_WRONG);
}
}

// Follow 조회
export const getFollowDAO = async (userId, clothId) => {
try{
const conn = await pool.getConnection();
const to_user = await pool.query(getUserIdToClothId, clothId);
const follow = await pool.query(getFollowSQL, [userId, to_user[0][0].uuid]);

conn.release();
return follow;
}catch (err) {
Expand Down
12 changes: 12 additions & 0 deletions src/domains/search/search.dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,17 @@ export const delFollowDTO = (follow) => {
follow_id = 0;
}

return {"follow_id": follow_id};
}

export const getFollowDTO = (follow) => {

let follow_id;
if(follow[0].length == 0){
follow_id = 0;
} else if(follow[0].length == 1){
follow_id = follow[0][0].id
}

return {"follow_id": follow_id};
}
9 changes: 7 additions & 2 deletions src/domains/search/search.provider.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { previewSearchResponseDTO, previewClothResponseDTO, SearchResultResponseDTO, SearchBrandResponseDTO,
previewMyClothResponseDTO, getWishDTO } from "./search.dto.js"
previewMyClothResponseDTO, getWishDTO, getFollowDTO } from "./search.dto.js"
import { getNicknameToClothId, getPreviewCloth, getUserToClothId, getNicknameToClothName, getPreviewBrand, getPreviewUser,
getBrand, getNicknameToBrand, getPreviewMyCloth, getWishDAO } from "./search.dao.js";
getBrand, getNicknameToBrand, getPreviewMyCloth, getWishDAO, getFollowDAO } from "./search.dao.js";

export const getSearch = async (query) => {
const { category } = query;
Expand Down Expand Up @@ -34,4 +34,9 @@ export const getMyCloth = async (userId, clothId) => {
export const getMyWish = async (userId, clothId) => {

return getWishDTO(await getWishDAO(userId, clothId));
}

export const getMyFollow = async (userId, clothId) => {

return getFollowDTO(await getFollowDAO(userId, clothId));
}
9 changes: 6 additions & 3 deletions src/routes/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import express from "express";
import asyncHandler from 'express-async-handler';
import { LoginCheck } from "../middlewares/logincheck.js";
import { searchPreview, clothView, searchView, brandView, addClothPreview, addCloth,
addWish, delWish, getWish, addFollow, delFollow } from "../domains/search/search.controller.js";
addWish, delWish, getWish, addFollow, delFollow, getFollow } from "../domains/search/search.controller.js";

export const searchRouter = express.Router({mergeParams: true});

Expand Down Expand Up @@ -30,11 +30,14 @@ searchRouter.post('/:clothId/wish', LoginCheck, asyncHandler(addWish));
//검색-wish에서 삭제
searchRouter.delete('/:clothId/wish', LoginCheck, asyncHandler(delWish));

//검색-wish
//검색-wish 조회
searchRouter.get('/:clothId/wish', LoginCheck, asyncHandler(getWish));

//검색-follow에 추가
searchRouter.post('/:clothId/follow', LoginCheck, asyncHandler(addFollow));

//검색-follow에서 삭제
searchRouter.delete('/:clothId/follow', LoginCheck, asyncHandler(delFollow));
searchRouter.delete('/:clothId/follow', LoginCheck, asyncHandler(delFollow));

//검색-follow 조회
searchRouter.get('/:clothId/follow', LoginCheck, asyncHandler(getFollow));
73 changes: 73 additions & 0 deletions src/swagger/search.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,79 @@ paths:
type: string
example: 잘못된 요청입니다

'500':
description: 서버 에러
schema:
type: object
properties:
status:
type: integer
example: 500
isSuccess:
type: boolean
example: false
code:
type: integer
example: COMMON000
message:
type: string
example: 서버 에러, 관리자에게 문의 바랍니다.

get:
tags:
- Search
summary: follow 조회 로직
operationId: getFollow
security:
- bearerAuth: []
parameters:
- name: clothId
in: path
required: true
schema:
type: integer
responses:
'200':
description: follow 조회 성공
schema:
type: object
properties:
status:
type: integer
example: 200
isSuccess:
type: boolean
example: true
code:
type: integer
example: 200
message:
type: string
example: "success!"
data:
type: array
example: {
"follow_id": 20
}

'400':
description: 잘못된 요청
schema:
type: object
properties:
status:
type: integer
example: 400
isSuccess:
type: boolean
example: false
code:
type: integer
example: COMMON001
message:
type: string
example: 잘못된 요청입니다

'500':
description: 서버 에러
schema:
Expand Down

0 comments on commit 33336de

Please sign in to comment.