Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Oneul-hyeon/Personalized-Virtual-Fitting-Service-Web
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: Oneul-hyeon/Personalized-Virtual-Fitting-Service-Web
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: develop
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Jul 1, 2023

  1. ✨ Feat: 구현 피팅, 사이즈 예측

    피팅을 위한 api 요청 기능 구현
    세부 사이즈 예측을 위해 ai로 api 요청 기능 구현
    로그인이 유지되지 않는 오류 해결
    S686 committed Jul 1, 2023
    Copy the full SHA
    03b405b View commit details
  2. 💄 Design : 마이페이지/피팅페이지 UI/UX

    - 마이페이지 사이즈 정보 Fetch 추가
    - 서버 sizeFetch api(/userInfo/api/...) 추가
    Titorima committed Jul 1, 2023
    Copy the full SHA
    a1cca1e View commit details
  3. Copy the full SHA
    02288c0 View commit details
  4. 🔀 Merge : develop

    Titorima committed Jul 1, 2023
    Copy the full SHA
    60c0f4a View commit details
  5. Copy the full SHA
    b6e9eb4 View commit details
  6. 🐛 Fix : 수정 app.js - dispatch

    - dispatch 할 때 인자로 token값이 주어지지 않아, 새로고침 시 토큰이
      삭제되는 문제 해결
    Titorima committed Jul 1, 2023
    Copy the full SHA
    04ae33d View commit details
  7. Merge pull request #13 from AIVLE-School-Third-Big-Project/mergeTemp

    🐛 Fix : 수정 app.js - dispatch
    Titosvarius authored Jul 1, 2023
    Copy the full SHA
    e33e0b2 View commit details
  8. ✨ Feat: 구현 피팅페이지 조회

    피팅페이지에서 조회 구현
    - 자신의 이미지, 업로드 된 의류 이미지
    
    옷 링크를 업로드 하도록 버튼 변경
    S686 committed Jul 1, 2023
    Copy the full SHA
    e8709d7 View commit details

Commits on Jul 2, 2023

  1. ✨ Feat : 추가 마이페이지 기능

    - 개인정보 로딩 / 수정
    - 개인정보 submit 시 기본 유효성 검사 제외 및 로직 추가
    - 수정 완료 시 완료 알림
    - 사이즈 정보 수정 : size api 동작되면 추가 예정
    Titorima committed Jul 2, 2023
    Copy the full SHA
    f98a544 View commit details
  2. Merge pull request #14 from AIVLE-School-Third-Big-Project/mergeTemp

    ✨ Feat : 추가 마이페이지 기능
    Titosvarius authored Jul 2, 2023
    Copy the full SHA
    e11a600 View commit details
  3. Copy the full SHA
    eccf161 View commit details
  4. 🔀 Merge!

    Titorima committed Jul 2, 2023
    Copy the full SHA
    264b8e5 View commit details
  5. Copy the full SHA
    0e86467 View commit details
  6. Copy the full SHA
    29499cf View commit details
  7. ✨ Feat : 추가 피팅, 사이즈예측 기능

    - 회원가입 시 신체사이즈 예측 받아오는 기능 추가
    - 피팅 기능 추가
    - closet db 수정 (의류 url 추가)
    S686 committed Jul 2, 2023
    Copy the full SHA
    7cce166 View commit details
  8. ✨ Feat: 추가 의류 업로드(크롤링)

    - 의류 업로드 모달창 디자인 수정
    - 의류 URL 입력 시 이미지 크롤링
    - 미로그인 상태로 피팅페이지 접근 시 메인 화면으로 이동
    Titorima committed Jul 2, 2023
    Copy the full SHA
    88ee909 View commit details
  9. 🔀 Merge!

    Titorima committed Jul 2, 2023
    Copy the full SHA
    6ab01e4 View commit details
  10. Merge pull request #17 from AIVLE-School-Third-Big-Project/mergeTemp

    ✨ Feat: 추가 의류 업로드(크롤링)
    Titosvarius authored Jul 2, 2023
    Copy the full SHA
    a2ac520 View commit details
  11. 🐛 Fix: 수정 피팅 페이지

    - 옷 링크 업로드 모달창 close버튼 수정
    Titorima committed Jul 2, 2023
    Copy the full SHA
    b552a54 View commit details
  12. Merge pull request #18 from AIVLE-School-Third-Big-Project/mergeTemp

    🐛 Fix: 수정 피팅 페이지
    Titosvarius authored Jul 2, 2023
    Copy the full SHA
    402c2ea View commit details

