-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…docs #41-update to swagger
- Loading branch information
Showing
7 changed files
with
311 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,57 @@ | ||
// repositories/user.home.repository.js | ||
import { pool } from '../db.config.js'; | ||
|
||
export class UserHomeRepository { | ||
async findTodayMemory(userId) { | ||
try { | ||
const [rows] = await pool.query( | ||
`SELECT title, visit_date | ||
FROM memories | ||
WHERE DATE_FORMAT(visit_date, '%m-%d') = DATE_FORMAT(CURRENT_DATE, '%m-%d') | ||
AND user_id = ? | ||
AND is_deleted = false | ||
ORDER BY RAND() | ||
LIMIT 1`, | ||
[userId] | ||
); | ||
|
||
return rows[0] || null; // 결과가 없으면 null 반환 | ||
} catch (error) { | ||
console.error('추억 조회 중 DB 오류:', error); | ||
throw error; | ||
} | ||
export const findTodayMemory = async (userId) => { | ||
try { | ||
const [rows] = await pool.query( | ||
`SELECT title, visit_date | ||
FROM memories | ||
WHERE DATE_FORMAT(visit_date, '%m-%d') = DATE_FORMAT(CURRENT_DATE, '%m-%d') | ||
AND user_id = ? | ||
AND is_deleted = false | ||
ORDER BY RAND() | ||
LIMIT 1`, | ||
[userId] | ||
); | ||
|
||
return rows[0] || null; | ||
} catch (error) { | ||
console.error('추억 조회 중 DB 오류:', error); | ||
throw error; | ||
} | ||
async fetchRandomMemory(userId) { | ||
const conn = await pool.getConnection(); | ||
try { | ||
const [memories] = await pool.query( | ||
`SELECT | ||
m.title, | ||
m.content, | ||
m.friends, | ||
m.visit_date, | ||
GROUP_CONCAT(mi.image_url) as images | ||
FROM memories m | ||
LEFT JOIN memory_images mi ON m.id = mi.memory_id | ||
WHERE m.user_id = ? | ||
AND m.is_deleted = false | ||
GROUP BY m.id, m.title, m.content, m.friends, m.visit_date | ||
ORDER BY RAND() | ||
LIMIT 1`, | ||
[userId] | ||
); | ||
|
||
if (!memories || memories.length === 0) { | ||
return null; | ||
} | ||
|
||
const memory = memories[0]; | ||
// 콤마 구분된 이미지 URL 문자열을 배열로 | ||
memory.images = memory.images ? memory.images.split(',') : []; | ||
|
||
return memory; | ||
} catch (error) { | ||
console.error('Repository error:', error); | ||
throw error; | ||
} finally { | ||
conn.release(); | ||
}; | ||
|
||
export const fetchRandomMemory = async (userId) => { | ||
const conn = await pool.getConnection(); | ||
try { | ||
const [memories] = await pool.query( | ||
`SELECT | ||
m.title, | ||
m.content, | ||
m.friends, | ||
m.visit_date, | ||
GROUP_CONCAT(mi.image_url) as images | ||
FROM memories m | ||
LEFT JOIN memory_images mi ON m.id = mi.memory_id | ||
WHERE m.user_id = ? | ||
AND m.is_deleted = false | ||
GROUP BY m.id, m.title, m.content, m.friends, m.visit_date | ||
ORDER BY RAND() | ||
LIMIT 1`, | ||
[userId] | ||
); | ||
|
||
if (!memories || memories.length === 0) { | ||
return null; | ||
} | ||
|
||
const memory = memories[0]; | ||
memory.images = memory.images ? memory.images.split(',') : []; | ||
|
||
return memory; | ||
} catch (error) { | ||
console.error('Repository error:', error); | ||
throw error; | ||
} finally { | ||
conn.release(); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.