Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#124_backend_recommend-style #124
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/domains/recommend/recommend.controller.js
#	src/domains/recommend/recommend.dao.js
#	src/domains/recommend/recommend.dto.js
#	src/domains/recommend/recommend.provider.js
#	src/domains/recommend/recommend.sql.js
#	src/routes/recommend.js
#	src/swagger/recommend.swagger.yaml
  • Loading branch information
seoyeoneel02 committed Sep 19, 2024
2 parents 8f0f4b8 + 14edc93 commit cd6ce08
Show file tree
Hide file tree
Showing 7 changed files with 316 additions and 19 deletions.
14 changes: 13 additions & 1 deletion src/domains/recommend/recommend.controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { response } from "../../config/response.js";
import { status } from "../../config/response.status.js";
import { getStyle, getStyleAll } from "./recommend.provider.js";
import { getBodyInfo, getBodyInfoAll, getStyle, getStyleAll } from "./recommend.provider.js";

export const bodyInfo = async (req, res, next) => {
console.log("비슷한 체형의 유저를 추천합니다");
const userId = res.locals.uuid;
res.send(response(status.SUCCESS, await getBodyInfo(userId)));
}

export const bodyInfoAll = async (req, res, next) => {
console.log("비슷한 체형의 유저를 모두 추천합니다");
const userId = res.locals.uuid;
res.send(response(status.SUCCESS, await getBodyInfoAll(userId)));
}