Commits on Jul 3, 2023

  1. ✨ Feat: 의류 업로드 기능 구현

    - 의류 업로드 후, db 저장 구현
    - s3에 이미지 저장 경로 변경
    - 되돌리기 버튼 기능 구현
    S686 committed Jul 3, 2023
    Copy the full SHA
    4f192d3 View commit details
  2. Copy the full SHA
    d4d144f View commit details
  3. 🐛 Fix: allowedOrigins

    Titorima committed Jul 3, 2023
    Copy the full SHA
    f432cef View commit details
  4. 🔀 Merge!

    Titorima committed Jul 3, 2023
    Copy the full SHA
    28f6302 View commit details
  5. Merge pull request #19 from AIVLE-School-Third-Big-Project/mergeTemp

    💄 Design : 피팅 페이지 수정
    Titosvarius authored Jul 3, 2023
    Copy the full SHA
    ff893b2 View commit details
  6. 🐛 Fix: 수정 회원가입 (RegisterUser.js)

    - 회원가입 시 사진이 undefined에 저장되는 문제 수정
    Titorima committed Jul 3, 2023
    Copy the full SHA
    f6a4bc6 View commit details
  7. Copy the full SHA
    1c994f5 View commit details
  8. 🔀 Merge!

    Titorima committed Jul 3, 2023
    Copy the full SHA
    6fe4847 View commit details
  9. Merge pull request #20 from AIVLE-School-Third-Big-Project/mergeTemp

    🐛 Fix: 수정 회원가입 (RegisterUser.js)
    Titosvarius authored Jul 3, 2023
    Copy the full SHA
    801f9c8 View commit details
  10. ✨ Feat: 추가 마이페이지 기능

    - 사이즈 정보 수정 기능 추가
    - 키/몸무게만 입력되어 있는 경우 sizeAPI를 이용해서 값을 채움
    Titorima committed Jul 3, 2023
    Copy the full SHA
    3c7c679 View commit details
  11. 🐛 Fix: 수정 마이페이지

    - 사이즈 정보 : 정수만 입력 가능 -> 소수 입력 가능
    Titorima committed Jul 3, 2023
    Copy the full SHA
    050b3ab View commit details
  12. Copy the full SHA
    46e5d9e View commit details
  13. ✨ Feat: 피팅 및 의류 삭제 기능 구현

    - 업로드 된 의류 (옷장) 삭제 기능 구현
    - 피팅 기능 구현
    - 로딩 인디케이터 추가
    S686 committed Jul 3, 2023
    Copy the full SHA
    aafd9d6 View commit details
  14. Copy the full SHA
    b5cac30 View commit details
  15. 🐛 Fix: 수정 자잘한 오류

    - 회원가입 구문 오류 수정
    - 이미지 업로드 구문 오류 수정
    Titorima committed Jul 3, 2023
    Copy the full SHA
    381e626 View commit details
  16. Merge pull request #22 from AIVLE-School-Third-Big-Project/mergeTemp

    🐛 Fix: 수정 자잘한 오류
    Titosvarius authored Jul 3, 2023
    Copy the full SHA
    027332d View commit details
  17. 🐛 Fix: 수정 크롤링

    - 크롤링 API로 전달하는 params 전송 방법 변경
    - 이미지URL이 파일 확장자로 끝나지 않는 경우 많음 : 확장자 필터링 제거
    Titorima committed Jul 3, 2023
    Copy the full SHA
    233eee1 View commit details
  18. ✨ Feat: 구현 회원가입 검증 기능

    - 이미지, 키, 몸무게 필드 입력했는지 검증
    - 키, 몸무게 를 정수, 소수점 한자리까지 실수 입력가능하게 변경
    - 회원가입 로딩 인디케이터 추가
    - 회원가입 시 발생한 오류를 알 수 있도록 alert 추가
    - 코디 추천 페이지 임시 구현
    S686 committed Jul 3, 2023
    Copy the full SHA
    01dea77 View commit details
  19. ✨ Feat: 이메일인증 API 추가

    - 서버에 이메일 인증 관련 API 추가
    - 인증 이메일 전송 : /auth/api/sendMail
    - 인증 코드 체크 : /auth/api/mailAuthCheck
    - (예정) 회원가입 UI 수정
    Titorima committed Jul 3, 2023
    Copy the full SHA
    2010c4f View commit details
  20. Copy the full SHA
    d70ed53 View commit details
  21. 🐛 Fix: 수정 피팅 및 푸터

    - 약관 페이지가 뜨지 않는 오류 해결
    - 피팅 요청 수정
    S686 committed Jul 3, 2023
    Copy the full SHA
    f1f5c08 View commit details
  22. Copy the full SHA
    abe327d View commit details
  23. Merge pull request #24 from AIVLE-School-Third-Big-Project/mergeTemp

    💄 Design: 수정 마이페이지
    Titosvarius authored Jul 3, 2023
    Copy the full SHA
    f56f8da View commit details
  24. Copy the full SHA
    a7d0182 View commit details

