Skip to content

Commit 761cf3a

Browse files
committed
feat(analysis): 리포지토리 공개 설정 분석 결과 주인에게만 보이도록 설정
1 parent f3a1594 commit 761cf3a

File tree

4 files changed

+28
-115
lines changed

4 files changed

+28
-115
lines changed

front/src/app/(dashboard)/analysis/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function ResultsPage() {
4343

4444
{/* 🌐 공개 설정 및 커뮤니티 섹션 */}
4545
<RepositoryPublicSection
46-
userId={userId}
46+
userId={history.repository.ownerId}
4747
repoId={repoId}
4848
initialPublic={history.repository.publicRepository}
4949
/>

front/src/components/analysis/RepositoryPublicSection.tsx

Lines changed: 24 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,8 @@
1-
// "use client"
2-
3-
// import { useEffect, useState } from "react"
4-
// import { Card } from "@/components/ui/card"
5-
// import { Button } from "@/components/ui/Button"
6-
// import { Switch } from "@/components/ui/switch"
7-
// import { ShareButton } from "@/components/analysis/ShareButton"
8-
// import { Globe, Lock, MessageSquare } from "lucide-react"
9-
// import { useRepositoryPublic } from "@/hooks/analysis/useRepositoryPublic"
10-
// import { CommentSection } from "@/components/community/CommentSection"
11-
// import { analysisApi } from "@/lib/api/analysis"
12-
// import type { HistoryResponseDto } from "@/types/analysis"
13-
14-
// interface Props {
15-
// userId: number
16-
// repoId: number
17-
// initialPublic: boolean
18-
// }
19-
20-
// export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props) {
21-
// const { isPublic, togglePublic } = useRepositoryPublic(initialPublic, userId, repoId)
22-
23-
// const [analysisResultId, setAnalysisResultId] = useState<number | null>(null)
24-
// const [loading, setLoading] = useState(true)
25-
26-
// useEffect(() => {
27-
// const loadAnalysisId = async () => {
28-
// try {
29-
// const historyResponse: HistoryResponseDto = await analysisApi.getRepositoryHistory(userId, repoId)
30-
// // ✅ 최신 분석 결과 ID 추출
31-
// if (historyResponse.analysisVersions && historyResponse.analysisVersions.length > 0) {
32-
// const latest = historyResponse.analysisVersions[0]
33-
// setAnalysisResultId(latest.analysisId)
34-
// } else {
35-
// console.warn("이 리포지토리에 분석 기록이 없습니다.")
36-
// }
37-
// } catch (err) {
38-
// console.error("❌ 분석 히스토리 조회 실패:", err)
39-
// } finally {
40-
// setLoading(false)
41-
// }
42-
// }
43-
44-
// loadAnalysisId()
45-
// }, [userId, repoId])
46-
47-
// return (
48-
// <>
49-
// {/* 🌐 공개 설정 */}
50-
// <Card className="mb-8 p-6">
51-
// <div className="flex items-center justify-between">
52-
// <div className="flex items-center gap-3">
53-
// {isPublic ? (
54-
// <Globe className="h-5 w-5 text-green-500" />
55-
// ) : (
56-
// <Lock className="h-5 w-5 text-muted-foreground" />
57-
// )}
58-
// <div>
59-
// <h3 className="font-semibold">리포지토리 공개 설정</h3>
60-
// <p className="text-sm text-muted-foreground">
61-
// {isPublic
62-
// ? "이 리포지토리의 분석 결과가 커뮤니티에 공개됩니다."
63-
// : "이 리포지토리의 분석 결과는 비공개 상태입니다."}
64-
// </p>
65-
// </div>
66-
// </div>
67-
68-
// <div className="flex items-center gap-2">
69-
// <span className="text-sm text-muted-foreground">{isPublic ? "공개" : "비공개"}</span>
70-
// <Switch checked={isPublic} onCheckedChange={togglePublic} />
71-
// </div>
72-
// </div>
73-
// </Card>
74-
75-
// {/* 💬 커뮤니티 섹션 */}
76-
// {isPublic ? (
77-
// <>
78-
// <Card className="p-6 mb-8">
79-
// <div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
80-
// <div>
81-
// <h3 className="mb-1 font-semibold">커뮤니티 반응</h3>
82-
// <p className="text-sm text-muted-foreground">다른 개발자들과 소통하세요.</p>
83-
// </div>
84-
// <div className="flex gap-2">
85-
// <Button variant="outline" size="sm" className="gap-2 bg-transparent">
86-
// <MessageSquare className="h-4 w-4" />
87-
// 댓글 (n)
88-
// </Button>
89-
// <ShareButton />
90-
// </div>
91-
// </div>
92-
// </Card>
93-
94-
// {/* ✅ analysisResultId가 있을 때만 CommentSection 표시 */}
95-
// {loading ? (
96-
// <p className="text-muted-foreground text-sm">분석 데이터를 불러오는 중...</p>
97-
// ) : analysisResultId ? (
98-
// <CommentSection analysisResultId={analysisResultId} memberId={userId} />
99-
// ) : (
100-
// <p className="text-muted-foreground text-sm">아직 분석 기록이 없습니다.</p>
101-
// )}
102-
// </>
103-
// ) : (
104-
// <Card className="p-6 text-center text-muted-foreground">
105-
// 🔒 이 리포지토리는 현재 비공개 상태입니다.
106-
// </Card>
107-
// )}
108-
// </>
109-
// )
110-
// }
111-
1121
"use client"
1132

1143
import { useEffect, useState } from "react"
1154
import { Card } from "@/components/ui/card"
116-
import { Button } from "@/components/ui/button" // ✅ 대소문자 수정
5+
import { Button } from "@/components/ui/Button" // ✅ 대소문자 수정
1176
import { Switch } from "@/components/ui/switch"
1187
import { ShareButton } from "@/components/analysis/ShareButton"
1198
import { Globe, Lock, MessageSquare } from "lucide-react"
@@ -133,8 +22,23 @@ export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props
13322

13423
const [analysisResultId, setAnalysisResultId] = useState<number | null>(null)
13524
const [loading, setLoading] = useState(true)
25+
const [currentUserId, setCurrentUserId] = useState<number | null>(null)
13626

13727
useEffect(() => {
28+
const stored = localStorage.getItem("user")
29+
if (stored) {
30+
try {
31+
const parsed = JSON.parse(stored)
32+
setCurrentUserId(Number(parsed.id))
33+
} catch (err) {
34+
console.error("유저 정보 파싱 실패:", err)
35+
}
36+
}
37+
}, [])
38+
39+
useEffect(() => {
40+
if (!userId || !repoId) return
41+
13842
const loadAnalysisId = async () => {
13943
try {
14044
const historyResponse: HistoryResponseDto = await analysisApi.getRepositoryHistory(userId, repoId)
@@ -155,9 +59,14 @@ export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props
15559
loadAnalysisId()
15660
}, [userId, repoId])
15761

62+
if (currentUserId === null) {
63+
return <div className="p-6 text-center text-muted-foreground">사용자 정보를 불러오는 중...</div>
64+
}
65+
15866
return (
15967
<>
16068
{/* 🌐 공개 설정 */}
69+
{currentUserId === userId && (
16170
<Card className="mb-8 p-6">
16271
<div className="flex items-center justify-between">
16372
<div className="flex items-center gap-3">
@@ -182,6 +91,7 @@ export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props
18291
</div>
18392
</div>
18493
</Card>
94+
)}
18595

18696
{/* 💬 커뮤니티 섹션 */}
18797
{isPublic ? (
@@ -193,13 +103,13 @@ export function RepositoryPublicSection({ userId, repoId, initialPublic }: Props
193103
<h3 className="mb-1 font-semibold">커뮤니티 반응</h3>
194104
<p className="text-sm text-muted-foreground">다른 개발자들과 소통하세요.</p>
195105
</div>
196-
{/*<div className="flex gap-2">
106+
<div className="flex gap-2">
197107
<Button variant="outline" size="sm" className="gap-2 bg-transparent">
198108
<MessageSquare className="h-4 w-4" />
199109
댓글 (n)
200110
</Button>
201111
<ShareButton />
202-
</div>*/}
112+
</div>
203113
</div>
204114

205115
{/* 본문 영역: 댓글 작성 → 댓글 목록 */}

front/src/types/analysis.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export interface RepositoryResponse {
1919
publicRepository: boolean
2020
mainBranch: string
2121
languages: string[]
22+
createDate: string
23+
ownerId: number
2224
}
2325

2426
// Repository 상세 정보 + 분석 버전 목록 응답 DTO, 특정 Repository의 모든 분석 버전을 조회할 때 사용

front/src/types/history.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export interface RepositoryResponse {
1010
createDate: string,
1111
latestScore?: number | null
1212
latestAnalysisDate?: string | null
13+
ownerId: number
1314
}
1415

0 commit comments

Comments
 (0)