export const style = async (req, res, next) => {
console.log("비슷한 스타일의 유저를 추천합니다");
Expand Down
57 changes: 56 additions & 1 deletion src/domains/recommend/recommend.dao.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,62 @@
import { pool } from "../../config/db.config.js";
import { BaseError } from "../../config/error.js";
import { status } from "../../config/response.status.js";
import { getUser, getFitToUserId, getStyleToUserId, findUserToStyle1, findUserToStyle2, findUserAllToStyle1, findUserAllToStyle2 } from "./recommend.sql.js";
import { getUser, findUserToBody, getFitToUserId, getStyleToUserId, findUserAllToBody,
findUserToStyle1, findUserToStyle2, findUserAllToStyle1, findUserAllToStyle2 } from "./recommend.sql.js";

export const getBodyInfoDAO = async (userId) => {
try {
const conn = await pool.getConnection();
const result = [];
const user = await pool.query(getUser, userId);
const height = user[0][0].height;
const weight = user[0][0].weight;
const recommend = await pool.query(findUserToBody, [userId, height, height, weight, weight, height, weight]);

if(recommend[0].length == 0){
conn.release();
return -1;
}else{
for (let i = 0; i < recommend[0].length; i++) {
const user = await pool.query(getUser, recommend[0][i].uuid);
const fit = await pool.query(getFitToUserId, recommend[0][i].uuid);
const style = await pool.query(getStyleToUserId, recommend[0][i].uuid);
result.push({user, fit, style});
}
}
conn.release();
return result;
} catch (err) {
throw new BaseError(status.PARAMETER_IS_WRONG);
}
}

export const getBodyInfoAllDAO = async (userId) => {
try {
const conn = await pool.getConnection();
const result = [];
const user = await pool.query(getUser, userId);
const height = user[0][0].height;
const weight = user[0][0].weight;
const recommend = await pool.query(findUserAllToBody, [userId, height, height, weight, weight, height, weight]);

if(recommend[0].length == 0){
conn.release();
return -1;
}else{
for (let i = 0; i < recommend[0].length; i++) {
const user = await pool.query(getUser, recommend[0][i].uuid);
const fit = await pool.query(getFitToUserId, recommend[0][i].uuid);
const style = await pool.query(getStyleToUserId, recommend[0][i].uuid);
result.push({user, fit, style});
}
}
conn.release();
return result;
} catch (err) {
throw new BaseError(status.PARAMETER_IS_WRONG);
}
}

export const getStyleDAO = async (userId) => {
try {
Expand Down
20 changes: 20 additions & 0 deletions src/domains/recommend/recommend.dto.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
export const getBodyInfoDTO = (data) => {
const user = [];
if(data == -1){
user.push("해당 유저는 등록되어 있지 않아요.");
}else{
for (let i = 0; i < data.length; i++) {
user.push({
"user_id": data[i].user[0][0].uuid,
"nickname": data[i].user[0][0].nickname,
"user_image": data[i].user[0][0].img_url,
"height": data[i].user[0][0].height,
"weight": data[i].user[0][0].weight,
"prefer_fit": data[i].fit[0].map(fitItem => fitItem.pf_name),
"prefer_style": data[i].style[0].map(styleItem => styleItem.style_name)
})
}
}
return {"userData": user};
}

export const getStyleDTO = (data) => {
const user = [];
if(data == -1){
Expand Down
12 changes: 10 additions & 2 deletions src/domains/recommend/recommend.provider.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { getStyleDTO } from "./recommend.dto.js"
import { getStyleDAO, getStyleAllDAO } from "./recommend.dao.js";
import { getBodyInfoDTO, getStyleDTO } from "./recommend.dto.js"
import { getBodyInfoDAO, getBodyInfoAllDAO, getStyleDAO, getStyleAllDAO } from "./recommend.dao.js";

export const getBodyInfo = async (userId) => {
return getBodyInfoDTO(await getBodyInfoDAO(userId));
}

export const getBodyInfoAll = async (userId) => {
return getBodyInfoDTO(await getBodyInfoAllDAO(userId));
}

export const getStyle = async (userId) => {
return getStyleDTO(await getStyleDAO(userId));
Expand Down
40 changes: 27 additions & 13 deletions src/domains/recommend/recommend.sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ export const getUser =
+ "FROM body_info b JOIN member m on b.uuid = m.uuid "
+ "WHERE b.uuid = ? ;"

export const findUserToStyle1 =
"SELECT DISTINCT uuid "
+ "FROM user_style "
+ "WHERE NOT uuid = ? "
+ "AND style_name = ? "
+ "ORDER BY uuid LIMIT 8;"

export const findUserToStyle2 =
"SELECT DISTINCT uuid "
+ "FROM user_style "
+ "WHERE NOT uuid = ? "
+ "AND (style_name = ? OR style_name = ?) "
+ "ORDER BY uuid LIMIT 8;"
export const findUserToBody =
"SELECT b.uuid "
+ "FROM body_info b "
+ "WHERE NOT uuid = ? and height BETWEEN ?-5 AND ?+5 "
+ "AND weight BETWEEN ?-5 AND ?+5 "
+ "ORDER BY ABS(height-?) + ABS(weight-?) ASC LIMIT 8;"

export const getFitToUserId =
"SELECT uf.uuid, uf.pf_name "
Expand All @@ -32,6 +25,27 @@ export const findUserToFit =
+ "FROM user_fit uf "
+ "WHERE uf.pf_name = ? ;"

export const findUserAllToBody =
"SELECT b.uuid "
+ "FROM body_info b "
+ "WHERE NOT uuid = ? and height BETWEEN ?-5 AND ?+5 "
+ "AND weight BETWEEN ?-5 AND ?+5 "
+ "ORDER BY ABS(height-?) + ABS(weight-?) ASC LIMIT 24;"

export const findUserToStyle1 =
"SELECT DISTINCT uuid "
+ "FROM user_style "
+ "WHERE NOT uuid = ? "
+ "AND style_name = ? "
+ "ORDER BY uuid LIMIT 8;"

export const findUserToStyle2 =
"SELECT DISTINCT uuid "
+ "FROM user_style "
+ "WHERE NOT uuid = ? "
+ "AND (style_name = ? OR style_name = ?) "
+ "ORDER BY uuid LIMIT 8;"

export const findUserAllToStyle1 =
"SELECT DISTINCT uuid "
+ "FROM user_style "
Expand Down
8 changes: 7 additions & 1 deletion src/routes/recommend.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import express from "express";
import asyncHandler from 'express-async-handler';
import { LoginCheck } from "../middlewares/logincheck.js";
import { style, styleAll } from "../domains/recommend/recommend.controller.js";
import { bodyInfo, bodyInfoAll, style, styleAll } from "../domains/recommend/recommend.controller.js";

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

//체형 추천
recommendRouter.get('/body_info', LoginCheck, asyncHandler(bodyInfo));

//체형 추천-모두 보기
recommendRouter.get('/body_info/all', LoginCheck, asyncHandler(bodyInfoAll));

//스타일 추천
recommendRouter.get('/style', LoginCheck, asyncHandler(style));

Expand Down
184 changes: 183 additions & 1 deletion src/swagger/recommend.swagger.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,186 @@
paths:
/FITple/recommend/body_info:
get:
tags:
- Recommend
summary: 비슷한 체형의 유저 추천
operationId: profile
security:
- bearerAuth: []
responses:
'200':
description: 비슷한 체형의 유저 조회 성공
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: {
"userData": [
{
"user_id": 32,
"nickname": "선도하는요리사",
"user_image": "https://fitple-dev-bucket.s3.ap-northeast-2.amazonaws.com/image/1724175918950-fitple_logo.png",
"height": 165,
"weight": 56,
"prefer_fit": [
"오버",
"슬림"
],
"prefer_style": [
"모던시크",
"유니크"
]
},
{
"user_id": 23,
"nickname": "지속가능한펭귄",
"user_image": "https://fitple-dev-bucket.s3.ap-northeast-2.amazonaws.com/image/1724175918950-fitple_logo.png",
"height": 166,
"weight": 59,
"prefer_fit": [
"레귤러",
"슬림"
],
"prefer_style": [
"러블리",
"아메카지"
]
}
]
}

'400':
description: 잘못된 요청
schema:
type: object
properties:
status:
type: integer
isSuccess:
type: boolean
code:
type: integer
message:
type: string

'500':
description: 서버 에러
schema:
type: object
properties:
status:
type: integer
isSuccess:
type: boolean
code:
type: integer
message:
type: string

/FITple/recommend/body_info/all:
get:
tags:
- Recommend
summary: 비슷한 체형의 유저 모두 추천
operationId: profile
security:
- bearerAuth: []
responses:
'200':
description: 비슷한 체형의 유저 모두 조회 성공
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: {
"userData": [
{
"user_id": 32,
"nickname": "선도하는요리사",
"user_image": "https://fitple-dev-bucket.s3.ap-northeast-2.amazonaws.com/image/1724175918950-fitple_logo.png",
"height": 165,
"weight": 56,
"prefer_fit": [
"오버",
"슬림"
],
"prefer_style": [
"모던시크",
"유니크"
]
},
{
"user_id": 23,
"nickname": "지속가능한펭귄",
"user_image": "https://fitple-dev-bucket.s3.ap-northeast-2.amazonaws.com/image/1724175918950-fitple_logo.png",
"height": 166,
"weight": 59,
"prefer_fit": [
"레귤러",
"슬림"
],
"prefer_style": [
"러블리",
"아메카지"
]
}
]
}

'400':
description: 잘못된 요청
schema:
type: object
properties:
status:
type: integer
isSuccess:
type: boolean
code:
type: integer
message:
type: string

'500':
description: 서버 에러
schema:
type: object
properties:
status:
type: integer
isSuccess:
type: boolean
code:
type: integer
message:
type: string

/FITple/recommend/style:
get:
tags:
Expand Down Expand Up @@ -179,4 +361,4 @@ paths:
code:
type: integer
message:
type: string
type: string

0 comments on commit cd6ce08

Please sign in to comment.