Commits on Jul 4, 2023

  1. ✨: 추가 피팅 페이지

    - 되돌리기 기능 추가
    - 피팅하기 오류 수정
    Oneul-hyeon committed Jul 4, 2023
    Copy the full SHA
    4dea947 View commit details
  2. Merge pull request #25 from AIVLE-School-Third-Big-Project/temp

    ✨: 추가 피팅 페이지
    S686 authored Jul 4, 2023
    Copy the full SHA
    da94a84 View commit details
  3. Copy the full SHA
    c0fc92b View commit details
  4. 🔀 Merge!

    Paruru committed Jul 4, 2023
    Copy the full SHA
    3c477f5 View commit details
  5. Copy the full SHA
    bfa5a43 View commit details
  6. ✨ Feat: 구현 의류 삭제 알림

    - 옷장 의류 삭제 시, 삭제 메세지 알림
    - 로그아웃 시 로그아웃이 되지 않는 오류 해결
    S686 committed Jul 4, 2023
    Copy the full SHA
    69faa1e View commit details
Showing with 4,679 additions and 409 deletions.
  1. +2 −0 package.json
  2. +29 −5 src/main.js
  3. +11 −0 src/models/Closet.js
  4. +27 −0 src/models/Forum.js
  5. +4 −4 src/models/SizeProfile.js
  6. +2 −1 src/models/User.js
  7. +43 −0 src/modules/AuthMail/AuthMail.js
  8. +13 −0 src/modules/AuthMail/generateAuthCode.js
  9. +40 −0 src/routes/ClothSize.js
  10. +69 −0 src/routes/Clothes.js
  11. +91 −0 src/routes/FittingImage.js
  12. +42 −5 src/routes/ImageUploader.js
  13. +43 −0 src/routes/MailAuthRouter.js
  14. +112 −0 src/routes/OutfitForum.js
  15. +114 −73 src/routes/RegisterUser.js
  16. +64 −0 src/routes/UploadClothImage.js
  17. +252 −0 src/routes/UserInfo.js
  18. +111 −0 src/routes/crawling.js
  19. +5 −0 style/babel-plugin-macros.config.js
  20. +7 −0 style/babelrc.config.js
  21. +10 −1 style/package.json
  22. +33 −3 style/src/App.js
  23. +2 −2 style/src/api/apiConfig.js
  24. +5 −0 style/src/api/authenticatedAxios.js
  25. +0 −22 style/src/components/FittingPage.js
  26. +306 −0 style/src/components/FittingPage/ButtonBar.js
  27. +14 −0 style/src/components/FittingPage/CardButton.js
  28. +90 −0 style/src/components/FittingPage/FittingPage.js
  29. +487 −0 style/src/components/FittingPage/FittingPage.module.css
  30. +50 −0 style/src/components/FittingPage/FittingPageAlert.js
  31. +44 −0 style/src/components/FittingPage/LeftFitContainer.js
  32. +393 −0 style/src/components/FittingPage/RightFitContainer.js
  33. +2 −2 style/src/components/Footer.js
  34. +29 −0 style/src/components/ForumPage/ForumDetails.css
  35. +36 −0 style/src/components/ForumPage/ForumDetails.js
  36. +108 −0 style/src/components/ForumPage/ForumList.css
  37. +96 −0 style/src/components/ForumPage/ForumList.js
  38. +58 −0 style/src/components/ForumPage/NewForumPost.css
  39. +65 −0 style/src/components/ForumPage/NewForumPost.js
  40. +50 −0 style/src/components/LoadingIndicator.css
  41. +16 −0 style/src/components/LoadingIndicator.js
  42. +1 −1 style/src/components/MainPage/Content.js
  43. +58 −0 style/src/components/MyPage/FormBox.js
  44. +67 −0 style/src/components/MyPage/ImageUploaders.css
  45. +70 −0 style/src/components/MyPage/ImageUploaders.js
  46. +115 −0 style/src/components/MyPage/LeftSubMyPage.js
  47. +52 −0 style/src/components/MyPage/MyPage.js
  48. +205 −0 style/src/components/MyPage/MyPage.module.css
  49. +35 −0 style/src/components/MyPage/MyPageAlert.js
  50. +175 −0 style/src/components/MyPage/MyPrivacy.js
  51. +178 −0 style/src/components/MyPage/MySize.js
  52. +45 −0 style/src/components/MyPage/RightSubMyPage.js
  53. +43 −0 style/src/components/MyPage/SizeFormBox.js
  54. 0 style/src/components/MyPage/getUserInfo.js
  55. +1 −1 style/src/components/Navigationbar/DropdownMenu.js
  56. +2 −2 style/src/components/Navigationbar/Nav.js
  57. +28 −0 style/src/components/QnAPage/QnAPage.css
  58. +24 −0 style/src/components/QnAPage/QnAPage.js
  59. +0 −12 style/src/components/RecommendPage.js
  60. +36 −0 style/src/components/RecommendPage/RecommendPage.css
  61. +26 −0 style/src/components/RecommendPage/RecommendPage.js
  62. +1 −2 style/src/components/User/Login.js
  63. +1 −0 style/src/components/User/Logout.js
  64. +13 −5 style/src/components/User/Register.js
  65. +12 −0 style/src/components/User/SignupPage.css
  66. +304 −265 style/src/components/User/SignupPage.js
  67. +40 −0 style/src/components/User/UpdateInfo.js
  68. +3 −2 style/src/components/User/Validations.js
  69. +28 −0 style/src/components/common/AlertMessage.js
  70. +6 −0 style/src/components/common/AlertMessage.module.css
  71. +5 −0 style/src/components/common/ClassNameGenerater.js
  72. +28 −0 style/src/components/common/getProfileImage.js
  73. +4 −1 style/src/features/authSlices.js
  74. +22 −0 style/src/features/clothSlice.js
  75. +72 −0 style/src/features/forumsSlice.js
  76. BIN style/src/images/bg1.png
  77. BIN style/src/images/bg2.jpg
  78. BIN style/src/images/bg3.jpg
  79. BIN style/src/images/bg4.jpg
  80. BIN style/src/images/commingsoon.png
  81. BIN style/src/images/fithelp1.png
  82. BIN style/src/images/fithelp2.png
  83. BIN style/src/images/fithelp3.png
  84. BIN style/src/images/fithelp4.png
  85. BIN style/src/images/help.png
  86. BIN style/src/images/landscape.png
  87. BIN style/src/images/profile.jpg
  88. BIN style/src/images/profileImageLoading.png
  89. BIN style/src/images/reset.png
  90. BIN style/src/images/save.png
  91. BIN style/src/images/search.png
  92. BIN style/src/images/upload.png
  93. +4 −0 style/src/store.js
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
"axios": "^1.4.0",
"bcrypt": "^5.1.0",
"bull": "^4.10.4",
"cheerio": "^1.0.0-rc.12",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
@@ -31,6 +32,7 @@
"mongoose": "^7.3.0",
"multer": "^1.4.5-lts.1",
"multer-s3": "^3.0.1",
"nodemailer": "^6.9.3",
"passport": "^0.6.0",
"passport-local": "^1.0.0"
}
34 changes: 29 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -18,7 +18,9 @@ const aiAPI = process.env.AI_API

