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 4463422 commit b7e008f
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 27 deletions.
8 changes: 7 additions & 1 deletion src/domains/search/search.controller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 { addMyCloth, addMyWish, delMyWish, addMyFollow } from "./search.service.js";
import { addMyCloth, addMyWish, delMyWish, addMyFollow, delMyFollow } from "./search.service.js";

export const searchPreview = async (req, res, next) => {
console.log("검색 메인화면을 조회합니다");
Expand Down Expand Up @@ -57,4 +57,10 @@ export const addFollow = async (req, res, next) => {
console.log("팔로우를 요청하였습니다!");
const userId = res.locals.uuid;
res.send(response(status.SUCCESS, await addMyFollow(userId, req.params.clothId)));
}

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)));
}
20 changes: 19 additions & 1 deletion src/domains/search/search.dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { UserNicknameToClothId, UserCategoryToClothId,
brandToBrandName, userIdToNickname, userToNickname, getBrandToBrandId,
userToBrand, categoryToBrand, clothToBrand, clothCategoryToBrand,
insertCloth, insertRealSize, getCloth,
addWishSQL, delWishSQL, getWishSQL, getFollowSQL, addFollowSQL } from "./search.sql.js";
addWishSQL, delWishSQL, getWishSQL, getFollowSQL, addFollowSQL, delFollowSQL } from "./search.sql.js";

// nickname+cloth 반환
export const getNicknameToClothId = async (category) => {
Expand Down Expand Up @@ -289,4 +289,22 @@ export const addFollowDAO = async (userId, clothId) => {
}catch (err) {
throw new BaseError(status.PARAMETER_IS_WRONG);
}
}

// Follow 취소
export const delFollowDAO = async (userId, clothId) => {
try{
const conn = await pool.getConnection();
const to_user = await pool.query(getUserIdToClothId, clothId);
const is_exist = await pool.query(getFollowSQL, [userId, to_user[0][0].uuid]);
if(is_exist[0].length == 0){
throw new BaseError(status.PARAMETER_IS_WRONG);
}
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);
}
}
9 changes: 9 additions & 0 deletions src/domains/search/search.dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,13 @@ export const getWishDTO = (wish) => {

export const addFollowDTO = (follow) => {
return {"follow_id": follow};
}

export const delFollowDTO = (follow) => {
let follow_id;
if(follow[0].length == 0){
follow_id = 0;
}

return {"follow_id": follow_id};
}
8 changes: 6 additions & 2 deletions src/domains/search/search.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseError } from "../../config/error.js";
import { status } from "../../config/response.status.js";
import { addClothResponseDTO, addWishDTO, delWishDTO, addFollowDTO } from "./search.dto.js";
import { clothAdd, getAddCloth, addWishDAO, delWishDAO, addFollowDAO } from "./search.dao.js";
import { addClothResponseDTO, addWishDTO, delWishDTO, addFollowDTO, delFollowDTO } from "./search.dto.js";
import { clothAdd, getAddCloth, addWishDAO, delWishDAO, addFollowDAO, delFollowDAO } from "./search.dao.js";

export const addMyCloth = async (userId, body) => {
const requiredFields = ['name', 'product_code', 'category', 'size', 'fit'];
Expand Down Expand Up @@ -58,4 +58,8 @@ export const delMyWish = async (userId, clothId) => {

export const addMyFollow = async (userId, clothId) => {
return addFollowDTO(await addFollowDAO(userId, clothId));
}

export const delMyFollow = async (userId, clothId) => {
return delFollowDTO(await delFollowDAO(userId, clothId));
}
4 changes: 3 additions & 1 deletion src/domains/search/search.sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,6 @@ export const getWishSQL = "SELECT id FROM wish WHERE cloth_id = ? AND wisher_uui

export const getFollowSQL = "SELECT id FROM follow WHERE from_uuid = ? AND to_uuid = ? ;"

export const addFollowSQL = "INSERT INTO follow (from_uuid, to_uuid) VALUES (?, ?) ;"
export const addFollowSQL = "INSERT INTO follow (from_uuid, to_uuid) VALUES (?, ?) ;"

export const delFollowSQL = "DELETE FROM follow WHERE from_uuid = ? AND to_uuid = ? ;"
7 changes: 5 additions & 2 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 } from "../domains/search/search.controller.js";
addWish, delWish, getWish, addFollow, delFollow } from "../domains/search/search.controller.js";

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

Expand Down Expand Up @@ -34,4 +34,7 @@ searchRouter.delete('/:clothId/wish', LoginCheck, asyncHandler(delWish));
searchRouter.get('/:clothId/wish', LoginCheck, asyncHandler(getWish));

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

//검색-follow에서 삭제
searchRouter.delete('/:clothId/follow', LoginCheck, asyncHandler(delFollow));
97 changes: 77 additions & 20 deletions src/swagger/search.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,7 @@ paths:
data:
type: array
example: {
"clothData": [
{
"wish_id": 20
}
]
"wish_id": 20
}

'400':
Expand Down Expand Up @@ -730,11 +726,7 @@ paths:
data:
type: array
example: {
"clothData": [
{
"wish_id": 20
}
]
"wish_id": 20
}

'400':
Expand Down Expand Up @@ -807,11 +799,7 @@ paths:
data:
type: array
example: {
"clothData": [
{
"wish_id": 20
}
]
"wish_id": 20
}

'400':
Expand Down Expand Up @@ -885,11 +873,80 @@ paths:
data:
type: array
example: {
"clothData": [
{
"wish_id": 20
}
]
"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:
type: object
properties:
status:
type: integer
example: 500
isSuccess:
type: boolean
example: false
code:
type: integer
example: COMMON000
message:
type: string
example: 서버 에러, 관리자에게 문의 바랍니다.

delete:
tags:
- Search
summary: follow 취소 로직
operationId: delFollow
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": 0
}

'400':
Expand Down

0 comments on commit b7e008f

Please sign in to comment.