const allowedOrigins = [
'http://localhost:3000',
'http://www.model-fit.kro.kr',
'http://localhost:3001',
process.env.WEB_API,
process.env.WEB_IP,
aiAPI,
]

@@ -35,7 +37,7 @@ mongoose
.catch((err) => console.log(err))

app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(express.urlencoded({ extended: true }))
app.use(
cors({
origin: function (origin, callback) {
@@ -49,6 +51,7 @@ app.use(
credentials: true,
})
)

app.use(passport.initialize())
require('./config/passport')(passport)

@@ -60,13 +63,34 @@ app.use(express.static(path.join(__dirname, '../style/build')))
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname, '../style/build/index.html'))
})
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../style/build/index.html'))
})

const usersRouter = require('./routes/RegisterUser')
const loginRouter = require('./routes/LoginUser')
const logoutRouter = require('./routes/LogoutUser')
app.use('/users', usersRouter)
app.use('/users', loginRouter)
app.use('/users', logoutRouter)

const authRouter = require('./routes/MailAuthRouter')
app.use('/auth', authRouter)

// userInfo 조회
const infoRouter = require('./routes/UserInfo')
app.use('/userInfo', infoRouter)

const fittingRouter = require('./routes/FittingImage')
const clothUploadRouter = require('./routes/UploadClothImage')
app.use('/api', fittingRouter)
app.use('/api', clothUploadRouter)

const clothRouter = require('./routes/Clothes')
const clothSizeRouter = require('./routes/ClothSize')
app.use('/cloth', clothRouter)
app.use('/cloth', clothSizeRouter)

const forumRouter = require('./routes/OutfitForum')
app.use('/api/outfitforums', forumRouter)

app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../style/build/index.html'))
})
11 changes: 11 additions & 0 deletions src/models/Closet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require('mongoose')
const { Schema } = mongoose

const closetSchema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
clothesUrl: { type: String, required: true },
clothesImageLink: { type: String, required: true },
fittingImageLink: { type: String },
})

module.exports = mongoose.model('Closet', closetSchema)
27 changes: 27 additions & 0 deletions src/models/Forum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const mongoose = require('mongoose')
const { Schema } = mongoose

const forumSchema = new mongoose.Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'User',
required: true,
},
title: {
type: String,
required: true,
},
content: {
type: String,
required: true,
},
image: {
type: String,
},
createdAt: {
type: Date,
default: Date.now,
},
})

module.exports = mongoose.model('Forum', forumSchema)
8 changes: 4 additions & 4 deletions src/models/SizeProfile.js
Original file line number Diff line number Diff line change
@@ -2,10 +2,10 @@ const mongoose = require('mongoose')
const { Schema } = mongoose

const sizeProfileSchema = new Schema({
userId: { type: Schema.Types.ObjectId, ref: 'User' },
length: { type: Number },
shoulderWidth: { type: Number },
chestWidth: { type: Number },
userId: { type: Schema.Types.ObjectId, ref: 'User', required: true },
length: { type: Number, required: true },
shoulderWidth: { type: Number, required: true },
chestWidth: { type: Number, required: true },
})

module.exports = mongoose.model('SizeProfile', sizeProfileSchema)
3 changes: 2 additions & 1 deletion src/models/User.js
Original file line number Diff line number Diff line change
@@ -9,13 +9,14 @@ const userSchema = new Schema({
gender: { type: String, required: true },
height: { type: Number, required: true },
weight: { type: Number, required: true },
file: { type: String },
file: { type: String, required: true },
favoriteStyle: {
style: { type: String, default: '' },
color: { type: String, default: '' },
fit: { type: String, default: '정핏' },
},
sizeProfile: { type: Schema.Types.ObjectId, ref: 'SizeProfile' },
clothes: [{ type: Schema.Types.ObjectId, ref: 'Clothes' }],
})

module.exports = mongoose.model('User', userSchema)
43 changes: 43 additions & 0 deletions src/modules/AuthMail/AuthMail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const nodemailer = require('nodemailer')
const generateAuthCode = require('./generateAuthCode')

/*
구글에서는 from 바꾸는 부분 동작하지 않음
참고 : https://nodemailer.com/usage/using-gmail/
*/
const noreply = 'noreply@model-fit.kro.kr'

async function sendAuthMail(email) {
try {
// SMTP 전송을 위한 transporter 생성
const transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: process.env.AUTH_BOT_MAIL,
pass: process.env.AUTH_BOT_PASS,
},
})

// 이메일 옵션 설정
const code = generateAuthCode()
const mailOptions = {
from: `AuthBot<${noreply}>`,
to: email,
subject: 'The authorization code for model.fit.',
text: `code : ${code}`,
}

// 이메일 전송
const info = await transporter.sendMail(mailOptions)
console.log(`Email sent successfully : ${email}`)
return {
authCode: code,
result: { success: true, code: 'SEND_DONE', errno: 0 },
}
} catch (error) {
console.error(`Email sent failed : ${email}`)
return { success: false, code: error.code, errno: -1 }
}
}

module.exports = sendAuthMail
13 changes: 13 additions & 0 deletions src/modules/AuthMail/generateAuthCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const crypto = require('crypto')

// 6자리의 숫자로만 구성된 난수 생성
function generateAuthCode() {
const byteLength = 4

const buffer = crypto.randomBytes(byteLength)
const randomCode = parseInt(buffer.toString('hex'), 16).toString().slice(0, 6)

return randomCode
}

module.exports = generateAuthCode
40 changes: 40 additions & 0 deletions src/routes/ClothSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const express = require('express')
const router = express.Router()
const User = require('../models/User')
const SizeProfile = require('../models/SizeProfile')
const Closet = require('../models/Closet')
const axios = require('axios')

router.post('/cloth_size', async (req, res) => {
try {
const { userId, clothId } = req.body

const user = await User.findById(userId).populate('sizeProfile')
const sizeProfile = user.sizeProfile
const closet = await Closet.findById(clothId)

const length = sizeProfile.length
const shoulderWidth = sizeProfile.shoulderWidth
const chestWidth = sizeProfile.chestWidth
const imageUrl = closet.clothesUrl
const overfit = user.favoriteStyle.fit

const aiApiResponse = await axios.get(process.env.AI_CLOTH_SIZE_API_URL, {
params: {
length,
shoulderWidth,
chestWidth,
imageUrl,
overfit,
},
})

const recommendedSize = aiApiResponse.data.size
res.json({ size: recommendedSize })
} catch (error) {
console.error(error)
res.status(500).json({ message: 'Server error' })
}
})

module.exports = router
69 changes: 69 additions & 0 deletions src/routes/Clothes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const express = require('express')
const router = express.Router()
const Clothes = require('../models/Closet')
const User = require('../models/User')
const { getClothesImageUrls } = require('./crawling')
const { deleteImageFromS3 } = require('./ImageUploader')

router.get('/api/clothes', async (req, res) => {
const { userId } = req.query
try {
const user = await User.findById(userId)
if (!user) {
return res
.status(404)
.json({ success: false, message: 'The user was not found.' })
}
const clothes = await Clothes.find({ userId: userId })
res.json(
clothes.map((cloth) => ({
clothesImageLink: cloth.clothesImageLink,
_id: cloth._id,
}))
)
} catch (err) {
console.error(err.message)
res.status(500).send('Server Error')
}
})

// 입력받은 url에서 이미지 링크 검색 후 반환
router.get('/api/clothesFromUrl', async (req, res) => {
const { url } = req.query

const result = await getClothesImageUrls(url)
if (result.success) {
console.log('success')
return res.status(200).json(result)
} else {
return res.status(500).json(result)
}
})

router.delete('/api/delete/:id', async (req, res) => {
const clothId = req.params.id
try {
const cloth = await Clothes.findById(clothId)
if (!cloth) {
return res.status(404).json({ error: 'No cloth found for given id' })
}
if (cloth.clothesImageLink && cloth.clothesImageLink.trim() !== '') {
console.log(cloth.clothesImageLink)
await deleteImageFromS3(cloth.clothesImageLink)
}

if (cloth.fittingImageLink && cloth.fittingImageLink.trim() !== '') {
console.log(cloth.fittingImageLink)
await deleteImageFromS3(cloth.fittingImageLink)
}

await Clothes.findByIdAndDelete(clothId)
res
.status(200)
.json({ message: 'Cloth deleted successfully', code: 'DELETE_DONE' })
} catch (error) {
res.status(400).json({ error: 'Error while deleting the cloth' })
}
})

module.exports = router
Loading