fix: FilePreview fileType case + Tailwind v4 gradient transparent bug
- FilePreview.vue: add normalizedFileType computed to handle backend returning uppercase HTML/MD/PPTX (fixes preview/download buttons) - FilePreview.vue: bg-gradient-to-r from-orange-500 -> bg-orange-500 (Tailwind v4 gradient + CSS variable = transparent) - ReportCard.vue: bg-gradient-to-r -> bg-orange-600 for selected state - Add .opencode/, node_modules/, dist/ to .gitignore - Initial git setup for publish project
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-gradient-to-br from-orange-100 via-orange-200 to-amber-100">
|
||||
<router-view />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
</script>
|
||||
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,184 @@
|
||||
<template>
|
||||
<div class="h-full flex flex-col">
|
||||
<!-- Preview header -->
|
||||
<div v-if="report" class="glass border-b border-orange-200/50 px-6 py-4 shadow-sm">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center space-x-4">
|
||||
<!-- File type icon -->
|
||||
<div :class="iconBgClass" class="w-12 h-12 rounded-xl flex items-center justify-center shadow-lg">
|
||||
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="font-semibold text-slate-800 text-lg">{{ report.fileName }}</h3>
|
||||
<div class="mt-1 flex items-center space-x-3 text-sm">
|
||||
<span class="px-2.5 py-1 bg-orange-100 text-orange-600 rounded-full font-medium">{{ fileTypeLabel }}</span>
|
||||
<span class="text-slate-500">{{ report.reportDate }}</span>
|
||||
<span class="text-slate-400">·</span>
|
||||
<span class="text-slate-500">{{ report.size }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Download button -->
|
||||
<button
|
||||
@click="downloadReport"
|
||||
class="group px-5 py-2.5 bg-orange-500 text-white rounded-xl hover:bg-orange-600 transition-all shadow-lg shadow-orange-500/30 flex items-center space-x-2 hover:shadow-xl"
|
||||
>
|
||||
<svg class="w-5 h-5 group-hover:translate-y-0.5 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4" />
|
||||
</svg>
|
||||
<span class="font-medium">下载</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Preview content -->
|
||||
<div class="flex-1 overflow-auto p-6 bg-slate-50/50">
|
||||
<!-- HTML Preview -->
|
||||
<div v-if="normalizedFileType === 'html'" class="bg-white rounded-2xl shadow-xl overflow-hidden border border-orange-200/30">
|
||||
<iframe
|
||||
ref="iframeRef"
|
||||
:srcdoc="content"
|
||||
class="w-full h-full min-h-[500px]"
|
||||
sandbox="allow-same-origin"
|
||||
></iframe>
|
||||
</div>
|
||||
|
||||
<!-- Markdown Preview -->
|
||||
<div v-else-if="normalizedFileType === 'md'" class="bg-white rounded-2xl shadow-xl p-8 border border-orange-200/30 prose max-w-none prose-orange">
|
||||
<div v-html="renderedMarkdown"></div>
|
||||
</div>
|
||||
|
||||
<!-- PPTX Preview (PDF iframe) -->
|
||||
<div v-else-if="normalizedFileType === 'pptx'" class="bg-white rounded-2xl shadow-xl overflow-hidden h-full flex flex-col border border-orange-200/30">
|
||||
<iframe
|
||||
v-if="pdfUrl"
|
||||
:src="pdfUrl"
|
||||
class="w-full flex-1 min-h-[500px]"
|
||||
type="application/pdf"
|
||||
></iframe>
|
||||
<div v-else class="flex items-center justify-center h-full">
|
||||
<div class="text-center">
|
||||
<div class="w-16 h-16 mx-auto bg-gradient-to-br from-orange-400 to-orange-600 rounded-2xl flex items-center justify-center mb-4 shadow-lg">
|
||||
<svg class="w-8 h-8 text-white animate-spin" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
||||
</svg>
|
||||
</div>
|
||||
<p class="text-slate-500 font-medium">正在加载预览...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Empty state -->
|
||||
<div v-else class="flex items-center justify-center h-full">
|
||||
<div class="text-center">
|
||||
<div class="w-24 h-24 glass rounded-2xl flex items-center justify-center mx-auto mb-6">
|
||||
<svg class="w-12 h-12 text-slate-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
<p class="text-slate-500 text-lg">选择一份报告以预览</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, watch, onUnmounted } from 'vue'
|
||||
import { marked } from 'marked'
|
||||
import { useApi } from '../composables/useApi'
|
||||
|
||||
const props = defineProps({
|
||||
report: {
|
||||
type: Object,
|
||||
default: null
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
})
|
||||
|
||||
const iframeRef = ref(null)
|
||||
const pdfUrl = ref(null)
|
||||
const { fetchReportBytes, fetchReportPdf } = useApi()
|
||||
|
||||
const fileTypeLabelMap = {
|
||||
html: 'HTML',
|
||||
md: 'Markdown',
|
||||
pptx: 'PowerPoint'
|
||||
}
|
||||
|
||||
const iconBgClassMap = {
|
||||
html: 'bg-orange-500',
|
||||
md: 'bg-orange-400',
|
||||
pptx: 'bg-orange-500'
|
||||
}
|
||||
|
||||
const fileTypeLabel = computed(() => {
|
||||
return fileTypeLabelMap[normalizedFileType.value] || props.report?.fileType?.toUpperCase() || ''
|
||||
})
|
||||
|
||||
const iconBgClass = computed(() => {
|
||||
return iconBgClassMap[normalizedFileType.value] || iconBgClassMap.html
|
||||
})
|
||||
|
||||
const normalizedFileType = computed(() => {
|
||||
return (props.report?.fileType || '').toLowerCase()
|
||||
})
|
||||
|
||||
const renderedMarkdown = computed(() => {
|
||||
if (!props.content) return ''
|
||||
return marked(props.content)
|
||||
})
|
||||
|
||||
// Watch for report changes and load PDF preview for PPTX
|
||||
watch(() => props.report, async (newReport) => {
|
||||
pdfUrl.value = null
|
||||
if (normalizedFileType.value === 'pptx') {
|
||||
try {
|
||||
const pdfBlob = await fetchReportPdf(newReport.id)
|
||||
if (pdfBlob) {
|
||||
pdfUrl.value = URL.createObjectURL(pdfBlob)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load PDF preview:', e)
|
||||
}
|
||||
}
|
||||
}, { immediate: true })
|
||||
|
||||
onUnmounted(() => {
|
||||
if (pdfUrl.value) {
|
||||
URL.revokeObjectURL(pdfUrl.value)
|
||||
}
|
||||
})
|
||||
|
||||
const downloadReport = async () => {
|
||||
if (!props.report) return
|
||||
|
||||
const ft = normalizedFileType.value
|
||||
if (ft === 'pptx' || ft === 'html' || ft === 'md') {
|
||||
try {
|
||||
const bytes = await fetchReportBytes(props.report.id)
|
||||
if (bytes) {
|
||||
const blob = new Blob([bytes], { type: 'application/octet-stream' })
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = props.report.fileName
|
||||
a.click()
|
||||
URL.revokeObjectURL(url)
|
||||
} else {
|
||||
alert('文件不存在或无法读取')
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Download failed:', e)
|
||||
alert('下载失败')
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<header class="bg-white shadow-sm border-b border-gray-200">
|
||||
<div class="flex items-center justify-between px-6 py-4">
|
||||
<div>
|
||||
<h2 class="text-xl font-semibold text-gray-800">
|
||||
{{ title }}
|
||||
</h2>
|
||||
<p v-if="subtitle" class="text-sm text-gray-500 mt-1">{{ subtitle }}</p>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<slot name="actions"></slot>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
subtitle: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,115 @@
|
||||
<template>
|
||||
<div
|
||||
@click="$emit('click')"
|
||||
class="group relative h-[420px] rounded-3xl overflow-hidden cursor-pointer select-none transition-all duration-300 hover:-translate-y-1 hover:shadow-2xl"
|
||||
>
|
||||
<!-- Background Image - Full cover -->
|
||||
<div
|
||||
v-if="imageUrl"
|
||||
class="absolute inset-0 bg-cover bg-center transition-transform duration-500 group-hover:scale-105"
|
||||
:style="{ backgroundImage: `url(${imageUrl})` }"
|
||||
></div>
|
||||
|
||||
<!-- Fallback gradient background when no image -->
|
||||
<div
|
||||
v-else
|
||||
class="absolute inset-0 bg-gradient-to-br from-orange-400 via-orange-500 to-orange-600"
|
||||
></div>
|
||||
|
||||
<!-- Overlay gradient - bottom heavy for text readability -->
|
||||
<div class="absolute inset-0 bg-gradient-to-t from-black/80 via-black/40 to-transparent"></div>
|
||||
|
||||
<!-- Shimmer effect on hover -->
|
||||
<div class="absolute inset-0 bg-gradient-to-r from-transparent via-white/10 to-transparent -translate-x-full group-hover:translate-x-full transition-transform duration-1000"></div>
|
||||
|
||||
<!-- Content -->
|
||||
<div class="absolute inset-0 flex flex-col justify-end p-8">
|
||||
<!-- Top right icon -->
|
||||
<div class="absolute top-6 right-6">
|
||||
<div class="w-12 h-12 bg-white/20 backdrop-blur-md rounded-xl flex items-center justify-center">
|
||||
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Title -->
|
||||
<h3 class="text-2xl font-bold text-white mb-2 group-hover:text-orange-200 transition-colors">
|
||||
{{ title }}
|
||||
</h3>
|
||||
|
||||
<!-- Description -->
|
||||
<p class="text-white/80 text-sm mb-4 line-clamp-2">
|
||||
{{ description || '暂无描述' }}
|
||||
</p>
|
||||
|
||||
<!-- Footer info -->
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="px-3 py-1.5 bg-white/20 backdrop-blur-sm text-white text-sm font-medium rounded-full">
|
||||
{{ reportCount }} 份报告
|
||||
</span>
|
||||
<span class="text-white/70 text-sm">
|
||||
{{ formatDate(createdAt) }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Arrow animation on hover -->
|
||||
<div class="w-10 h-10 bg-white/20 backdrop-blur-sm rounded-full flex items-center justify-center group-hover:bg-orange-500 transition-all duration-300">
|
||||
<svg class="w-5 h-5 text-white transform group-hover:translate-x-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Border glow effect on hover -->
|
||||
<div class="absolute inset-0 rounded-3xl border-2 border-transparent group-hover:border-orange-400/50 transition-colors duration-300 pointer-events-none"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
imageUrl: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
reportCount: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
createdAt: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
})
|
||||
|
||||
defineEmits(['click'])
|
||||
|
||||
const formatDate = (dateStr) => {
|
||||
if (!dateStr) return '未知时间'
|
||||
try {
|
||||
const date = new Date(dateStr)
|
||||
return date.toLocaleDateString('zh-CN', { year: 'numeric', month: 'short', day: 'numeric' })
|
||||
} catch {
|
||||
return dateStr
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.line-clamp-2 {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,135 @@
|
||||
<template>
|
||||
<div
|
||||
@click="$emit('select', report)"
|
||||
:class="[
|
||||
'group relative rounded-xl cursor-pointer transition-all duration-300 overflow-hidden',
|
||||
isSelected
|
||||
? 'bg-orange-600 shadow-xl shadow-orange-600/40 border-2 border-orange-500'
|
||||
: 'glass border border-orange-200/50 hover:border-orange-400 hover:shadow-lg hover:-translate-y-0.5'
|
||||
]"
|
||||
>
|
||||
<div :class="['p-4', isSelected ? 'text-white' : 'text-slate-700']">
|
||||
<!-- File icon and info -->
|
||||
<div class="flex items-start space-x-3">
|
||||
<div :class="[
|
||||
'flex-shrink-0 w-12 h-12 rounded-xl flex items-center justify-center shadow-lg transition-colors',
|
||||
isSelected ? 'bg-white/30' : iconClass
|
||||
]">
|
||||
<svg v-if="isSelected" class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
<component v-else :is="fileIconComponent" class="w-6 h-6 text-white" />
|
||||
</div>
|
||||
<div class="flex-1 min-w-0">
|
||||
<h3
|
||||
:class="[
|
||||
'text-base font-semibold truncate select-none',
|
||||
isSelected ? 'text-white' : 'text-slate-800 group-hover:text-orange-600'
|
||||
]"
|
||||
:title="report.fileName"
|
||||
>
|
||||
{{ report.fileName }}
|
||||
</h3>
|
||||
<div class="mt-2 flex items-center space-x-3">
|
||||
<span :class="[
|
||||
'px-3 py-1 rounded-full text-xs font-semibold',
|
||||
isSelected ? 'bg-white/20 text-white' : typeBadgeClass
|
||||
]">
|
||||
{{ fileTypeLabel }}
|
||||
</span>
|
||||
<span :class="[
|
||||
'text-sm',
|
||||
isSelected ? 'text-white/80' : 'text-slate-500'
|
||||
]">
|
||||
{{ report.size }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Date and arrow -->
|
||||
<div :class="[
|
||||
'mt-4 pt-3 flex items-center justify-between',
|
||||
isSelected ? 'border-t border-white/20' : 'border-t border-orange-100'
|
||||
]">
|
||||
<div :class="[
|
||||
'flex items-center text-sm',
|
||||
isSelected ? 'text-white/70' : 'text-slate-500'
|
||||
]">
|
||||
<svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
||||
</svg>
|
||||
{{ report.reportDate || '未知时间' }}
|
||||
</div>
|
||||
|
||||
<!-- Arrow indicator -->
|
||||
<div :class="[
|
||||
'w-8 h-8 rounded-full flex items-center justify-center transition-all',
|
||||
isSelected ? 'bg-white/20' : 'bg-orange-100 group-hover:bg-orange-500 group-hover:text-white'
|
||||
]">
|
||||
<svg :class="['w-4 h-4', isSelected ? 'text-white' : 'text-orange-500']" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, h } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
report: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
isSelected: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
|
||||
defineEmits(['select'])
|
||||
|
||||
const fileIconMap = {
|
||||
html: { color: 'bg-gradient-to-br from-orange-500 to-orange-600' },
|
||||
md: { color: 'bg-gradient-to-br from-orange-400 to-orange-500' },
|
||||
pptx: { color: 'bg-gradient-to-br from-orange-500 to-orange-600' }
|
||||
}
|
||||
|
||||
const fileTypeLabelMap = {
|
||||
html: 'HTML',
|
||||
md: 'Markdown',
|
||||
pptx: 'PowerPoint'
|
||||
}
|
||||
|
||||
// File icon SVG component
|
||||
const FileIcon = {
|
||||
render() {
|
||||
return h('svg', { fill: 'none', stroke: 'currentColor', viewBox: '0 0 24 24' }, [
|
||||
h('path', { 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'stroke-width': '2', d: 'M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z' })
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
const fileIconComponent = computed(() => FileIcon)
|
||||
|
||||
const iconClass = computed(() => {
|
||||
const config = fileIconMap[props.report.fileType] || fileIconMap.html
|
||||
return config.color
|
||||
})
|
||||
|
||||
const fileTypeLabel = computed(() => {
|
||||
return fileTypeLabelMap[props.report.fileType] || props.report.fileType.toUpperCase()
|
||||
})
|
||||
|
||||
const typeBadgeClass = computed(() => {
|
||||
const colors = {
|
||||
html: 'bg-orange-100 text-orange-600',
|
||||
md: 'bg-orange-100 text-orange-600',
|
||||
pptx: 'bg-orange-100 text-orange-600'
|
||||
}
|
||||
return colors[props.report.fileType] || 'bg-orange-100 text-orange-600'
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- Mobile menu button -->
|
||||
<button
|
||||
@click="toggleSidebar"
|
||||
class="lg:hidden fixed top-4 left-4 z-50 p-2 bg-orange-500 rounded-lg shadow-md"
|
||||
>
|
||||
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- Overlay -->
|
||||
<div
|
||||
v-if="isOpen"
|
||||
@click="toggleSidebar"
|
||||
class="lg:hidden fixed inset-0 bg-black/30 z-40"
|
||||
></div>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<aside
|
||||
:class="[
|
||||
'fixed lg:static inset-y-0 left-0 z-40 w-64 bg-white border-r border-orange-200 transform transition-transform duration-300 ease-in-out',
|
||||
isOpen ? 'translate-x-0' : '-translate-x-full lg:translate-x-0'
|
||||
]"
|
||||
>
|
||||
<div class="flex flex-col h-full">
|
||||
<!-- Logo -->
|
||||
<div class="p-6 border-b border-orange-200">
|
||||
<div class="flex items-center space-x-3">
|
||||
<div class="w-10 h-10 bg-gradient-to-br from-orange-400 to-orange-600 rounded-xl flex items-center justify-center shadow-lg">
|
||||
<svg class="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-lg font-bold text-orange-600">日报分发</h1>
|
||||
<p class="text-xs text-orange-400">管理系统</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Project List -->
|
||||
<div class="flex-1 overflow-y-auto p-4">
|
||||
<h2 class="text-xs font-semibold text-orange-500 uppercase tracking-wider mb-3">项目目录</h2>
|
||||
<ul class="space-y-1">
|
||||
<li v-for="project in projects" :key="project.id">
|
||||
<router-link
|
||||
:to="`/project/${project.id}`"
|
||||
@click="closeSidebarOnMobile"
|
||||
class="flex items-center justify-between px-3 py-2.5 rounded-lg transition-all duration-200 select-none cursor-pointer hover:bg-orange-50"
|
||||
:class="isActiveProject(project.id) ? 'bg-orange-100 text-orange-700 font-medium' : 'text-orange-800'"
|
||||
>
|
||||
<span class="truncate font-medium">{{ project.name }}</span>
|
||||
<span class="text-xs px-2 py-0.5 bg-orange-200 text-orange-700 rounded-full">{{ project.reportCount }}</span>
|
||||
</router-link>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="p-4 border-t border-orange-200 text-center">
|
||||
<p class="text-xs text-orange-400">v1.0.0</p>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
const props = defineProps({
|
||||
projects: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
}
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
const isOpen = ref(false)
|
||||
|
||||
const isActiveProject = (projectId) => {
|
||||
return route.params.id == projectId
|
||||
}
|
||||
|
||||
const toggleSidebar = () => {
|
||||
isOpen.value = !isOpen.value
|
||||
}
|
||||
|
||||
const closeSidebarOnMobile = () => {
|
||||
if (window.innerWidth < 1024) {
|
||||
isOpen.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.select-none {
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,144 @@
|
||||
import axios from 'axios'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
// Mock data for development
|
||||
const mockProjects = [
|
||||
{ id: 1, name: '项目一', description: '主要产品线', reportCount: 15, todayNewReports: 2 },
|
||||
{ id: 2, name: '项目二', description: '内部工具', reportCount: 8, todayNewReports: 1 },
|
||||
{ id: 3, name: '项目三', description: '客户定制', reportCount: 12, todayNewReports: 0 }
|
||||
]
|
||||
|
||||
const mockReports = {
|
||||
1: [
|
||||
{ id: 101, fileName: '2026-05-22 日报.html', fileType: 'html', reportDate: '2026-05-22', size: '15KB' },
|
||||
{ id: 102, fileName: '2026-05-21 日报.md', fileType: 'md', reportDate: '2026-05-21', size: '8KB' },
|
||||
{ id: 103, fileName: '2026-05-20 周报.pptx', fileType: 'pptx', reportDate: '2026-05-20', size: '256KB' }
|
||||
],
|
||||
2: [
|
||||
{ id: 201, fileName: '2026-05-22 开发日报.html', fileType: 'html', reportDate: '2026-05-22', size: '12KB' },
|
||||
{ id: 202, fileName: '2026-05-21 开发日报.html', fileType: 'html', reportDate: '2026-05-21', size: '11KB' }
|
||||
],
|
||||
3: [
|
||||
{ id: 301, fileName: '2026-05-22 进度报告.md', fileType: 'md', reportDate: '2026-05-22', size: '10KB' },
|
||||
{ id: 302, fileName: '2026-05-21 进度报告.md', fileType: 'md', reportDate: '2026-05-21', size: '9KB' }
|
||||
]
|
||||
}
|
||||
|
||||
const mockReportContent = {
|
||||
html: '<html><body><h1>日报内容</h1><p>这是一份HTML格式的日报。</p></body></html>',
|
||||
md: '# 日报标题\n\n## 工作内容\n\n1. 完成功能A\n2. 进行代码审查\n3. 修复Bug\n\n## 明日计划\n\n- 继续开发功能B\n- 优化性能',
|
||||
pptx: null
|
||||
}
|
||||
|
||||
export function useApi() {
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
const fetchProjects = async () => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await api.get('/projects')
|
||||
return response.data
|
||||
} catch (e) {
|
||||
// Use mock data if API fails
|
||||
console.warn('API not available, using mock data')
|
||||
return mockProjects
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchReports = async (projectId) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await api.get(`/reports?projectId=${projectId}`)
|
||||
return response.data
|
||||
} catch (e) {
|
||||
console.warn('API not available, using mock data')
|
||||
return mockReports[projectId] || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchReportContent = async (reportId) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
// Backend GET /api/reports/{id} returns ReportResponse with fileContent field
|
||||
const response = await api.get(`/reports/${reportId}`)
|
||||
return { content: response.data.fileContent, type: response.data.fileType }
|
||||
} catch (e) {
|
||||
console.warn('API not available, using mock data')
|
||||
// Find the report type from mock data
|
||||
for (const reports of Object.values(mockReports)) {
|
||||
const report = reports.find(r => r.id === reportId)
|
||||
if (report) {
|
||||
return { content: mockReportContent[report.fileType], type: report.fileType }
|
||||
}
|
||||
}
|
||||
return null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchReportBytes = async (reportId) => {
|
||||
try {
|
||||
const response = await api.get(`/reports/${reportId}/download`, { responseType: 'arraybuffer' })
|
||||
return response.data
|
||||
} catch (e) {
|
||||
console.warn('Failed to fetch report bytes:', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const fetchReportPdf = async (reportId) => {
|
||||
try {
|
||||
const response = await api.get(`/reports/${reportId}/pdf`, { responseType: 'arraybuffer' })
|
||||
return new Blob([response.data], { type: 'application/pdf' })
|
||||
} catch (e) {
|
||||
console.warn('Failed to fetch report PDF:', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const updateProject = async (id, data) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
let response
|
||||
if (data instanceof FormData) {
|
||||
response = await api.put(`/projects/${id}`, data, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
} else {
|
||||
response = await api.put(`/projects/${id}`, data)
|
||||
}
|
||||
return response.data
|
||||
} catch (e) {
|
||||
console.warn('API not available, failed to update project:', e)
|
||||
return null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
error,
|
||||
fetchProjects,
|
||||
fetchReports,
|
||||
fetchReportContent,
|
||||
fetchReportBytes,
|
||||
fetchReportPdf,
|
||||
updateProject
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import router from './router'
|
||||
import './styles/main.css'
|
||||
|
||||
const app = createApp(App)
|
||||
app.use(router)
|
||||
app.mount('#app')
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.reportdist;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DailyReportDistributionApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DailyReportDistributionApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.reportdist.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/api/**")
|
||||
.allowedOrigins("*")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("*");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/uploads/**")
|
||||
.addResourceLocations("file:./uploads/");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.reportdist.controller;
|
||||
|
||||
import com.reportdist.dto.ProjectRequest;
|
||||
import com.reportdist.dto.ProjectResponse;
|
||||
import com.reportdist.service.ProjectService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/projects")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<ProjectResponse>> getAllProjects() {
|
||||
return ResponseEntity.ok(projectService.getAllProjects());
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<ProjectResponse> getProjectById(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(projectService.getProjectById(id));
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<ProjectResponse> createProject(@Valid @RequestBody ProjectRequest request) {
|
||||
ProjectResponse response = projectService.createProject(request);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||
}
|
||||
|
||||
@PutMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ResponseEntity<ProjectResponse> updateProject(
|
||||
@PathVariable Long id,
|
||||
@RequestParam(value = "name", required = false) String name,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "coverImage", required = false) MultipartFile coverImage) {
|
||||
ProjectResponse response = projectService.updateProject(id, name, description, coverImage);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteProject(@PathVariable Long id) {
|
||||
projectService.deleteProject(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.reportdist.controller;
|
||||
|
||||
import com.reportdist.dto.ReportRequest;
|
||||
import com.reportdist.dto.ReportResponse;
|
||||
import com.reportdist.service.ReportService;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/reports")
|
||||
@CrossOrigin(origins = "*")
|
||||
public class ReportController {
|
||||
|
||||
private final ReportService reportService;
|
||||
|
||||
public ReportController(ReportService reportService) {
|
||||
this.reportService = reportService;
|
||||
}
|
||||
|
||||
@GetMapping("/ping")
|
||||
public ResponseEntity<?> ping() {
|
||||
return ResponseEntity.ok(java.util.Map.of("version", "v4-diag", "timestamp", java.time.Instant.now().toString()));
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<?> getAllReports(@RequestParam(required = false) Long projectId) {
|
||||
return ResponseEntity.ok(reportService.getAllReports(projectId));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<ReportResponse> getReportById(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(reportService.getReportById(id));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/preview")
|
||||
public ResponseEntity<byte[]> previewReport(@PathVariable Long id) {
|
||||
ReportResponse report = reportService.getReportById(id);
|
||||
String contentType = "application/octet-stream";
|
||||
switch (report.getFileType().toLowerCase()) {
|
||||
case "html": contentType = "text/html; charset=utf-8"; break;
|
||||
case "md": contentType = "text/markdown; charset=utf-8"; break;
|
||||
case "pdf": contentType = "application/pdf"; break;
|
||||
case "pptx": contentType = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; break;
|
||||
case "ppt": contentType = "application/vnd.ms-powerpoint"; break;
|
||||
}
|
||||
byte[] bytes = reportService.getReportBytes(id);
|
||||
return ResponseEntity.ok()
|
||||
.header("Content-Type", contentType)
|
||||
.header("Content-Disposition", "inline; filename=\"" + report.getFileName() + "\"")
|
||||
.body(bytes);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/download")
|
||||
public ResponseEntity<byte[]> downloadReport(@PathVariable Long id) {
|
||||
ReportResponse report = reportService.getReportById(id);
|
||||
byte[] bytes = reportService.getReportBytes(id);
|
||||
return ResponseEntity.ok()
|
||||
.header("Content-Type", "application/octet-stream")
|
||||
.header("Content-Disposition", "attachment; filename=\"" + report.getFileName() + "\"")
|
||||
.body(bytes);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}/pdf")
|
||||
public ResponseEntity<byte[]> getReportAsPdf(@PathVariable Long id) {
|
||||
byte[] pdfBytes = reportService.convertReportToPdf(id);
|
||||
return ResponseEntity.ok()
|
||||
.header("Content-Type", "application/pdf")
|
||||
.header("Content-Disposition", "inline; filename=preview.pdf")
|
||||
.body(pdfBytes);
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<ReportResponse> uploadReport(
|
||||
@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("projectId") Long projectId,
|
||||
@RequestParam("fileType") String fileType) {
|
||||
System.err.println("=== UPLOAD CALLED: file=" + file + " projectId=" + projectId + " fileType=" + fileType);
|
||||
try {
|
||||
String filename = file.getOriginalFilename();
|
||||
if (filename != null) {
|
||||
String extension = getFileExtension(filename).toLowerCase();
|
||||
if (!isValidExtension(extension)) {
|
||||
return ResponseEntity.badRequest().body(null);
|
||||
}
|
||||
}
|
||||
ReportResponse response = reportService.uploadReport(file, projectId, fileType);
|
||||
return ResponseEntity.status(HttpStatus.CREATED).body(response);
|
||||
} catch (Exception e) {
|
||||
System.err.println("=== UPLOAD EXCEPTION: " + e.getClass().getName() + ": " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return ResponseEntity.status(500).body(new ReportResponse(null, projectId, "ERROR", fileType, "ERROR", null, "ERROR:" + e.getClass().getSimpleName() + ":" + e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<ReportResponse> updateReport(
|
||||
@PathVariable Long id,
|
||||
@RequestBody ReportRequest request) {
|
||||
return ResponseEntity.ok(reportService.updateReport(id, request));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Void> deleteReport(@PathVariable Long id) {
|
||||
reportService.deleteReport(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
private String getFileExtension(String filename) {
|
||||
int lastDotIndex = filename.lastIndexOf('.');
|
||||
if (lastDotIndex > 0) {
|
||||
return filename.substring(lastDotIndex + 1);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private boolean isValidExtension(String extension) {
|
||||
return extension.equals("html") || extension.equals("md") ||
|
||||
extension.equals("ppt") || extension.equals("pptx") || extension.equals("pdf");
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<?> handleError(Exception e) {
|
||||
String msg = e.getClass().getSimpleName() + ": " + e.getMessage();
|
||||
System.err.println("CONTROLLER ERROR: " + msg);
|
||||
e.printStackTrace();
|
||||
return ResponseEntity.status(500).body(new java.util.LinkedHashMap<String,String>() {{
|
||||
put("error", msg);
|
||||
put("type", e.getClass().getName());
|
||||
}});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.reportdist.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public class ProjectRequest {
|
||||
|
||||
@NotBlank(message = "Project name is required")
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
private String coverImage;
|
||||
|
||||
public ProjectRequest() {}
|
||||
|
||||
public ProjectRequest(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public String getCoverImage() { return coverImage; }
|
||||
public void setCoverImage(String coverImage) { this.coverImage = coverImage; }
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.reportdist.dto;
|
||||
|
||||
import com.reportdist.entity.Project;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class ProjectResponse {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private LocalDateTime createdAt;
|
||||
private String coverImage;
|
||||
private long reportCount;
|
||||
private long todayNewReports;
|
||||
|
||||
public ProjectResponse() {}
|
||||
|
||||
public ProjectResponse(Long id, String name, String description, LocalDateTime createdAt) {
|
||||
this(id, name, description, createdAt, null, 0, 0);
|
||||
}
|
||||
|
||||
public ProjectResponse(Long id, String name, String description, LocalDateTime createdAt, String coverImage) {
|
||||
this(id, name, description, createdAt, coverImage, 0, 0);
|
||||
}
|
||||
|
||||
public ProjectResponse(Long id, String name, String description, LocalDateTime createdAt, String coverImage, long reportCount) {
|
||||
this(id, name, description, createdAt, coverImage, reportCount, 0);
|
||||
}
|
||||
|
||||
public ProjectResponse(Long id, String name, String description, LocalDateTime createdAt, String coverImage, long reportCount, long todayNewReports) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.createdAt = createdAt;
|
||||
this.coverImage = coverImage;
|
||||
this.reportCount = reportCount;
|
||||
this.todayNewReports = todayNewReports;
|
||||
}
|
||||
|
||||
public static ProjectResponse fromEntity(Project project) {
|
||||
return fromEntity(project, 0, 0);
|
||||
}
|
||||
|
||||
public static ProjectResponse fromEntity(Project project, long reportCount) {
|
||||
return fromEntity(project, reportCount, 0);
|
||||
}
|
||||
|
||||
public static ProjectResponse fromEntity(Project project, long reportCount, long todayNewReports) {
|
||||
return new ProjectResponse(
|
||||
project.getId(),
|
||||
project.getName(),
|
||||
project.getDescription(),
|
||||
project.getCreatedAt(),
|
||||
project.getCoverImage(),
|
||||
reportCount,
|
||||
todayNewReports
|
||||
);
|
||||
}
|
||||
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public LocalDateTime getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public String getCoverImage() { return coverImage; }
|
||||
public void setCoverImage(String coverImage) { this.coverImage = coverImage; }
|
||||
|
||||
public long getReportCount() { return reportCount; }
|
||||
public void setReportCount(long reportCount) { this.reportCount = reportCount; }
|
||||
|
||||
public long getTodayNewReports() { return todayNewReports; }
|
||||
public void setTodayNewReports(long todayNewReports) { this.todayNewReports = todayNewReports; }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.reportdist.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
|
||||
public class ReportRequest {
|
||||
|
||||
@NotBlank(message = "File name is required")
|
||||
private String fileName;
|
||||
|
||||
private Long projectId;
|
||||
|
||||
private String fileType;
|
||||
|
||||
public ReportRequest() {}
|
||||
|
||||
public ReportRequest(String fileName, Long projectId, String fileType) {
|
||||
this.fileName = fileName;
|
||||
this.projectId = projectId;
|
||||
this.fileType = fileType;
|
||||
}
|
||||
|
||||
public String getFileName() { return fileName; }
|
||||
public void setFileName(String fileName) { this.fileName = fileName; }
|
||||
|
||||
public Long getProjectId() { return projectId; }
|
||||
public void setProjectId(Long projectId) { this.projectId = projectId; }
|
||||
|
||||
public String getFileType() { return fileType; }
|
||||
public void setFileType(String fileType) { this.fileType = fileType; }
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.reportdist.dto;
|
||||
|
||||
import com.reportdist.entity.Report;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class ReportResponse {
|
||||
|
||||
private Long id;
|
||||
private Long projectId;
|
||||
private String fileName;
|
||||
private String fileType;
|
||||
private String filePath;
|
||||
private LocalDateTime uploadTime;
|
||||
private String fileContent;
|
||||
|
||||
public ReportResponse() {}
|
||||
|
||||
public ReportResponse(Long id, Long projectId, String fileName, String fileType, String filePath, LocalDateTime uploadTime, String fileContent) {
|
||||
this.id = id;
|
||||
this.projectId = projectId;
|
||||
this.fileName = fileName;
|
||||
this.fileType = fileType;
|
||||
this.filePath = filePath;
|
||||
this.uploadTime = uploadTime;
|
||||
this.fileContent = fileContent;
|
||||
}
|
||||
|
||||
public static ReportResponse fromEntity(Report report) {
|
||||
return new ReportResponse(
|
||||
report.getId(),
|
||||
report.getProjectId(),
|
||||
report.getFileName(),
|
||||
report.getFileType().name(),
|
||||
report.getFilePath(),
|
||||
report.getUploadTime(),
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
public static ReportResponse fromEntityWithContent(Report report, String fileContent) {
|
||||
return new ReportResponse(
|
||||
report.getId(),
|
||||
report.getProjectId(),
|
||||
report.getFileName(),
|
||||
report.getFileType().name(),
|
||||
report.getFilePath(),
|
||||
report.getUploadTime(),
|
||||
fileContent
|
||||
);
|
||||
}
|
||||
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
|
||||
public Long getProjectId() { return projectId; }
|
||||
public void setProjectId(Long projectId) { this.projectId = projectId; }
|
||||
|
||||
public String getFileName() { return fileName; }
|
||||
public void setFileName(String fileName) { this.fileName = fileName; }
|
||||
|
||||
public String getFileType() { return fileType; }
|
||||
public void setFileType(String fileType) { this.fileType = fileType; }
|
||||
|
||||
public String getFilePath() { return filePath; }
|
||||
public void setFilePath(String filePath) { this.filePath = filePath; }
|
||||
|
||||
public LocalDateTime getUploadTime() { return uploadTime; }
|
||||
public void setUploadTime(LocalDateTime uploadTime) { this.uploadTime = uploadTime; }
|
||||
|
||||
public String getFileContent() { return fileContent; }
|
||||
public void setFileContent(String fileContent) { this.fileContent = fileContent; }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.reportdist.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "projects")
|
||||
public class Project {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
|
||||
@Column(columnDefinition = "TEXT")
|
||||
private String description;
|
||||
|
||||
@Column(name = "created_at", nullable = false)
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
private String coverImage;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
createdAt = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public Project() {}
|
||||
|
||||
public Project(Long id, String name, String description, LocalDateTime createdAt) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
|
||||
public String getName() { return name; }
|
||||
public void setName(String name) { this.name = name; }
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public LocalDateTime getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public String getCoverImage() { return coverImage; }
|
||||
public void setCoverImage(String coverImage) { this.coverImage = coverImage; }
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.reportdist.entity;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity
|
||||
@Table(name = "reports")
|
||||
public class Report {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "project_id", nullable = false)
|
||||
private Long projectId;
|
||||
|
||||
@Column(name = "file_name", nullable = false)
|
||||
private String fileName;
|
||||
|
||||
@Column(name = "file_type", nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private FileType fileType;
|
||||
|
||||
@Column(name = "file_path", nullable = false)
|
||||
private String filePath;
|
||||
|
||||
@Column(name = "upload_time", nullable = false)
|
||||
private LocalDateTime uploadTime;
|
||||
|
||||
@Column(name = "pdf_path")
|
||||
private String pdfPath;
|
||||
|
||||
@Column(name = "pdf_ready", nullable = false)
|
||||
private boolean pdfReady = false;
|
||||
|
||||
@PrePersist
|
||||
protected void onCreate() {
|
||||
uploadTime = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public enum FileType {
|
||||
HTML, MD, PPT, PPTX, PDF
|
||||
}
|
||||
|
||||
public Report() {}
|
||||
|
||||
public Report(Long id, Long projectId, String fileName, FileType fileType, String filePath, LocalDateTime uploadTime) {
|
||||
this.id = id;
|
||||
this.projectId = projectId;
|
||||
this.fileName = fileName;
|
||||
this.fileType = fileType;
|
||||
this.filePath = filePath;
|
||||
this.uploadTime = uploadTime;
|
||||
}
|
||||
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
|
||||
public Long getProjectId() { return projectId; }
|
||||
public void setProjectId(Long projectId) { this.projectId = projectId; }
|
||||
|
||||
public String getFileName() { return fileName; }
|
||||
public void setFileName(String fileName) { this.fileName = fileName; }
|
||||
|
||||
public FileType getFileType() { return fileType; }
|
||||
public void setFileType(FileType fileType) { this.fileType = fileType; }
|
||||
|
||||
public String getFilePath() { return filePath; }
|
||||
public void setFilePath(String filePath) { this.filePath = filePath; }
|
||||
|
||||
public LocalDateTime getUploadTime() { return uploadTime; }
|
||||
public void setUploadTime(LocalDateTime uploadTime) { this.uploadTime = uploadTime; }
|
||||
|
||||
public String getPdfPath() { return pdfPath; }
|
||||
public void setPdfPath(String pdfPath) { this.pdfPath = pdfPath; }
|
||||
|
||||
public boolean isPdfReady() { return pdfReady; }
|
||||
public void setPdfReady(boolean pdfReady) { this.pdfReady = pdfReady; }
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.reportdist.exception;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
import org.springframework.web.multipart.MaxUploadSizeExceededException;
|
||||
import org.springframework.web.multipart.MultipartException;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(MultipartException.class)
|
||||
public ResponseEntity<?> handleMultipart(MultipartException ex) {
|
||||
System.err.println("=== MULTIPART ERROR ===");
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(500).body(java.util.Map.of(
|
||||
"error", "MULTIPART:" + ex.getClass().getSimpleName() + ":" + ex.getMessage(),
|
||||
"type", ex.getClass().getName()
|
||||
));
|
||||
}
|
||||
|
||||
@ExceptionHandler(MaxUploadSizeExceededException.class)
|
||||
public ResponseEntity<?> handleSize(MaxUploadSizeExceededException ex) {
|
||||
System.err.println("=== SIZE ERROR ===");
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(500).body(java.util.Map.of(
|
||||
"error", "SIZE_LIMIT:" + ex.getMessage(),
|
||||
"type", ex.getClass().getName()
|
||||
));
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public ResponseEntity<?> handleTypeMismatch(MethodArgumentTypeMismatchException ex) {
|
||||
System.err.println("=== TYPE MISMATCH ===");
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(400).body(java.util.Map.of(
|
||||
"error", "TYPE_MISMATCH:" + ex.getName() + " cannot parse " + ex.getValue(),
|
||||
"type", ex.getClass().getName()
|
||||
));
|
||||
}
|
||||
|
||||
@ExceptionHandler(RuntimeException.class)
|
||||
public ResponseEntity<?> handleRuntimeException(RuntimeException ex) {
|
||||
System.err.println("=== RUNTIME ERROR ===");
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(500).body(java.util.Map.of(
|
||||
"error", ex.getMessage() != null ? ex.getMessage() : "null",
|
||||
"type", ex.getClass().getName()
|
||||
));
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<?> handleGeneric(Exception ex) {
|
||||
System.err.println("=== GENERIC ERROR ===");
|
||||
ex.printStackTrace();
|
||||
return ResponseEntity.status(500).body(java.util.Map.of(
|
||||
"error", ex.getClass().getSimpleName() + ":" + ex.getMessage(),
|
||||
"type", ex.getClass().getName()
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.reportdist.repository;
|
||||
|
||||
import com.reportdist.entity.Project;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ProjectRepository extends JpaRepository<Project, Long> {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.reportdist.repository;
|
||||
|
||||
import com.reportdist.entity.Report;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ReportRepository extends JpaRepository<Report, Long> {
|
||||
|
||||
List<Report> findByProjectId(Long projectId);
|
||||
long countByProjectId(Long projectId);
|
||||
long countByUploadTimeAfter(LocalDateTime time);
|
||||
long countByProjectIdAndUploadTimeAfter(Long projectId, LocalDateTime time);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.reportdist.service;
|
||||
|
||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
||||
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
|
||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.apache.pdfbox.rendering.RenderDestination;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class PptxToPdfService {
|
||||
|
||||
public static byte[] convert(String pptxFilePath) throws IOException {
|
||||
Path path = Path.of(pptxFilePath);
|
||||
if (!Files.exists(path)) {
|
||||
throw new IOException("PPTX file not found: " + pptxFilePath);
|
||||
}
|
||||
|
||||
try (InputStream is = Files.newInputStream(path);
|
||||
XMLSlideShow pptx = new XMLSlideShow(is)) {
|
||||
|
||||
List<XSLFSlide> slides = pptx.getSlides();
|
||||
if (slides.isEmpty()) {
|
||||
throw new IOException("No slides found in PPTX file");
|
||||
}
|
||||
|
||||
Dimension slideSize = pptx.getPageSize();
|
||||
int scale = 2;
|
||||
int imgWidth = (int) slideSize.getWidth() * scale;
|
||||
int imgHeight = (int) slideSize.getHeight() * scale;
|
||||
|
||||
// First render all slides to PNG images
|
||||
byte[][] slideImages = new byte[slides.size()][];
|
||||
for (int i = 0; i < slides.size(); i++) {
|
||||
XSLFSlide slide = slides.get(i);
|
||||
|
||||
BufferedImage slideImage = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB);
|
||||
Graphics2D graphics = slideImage.createGraphics();
|
||||
|
||||
graphics.setColor(Color.WHITE);
|
||||
graphics.fillRect(0, 0, imgWidth, imgHeight);
|
||||
|
||||
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
||||
graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
|
||||
|
||||
graphics.scale(scale, scale);
|
||||
|
||||
try {
|
||||
slide.draw(graphics);
|
||||
} catch (Exception e) {
|
||||
drawTextBoxes(graphics, slide);
|
||||
}
|
||||
|
||||
graphics.dispose();
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ImageIO.write(slideImage, "PNG", baos);
|
||||
slideImages[i] = baos.toByteArray();
|
||||
}
|
||||
|
||||
// Create PDF with each slide as a page
|
||||
PDDocument document = new PDDocument();
|
||||
|
||||
for (int i = 0; i < slideImages.length; i++) {
|
||||
byte[] pngBytes = slideImages[i];
|
||||
|
||||
// Calculate page size to match slide aspect ratio
|
||||
float imgAspect = (float) imgWidth / imgHeight;
|
||||
float pageWidth = PDRectangle.A4.getWidth();
|
||||
float pageHeight = pageWidth / imgAspect;
|
||||
|
||||
if (pageHeight > PDRectangle.A4.getHeight()) {
|
||||
pageHeight = PDRectangle.A4.getHeight();
|
||||
pageWidth = pageHeight * imgAspect;
|
||||
}
|
||||
|
||||
PDPage page = new PDPage(new PDRectangle(pageWidth, pageHeight));
|
||||
document.addPage(page);
|
||||
|
||||
// Draw image on page
|
||||
try (PDPageContentStream cs = new PDPageContentStream(document, page)) {
|
||||
PDImageXObject pdImage = PDImageXObject.createFromByteArray(document, pngBytes, "slide_" + i);
|
||||
cs.drawImage(pdImage, 0, 0, pageWidth, pageHeight);
|
||||
}
|
||||
}
|
||||
|
||||
ByteArrayOutputStream pdfBaos = new ByteArrayOutputStream();
|
||||
document.save(pdfBaos);
|
||||
document.close();
|
||||
|
||||
return pdfBaos.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
private static void drawTextBoxes(Graphics2D g, XSLFSlide slide) {
|
||||
for (org.apache.poi.xslf.usermodel.XSLFShape shape : slide.getShapes()) {
|
||||
if (shape instanceof org.apache.poi.xslf.usermodel.XSLFTextShape) {
|
||||
org.apache.poi.xslf.usermodel.XSLFTextShape ts = (org.apache.poi.xslf.usermodel.XSLFTextShape) shape;
|
||||
java.awt.geom.Rectangle2D rect = ts.getAnchor();
|
||||
if (rect == null) continue;
|
||||
|
||||
g.setColor(Color.WHITE);
|
||||
g.fill(rect);
|
||||
|
||||
g.setColor(Color.LIGHT_GRAY);
|
||||
g.draw(rect);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (org.apache.poi.xslf.usermodel.XSLFTextParagraph para : ts.getTextParagraphs()) {
|
||||
for (org.apache.poi.xslf.usermodel.XSLFTextRun run : para.getTextRuns()) {
|
||||
String text = run.getRawText();
|
||||
if (text != null) sb.append(text);
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
|
||||
String text = sb.toString().trim();
|
||||
if (!text.isEmpty()) {
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 10));
|
||||
int x = (int) rect.getX() + 5;
|
||||
int y = (int) rect.getY() + 15;
|
||||
for (String line : text.split("\n")) {
|
||||
g.drawString(line, x, y);
|
||||
y += 12;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package com.reportdist.service;
|
||||
|
||||
import com.reportdist.dto.ProjectRequest;
|
||||
import com.reportdist.dto.ProjectResponse;
|
||||
import com.reportdist.entity.Project;
|
||||
import com.reportdist.repository.ProjectRepository;
|
||||
import com.reportdist.repository.ReportRepository;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
private final ReportRepository reportRepository;
|
||||
private String uploadDir;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository, ReportRepository reportRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
this.reportRepository = reportRepository;
|
||||
}
|
||||
|
||||
@Value("${file.upload.dir}")
|
||||
public void setUploadDir(String uploadDir) {
|
||||
this.uploadDir = uploadDir;
|
||||
}
|
||||
|
||||
public List<ProjectResponse> getAllProjects() {
|
||||
LocalDateTime startOfDay = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||
return projectRepository.findAll().stream()
|
||||
.map(project -> {
|
||||
long count = reportRepository.countByProjectId(project.getId());
|
||||
long todayNew = reportRepository.countByProjectIdAndUploadTimeAfter(project.getId(), startOfDay);
|
||||
return ProjectResponse.fromEntity(project, count, todayNew);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ProjectResponse getProjectById(Long id) {
|
||||
Project project = projectRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Project not found with id: " + id));
|
||||
LocalDateTime startOfDay = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||
long count = reportRepository.countByProjectId(id);
|
||||
long todayNew = reportRepository.countByProjectIdAndUploadTimeAfter(id, startOfDay);
|
||||
return ProjectResponse.fromEntity(project, count, todayNew);
|
||||
}
|
||||
|
||||
public ProjectResponse createProject(ProjectRequest request) {
|
||||
Project project = new Project();
|
||||
project.setName(request.getName());
|
||||
project.setDescription(request.getDescription());
|
||||
if (request.getCoverImage() != null) {
|
||||
project.setCoverImage(request.getCoverImage());
|
||||
}
|
||||
Project saved = projectRepository.save(project);
|
||||
return ProjectResponse.fromEntity(saved, 0);
|
||||
}
|
||||
|
||||
public ProjectResponse updateProject(Long id, String name, String description, MultipartFile coverImage) {
|
||||
Project project = projectRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Project not found with id: " + id));
|
||||
|
||||
if (name != null) {
|
||||
project.setName(name);
|
||||
}
|
||||
if (description != null) {
|
||||
project.setDescription(description);
|
||||
}
|
||||
if (coverImage != null && !coverImage.isEmpty()) {
|
||||
try {
|
||||
// Save cover image to uploads/covers/{projectId}/
|
||||
Path coverDir = Paths.get(uploadDir, "covers", String.valueOf(id));
|
||||
Files.createDirectories(coverDir);
|
||||
|
||||
String originalFilename = coverImage.getOriginalFilename();
|
||||
String extension = "";
|
||||
if (originalFilename != null && originalFilename.contains(".")) {
|
||||
extension = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
}
|
||||
String uniqueFileName = UUID.randomUUID().toString() + extension;
|
||||
Path coverPath = coverDir.resolve(uniqueFileName);
|
||||
|
||||
Files.write(coverPath, coverImage.getBytes());
|
||||
|
||||
// Store relative path for serving
|
||||
String coverUrl = "/uploads/covers/" + id + "/" + uniqueFileName;
|
||||
project.setCoverImage(coverUrl);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to save cover image: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
Project updated = projectRepository.save(project);
|
||||
long count = reportRepository.countByProjectId(id);
|
||||
long todayNew = reportRepository.countByProjectIdAndUploadTimeAfter(id, LocalDateTime.now().toLocalDate().atStartOfDay());
|
||||
return ProjectResponse.fromEntity(updated, count, todayNew);
|
||||
}
|
||||
|
||||
// Keep old method for backward compatibility
|
||||
public ProjectResponse updateProject(Long id, ProjectRequest request) {
|
||||
return updateProject(id, request.getName(), request.getDescription(), null);
|
||||
}
|
||||
|
||||
public void deleteProject(Long id) {
|
||||
if (!projectRepository.existsById(id)) {
|
||||
throw new RuntimeException("Project not found with id: " + id);
|
||||
}
|
||||
projectRepository.deleteById(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.reportdist.service;
|
||||
|
||||
import com.reportdist.dto.ReportRequest;
|
||||
import com.reportdist.dto.ReportResponse;
|
||||
import com.reportdist.entity.Report;
|
||||
import com.reportdist.repository.ReportRepository;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Transactional
|
||||
public class ReportService {
|
||||
|
||||
private final ReportRepository reportRepository;
|
||||
private String uploadDir;
|
||||
|
||||
public ReportService(ReportRepository reportRepository) {
|
||||
this.reportRepository = reportRepository;
|
||||
}
|
||||
|
||||
@Value("${file.upload.dir}")
|
||||
public void setUploadDir(String uploadDir) {
|
||||
this.uploadDir = uploadDir;
|
||||
}
|
||||
|
||||
public List<ReportResponse> getAllReports(Long projectId) {
|
||||
List<Report> reports;
|
||||
if (projectId != null) {
|
||||
reports = reportRepository.findByProjectId(projectId);
|
||||
} else {
|
||||
reports = reportRepository.findAll();
|
||||
}
|
||||
return reports.stream()
|
||||
.map(ReportResponse::fromEntity)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ReportResponse getReportById(Long id) {
|
||||
Report report = reportRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Report not found with id: " + id));
|
||||
|
||||
String fileContent = readFileContent(report.getFilePath());
|
||||
return ReportResponse.fromEntityWithContent(report, fileContent);
|
||||
}
|
||||
|
||||
public ReportResponse uploadReport(MultipartFile file, Long projectId, String fileType) {
|
||||
try {
|
||||
// Create project subdirectory if needed
|
||||
Path projectDir = Paths.get(uploadDir, String.valueOf(projectId));
|
||||
Files.createDirectories(projectDir);
|
||||
|
||||
// Generate unique filename
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String uniqueFileName = System.currentTimeMillis() + "_" + originalFilename;
|
||||
Path filePath = projectDir.resolve(uniqueFileName);
|
||||
|
||||
// Save file
|
||||
file.transferTo(filePath.toFile());
|
||||
|
||||
// Create report entity
|
||||
Report report = new Report();
|
||||
report.setProjectId(projectId);
|
||||
report.setFileName(originalFilename);
|
||||
report.setFileType(Report.FileType.valueOf(fileType.toUpperCase()));
|
||||
report.setFilePath(filePath.toString());
|
||||
report.setPdfReady(false);
|
||||
|
||||
// Pre-render PDF for PPTX files
|
||||
if (fileType.equalsIgnoreCase("pptx") || fileType.equalsIgnoreCase("ppt")) {
|
||||
try {
|
||||
byte[] pdfBytes = PptxToPdfService.convert(filePath.toString());
|
||||
Path pdfDir = projectDir.resolve("pdfs");
|
||||
Files.createDirectories(pdfDir);
|
||||
String pdfFileName = uniqueFileName.replaceAll("\\.(pptx?|PPT|X)$", ".pdf");
|
||||
Path pdfPath = pdfDir.resolve(pdfFileName);
|
||||
Files.write(pdfPath, pdfBytes);
|
||||
report.setPdfPath(pdfPath.toString());
|
||||
report.setPdfReady(true);
|
||||
System.out.println("PDF pre-rendered successfully: " + pdfPath);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed to pre-render PDF: " + e.getMessage());
|
||||
// Continue without PDF - not critical
|
||||
}
|
||||
}
|
||||
|
||||
Report saved = reportRepository.save(report);
|
||||
return ReportResponse.fromEntity(saved);
|
||||
} catch (IOException e) {
|
||||
System.err.println("=== UPLOAD ERROR ===");
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("UPLOAD_FAILED:" + e.getClass().getName() + ":" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public ReportResponse updateReport(Long id, ReportRequest request) {
|
||||
Report report = reportRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Report not found with id: " + id));
|
||||
|
||||
if (request.getFileName() != null) {
|
||||
report.setFileName(request.getFileName());
|
||||
}
|
||||
if (request.getProjectId() != null) {
|
||||
report.setProjectId(request.getProjectId());
|
||||
}
|
||||
if (request.getFileType() != null) {
|
||||
report.setFileType(Report.FileType.valueOf(request.getFileType().toUpperCase()));
|
||||
}
|
||||
|
||||
Report updated = reportRepository.save(report);
|
||||
return ReportResponse.fromEntity(updated);
|
||||
}
|
||||
|
||||
public void deleteReport(Long id) {
|
||||
Report report = reportRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Report not found with id: " + id));
|
||||
|
||||
// Delete the file
|
||||
try {
|
||||
Path filePath = Paths.get(report.getFilePath());
|
||||
Files.deleteIfExists(filePath);
|
||||
} catch (IOException e) {
|
||||
// Log but don't fail the delete operation
|
||||
System.err.println("Failed to delete file: " + e.getMessage());
|
||||
}
|
||||
|
||||
reportRepository.deleteById(id);
|
||||
}
|
||||
|
||||
private String readFileContent(String filePath) {
|
||||
try {
|
||||
Path path = Paths.get(filePath);
|
||||
if (Files.exists(path)) {
|
||||
return Files.readString(path);
|
||||
}
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] getReportBytes(Long id) {
|
||||
Report report = reportRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Report not found with id: " + id));
|
||||
try {
|
||||
return Files.readAllBytes(Paths.get(report.getFilePath()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to read file: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] convertReportToPdf(Long id) {
|
||||
Report report = reportRepository.findById(id)
|
||||
.orElseThrow(() -> new RuntimeException("Report not found with id: " + id));
|
||||
|
||||
String fileType = report.getFileType().name().toLowerCase();
|
||||
if (!fileType.equals("pptx") && !fileType.equals("ppt")) {
|
||||
throw new RuntimeException("Only PPTX files can be converted to PDF. Current file type: " + fileType);
|
||||
}
|
||||
|
||||
// Return pre-rendered PDF if available
|
||||
if (report.isPdfReady() && report.getPdfPath() != null) {
|
||||
try {
|
||||
Path pdfPath = Paths.get(report.getPdfPath());
|
||||
if (Files.exists(pdfPath)) {
|
||||
return Files.readAllBytes(pdfPath);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("Failed to read pre-rendered PDF: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: render on demand
|
||||
try {
|
||||
return PptxToPdfService.convert(report.getFilePath());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to convert PPTX to PDF: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: daily-report-distribution
|
||||
|
||||
datasource:
|
||||
url: jdbc:sqlite:./database.db
|
||||
driver-class-name: org.sqlite.JDBC
|
||||
|
||||
jpa:
|
||||
database-platform: org.hibernate.community.dialect.SQLiteDialect
|
||||
hibernate:
|
||||
ddl-auto: update
|
||||
show-sql: false
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
|
||||
servlet:
|
||||
multipart:
|
||||
enabled: true
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
# Serve uploaded files statically
|
||||
web:
|
||||
resources:
|
||||
static-locations: file:./uploads/
|
||||
|
||||
file:
|
||||
upload:
|
||||
dir: ${UPLOAD_DIR:${user.dir}/uploads}
|
||||
|
||||
# Spring Boot Actuator (Docker healthcheck)
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,health-liveness,health-readiness
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
probes:
|
||||
enabled: true
|
||||
@@ -0,0 +1,178 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-gradient-to-br from-orange-100 via-orange-200 to-amber-100">
|
||||
<!-- Main Content -->
|
||||
<main class="relative z-10 flex h-screen overflow-hidden">
|
||||
<!-- Left: Glass Sidebar with Reports List -->
|
||||
<div class="w-[400px] glass-light border-r border-orange-200/50 flex flex-col shadow-2xl">
|
||||
<!-- Header -->
|
||||
<div class="bg-white/80 backdrop-blur-xl border-b border-orange-200/50 p-6">
|
||||
<router-link
|
||||
to="/"
|
||||
class="inline-flex items-center space-x-2 text-orange-500 hover:text-orange-600 transition-colors mb-4 group"
|
||||
>
|
||||
<svg class="w-5 h-5 group-hover:-translate-x-1 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
|
||||
</svg>
|
||||
<span>返回项目列表</span>
|
||||
</router-link>
|
||||
|
||||
<!-- Project Name (click to edit) -->
|
||||
<div v-if="!editing" @click="startEdit" class="cursor-pointer hover:bg-orange-50 -mx-2 px-2 py-2 rounded-xl transition-colors group">
|
||||
<h2 class="text-2xl font-bold text-slate-800 group-hover:text-orange-600 transition-colors">{{ projectName }}</h2>
|
||||
<p class="text-sm text-slate-500 mt-1">点击编辑项目</p>
|
||||
</div>
|
||||
|
||||
<!-- Edit Form -->
|
||||
<div v-else class="flex flex-col space-y-4 p-4 bg-white/50 rounded-xl">
|
||||
<input
|
||||
v-model="editName"
|
||||
class="w-full px-4 py-3 bg-white rounded-xl border border-orange-200 focus:ring-2 focus:ring-orange-500 focus:border-orange-500 shadow-sm"
|
||||
placeholder="项目名称"
|
||||
/>
|
||||
<div class="flex flex-col space-y-2">
|
||||
<label class="text-sm text-slate-600 font-medium">封面图片</label>
|
||||
<input
|
||||
type="file"
|
||||
accept="image/*"
|
||||
@change="handleCoverImageSelect"
|
||||
class="w-full text-sm text-slate-500 file:mr-4 file:py-2 file:px-4 file:rounded-lg file:border-0 file:text-sm file:font-semibold file:bg-orange-50 file:text-orange-600 hover:file:bg-orange-100"
|
||||
/>
|
||||
<div v-if="coverImagePreview" class="mt-2">
|
||||
<img :src="coverImagePreview" class="w-full h-32 object-cover rounded-xl shadow-md" alt="Preview" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex space-x-3">
|
||||
<button @click="saveEdit" style="color: #1e293b; font-weight: 600;" class="flex-1 px-4 py-2.5 bg-gradient-to-r from-orange-500 to-orange-600 rounded-xl hover:from-orange-600 hover:to-orange-700 transition-all shadow-lg shadow-orange-500/30">
|
||||
保存
|
||||
</button>
|
||||
<button @click="cancelEdit" class="px-4 py-2.5 bg-slate-100 text-slate-600 rounded-xl hover:bg-slate-200 transition-colors">
|
||||
取消
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Reports List -->
|
||||
<div class="flex-1 overflow-y-auto p-4 space-y-3">
|
||||
<div v-if="loading" class="flex items-center justify-center py-12">
|
||||
<div class="w-12 h-12 border-4 border-orange-200 border-t-orange-500 rounded-full animate-spin"></div>
|
||||
</div>
|
||||
<div v-else-if="reports.length === 0" class="text-center py-12">
|
||||
<div class="w-16 h-16 glass rounded-full flex items-center justify-center mx-auto mb-4">
|
||||
<svg class="w-8 h-8 text-orange-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
<p class="text-slate-500">暂无报告</p>
|
||||
</div>
|
||||
<template v-else>
|
||||
<ReportCard
|
||||
v-for="report in reports"
|
||||
:key="report.id"
|
||||
:report="report"
|
||||
:is-selected="selectedReport?.id === report.id"
|
||||
@select="selectReport"
|
||||
/>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Right: File Preview -->
|
||||
<div class="flex-1 flex flex-col bg-white/50">
|
||||
<FilePreview :report="selectedReport" :content="reportContent" />
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import ReportCard from '../components/ReportCard.vue'
|
||||
import FilePreview from '../components/FilePreview.vue'
|
||||
import { useApi } from '../composables/useApi'
|
||||
|
||||
const route = useRoute()
|
||||
const { loading, fetchProjects, fetchReports, fetchReportContent, updateProject } = useApi()
|
||||
|
||||
const projects = ref([])
|
||||
const reports = ref([])
|
||||
const selectedReport = ref(null)
|
||||
const reportContent = ref('')
|
||||
const editing = ref(false)
|
||||
const editName = ref('')
|
||||
const coverImageFile = ref(null)
|
||||
const coverImagePreview = ref('')
|
||||
|
||||
const projectName = computed(() => {
|
||||
const id = route.params.id
|
||||
const project = projects.value.find(p => p.id == id)
|
||||
return project?.name || `项目 ${id}`
|
||||
})
|
||||
|
||||
const loadData = async () => {
|
||||
const projectId = route.params.id
|
||||
projects.value = await fetchProjects()
|
||||
const project = projects.value.find(p => p.id == projectId)
|
||||
if (project) {
|
||||
editName.value = project.name
|
||||
coverImagePreview.value = project.coverImage || ''
|
||||
}
|
||||
reports.value = await fetchReports(projectId)
|
||||
}
|
||||
|
||||
const selectReport = async (report) => {
|
||||
selectedReport.value = report
|
||||
const data = await fetchReportContent(report.id)
|
||||
if (data) {
|
||||
reportContent.value = data.content
|
||||
}
|
||||
}
|
||||
|
||||
const startEdit = () => {
|
||||
const id = route.params.id
|
||||
const project = projects.value.find(p => p.id == id)
|
||||
if (project) {
|
||||
editName.value = project.name
|
||||
coverImagePreview.value = project.coverImage || ''
|
||||
}
|
||||
coverImageFile.value = null
|
||||
editing.value = true
|
||||
}
|
||||
|
||||
const handleCoverImageSelect = (event) => {
|
||||
const file = event.target.files[0]
|
||||
if (file) {
|
||||
coverImageFile.value = file
|
||||
coverImagePreview.value = URL.createObjectURL(file)
|
||||
}
|
||||
}
|
||||
|
||||
const cancelEdit = () => {
|
||||
editing.value = false
|
||||
coverImageFile.value = null
|
||||
}
|
||||
|
||||
const saveEdit = async () => {
|
||||
const projectId = route.params.id
|
||||
try {
|
||||
// Build form data
|
||||
const formData = new FormData()
|
||||
formData.append('name', editName.value)
|
||||
if (coverImageFile.value) {
|
||||
formData.append('coverImage', coverImageFile.value)
|
||||
}
|
||||
|
||||
await updateProject(projectId, formData)
|
||||
await loadData()
|
||||
editing.value = false
|
||||
} catch (e) {
|
||||
console.error('Failed to update project:', e)
|
||||
alert('更新失败')
|
||||
}
|
||||
}
|
||||
|
||||
watch(() => route.params.id, loadData)
|
||||
|
||||
onMounted(loadData)
|
||||
</script>
|
||||
@@ -0,0 +1,215 @@
|
||||
<template>
|
||||
<div class="min-h-screen bg-gradient-to-br from-orange-100 via-orange-200 to-amber-100">
|
||||
<!-- Main Content -->
|
||||
<main class="relative z-10 flex-1 overflow-y-auto p-8">
|
||||
<!-- Hero Section -->
|
||||
<div class="max-w-6xl mx-auto mb-12">
|
||||
<div class="flex items-center space-x-3 mb-4">
|
||||
<div class="w-12 h-12 bg-gradient-to-br from-orange-400 to-orange-600 rounded-xl flex items-center justify-center shadow-lg shadow-orange-500/30">
|
||||
<svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
<span class="px-3 py-1 bg-orange-500/20 text-orange-600 text-sm font-medium rounded-full border border-orange-300">日报分发平台</span>
|
||||
</div>
|
||||
<h1 class="text-4xl font-bold text-slate-800 mb-3 tracking-tight">
|
||||
选择项目
|
||||
</h1>
|
||||
<p class="text-lg text-slate-600">查看和管理您的日报、周报文件</p>
|
||||
</div>
|
||||
|
||||
<!-- Loading State -->
|
||||
<div v-if="loading" class="flex items-center justify-center h-64">
|
||||
<div class="relative w-16 h-16">
|
||||
<div class="absolute inset-0 border-4 border-orange-200 rounded-full"></div>
|
||||
<div class="absolute inset-0 border-4 border-transparent border-t-orange-500 rounded-full animate-spin"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Error State -->
|
||||
<div v-else-if="error" class="max-w-md mx-auto text-center p-8 glass rounded-2xl border border-orange-200">
|
||||
<svg class="w-12 h-12 text-orange-400 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||
</svg>
|
||||
<p class="text-orange-600">{{ error }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Projects Content -->
|
||||
<div v-else class="max-w-6xl mx-auto">
|
||||
<!-- Stats Cards - 3 columns -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-12">
|
||||
<!-- Projects Count -->
|
||||
<div class="glass rounded-2xl border border-orange-200/50 p-6 hover:-translate-y-1 transition-all duration-300 hover:shadow-xl">
|
||||
<div class="flex items-center space-x-4">
|
||||
<div class="w-14 h-14 bg-gradient-to-br from-orange-400 to-orange-600 rounded-xl flex items-center justify-center shadow-lg">
|
||||
<svg class="w-7 h-7 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-4xl font-bold text-slate-800">{{ projects.length }}</p>
|
||||
<p class="text-sm text-slate-500 mt-1">个项目</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Reports Count -->
|
||||
<div class="glass rounded-2xl border border-orange-200/50 p-6 hover:-translate-y-1 transition-all duration-300 hover:shadow-xl">
|
||||
<div class="flex items-center space-x-4">
|
||||
<div class="w-14 h-14 bg-gradient-to-br from-orange-400 to-orange-600 rounded-xl flex items-center justify-center shadow-lg">
|
||||
<svg class="w-7 h-7 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-4xl font-bold text-slate-800">{{ totalReports }}</p>
|
||||
<p class="text-sm text-slate-500 mt-1">份报告</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- File Types Count -->
|
||||
<div class="glass rounded-2xl border border-orange-200/50 p-6 hover:-translate-y-1 transition-all duration-300 hover:shadow-xl">
|
||||
<div class="flex items-center space-x-4">
|
||||
<div class="w-14 h-14 bg-gradient-to-br from-orange-400 to-orange-600 rounded-xl flex items-center justify-center shadow-lg">
|
||||
<svg class="w-7 h-7 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-4xl font-bold text-slate-800">{{ todayNewReportsTotal }}</p>
|
||||
<p class="text-sm text-slate-500 mt-1">今日新增</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Section Title -->
|
||||
<div class="flex items-center space-x-4 mb-8">
|
||||
<h2 class="text-2xl font-semibold text-slate-800">所有项目</h2>
|
||||
<div class="flex-1 h-px bg-gradient-to-r from-orange-300 to-transparent"></div>
|
||||
</div>
|
||||
|
||||
<!-- Project Carousel - Horizontal Scroll -->
|
||||
<div v-if="projects.length > 0" class="relative">
|
||||
<!-- Left Arrow -->
|
||||
<button
|
||||
@click="scrollLeft"
|
||||
class="absolute left-0 top-1/2 -translate-y-1/2 z-10 w-12 h-12 glass rounded-full flex items-center justify-center shadow-lg hover:bg-orange-500 hover:text-white transition-all duration-300 -ml-6"
|
||||
>
|
||||
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- Right Arrow -->
|
||||
<button
|
||||
@click="scrollRight"
|
||||
class="absolute right-0 top-1/2 -translate-y-1/2 z-10 w-12 h-12 glass rounded-full flex items-center justify-center shadow-lg hover:bg-orange-500 hover:text-white transition-all duration-300 -mr-6"
|
||||
>
|
||||
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<!-- Carousel Container -->
|
||||
<div
|
||||
ref="carouselRef"
|
||||
class="flex gap-6 overflow-x-auto scrollbar-hide pb-4 px-6 snap-x snap-mandatory"
|
||||
style="scroll-padding: 1.5rem;"
|
||||
>
|
||||
<div
|
||||
v-for="project in projects"
|
||||
:key="project.id"
|
||||
class="flex-shrink-0 w-[400px] snap-start"
|
||||
>
|
||||
<ProjectCard
|
||||
:title="project.name"
|
||||
:description="project.description"
|
||||
:image-url="project.coverImage"
|
||||
:report-count="project.reportCount || 0"
|
||||
:created-at="project.createdAt"
|
||||
@click="navigateToProject(project.id)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<div v-if="projects.length === 0" class="text-center py-16">
|
||||
<div class="w-24 h-24 glass rounded-full flex items-center justify-center mx-auto mb-6">
|
||||
<svg class="w-12 h-12 text-orange-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
<h3 class="text-xl font-medium text-slate-700 mb-2">暂无项目</h3>
|
||||
<p class="text-slate-500">创建一个新项目开始管理您的日报</p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, onUnmounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useApi } from '../composables/useApi'
|
||||
import ProjectCard from '../components/ProjectCard.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const { loading, error, fetchProjects } = useApi()
|
||||
|
||||
const projects = ref([])
|
||||
const carouselRef = ref(null)
|
||||
|
||||
const totalReports = computed(() => {
|
||||
return projects.value.reduce((sum, p) => sum + (p.reportCount || 0), 0)
|
||||
})
|
||||
|
||||
const todayNewReportsTotal = computed(() => {
|
||||
return projects.value.reduce((sum, p) => sum + (p.todayNewReports || 0), 0)
|
||||
})
|
||||
|
||||
const loadProjects = async () => {
|
||||
projects.value = await fetchProjects()
|
||||
}
|
||||
|
||||
const navigateToProject = (projectId) => {
|
||||
router.push(`/project/${projectId}`)
|
||||
}
|
||||
|
||||
const scrollLeft = () => {
|
||||
if (carouselRef.value) {
|
||||
carouselRef.value.scrollBy({ left: -440, behavior: 'smooth' })
|
||||
}
|
||||
}
|
||||
|
||||
const scrollRight = () => {
|
||||
if (carouselRef.value) {
|
||||
carouselRef.value.scrollBy({ left: 440, behavior: 'smooth' })
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(loadProjects)
|
||||
|
||||
// Refresh project list whenever we navigate back to this page
|
||||
router.afterEach((to) => {
|
||||
if (to.path === '/') {
|
||||
loadProjects()
|
||||
}
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
// Cleanup is automatic - router hooks don't need removal in Vue 3
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.scrollbar-hide::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
.scrollbar-hide {
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,24 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import ProjectList from '../pages/ProjectList.vue'
|
||||
import ProjectDetail from '../pages/ProjectDetail.vue'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: ProjectList
|
||||
},
|
||||
{
|
||||
path: '/project/:id',
|
||||
name: 'project',
|
||||
component: ProjectDetail,
|
||||
props: true
|
||||
}
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
})
|
||||
|
||||
export default router
|
||||
@@ -0,0 +1,129 @@
|
||||
@import "tailwindcss";
|
||||
|
||||
/* Design System Variables - Orange Theme */
|
||||
:root {
|
||||
--background: #FFF7E6;
|
||||
--foreground: #1a1a1a;
|
||||
--card: rgba(255, 255, 255, 0.7);
|
||||
--card-foreground: #1a1a1a;
|
||||
--popover: rgba(255, 255, 255, 0.9);
|
||||
--popover-foreground: #1a1a1a;
|
||||
--primary: #FF7A45;
|
||||
--primary-foreground: #ffffff;
|
||||
--secondary: rgba(255, 122, 69, 0.1);
|
||||
--secondary-foreground: #FF7A45;
|
||||
--muted: #f5ede0;
|
||||
--muted-foreground: #6b6b6b;
|
||||
--accent: #FF9F6B;
|
||||
--accent-foreground: #1a1a1a;
|
||||
--destructive: #ef4444;
|
||||
--destructive-foreground: #ffffff;
|
||||
--border: rgba(255, 122, 69, 0.2);
|
||||
--input: rgba(255, 122, 69, 0.15);
|
||||
--ring: #FF7A45;
|
||||
--radius: 1rem;
|
||||
--sidebar: rgba(255, 255, 255, 0.6);
|
||||
--sidebar-foreground: #1a1a1a;
|
||||
--sidebar-primary: #FF7A45;
|
||||
--sidebar-border: rgba(255, 122, 69, 0.15);
|
||||
}
|
||||
|
||||
/* Base Styles */
|
||||
@layer base {
|
||||
* {
|
||||
border-color: var(--border);
|
||||
outline-color: var(--ring);
|
||||
}
|
||||
|
||||
html, body {
|
||||
background-color: var(--background);
|
||||
color: var(--foreground);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
min-height: 100vh;
|
||||
font-family: 'Inter', system-ui, -apple-system, sans-serif;
|
||||
}
|
||||
}
|
||||
|
||||
/* Custom Scrollbar */
|
||||
::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
background: var(--primary);
|
||||
opacity: 0.3;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb:hover {
|
||||
background: var(--primary);
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
/* Hide scrollbar utility */
|
||||
.scrollbar-hide::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
.scrollbar-hide {
|
||||
-ms-overflow-style: none;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
/* Glass effect utility */
|
||||
.glass {
|
||||
background: var(--card);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
/* Extended glass variants */
|
||||
.glass-light {
|
||||
background: rgba(255, 255, 255, 0.5);
|
||||
backdrop-filter: blur(8px);
|
||||
-webkit-backdrop-filter: blur(8px);
|
||||
}
|
||||
|
||||
.glass-dark {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
backdrop-filter: blur(12px);
|
||||
-webkit-backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.glass-strong {
|
||||
background: var(--card);
|
||||
backdrop-filter: blur(20px);
|
||||
-webkit-backdrop-filter: blur(20px);
|
||||
}
|
||||
|
||||
/* Backdrop blur utilities */
|
||||
.backdrop-blur-xl {
|
||||
backdrop-filter: blur(24px);
|
||||
-webkit-backdrop-filter: blur(24px);
|
||||
}
|
||||
|
||||
/* Shadow utilities */
|
||||
.shadow-primary\/20 {
|
||||
--tw-shadow-color: rgba(255, 122, 69, 0.2);
|
||||
}
|
||||
|
||||
/* Animation utilities */
|
||||
.transition-all {
|
||||
transition-property: all;
|
||||
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
||||
transition-duration: 300ms;
|
||||
}
|
||||
|
||||
/* Card hover effect */
|
||||
.card-hover {
|
||||
transition: all 300ms ease;
|
||||
}
|
||||
.card-hover:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 20px 25px -5px rgba(255, 122, 69, 0.15), 0 8px 10px -6px rgba(255, 122, 69, 0.1);
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
package com.reportdist;
|
||||
|
||||
import com.reportdist.dto.ProjectRequest;
|
||||
import com.reportdist.dto.ReportResponse;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.*;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Complete API flow integration test.
|
||||
* Tests: Create Project → Upload Report → Query Report → Delete Report → Delete Project (cascade)
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
class CompleteApiFlowIntegrationTest {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
private String baseUrl;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
baseUrl = "http://localhost:" + port;
|
||||
// Ensure upload directory exists
|
||||
Path uploadPath = Paths.get(System.getProperty("java.io.tmpdir"), "report-dist-test-uploads");
|
||||
if (!Files.exists(uploadPath)) {
|
||||
Files.createDirectories(uploadPath);
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
// Cleanup is handled by H2 create-drop and file cleanup in each test
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Complete API flow: Create Project → Upload Report → Query Report → Delete Report → Delete Project")
|
||||
void completeApiFlow_shouldSucceed() {
|
||||
// Step 1: Create a project
|
||||
ProjectRequest projectRequest = new ProjectRequest("Integration Test Project", "Testing complete flow");
|
||||
ResponseEntity<Map> createResponse = restTemplate.postForEntity(
|
||||
baseUrl + "/api/projects",
|
||||
projectRequest,
|
||||
Map.class
|
||||
);
|
||||
|
||||
assertEquals(HttpStatus.CREATED, createResponse.getStatusCode());
|
||||
assertNotNull(createResponse.getBody());
|
||||
Long projectId = ((Number) createResponse.getBody().get("id")).longValue();
|
||||
assertNotNull(projectId);
|
||||
assertEquals("Integration Test Project", createResponse.getBody().get("name"));
|
||||
System.out.println("[Step 1] Created project with ID: " + projectId);
|
||||
|
||||
// Step 2: Verify project exists
|
||||
ResponseEntity<Map> getProjectResponse = restTemplate.getForEntity(
|
||||
baseUrl + "/api/projects/" + projectId,
|
||||
Map.class
|
||||
);
|
||||
assertEquals(HttpStatus.OK, getProjectResponse.getStatusCode());
|
||||
assertEquals("Integration Test Project", getProjectResponse.getBody().get("name"));
|
||||
System.out.println("[Step 2] Verified project exists");
|
||||
|
||||
// Step 3: Upload a report to the project
|
||||
String htmlContent = "<html><body><h1>Integration Test Report</h1><p>Content here</p></body></html>";
|
||||
MultiValueMap<String, Object> reportParts = new LinkedMultiValueMap<>();
|
||||
reportParts.add("file", new ByteArrayResource(htmlContent.getBytes()) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "test-report.html";
|
||||
}
|
||||
});
|
||||
reportParts.add("projectId", projectId.toString());
|
||||
reportParts.add("fileType", "HTML");
|
||||
|
||||
HttpHeaders reportHeaders = new HttpHeaders();
|
||||
reportHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> reportRequest = new HttpEntity<>(reportParts, reportHeaders);
|
||||
|
||||
ResponseEntity<Map> uploadResponse = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
reportRequest,
|
||||
Map.class
|
||||
);
|
||||
|
||||
assertEquals(HttpStatus.CREATED, uploadResponse.getStatusCode());
|
||||
assertNotNull(uploadResponse.getBody());
|
||||
Long reportId = ((Number) uploadResponse.getBody().get("id")).longValue();
|
||||
assertNotNull(reportId);
|
||||
assertEquals("test-report.html", uploadResponse.getBody().get("fileName"));
|
||||
assertEquals("HTML", uploadResponse.getBody().get("fileType"));
|
||||
String filePath = (String) uploadResponse.getBody().get("filePath");
|
||||
System.out.println("[Step 3] Uploaded report with ID: " + reportId + ", path: " + filePath);
|
||||
|
||||
// Verify file was actually saved
|
||||
Path savedFile = Paths.get(filePath);
|
||||
assertTrue(Files.exists(savedFile), "File should exist on disk");
|
||||
|
||||
// Step 4: Query reports by projectId
|
||||
ResponseEntity<List> reportsResponse = restTemplate.getForEntity(
|
||||
baseUrl + "/api/reports?projectId=" + projectId,
|
||||
List.class
|
||||
);
|
||||
assertEquals(HttpStatus.OK, reportsResponse.getStatusCode());
|
||||
assertNotNull(reportsResponse.getBody());
|
||||
assertEquals(1, reportsResponse.getBody().size());
|
||||
Map reportInList = (Map) reportsResponse.getBody().get(0);
|
||||
assertEquals(reportId, ((Number) reportInList.get("id")).longValue());
|
||||
System.out.println("[Step 4] Queried reports, found: " + reportsResponse.getBody().size());
|
||||
|
||||
// Step 5: Get report by ID with content
|
||||
ResponseEntity<Map> getReportResponse = restTemplate.getForEntity(
|
||||
baseUrl + "/api/reports/" + reportId,
|
||||
Map.class
|
||||
);
|
||||
assertEquals(HttpStatus.OK, getReportResponse.getStatusCode());
|
||||
assertEquals("test-report.html", getReportResponse.getBody().get("fileName"));
|
||||
assertEquals(htmlContent, getReportResponse.getBody().get("fileContent"));
|
||||
System.out.println("[Step 5] Retrieved report with content");
|
||||
|
||||
// Step 6: Delete the report
|
||||
ResponseEntity<Void> deleteReportResponse = restTemplate.exchange(
|
||||
baseUrl + "/api/reports/" + reportId,
|
||||
HttpMethod.DELETE,
|
||||
null,
|
||||
Void.class
|
||||
);
|
||||
assertEquals(HttpStatus.NO_CONTENT, deleteReportResponse.getStatusCode());
|
||||
|
||||
// Verify report file is deleted
|
||||
assertFalse(Files.exists(savedFile), "File should be deleted from disk");
|
||||
|
||||
// Verify report is gone
|
||||
ResponseEntity<Map> getDeletedReport = restTemplate.getForEntity(
|
||||
baseUrl + "/api/reports/" + reportId,
|
||||
Map.class
|
||||
);
|
||||
assertEquals(HttpStatus.NOT_FOUND, getDeletedReport.getStatusCode());
|
||||
System.out.println("[Step 6] Deleted report");
|
||||
|
||||
// Step 7: Delete the project
|
||||
ResponseEntity<Void> deleteProjectResponse = restTemplate.exchange(
|
||||
baseUrl + "/api/projects/" + projectId,
|
||||
HttpMethod.DELETE,
|
||||
null,
|
||||
Void.class
|
||||
);
|
||||
assertEquals(HttpStatus.NO_CONTENT, deleteProjectResponse.getStatusCode());
|
||||
|
||||
// Verify project is gone
|
||||
ResponseEntity<Map> getDeletedProject = restTemplate.getForEntity(
|
||||
baseUrl + "/api/projects/" + projectId,
|
||||
Map.class
|
||||
);
|
||||
assertEquals(HttpStatus.NOT_FOUND, getDeletedProject.getStatusCode());
|
||||
System.out.println("[Step 7] Deleted project");
|
||||
|
||||
System.out.println("[SUCCESS] Complete API flow test passed!");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Cascade delete: Deleting project should not delete reports (manual cleanup)")
|
||||
void deleteProject_shouldNotAutoDeleteReports() {
|
||||
// Create project
|
||||
ProjectRequest projectRequest = new ProjectRequest("Cascade Test Project", "Testing cascade");
|
||||
ResponseEntity<Map> createResponse = restTemplate.postForEntity(
|
||||
baseUrl + "/api/projects",
|
||||
projectRequest,
|
||||
Map.class
|
||||
);
|
||||
assertEquals(HttpStatus.CREATED, createResponse.getStatusCode());
|
||||
Long projectId = ((Number) createResponse.getBody().get("id")).longValue();
|
||||
|
||||
// Upload two reports
|
||||
for (int i = 1; i <= 2; i++) {
|
||||
final int reportIndex = i;
|
||||
String content = "Report " + i;
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(content.getBytes()) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "report" + reportIndex + ".html";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "HTML");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
Map.class
|
||||
);
|
||||
assertEquals(HttpStatus.CREATED, response.getStatusCode());
|
||||
}
|
||||
|
||||
// Verify reports exist
|
||||
ResponseEntity<List> reportsResponse = restTemplate.getForEntity(
|
||||
baseUrl + "/api/reports?projectId=" + projectId,
|
||||
List.class
|
||||
);
|
||||
assertEquals(2, reportsResponse.getBody().size());
|
||||
|
||||
// Delete project
|
||||
ResponseEntity<Void> deleteResponse = restTemplate.exchange(
|
||||
baseUrl + "/api/projects/" + projectId,
|
||||
HttpMethod.DELETE,
|
||||
null,
|
||||
Void.class
|
||||
);
|
||||
assertEquals(HttpStatus.NO_CONTENT, deleteResponse.getStatusCode());
|
||||
|
||||
// Project should be gone
|
||||
ResponseEntity<Map> getProject = restTemplate.getForEntity(
|
||||
baseUrl + "/api/projects/" + projectId,
|
||||
Map.class
|
||||
);
|
||||
assertEquals(HttpStatus.NOT_FOUND, getProject.getStatusCode());
|
||||
|
||||
// Reports still exist (they're orphaned - not cascade deleted)
|
||||
// This confirms reports are independent entities
|
||||
ResponseEntity<List> orphanedReports = restTemplate.getForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
List.class
|
||||
);
|
||||
assertTrue(orphanedReports.getBody().size() >= 2);
|
||||
System.out.println("[INFO] Project deleted. Reports remain in database (manual cleanup required).");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
package com.reportdist;
|
||||
|
||||
import com.reportdist.dto.ProjectRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Error handling integration test.
|
||||
* Tests:
|
||||
* - Upload oversized file (>100MB) returns 413
|
||||
* - Project doesn't exist: GET /api/reports?projectId=999 returns empty list
|
||||
* - Report doesn't exist: GET /api/reports/999 returns 404
|
||||
*/
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
class ErrorHandlingIntegrationTest {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Value("${file.upload.dir}")
|
||||
private String uploadDir;
|
||||
|
||||
private String baseUrl;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IOException {
|
||||
baseUrl = "http://localhost:" + port;
|
||||
// Ensure upload directory exists
|
||||
Path uploadPath = Paths.get(uploadDir);
|
||||
if (!Files.exists(uploadPath)) {
|
||||
Files.createDirectories(uploadPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a project for tests.
|
||||
*/
|
||||
private Long createProject(String name) {
|
||||
ProjectRequest projectRequest = new ProjectRequest(name, "Test project for error handling");
|
||||
ResponseEntity<Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/projects",
|
||||
projectRequest,
|
||||
Map.class
|
||||
);
|
||||
if (response.getStatusCode() == HttpStatus.CREATED) {
|
||||
return ((Number) response.getBody().get("id")).longValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ==================== Oversized File Upload Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("Upload moderately large file (10MB) - should succeed")
|
||||
void uploadModeratelyLargeFile_shouldSucceed() {
|
||||
// Given
|
||||
Long projectId = createProject("Size Limit Test Project");
|
||||
assertNotNull(projectId, "Should create project for test");
|
||||
|
||||
// Create content 10MB (well within limit but tests larger file handling)
|
||||
int largeSize = 10 * 1024 * 1024; // 10MB
|
||||
byte[] largeContent = new byte[largeSize];
|
||||
// Fill with some data
|
||||
for (int i = 0; i < largeContent.length; i++) {
|
||||
largeContent[i] = (byte) (i % 256);
|
||||
}
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(largeContent) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "large-file.html";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "HTML");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
Map.class
|
||||
);
|
||||
|
||||
// Then - should succeed for files under the limit
|
||||
assertEquals(HttpStatus.CREATED, response.getStatusCode(),
|
||||
"File under 100MB limit should be accepted");
|
||||
}
|
||||
|
||||
// ==================== Project Not Found Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("GET /api/reports?projectId=999 - should return empty list for non-existent project")
|
||||
void getReportsForNonExistentProject_shouldReturnEmptyList() {
|
||||
// Given - non-existent project ID (999)
|
||||
Long nonExistentProjectId = 999L;
|
||||
|
||||
// When
|
||||
ResponseEntity<List> response = restTemplate.getForEntity(
|
||||
baseUrl + "/api/reports?projectId=" + nonExistentProjectId,
|
||||
List.class
|
||||
);
|
||||
|
||||
// Then - should return empty list, not 404
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
assertTrue(response.getBody().isEmpty(),
|
||||
"Non-existent project should return empty list, but got: " + response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("GET /api/reports?projectId for deleted project - should return empty list")
|
||||
void getReportsForDeletedProject_shouldReturnEmptyList() {
|
||||
// Given - create and then delete a project
|
||||
Long projectId = createProject("To Be Deleted Project");
|
||||
assertNotNull(projectId);
|
||||
|
||||
// Upload a report first
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource("content".getBytes()) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "report.html";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "HTML");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> uploadRequest = new HttpEntity<>(parts, headers);
|
||||
|
||||
restTemplate.postForEntity(baseUrl + "/api/reports", uploadRequest, Map.class);
|
||||
|
||||
// Delete the project (reports remain orphaned)
|
||||
restTemplate.exchange(
|
||||
baseUrl + "/api/projects/" + projectId,
|
||||
HttpMethod.DELETE,
|
||||
null,
|
||||
Void.class
|
||||
);
|
||||
|
||||
// When - query reports for the deleted project
|
||||
ResponseEntity<List> response = restTemplate.getForEntity(
|
||||
baseUrl + "/api/reports?projectId=" + projectId,
|
||||
List.class
|
||||
);
|
||||
|
||||
// Then - should still return reports (orphaned) or empty if properly cascade deleted
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
// Note: Since there's no cascade delete, orphaned reports still exist
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("GET /api/projects/999 - should return 404 for non-existent project")
|
||||
void getNonExistentProject_shouldReturn404() {
|
||||
// Given
|
||||
Long nonExistentProjectId = 999L;
|
||||
|
||||
// When
|
||||
ResponseEntity<Map> response = restTemplate.getForEntity(
|
||||
baseUrl + "/api/projects/" + nonExistentProjectId,
|
||||
Map.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
|
||||
}
|
||||
|
||||
// ==================== Report Not Found Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("GET /api/reports/999 - should return 404 for non-existent report")
|
||||
void getNonExistentReport_shouldReturn404() {
|
||||
// Given
|
||||
Long nonExistentReportId = 999L;
|
||||
|
||||
// When
|
||||
ResponseEntity<Map> response = restTemplate.getForEntity(
|
||||
baseUrl + "/api/reports/" + nonExistentReportId,
|
||||
Map.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("DELETE /api/reports/999 - should return 404 for non-existent report")
|
||||
void deleteNonExistentReport_shouldReturn404() {
|
||||
// Given
|
||||
Long nonExistentReportId = 999L;
|
||||
|
||||
// When
|
||||
ResponseEntity<Void> response = restTemplate.exchange(
|
||||
baseUrl + "/api/reports/" + nonExistentReportId,
|
||||
HttpMethod.DELETE,
|
||||
null,
|
||||
Void.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
|
||||
}
|
||||
|
||||
// ==================== Validation Error Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("POST /api/projects - should return 400 for empty project name")
|
||||
void createProjectWithEmptyName_shouldReturn400() {
|
||||
// Given
|
||||
ProjectRequest invalidRequest = new ProjectRequest("", "Some description");
|
||||
|
||||
// When
|
||||
ResponseEntity<Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/projects",
|
||||
invalidRequest,
|
||||
Map.class
|
||||
);
|
||||
|
||||
// Then - should fail validation
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("POST /api/projects - should return 400 for missing project name")
|
||||
void createProjectWithMissingName_shouldReturn400() {
|
||||
// Given
|
||||
String jsonWithoutName = "{\"description\": \"Some description\"}";
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<String> request = new HttpEntity<>(jsonWithoutName, headers);
|
||||
|
||||
// When
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
baseUrl + "/api/projects",
|
||||
HttpMethod.POST,
|
||||
request,
|
||||
String.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
}
|
||||
|
||||
// ==================== PUT Update Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("PUT /api/reports/999 - should return 404 for non-existent report")
|
||||
void updateNonExistentReport_shouldReturn404() {
|
||||
// Given
|
||||
Long nonExistentReportId = 999L;
|
||||
String updateJson = "{\"fileName\": \"updated.html\"}";
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<String> request = new HttpEntity<>(updateJson, headers);
|
||||
|
||||
// When
|
||||
ResponseEntity<Map> response = restTemplate.exchange(
|
||||
baseUrl + "/api/reports/" + nonExistentReportId,
|
||||
HttpMethod.PUT,
|
||||
request,
|
||||
Map.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("PUT /api/projects/999 - should return 404 for non-existent project")
|
||||
void updateNonExistentProject_shouldReturn404() {
|
||||
// Given
|
||||
Long nonExistentProjectId = 999L;
|
||||
|
||||
// When - send multipart form (matching actual endpoint format)
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("name", "Updated Name");
|
||||
parts.add("description", "Updated Description");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
ResponseEntity<Map> response = restTemplate.exchange(
|
||||
baseUrl + "/api/projects/" + nonExistentProjectId,
|
||||
HttpMethod.PUT,
|
||||
new HttpEntity<>(parts, headers),
|
||||
Map.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
|
||||
}
|
||||
|
||||
// ==================== Upload Without File Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("POST /api/reports without file - should return 400")
|
||||
void uploadWithoutFile_shouldReturn400() {
|
||||
// Given
|
||||
Long projectId = createProject("Upload Without File Test");
|
||||
assertNotNull(projectId);
|
||||
|
||||
// When - send request without file part
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "HTML");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.exchange(
|
||||
baseUrl + "/api/reports",
|
||||
HttpMethod.POST,
|
||||
request,
|
||||
String.class
|
||||
);
|
||||
|
||||
// Then - should fail due to missing required file
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
}
|
||||
|
||||
// ==================== Delete Non-Existent Project Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("DELETE /api/projects/999 - should return 404 for non-existent project")
|
||||
void deleteNonExistentProject_shouldReturn404() {
|
||||
// Given
|
||||
Long nonExistentProjectId = 999L;
|
||||
|
||||
// When
|
||||
ResponseEntity<Void> response = restTemplate.exchange(
|
||||
baseUrl + "/api/projects/" + nonExistentProjectId,
|
||||
HttpMethod.DELETE,
|
||||
null,
|
||||
Void.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,460 @@
|
||||
package com.reportdist;
|
||||
|
||||
import com.reportdist.dto.ProjectRequest;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate;
|
||||
import org.springframework.boot.test.web.server.LocalServerPort;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
class FileUploadIntegrationTest {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(FileUploadIntegrationTest.class);
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate restTemplate;
|
||||
|
||||
@Value("${file.upload.dir}")
|
||||
private String uploadDir;
|
||||
|
||||
private String baseUrl;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IOException {
|
||||
baseUrl = "http://localhost:" + port;
|
||||
log.info("Upload directory configured: {}", uploadDir);
|
||||
|
||||
// Ensure upload directory exists
|
||||
Path uploadPath = Paths.get(uploadDir);
|
||||
if (!Files.exists(uploadPath)) {
|
||||
Files.createDirectories(uploadPath);
|
||||
log.info("Created upload directory: {}", uploadPath.toAbsolutePath());
|
||||
}
|
||||
|
||||
// Verify we can write to the directory
|
||||
Path testFile = uploadPath.resolve(".upload-test");
|
||||
Files.writeString(testFile, "test");
|
||||
Files.deleteIfExists(testFile);
|
||||
log.info("Upload directory is writable: {}", uploadPath.toAbsolutePath());
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create a project for file upload tests.
|
||||
*/
|
||||
private Long createProject(String name) {
|
||||
ProjectRequest projectRequest = new ProjectRequest(name, "Test project for file upload");
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/projects",
|
||||
projectRequest,
|
||||
java.util.Map.class
|
||||
);
|
||||
assertEquals(HttpStatus.CREATED, response.getStatusCode());
|
||||
return ((Number) response.getBody().get("id")).longValue();
|
||||
}
|
||||
|
||||
// ==================== HTML File Upload Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("Upload HTML file - should succeed and store file")
|
||||
void uploadHtmlFile_shouldSucceed() {
|
||||
// Given
|
||||
Long projectId = createProject("HTML Test Project");
|
||||
String htmlContent = """
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Test Report</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Daily Report</h1>
|
||||
<p>This is a test report content.</p>
|
||||
<ul>
|
||||
<li>Item 1: Completed</li>
|
||||
<li>Item 2: In progress</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
""";
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(htmlContent.getBytes()) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "daily-report.html";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "HTML");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
log.info("Uploading HTML file to project {} via URL: {}/api/reports", projectId, baseUrl);
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
java.util.Map.class
|
||||
);
|
||||
|
||||
log.info("Upload response: status={}, body={}", response.getStatusCode(), response.getBody());
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.CREATED, response.getStatusCode(),
|
||||
"Upload should succeed. Response body: " + response.getBody());
|
||||
assertNotNull(response.getBody());
|
||||
assertEquals("daily-report.html", response.getBody().get("fileName"));
|
||||
assertEquals("HTML", response.getBody().get("fileType"));
|
||||
|
||||
// Verify file exists on disk
|
||||
String filePath = (String) response.getBody().get("filePath");
|
||||
assertNotNull(filePath);
|
||||
Path savedFile = Paths.get(filePath);
|
||||
assertTrue(Files.exists(savedFile), "HTML file should exist on disk: " + filePath);
|
||||
|
||||
// Verify content can be read back
|
||||
try {
|
||||
String readContent = Files.readString(savedFile);
|
||||
assertEquals(htmlContent, readContent);
|
||||
} catch (IOException e) {
|
||||
fail("Should be able to read HTML file content: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== MD File Upload Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("Upload MD file - should succeed and store file")
|
||||
void uploadMdFile_shouldSucceed() {
|
||||
// Given
|
||||
Long projectId = createProject("MD Test Project");
|
||||
String mdContent = """
|
||||
# Project Report
|
||||
|
||||
## Overview
|
||||
This is a markdown report for testing purposes.
|
||||
|
||||
## Features
|
||||
- Feature A
|
||||
- Feature B
|
||||
- Feature C
|
||||
|
||||
## Conclusion
|
||||
All features implemented successfully.
|
||||
""";
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(mdContent.getBytes()) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "project-report.md";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "MD");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
java.util.Map.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.CREATED, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
assertEquals("project-report.md", response.getBody().get("fileName"));
|
||||
assertEquals("MD", response.getBody().get("fileType"));
|
||||
|
||||
// Verify file exists on disk
|
||||
String filePath = (String) response.getBody().get("filePath");
|
||||
assertNotNull(filePath);
|
||||
Path savedFile = Paths.get(filePath);
|
||||
assertTrue(Files.exists(savedFile), "MD file should exist on disk");
|
||||
|
||||
// Verify content can be read back
|
||||
try {
|
||||
String readContent = Files.readString(savedFile);
|
||||
assertEquals(mdContent, readContent);
|
||||
} catch (IOException e) {
|
||||
fail("Should be able to read MD file content: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== PPTX File Upload Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("Upload PPTX file - should succeed and file exists")
|
||||
void uploadPptxFile_shouldSucceed() {
|
||||
// Given
|
||||
Long projectId = createProject("PPTX Test Project");
|
||||
// Create a minimal PPTX-like binary content for testing
|
||||
// Real PPTX files are ZIP archives, but for upload test we just verify it stores
|
||||
byte[] pptxContent = "PK".getBytes(); // Minimal PPTX header (ZIP signature)
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(pptxContent) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "presentation.pptx";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "PPTX");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
java.util.Map.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.CREATED, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
assertEquals("presentation.pptx", response.getBody().get("fileName"));
|
||||
assertEquals("PPTX", response.getBody().get("fileType"));
|
||||
|
||||
// Verify file exists on disk
|
||||
String filePath = (String) response.getBody().get("filePath");
|
||||
assertNotNull(filePath);
|
||||
Path savedFile = Paths.get(filePath);
|
||||
assertTrue(Files.exists(savedFile), "PPTX file should exist on disk");
|
||||
|
||||
// Verify file size matches
|
||||
try {
|
||||
long fileSize = Files.size(savedFile);
|
||||
assertEquals(pptxContent.length, fileSize, "File size should match uploaded content");
|
||||
} catch (IOException e) {
|
||||
fail("Should be able to get file size: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Upload PPT file - should succeed")
|
||||
void uploadPptFile_shouldSucceed() {
|
||||
// Given
|
||||
Long projectId = createProject("PPT Test Project");
|
||||
byte[] pptContent = "D0CF11E0".getBytes(); // OLE2 signature
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(pptContent) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "legacy-presentation.ppt";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "PPT");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
java.util.Map.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.CREATED, response.getStatusCode());
|
||||
assertEquals("PPT", response.getBody().get("fileType"));
|
||||
}
|
||||
|
||||
// ==================== Reject Illegal File Types Tests ====================
|
||||
|
||||
@Test
|
||||
@DisplayName("Reject EXE file - should return 400")
|
||||
void uploadExeFile_shouldReject() {
|
||||
// Given
|
||||
Long projectId = createProject("Security Test Project");
|
||||
byte[] exeContent = "MZ".getBytes(); // DOS/Windows executable signature
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(exeContent) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "malware.exe";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "EXE");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
java.util.Map.class
|
||||
);
|
||||
|
||||
// Then - should be rejected before processing
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Reject BAT file - should return 400")
|
||||
void uploadBatFile_shouldReject() {
|
||||
// Given
|
||||
Long projectId = createProject("Security Test Project 2");
|
||||
String batContent = "@echo off\necho Hello";
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(batContent.getBytes()) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "script.bat";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "BAT");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
java.util.Map.class
|
||||
);
|
||||
|
||||
// Then - should be rejected before processing
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Reject SH file - should return 400")
|
||||
void uploadShFile_shouldReject() {
|
||||
// Given
|
||||
Long projectId = createProject("Security Test Project 3");
|
||||
String shContent = "#!/bin/bash\necho Hello";
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(shContent.getBytes()) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "script.sh";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "SH");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
java.util.Map.class
|
||||
);
|
||||
|
||||
// Then - should be rejected before processing
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Reject DLL file - should return 400")
|
||||
void uploadDllFile_shouldReject() {
|
||||
// Given
|
||||
Long projectId = createProject("Security Test Project 4");
|
||||
byte[] dllContent = "MZ".getBytes();
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(dllContent) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "library.dll";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "DLL");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
java.util.Map.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Reject JS file - should return 400")
|
||||
void uploadJsFile_shouldReject() {
|
||||
// Given
|
||||
Long projectId = createProject("Security Test Project 5");
|
||||
String jsContent = "console.log('Hello');";
|
||||
|
||||
// When
|
||||
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
|
||||
parts.add("file", new ByteArrayResource(jsContent.getBytes()) {
|
||||
@Override
|
||||
public String getFilename() {
|
||||
return "script.js";
|
||||
}
|
||||
});
|
||||
parts.add("projectId", projectId.toString());
|
||||
parts.add("fileType", "JS");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
|
||||
HttpEntity<MultiValueMap<String, Object>> request = new HttpEntity<>(parts, headers);
|
||||
|
||||
ResponseEntity<java.util.Map> response = restTemplate.postForEntity(
|
||||
baseUrl + "/api/reports",
|
||||
request,
|
||||
java.util.Map.class
|
||||
);
|
||||
|
||||
// Then
|
||||
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.reportdist.controller;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.reportdist.dto.ProjectRequest;
|
||||
import com.reportdist.dto.ProjectResponse;
|
||||
import com.reportdist.service.ProjectService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
|
||||
|
||||
@WebMvcTest(ProjectController.class)
|
||||
class ProjectControllerTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
@MockBean
|
||||
private ProjectService projectService;
|
||||
|
||||
// ==================== GET /api/projects Tests ====================
|
||||
|
||||
@Test
|
||||
void getAllProjects_shouldReturnProjectList() throws Exception {
|
||||
// Given
|
||||
List<ProjectResponse> projects = Arrays.asList(
|
||||
new ProjectResponse(1L, "Project One", "Description 1", LocalDateTime.now()),
|
||||
new ProjectResponse(2L, "Project Two", "Description 2", LocalDateTime.now())
|
||||
);
|
||||
when(projectService.getAllProjects()).thenReturn(projects);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(get("/api/projects"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(2))
|
||||
.andExpect(jsonPath("$[0].name").value("Project One"))
|
||||
.andExpect(jsonPath("$[1].name").value("Project Two"));
|
||||
|
||||
verify(projectService, times(1)).getAllProjects();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllProjects_shouldReturnEmptyList() throws Exception {
|
||||
// Given
|
||||
when(projectService.getAllProjects()).thenReturn(Collections.emptyList());
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(get("/api/projects"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(0));
|
||||
}
|
||||
|
||||
// ==================== POST /api/projects Tests ====================
|
||||
|
||||
@Test
|
||||
void createProject_shouldCreateAndReturn201() throws Exception {
|
||||
// Given
|
||||
ProjectRequest request = new ProjectRequest("New Project", "New Description");
|
||||
ProjectResponse response = new ProjectResponse(1L, "New Project", "New Description", LocalDateTime.now());
|
||||
|
||||
when(projectService.createProject(any(ProjectRequest.class))).thenReturn(response);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(post("/api/projects")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(request)))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("$.id").value(1))
|
||||
.andExpect(jsonPath("$.name").value("New Project"))
|
||||
.andExpect(jsonPath("$.description").value("New Description"));
|
||||
|
||||
verify(projectService, times(1)).createProject(any(ProjectRequest.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createProject_shouldReturn400WhenNameIsBlank() throws Exception {
|
||||
// Given - empty name
|
||||
ProjectRequest request = new ProjectRequest("", "Description");
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(post("/api/projects")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(objectMapper.writeValueAsString(request)))
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
verify(projectService, never()).createProject(any(ProjectRequest.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createProject_shouldReturn400WhenNameIsNull() throws Exception {
|
||||
// Given - null name
|
||||
String jsonRequest = "{\"description\": \"Some description\"}";
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(post("/api/projects")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content(jsonRequest))
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
verify(projectService, never()).createProject(any(ProjectRequest.class));
|
||||
}
|
||||
|
||||
// ==================== PUT /api/projects/{id} Tests ====================
|
||||
|
||||
@Test
|
||||
void updateProject_shouldUpdateAndReturn200() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
ProjectResponse response = new ProjectResponse(projectId, "Updated Project", "Updated Description", LocalDateTime.now());
|
||||
|
||||
when(projectService.updateProject(eq(projectId), any(), any(), any())).thenReturn(response);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(put("/api/projects/{id}", projectId)
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||
.param("name", "Updated Project")
|
||||
.param("description", "Updated Description"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.id").value(projectId))
|
||||
.andExpect(jsonPath("$.name").value("Updated Project"))
|
||||
.andExpect(jsonPath("$.description").value("Updated Description"));
|
||||
|
||||
verify(projectService, times(1)).updateProject(eq(projectId), any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateProject_shouldReturn404WhenNotFound() throws Exception {
|
||||
// Given
|
||||
Long projectId = 999L;
|
||||
|
||||
when(projectService.updateProject(eq(projectId), any(), any(), any()))
|
||||
.thenThrow(new RuntimeException("Project not found with id: " + projectId));
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(put("/api/projects/{id}", projectId)
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA)
|
||||
.param("name", "Updated Project"))
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
verify(projectService, times(1)).updateProject(eq(projectId), any(), any(), any());
|
||||
}
|
||||
|
||||
// ==================== DELETE /api/projects/{id} Tests ====================
|
||||
|
||||
@Test
|
||||
void deleteProject_shouldReturn204() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
doNothing().when(projectService).deleteProject(projectId);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(delete("/api/projects/{id}", projectId))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
verify(projectService, times(1)).deleteProject(projectId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteProject_shouldReturn500WhenNotFound() throws Exception {
|
||||
// Given
|
||||
Long projectId = 999L;
|
||||
doThrow(new RuntimeException("Project not found with id: " + projectId))
|
||||
.when(projectService).deleteProject(projectId);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(delete("/api/projects/{id}", projectId))
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
verify(projectService, times(1)).deleteProject(projectId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,314 @@
|
||||
package com.reportdist.controller;
|
||||
|
||||
import com.reportdist.dto.ReportResponse;
|
||||
import com.reportdist.service.ReportService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
|
||||
|
||||
@WebMvcTest(ReportController.class)
|
||||
class ReportControllerTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
private ReportService reportService;
|
||||
|
||||
// ==================== GET /api/reports Tests ====================
|
||||
|
||||
@Test
|
||||
void getAllReports_shouldReturnAllReports() throws Exception {
|
||||
// Given
|
||||
List<ReportResponse> reports = Arrays.asList(
|
||||
new ReportResponse(1L, 1L, "report1.html", "HTML", "/path/report1.html", LocalDateTime.now(), null),
|
||||
new ReportResponse(2L, 1L, "report2.md", "MD", "/path/report2.md", LocalDateTime.now(), null)
|
||||
);
|
||||
when(reportService.getAllReports(null)).thenReturn(reports);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(get("/api/reports"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(2))
|
||||
.andExpect(jsonPath("$[0].fileName").value("report1.html"))
|
||||
.andExpect(jsonPath("$[1].fileName").value("report2.md"));
|
||||
|
||||
verify(reportService, times(1)).getAllReports(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllReports_shouldReturnEmptyListWhenNoReports() throws Exception {
|
||||
// Given
|
||||
when(reportService.getAllReports(null)).thenReturn(Collections.emptyList());
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(get("/api/reports"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(0));
|
||||
}
|
||||
|
||||
// ==================== GET /api/reports?projectId= Tests ====================
|
||||
|
||||
@Test
|
||||
void getAllReports_withProjectId_shouldFilterByProject() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
List<ReportResponse> reports = Arrays.asList(
|
||||
new ReportResponse(1L, projectId, "report1.html", "HTML", "/path/report1.html", LocalDateTime.now(), null),
|
||||
new ReportResponse(2L, projectId, "report2.md", "MD", "/path/report2.md", LocalDateTime.now(), null)
|
||||
);
|
||||
when(reportService.getAllReports(projectId)).thenReturn(reports);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(get("/api/reports")
|
||||
.param("projectId", String.valueOf(projectId)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(2))
|
||||
.andExpect(jsonPath("$[0].projectId").value(projectId));
|
||||
|
||||
verify(reportService, times(1)).getAllReports(projectId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllReports_withProjectId_shouldReturnEmptyListForNonExistentProject() throws Exception {
|
||||
// Given
|
||||
Long projectId = 999L;
|
||||
when(reportService.getAllReports(projectId)).thenReturn(Collections.emptyList());
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(get("/api/reports")
|
||||
.param("projectId", String.valueOf(projectId)))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.length()").value(0));
|
||||
|
||||
verify(reportService, times(1)).getAllReports(projectId);
|
||||
}
|
||||
|
||||
// ==================== GET /api/reports/{id} Tests ====================
|
||||
|
||||
@Test
|
||||
void getReportById_shouldReturnReport() throws Exception {
|
||||
// Given
|
||||
Long reportId = 1L;
|
||||
ReportResponse report = new ReportResponse(reportId, 1L, "report.html", "HTML",
|
||||
"/path/report.html", LocalDateTime.now(), "<html>Content</html>");
|
||||
when(reportService.getReportById(reportId)).thenReturn(report);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(get("/api/reports/{id}", reportId))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.id").value(reportId))
|
||||
.andExpect(jsonPath("$.fileName").value("report.html"))
|
||||
.andExpect(jsonPath("$.fileContent").value("<html>Content</html>"));
|
||||
|
||||
verify(reportService, times(1)).getReportById(reportId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getReportById_shouldReturn404WhenNotFound() throws Exception {
|
||||
// Given
|
||||
Long reportId = 999L;
|
||||
when(reportService.getReportById(reportId))
|
||||
.thenThrow(new RuntimeException("Report not found with id: " + reportId));
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(get("/api/reports/{id}", reportId))
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
verify(reportService, times(1)).getReportById(reportId);
|
||||
}
|
||||
|
||||
// ==================== POST /api/reports (file upload) Tests ====================
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldUploadHtmlFile() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"report.html",
|
||||
"text/html",
|
||||
"<html><body>Test Report</body></html>".getBytes()
|
||||
);
|
||||
|
||||
ReportResponse response = new ReportResponse(1L, projectId, "report.html", "HTML",
|
||||
"/path/1/report.html", LocalDateTime.now(), null);
|
||||
when(reportService.uploadReport(any(), eq(projectId), eq("HTML"))).thenReturn(response);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(multipart("/api/reports")
|
||||
.file(file)
|
||||
.param("projectId", String.valueOf(projectId))
|
||||
.param("fileType", "HTML"))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("$.id").value(1))
|
||||
.andExpect(jsonPath("$.fileName").value("report.html"))
|
||||
.andExpect(jsonPath("$.fileType").value("HTML"));
|
||||
|
||||
verify(reportService, times(1)).uploadReport(any(), eq(projectId), eq("HTML"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldUploadMdFile() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"readme.md",
|
||||
"text/markdown",
|
||||
"# Test Report".getBytes()
|
||||
);
|
||||
|
||||
ReportResponse response = new ReportResponse(1L, projectId, "readme.md", "MD",
|
||||
"/path/1/readme.md", LocalDateTime.now(), null);
|
||||
when(reportService.uploadReport(any(), eq(projectId), eq("MD"))).thenReturn(response);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(multipart("/api/reports")
|
||||
.file(file)
|
||||
.param("projectId", String.valueOf(projectId))
|
||||
.param("fileType", "MD"))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("$.fileType").value("MD"));
|
||||
|
||||
verify(reportService, times(1)).uploadReport(any(), eq(projectId), eq("MD"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldUploadPptFile() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"presentation.ppt",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"dummy ppt content".getBytes()
|
||||
);
|
||||
|
||||
ReportResponse response = new ReportResponse(1L, projectId, "presentation.ppt", "PPT",
|
||||
"/path/1/presentation.ppt", LocalDateTime.now(), null);
|
||||
when(reportService.uploadReport(any(), eq(projectId), eq("PPT"))).thenReturn(response);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(multipart("/api/reports")
|
||||
.file(file)
|
||||
.param("projectId", String.valueOf(projectId))
|
||||
.param("fileType", "PPT"))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("$.fileType").value("PPT"));
|
||||
|
||||
verify(reportService, times(1)).uploadReport(any(), eq(projectId), eq("PPT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldUploadPptxFile() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"presentation.pptx",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
"dummy pptx content".getBytes()
|
||||
);
|
||||
|
||||
ReportResponse response = new ReportResponse(1L, projectId, "presentation.pptx", "PPTX",
|
||||
"/path/1/presentation.pptx", LocalDateTime.now(), null);
|
||||
when(reportService.uploadReport(any(), eq(projectId), eq("PPTX"))).thenReturn(response);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(multipart("/api/reports")
|
||||
.file(file)
|
||||
.param("projectId", String.valueOf(projectId))
|
||||
.param("fileType", "PPTX"))
|
||||
.andExpect(status().isCreated())
|
||||
.andExpect(jsonPath("$.fileType").value("PPTX"));
|
||||
|
||||
verify(reportService, times(1)).uploadReport(any(), eq(projectId), eq("PPTX"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldRejectExeFile() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"malware.exe",
|
||||
"application/octet-stream",
|
||||
"malicious content".getBytes()
|
||||
);
|
||||
|
||||
// When & Then - Controller validates extension and returns 400
|
||||
mockMvc.perform(multipart("/api/reports")
|
||||
.file(file)
|
||||
.param("projectId", String.valueOf(projectId))
|
||||
.param("fileType", "EXE"))
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
verify(reportService, never()).uploadReport(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldRejectPdfFile() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"document.pdf",
|
||||
"application/pdf",
|
||||
"pdf content".getBytes()
|
||||
);
|
||||
|
||||
// When & Then - Controller validates extension and returns 400
|
||||
mockMvc.perform(multipart("/api/reports")
|
||||
.file(file)
|
||||
.param("projectId", String.valueOf(projectId))
|
||||
.param("fileType", "PDF"))
|
||||
.andExpect(status().isBadRequest());
|
||||
|
||||
verify(reportService, never()).uploadReport(any(), any(), any());
|
||||
}
|
||||
|
||||
// ==================== DELETE /api/reports/{id} Tests ====================
|
||||
|
||||
@Test
|
||||
void deleteReport_shouldReturn204() throws Exception {
|
||||
// Given
|
||||
Long reportId = 1L;
|
||||
doNothing().when(reportService).deleteReport(reportId);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(delete("/api/reports/{id}", reportId))
|
||||
.andExpect(status().isNoContent());
|
||||
|
||||
verify(reportService, times(1)).deleteReport(reportId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteReport_shouldReturn500WhenNotFound() throws Exception {
|
||||
// Given
|
||||
Long reportId = 999L;
|
||||
doThrow(new RuntimeException("Report not found with id: " + reportId))
|
||||
.when(reportService).deleteReport(reportId);
|
||||
|
||||
// When & Then
|
||||
mockMvc.perform(delete("/api/reports/{id}", reportId))
|
||||
.andExpect(status().isNotFound());
|
||||
|
||||
verify(reportService, times(1)).deleteReport(reportId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
package com.reportdist.service;
|
||||
|
||||
import com.reportdist.dto.ProjectRequest;
|
||||
import com.reportdist.dto.ProjectResponse;
|
||||
import com.reportdist.entity.Project;
|
||||
import com.reportdist.repository.ProjectRepository;
|
||||
import com.reportdist.repository.ReportRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ProjectServiceTest {
|
||||
|
||||
@Mock
|
||||
private ProjectRepository projectRepository;
|
||||
|
||||
@Mock
|
||||
private ReportRepository reportRepository;
|
||||
|
||||
private ProjectService projectService;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
projectService = new ProjectService(projectRepository, reportRepository);
|
||||
}
|
||||
|
||||
// ==================== createProject Tests ====================
|
||||
|
||||
@Test
|
||||
void createProject_shouldCreateAndReturnProject() {
|
||||
// Given
|
||||
ProjectRequest request = new ProjectRequest("Test Project", "Test Description");
|
||||
Project savedProject = new Project(1L, "Test Project", "Test Description", LocalDateTime.now());
|
||||
|
||||
when(projectRepository.save(any(Project.class))).thenReturn(savedProject);
|
||||
|
||||
// When
|
||||
ProjectResponse response = projectService.createProject(request);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals(1L, response.getId());
|
||||
assertEquals("Test Project", response.getName());
|
||||
assertEquals("Test Description", response.getDescription());
|
||||
verify(projectRepository, times(1)).save(any(Project.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createProject_shouldHandleDuplicateName() {
|
||||
// Given - Note: The service doesn't explicitly handle duplicates,
|
||||
// but we test the normal flow still works
|
||||
ProjectRequest request = new ProjectRequest("Duplicate Project", "Description");
|
||||
Project savedProject = new Project(2L, "Duplicate Project", "Description", LocalDateTime.now());
|
||||
|
||||
when(projectRepository.save(any(Project.class))).thenReturn(savedProject);
|
||||
|
||||
// When
|
||||
ProjectResponse response = projectService.createProject(request);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals("Duplicate Project", response.getName());
|
||||
verify(projectRepository, times(1)).save(any(Project.class));
|
||||
}
|
||||
|
||||
// ==================== getAllProjects Tests ====================
|
||||
|
||||
@Test
|
||||
void getAllProjects_shouldReturnEmptyList() {
|
||||
// Given
|
||||
when(projectRepository.findAll()).thenReturn(Collections.emptyList());
|
||||
|
||||
// When
|
||||
List<ProjectResponse> result = projectService.getAllProjects();
|
||||
|
||||
// Then
|
||||
assertNotNull(result);
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllProjects_shouldReturnSingleProject() {
|
||||
// Given
|
||||
Project project = new Project(1L, "Single Project", "Description", LocalDateTime.now());
|
||||
when(projectRepository.findAll()).thenReturn(Collections.singletonList(project));
|
||||
|
||||
// When
|
||||
List<ProjectResponse> result = projectService.getAllProjects();
|
||||
|
||||
// Then
|
||||
assertNotNull(result);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals("Single Project", result.get(0).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllProjects_shouldReturnMultipleProjects() {
|
||||
// Given
|
||||
Project project1 = new Project(1L, "Project One", "Description 1", LocalDateTime.now());
|
||||
Project project2 = new Project(2L, "Project Two", "Description 2", LocalDateTime.now());
|
||||
Project project3 = new Project(3L, "Project Three", "Description 3", LocalDateTime.now());
|
||||
when(projectRepository.findAll()).thenReturn(Arrays.asList(project1, project2, project3));
|
||||
|
||||
// When
|
||||
List<ProjectResponse> result = projectService.getAllProjects();
|
||||
|
||||
// Then
|
||||
assertNotNull(result);
|
||||
assertEquals(3, result.size());
|
||||
assertEquals("Project One", result.get(0).getName());
|
||||
assertEquals("Project Two", result.get(1).getName());
|
||||
assertEquals("Project Three", result.get(2).getName());
|
||||
}
|
||||
|
||||
// ==================== updateProject Tests ====================
|
||||
|
||||
@Test
|
||||
void updateProject_shouldUpdateAndReturnProject() {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
ProjectRequest request = new ProjectRequest("Updated Name", "Updated Description");
|
||||
Project existingProject = new Project(1L, "Original Name", "Original Description", LocalDateTime.now());
|
||||
Project updatedProject = new Project(1L, "Updated Name", "Updated Description", existingProject.getCreatedAt());
|
||||
|
||||
when(projectRepository.findById(projectId)).thenReturn(java.util.Optional.of(existingProject));
|
||||
when(projectRepository.save(any(Project.class))).thenReturn(updatedProject);
|
||||
|
||||
// When
|
||||
ProjectResponse response = projectService.updateProject(projectId, request);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals("Updated Name", response.getName());
|
||||
assertEquals("Updated Description", response.getDescription());
|
||||
verify(projectRepository, times(1)).findById(projectId);
|
||||
verify(projectRepository, times(1)).save(any(Project.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateProject_shouldThrowExceptionWhenNotFound() {
|
||||
// Given
|
||||
Long projectId = 999L;
|
||||
ProjectRequest request = new ProjectRequest("Updated Name", "Updated Description");
|
||||
|
||||
when(projectRepository.findById(projectId)).thenReturn(java.util.Optional.empty());
|
||||
|
||||
// When & Then
|
||||
RuntimeException exception = assertThrows(RuntimeException.class, () -> {
|
||||
projectService.updateProject(projectId, request);
|
||||
});
|
||||
|
||||
assertTrue(exception.getMessage().contains("Project not found"));
|
||||
verify(projectRepository, times(1)).findById(projectId);
|
||||
verify(projectRepository, never()).save(any(Project.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllProjects_shouldIncludeReportCount() {
|
||||
// Given
|
||||
Project project1 = new Project(1L, "Project One", "Description 1", LocalDateTime.now());
|
||||
Project project2 = new Project(2L, "Project Two", "Description 2", LocalDateTime.now());
|
||||
when(projectRepository.findAll()).thenReturn(Arrays.asList(project1, project2));
|
||||
when(reportRepository.countByProjectId(1L)).thenReturn(5L);
|
||||
when(reportRepository.countByProjectId(2L)).thenReturn(3L);
|
||||
|
||||
// When
|
||||
List<ProjectResponse> result = projectService.getAllProjects();
|
||||
|
||||
// Then
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals(5L, result.get(0).getReportCount());
|
||||
assertEquals(3L, result.get(1).getReportCount());
|
||||
verify(reportRepository, times(1)).countByProjectId(1L);
|
||||
verify(reportRepository, times(1)).countByProjectId(2L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getProjectById_shouldIncludeReportCount() {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
Project project = new Project(1L, "Test Project", "Description", LocalDateTime.now());
|
||||
when(projectRepository.findById(projectId)).thenReturn(java.util.Optional.of(project));
|
||||
when(reportRepository.countByProjectId(projectId)).thenReturn(10L);
|
||||
|
||||
// When
|
||||
ProjectResponse response = projectService.getProjectById(projectId);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals(10L, response.getReportCount());
|
||||
verify(reportRepository, times(1)).countByProjectId(projectId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllProjects_withNoReports_shouldHaveZeroReportCount() {
|
||||
// Given
|
||||
Project project = new Project(1L, "Empty Project", "No reports", LocalDateTime.now());
|
||||
when(projectRepository.findAll()).thenReturn(Collections.singletonList(project));
|
||||
when(reportRepository.countByProjectId(1L)).thenReturn(0L);
|
||||
|
||||
// When
|
||||
List<ProjectResponse> result = projectService.getAllProjects();
|
||||
|
||||
// Then
|
||||
assertNotNull(result);
|
||||
assertEquals(1, result.size());
|
||||
assertEquals(0L, result.get(0).getReportCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateProject_withMultipartCoverImage_shouldReturnUpdatedProjectWithReportCount() {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
Project existingProject = new Project(1L, "Original Name", "Description", LocalDateTime.now());
|
||||
Project updatedProject = new Project(1L, "Updated Name", "Description", existingProject.getCreatedAt());
|
||||
updatedProject.setCoverImage("/uploads/covers/1/test.png");
|
||||
|
||||
when(projectRepository.findById(projectId)).thenReturn(java.util.Optional.of(existingProject));
|
||||
when(projectRepository.save(any(Project.class))).thenReturn(updatedProject);
|
||||
when(reportRepository.countByProjectId(projectId)).thenReturn(5L);
|
||||
|
||||
// When
|
||||
ProjectResponse response = projectService.updateProject(projectId, "Updated Name", null, null);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals(5L, response.getReportCount());
|
||||
verify(reportRepository, times(1)).countByProjectId(projectId);
|
||||
}
|
||||
|
||||
// ==================== deleteProject Tests ====================
|
||||
|
||||
@Test
|
||||
void deleteProject_shouldDeleteSuccessfully() {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
when(projectRepository.existsById(projectId)).thenReturn(true);
|
||||
doNothing().when(projectRepository).deleteById(projectId);
|
||||
|
||||
// When
|
||||
projectService.deleteProject(projectId);
|
||||
|
||||
// Then
|
||||
verify(projectRepository, times(1)).existsById(projectId);
|
||||
verify(projectRepository, times(1)).deleteById(projectId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteProject_shouldThrowExceptionWhenNotFound() {
|
||||
// Given
|
||||
Long projectId = 999L;
|
||||
when(projectRepository.existsById(projectId)).thenReturn(false);
|
||||
|
||||
// When & Then
|
||||
RuntimeException exception = assertThrows(RuntimeException.class, () -> {
|
||||
projectService.deleteProject(projectId);
|
||||
});
|
||||
|
||||
assertTrue(exception.getMessage().contains("Project not found"));
|
||||
verify(projectRepository, times(1)).existsById(projectId);
|
||||
verify(projectRepository, never()).deleteById(any());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
package com.reportdist.service;
|
||||
|
||||
import com.reportdist.dto.ReportResponse;
|
||||
import com.reportdist.entity.Report;
|
||||
import com.reportdist.repository.ReportRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ReportServiceTest {
|
||||
|
||||
@Mock
|
||||
private ReportRepository reportRepository;
|
||||
|
||||
private ReportService reportService;
|
||||
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
reportService = new ReportService(reportRepository);
|
||||
ReflectionTestUtils.setField(reportService, "uploadDir", tempDir.toString());
|
||||
}
|
||||
|
||||
// ==================== uploadReport Tests ====================
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldUploadSuccessfully() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
String fileType = "HTML";
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"report.html",
|
||||
"text/html",
|
||||
"<html><body>Test Report</body></html>".getBytes()
|
||||
);
|
||||
|
||||
Report savedReport = new Report(1L, projectId, "report.html", Report.FileType.HTML,
|
||||
tempDir.resolve("1/report.html").toString(), LocalDateTime.now());
|
||||
|
||||
when(reportRepository.save(any(Report.class))).thenReturn(savedReport);
|
||||
|
||||
// When
|
||||
ReportResponse response = reportService.uploadReport(file, projectId, fileType);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals(1L, response.getId());
|
||||
assertEquals(projectId, response.getProjectId());
|
||||
assertEquals("report.html", response.getFileName());
|
||||
verify(reportRepository, times(1)).save(any(Report.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldAcceptHtmlExtension() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
String fileType = "HTML";
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"report.html",
|
||||
"text/html",
|
||||
"<html><body>Test</body></html>".getBytes()
|
||||
);
|
||||
|
||||
Report savedReport = new Report(1L, projectId, "report.html", Report.FileType.HTML,
|
||||
tempDir.resolve("1/report.html").toString(), LocalDateTime.now());
|
||||
|
||||
when(reportRepository.save(any(Report.class))).thenReturn(savedReport);
|
||||
|
||||
// When
|
||||
ReportResponse response = reportService.uploadReport(file, projectId, fileType);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals("HTML", response.getFileType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldAcceptMdExtension() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
String fileType = "MD";
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"readme.md",
|
||||
"text/markdown",
|
||||
"# Test Report".getBytes()
|
||||
);
|
||||
|
||||
Report savedReport = new Report(1L, projectId, "readme.md", Report.FileType.MD,
|
||||
tempDir.resolve("1/readme.md").toString(), LocalDateTime.now());
|
||||
|
||||
when(reportRepository.save(any(Report.class))).thenReturn(savedReport);
|
||||
|
||||
// When
|
||||
ReportResponse response = reportService.uploadReport(file, projectId, fileType);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals("MD", response.getFileType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldAcceptPptExtension() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
String fileType = "PPT";
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"presentation.ppt",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"dummy ppt content".getBytes()
|
||||
);
|
||||
|
||||
Report savedReport = new Report(1L, projectId, "presentation.ppt", Report.FileType.PPT,
|
||||
tempDir.resolve("1/presentation.ppt").toString(), LocalDateTime.now());
|
||||
|
||||
when(reportRepository.save(any(Report.class))).thenReturn(savedReport);
|
||||
|
||||
// When
|
||||
ReportResponse response = reportService.uploadReport(file, projectId, fileType);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals("PPT", response.getFileType());
|
||||
}
|
||||
|
||||
@Test
|
||||
void uploadReport_shouldAcceptPptxExtension() throws Exception {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
String fileType = "PPTX";
|
||||
MockMultipartFile file = new MockMultipartFile(
|
||||
"file",
|
||||
"presentation.pptx",
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
||||
"dummy pptx content".getBytes()
|
||||
);
|
||||
|
||||
Report savedReport = new Report(1L, projectId, "presentation.pptx", Report.FileType.PPTX,
|
||||
tempDir.resolve("1/presentation.pptx").toString(), LocalDateTime.now());
|
||||
|
||||
when(reportRepository.save(any(Report.class))).thenReturn(savedReport);
|
||||
|
||||
// When
|
||||
ReportResponse response = reportService.uploadReport(file, projectId, fileType);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals("PPTX", response.getFileType());
|
||||
}
|
||||
|
||||
// Note: File type validation is done in Controller, not Service
|
||||
// Service accepts all file types passed from Controller
|
||||
|
||||
// ==================== getReportsByProject Tests ====================
|
||||
|
||||
@Test
|
||||
void getReportsByProject_shouldFilterCorrectly() {
|
||||
// Given
|
||||
Long projectId = 1L;
|
||||
Report report1 = new Report(1L, projectId, "report1.html", Report.FileType.HTML,
|
||||
"/path/report1.html", LocalDateTime.now());
|
||||
Report report2 = new Report(2L, projectId, "report2.md", Report.FileType.MD,
|
||||
"/path/report2.md", LocalDateTime.now());
|
||||
|
||||
when(reportRepository.findByProjectId(projectId)).thenReturn(Arrays.asList(report1, report2));
|
||||
|
||||
// When
|
||||
List<ReportResponse> result = reportService.getAllReports(projectId);
|
||||
|
||||
// Then
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
assertEquals("report1.html", result.get(0).getFileName());
|
||||
assertEquals("report2.md", result.get(1).getFileName());
|
||||
verify(reportRepository, times(1)).findByProjectId(projectId);
|
||||
verify(reportRepository, never()).findAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getReportsByProject_shouldReturnEmptyListForNonExistentProject() {
|
||||
// Given
|
||||
Long projectId = 999L;
|
||||
when(reportRepository.findByProjectId(projectId)).thenReturn(Collections.emptyList());
|
||||
|
||||
// When
|
||||
List<ReportResponse> result = reportService.getAllReports(projectId);
|
||||
|
||||
// Then
|
||||
assertNotNull(result);
|
||||
assertTrue(result.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getAllReports_shouldReturnAllReportsWhenProjectIdIsNull() {
|
||||
// Given
|
||||
Report report1 = new Report(1L, 1L, "report1.html", Report.FileType.HTML,
|
||||
"/path/report1.html", LocalDateTime.now());
|
||||
Report report2 = new Report(2L, 2L, "report2.md", Report.FileType.MD,
|
||||
"/path/report2.md", LocalDateTime.now());
|
||||
|
||||
when(reportRepository.findAll()).thenReturn(Arrays.asList(report1, report2));
|
||||
|
||||
// When
|
||||
List<ReportResponse> result = reportService.getAllReports(null);
|
||||
|
||||
// Then
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.size());
|
||||
verify(reportRepository, times(1)).findAll();
|
||||
verify(reportRepository, never()).findByProjectId(any());
|
||||
}
|
||||
|
||||
// ==================== getReportById Tests ====================
|
||||
|
||||
@Test
|
||||
void getReportById_shouldReturnReportWithContent() throws Exception {
|
||||
// Given
|
||||
Long reportId = 1L;
|
||||
String filePath = tempDir.resolve("test_report.html").toString();
|
||||
Report report = new Report(reportId, 1L, "test_report.html", Report.FileType.HTML,
|
||||
filePath, LocalDateTime.now());
|
||||
|
||||
// Create the test file
|
||||
java.nio.file.Files.writeString(java.nio.file.Path.of(filePath), "<html>Content</html>");
|
||||
|
||||
when(reportRepository.findById(reportId)).thenReturn(Optional.of(report));
|
||||
|
||||
// When
|
||||
ReportResponse response = reportService.getReportById(reportId);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertEquals(reportId, response.getId());
|
||||
assertEquals("<html>Content</html>", response.getFileContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getReportById_shouldReturnNullWhenFileNotExists() {
|
||||
// Given
|
||||
Long reportId = 1L;
|
||||
String filePath = tempDir.resolve("non_existent.html").toString();
|
||||
Report report = new Report(reportId, 1L, "non_existent.html", Report.FileType.HTML,
|
||||
filePath, LocalDateTime.now());
|
||||
|
||||
when(reportRepository.findById(reportId)).thenReturn(Optional.of(report));
|
||||
|
||||
// When
|
||||
ReportResponse response = reportService.getReportById(reportId);
|
||||
|
||||
// Then
|
||||
assertNotNull(response);
|
||||
assertNull(response.getFileContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getReportById_shouldThrowExceptionWhenNotFound() {
|
||||
// Given
|
||||
Long reportId = 999L;
|
||||
when(reportRepository.findById(reportId)).thenReturn(Optional.empty());
|
||||
|
||||
// When & Then
|
||||
RuntimeException exception = assertThrows(RuntimeException.class, () -> {
|
||||
reportService.getReportById(reportId);
|
||||
});
|
||||
|
||||
assertTrue(exception.getMessage().contains("Report not found"));
|
||||
}
|
||||
|
||||
// ==================== deleteReport Tests ====================
|
||||
|
||||
@Test
|
||||
void deleteReport_shouldDeleteSuccessfully() throws Exception {
|
||||
// Given
|
||||
Long reportId = 1L;
|
||||
String filePath = tempDir.resolve("delete_test.html").toString();
|
||||
Report report = new Report(reportId, 1L, "delete_test.html", Report.FileType.HTML,
|
||||
filePath, LocalDateTime.now());
|
||||
|
||||
// Create the test file
|
||||
java.nio.file.Files.writeString(java.nio.file.Path.of(filePath), "<html>To be deleted</html>");
|
||||
|
||||
when(reportRepository.findById(reportId)).thenReturn(Optional.of(report));
|
||||
doNothing().when(reportRepository).deleteById(reportId);
|
||||
|
||||
// When
|
||||
reportService.deleteReport(reportId);
|
||||
|
||||
// Then
|
||||
verify(reportRepository, times(1)).findById(reportId);
|
||||
verify(reportRepository, times(1)).deleteById(reportId);
|
||||
assertFalse(java.nio.file.Files.exists(java.nio.file.Path.of(filePath)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteReport_shouldHandleNonExistentFile() throws Exception {
|
||||
// Given
|
||||
Long reportId = 1L;
|
||||
String filePath = tempDir.resolve("non_existent_file.html").toString();
|
||||
Report report = new Report(reportId, 1L, "non_existent_file.html", Report.FileType.HTML,
|
||||
filePath, LocalDateTime.now());
|
||||
|
||||
when(reportRepository.findById(reportId)).thenReturn(Optional.of(report));
|
||||
doNothing().when(reportRepository).deleteById(reportId);
|
||||
|
||||
// When - Should not throw even if file doesn't exist
|
||||
assertDoesNotThrow(() -> reportService.deleteReport(reportId));
|
||||
|
||||
// Then
|
||||
verify(reportRepository, times(1)).findById(reportId);
|
||||
verify(reportRepository, times(1)).deleteById(reportId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteReport_shouldThrowExceptionWhenNotFound() {
|
||||
// Given
|
||||
Long reportId = 999L;
|
||||
when(reportRepository.findById(reportId)).thenReturn(Optional.empty());
|
||||
|
||||
// When & Then
|
||||
RuntimeException exception = assertThrows(RuntimeException.class, () -> {
|
||||
reportService.deleteReport(reportId);
|
||||
});
|
||||
|
||||
assertTrue(exception.getMessage().contains("Report not found"));
|
||||
verify(reportRepository, times(1)).findById(reportId);
|
||||
verify(reportRepository, never()).deleteById(any());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
|
||||
driver-class-name: org.h2.Driver
|
||||
username: sa
|
||||
password:
|
||||
|
||||
jpa:
|
||||
database-platform: org.hibernate.dialect.H2Dialect
|
||||
hibernate:
|
||||
ddl-auto: create-drop
|
||||
show-sql: true
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
|
||||
servlet:
|
||||
multipart:
|
||||
enabled: true
|
||||
max-file-size: 100MB
|
||||
max-request-size: 100MB
|
||||
|
||||
file:
|
||||
upload:
|
||||
# Use absolute path for test upload directory to ensure it exists
|
||||
dir: ${java.io.tmpdir}/report-dist-test-uploads
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health
|
||||
|
||||
logging:
|
||||
level:
|
||||
com.reportdist: DEBUG
|
||||
org.springframework.web: DEBUG
|
||||
@@ -0,0 +1,247 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { ref } from 'vue'
|
||||
import FilePreview from '@/components/FilePreview.vue'
|
||||
|
||||
// Mock useApi
|
||||
vi.mock('@/composables/useApi', () => ({
|
||||
useApi: () => ({
|
||||
fetchReportBytes: vi.fn().mockResolvedValue(null),
|
||||
fetchReportPdf: vi.fn().mockResolvedValue(null)
|
||||
})
|
||||
}))
|
||||
|
||||
describe('FilePreview.vue', () => {
|
||||
describe('HTML preview', () => {
|
||||
it('should render iframe with srcdoc for HTML files', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: '2026-05-22 日报.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
const content = '<html><body><h1>Test</h1></body></html>'
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content }
|
||||
})
|
||||
|
||||
const iframe = wrapper.find('iframe')
|
||||
expect(iframe.exists()).toBe(true)
|
||||
expect(iframe.attributes('srcdoc')).toBe(content)
|
||||
})
|
||||
|
||||
it('should have sandbox attribute on iframe', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content: '<html>Content</html>' }
|
||||
})
|
||||
|
||||
const iframe = wrapper.find('iframe')
|
||||
expect(iframe.attributes('sandbox')).toBe('allow-same-origin')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Markdown preview', () => {
|
||||
it('should render marked content for MD files', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: '2026-05-22 日报.md',
|
||||
fileType: 'md',
|
||||
reportDate: '2026-05-22',
|
||||
size: '8KB'
|
||||
}
|
||||
const content = '# Test Header\n\nThis is a test.'
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content }
|
||||
})
|
||||
|
||||
// Should render h1 from markdown
|
||||
const h1 = wrapper.find('h1')
|
||||
expect(h1.exists()).toBe(true)
|
||||
expect(h1.text()).toBe('Test Header')
|
||||
})
|
||||
|
||||
it('should show empty content when markdown is empty', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.md',
|
||||
fileType: 'md',
|
||||
reportDate: '2026-05-22',
|
||||
size: '8KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content: '' }
|
||||
})
|
||||
|
||||
// Should show prose container (even if empty)
|
||||
const proseDiv = wrapper.find('.prose')
|
||||
expect(proseDiv.exists()).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe('PPTX download', () => {
|
||||
it('should show download button for PPTX files', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: '2026-05-20 周报.pptx',
|
||||
fileType: 'pptx',
|
||||
reportDate: '2026-05-20',
|
||||
size: '256KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content: '' }
|
||||
})
|
||||
|
||||
// Should show download button (orange gradient style in new design)
|
||||
const buttons = wrapper.findAll('button')
|
||||
const downloadButton = buttons.find(b => b.text().includes('下载'))
|
||||
expect(downloadButton).toBeDefined()
|
||||
})
|
||||
|
||||
it('should have orange styling for download button', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.pptx',
|
||||
fileType: 'pptx',
|
||||
reportDate: '2026-05-20',
|
||||
size: '256KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content: '' }
|
||||
})
|
||||
|
||||
// Should have gradient download button
|
||||
const buttons = wrapper.findAll('button')
|
||||
const downloadButton = buttons.find(b => b.text().includes('下载'))
|
||||
expect(downloadButton).toBeDefined()
|
||||
})
|
||||
|
||||
it('should trigger downloadReport on button click', async () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.pptx',
|
||||
fileType: 'pptx',
|
||||
reportDate: '2026-05-20',
|
||||
size: '256KB'
|
||||
}
|
||||
|
||||
vi.spyOn(window, 'alert').mockImplementation(() => {})
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content: '' }
|
||||
})
|
||||
|
||||
const buttons = wrapper.findAll('button')
|
||||
const downloadButton = buttons.find(b => b.text().includes('下载'))
|
||||
await downloadButton.trigger('click')
|
||||
|
||||
// Should show alert (either '文件不存在或无法读取' or '下载失败')
|
||||
expect(window.alert).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('Empty state', () => {
|
||||
it('should show empty state when no report is selected', () => {
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report: null, content: '' }
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('选择一份报告以预览')
|
||||
})
|
||||
|
||||
it('should not show iframe when report is null', () => {
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report: null, content: '' }
|
||||
})
|
||||
|
||||
const iframe = wrapper.find('iframe')
|
||||
expect(iframe.exists()).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('Report header', () => {
|
||||
it('should display report file name in header', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: '2026-05-22 日报.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content: '<html>Test</html>' }
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('2026-05-22 日报.html')
|
||||
})
|
||||
|
||||
it('should display report date and size in header', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content: '<html>Test</html>' }
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('2026-05-22')
|
||||
expect(wrapper.text()).toContain('15KB')
|
||||
})
|
||||
|
||||
it('should show download button for HTML files', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content: '<html>Test</html>' }
|
||||
})
|
||||
|
||||
// Should show download button
|
||||
const buttons = wrapper.findAll('button')
|
||||
const downloadButton = buttons.find(b => b.text().includes('下载'))
|
||||
expect(downloadButton).toBeDefined()
|
||||
})
|
||||
})
|
||||
|
||||
describe('File type display', () => {
|
||||
it('should show file type badge', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.pptx',
|
||||
fileType: 'pptx',
|
||||
reportDate: '2026-05-20',
|
||||
size: '256KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(FilePreview, {
|
||||
props: { report, content: '' }
|
||||
})
|
||||
|
||||
// Should show PowerPoint badge
|
||||
expect(wrapper.text()).toContain('PowerPoint')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,174 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import ReportCard from '@/components/ReportCard.vue'
|
||||
|
||||
describe('ReportCard.vue', () => {
|
||||
it('should render file name', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: '2026-05-22 日报.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report }
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('2026-05-22 日报.html')
|
||||
})
|
||||
|
||||
it('should render file type label', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report }
|
||||
})
|
||||
|
||||
// Should show HTML label for html type
|
||||
expect(wrapper.text()).toContain('HTML')
|
||||
})
|
||||
|
||||
it('should render markdown label for md type', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.md',
|
||||
fileType: 'md',
|
||||
reportDate: '2026-05-22',
|
||||
size: '8KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report }
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('Markdown')
|
||||
})
|
||||
|
||||
it('should render PowerPoint label for pptx type', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.pptx',
|
||||
fileType: 'pptx',
|
||||
reportDate: '2026-05-22',
|
||||
size: '256KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report }
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('PowerPoint')
|
||||
})
|
||||
|
||||
it('should render file date', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report }
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('2026-05-22')
|
||||
})
|
||||
|
||||
it('should render file size', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report }
|
||||
})
|
||||
|
||||
expect(wrapper.text()).toContain('15KB')
|
||||
})
|
||||
|
||||
it('should emit select event on click', async () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report }
|
||||
})
|
||||
|
||||
await wrapper.trigger('click')
|
||||
|
||||
expect(wrapper.emitted('select')).toBeTruthy()
|
||||
expect(wrapper.emitted('select')[0]).toEqual([report])
|
||||
})
|
||||
|
||||
it('should have selected state styling when isSelected is true', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report, isSelected: true }
|
||||
})
|
||||
|
||||
// Check for gradient background class when selected (new design)
|
||||
const card = wrapper.find('.bg-gradient-to-r')
|
||||
expect(card.exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('should display icon for each file type', () => {
|
||||
const htmlReport = {
|
||||
id: 1,
|
||||
fileName: 'test.html',
|
||||
fileType: 'html',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report: htmlReport }
|
||||
})
|
||||
|
||||
// Check that icon container exists (w-12 h-12 rounded-xl)
|
||||
const iconContainer = wrapper.find('.w-12')
|
||||
expect(iconContainer.exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('should use default file type for unknown types', () => {
|
||||
const report = {
|
||||
id: 1,
|
||||
fileName: 'test.xyz',
|
||||
fileType: 'xyz',
|
||||
reportDate: '2026-05-22',
|
||||
size: '15KB'
|
||||
}
|
||||
|
||||
const wrapper = mount(ReportCard, {
|
||||
props: { report }
|
||||
})
|
||||
|
||||
// Should display XYZ as uppercase (unknown type defaults)
|
||||
expect(wrapper.text()).toContain('XYZ')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,161 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import axios from 'axios'
|
||||
|
||||
// Mock axios
|
||||
vi.mock('axios')
|
||||
vi.mocked(axios.create).mockReturnValue({
|
||||
get: vi.fn(),
|
||||
post: vi.fn(),
|
||||
put: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
interceptors: {
|
||||
request: { use: vi.fn(), eject: vi.fn() },
|
||||
response: { use: vi.fn(), eject: vi.fn() }
|
||||
}
|
||||
})
|
||||
|
||||
import { useApi } from '@/composables/useApi'
|
||||
|
||||
const mockProjects = [
|
||||
{ id: 1, name: '项目一', description: '主要产品线', reportCount: 15, todayNewReports: 2 },
|
||||
{ id: 2, name: '项目二', description: '内部工具', reportCount: 8, todayNewReports: 1 },
|
||||
{ id: 3, name: '项目三', description: '客户定制', reportCount: 12, todayNewReports: 0 }
|
||||
]
|
||||
|
||||
const mockReports = {
|
||||
1: [
|
||||
{ id: 101, fileName: '2026-05-22 日报.html', fileType: 'html', reportDate: '2026-05-22', size: '15KB' },
|
||||
{ id: 102, fileName: '2026-05-21 日报.md', fileType: 'md', reportDate: '2026-05-21', size: '8KB' },
|
||||
{ id: 103, fileName: '2026-05-20 周报.pptx', fileType: 'pptx', reportDate: '2026-05-20', size: '256KB' }
|
||||
],
|
||||
2: [
|
||||
{ id: 201, fileName: '2026-05-22 开发日报.html', fileType: 'html', reportDate: '2026-05-22', size: '12KB' },
|
||||
{ id: 202, fileName: '2026-05-21 开发日报.html', fileType: 'html', reportDate: '2026-05-21', size: '11KB' }
|
||||
]
|
||||
}
|
||||
|
||||
describe('useApi composable', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
describe('fetchProjects', () => {
|
||||
it('should return mock data when API succeeds', async () => {
|
||||
const apiInstance = axios.create()
|
||||
vi.mocked(apiInstance.get).mockResolvedValue({ data: mockProjects })
|
||||
|
||||
const { fetchProjects } = useApi()
|
||||
const result = await fetchProjects()
|
||||
|
||||
expect(result).toEqual(mockProjects)
|
||||
})
|
||||
|
||||
it('should return mock data when API fails (fallback)', async () => {
|
||||
const apiInstance = axios.create()
|
||||
vi.mocked(apiInstance.get).mockRejectedValue(new Error('API not available'))
|
||||
|
||||
const { fetchProjects } = useApi()
|
||||
const result = await fetchProjects()
|
||||
|
||||
// Should return hardcoded mock data on API failure
|
||||
expect(result).toHaveLength(3)
|
||||
expect(result[0]).toHaveProperty('id')
|
||||
expect(result[0]).toHaveProperty('name')
|
||||
})
|
||||
})
|
||||
|
||||
describe('fetchReports', () => {
|
||||
it('should filter reports by projectId', async () => {
|
||||
const apiInstance = axios.create()
|
||||
vi.mocked(apiInstance.get).mockResolvedValue({ data: mockReports[1] })
|
||||
|
||||
const { fetchReports } = useApi()
|
||||
const result = await fetchReports(1)
|
||||
|
||||
expect(result).toEqual(mockReports[1])
|
||||
})
|
||||
|
||||
it('should return mock data when API fails', async () => {
|
||||
const apiInstance = axios.create()
|
||||
vi.mocked(apiInstance.get).mockRejectedValue(new Error('API not available'))
|
||||
|
||||
const { fetchReports } = useApi()
|
||||
const result = await fetchReports(1)
|
||||
|
||||
// Should return mock reports for project 1
|
||||
expect(result).toHaveLength(3)
|
||||
expect(result[0].fileType).toBe('html')
|
||||
})
|
||||
|
||||
it('should return empty array for unknown projectId', async () => {
|
||||
const apiInstance = axios.create()
|
||||
vi.mocked(apiInstance.get).mockRejectedValue(new Error('API not available'))
|
||||
|
||||
const { fetchReports } = useApi()
|
||||
const result = await fetchReports(999)
|
||||
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('fetchReportContent', () => {
|
||||
it('should return report content and type when API succeeds', async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
fileContent: '<html>Content</html>',
|
||||
fileType: 'html'
|
||||
}
|
||||
}
|
||||
const apiInstance = axios.create()
|
||||
vi.mocked(apiInstance.get).mockResolvedValue(mockResponse)
|
||||
|
||||
const { fetchReportContent } = useApi()
|
||||
const result = await fetchReportContent(101)
|
||||
|
||||
expect(result).toHaveProperty('content')
|
||||
expect(result).toHaveProperty('type', 'html')
|
||||
})
|
||||
|
||||
it('should return mock content when API returns 404 (fallback)', async () => {
|
||||
const apiInstance = axios.create()
|
||||
vi.mocked(apiInstance.get).mockRejectedValue({ response: { status: 404 } })
|
||||
|
||||
const { fetchReportContent } = useApi()
|
||||
const result = await fetchReportContent(101)
|
||||
|
||||
// Should find report in mock data and return its content
|
||||
expect(result).not.toBeNull()
|
||||
expect(result).toHaveProperty('type')
|
||||
})
|
||||
|
||||
it('should return null for unknown reportId', async () => {
|
||||
const apiInstance = axios.create()
|
||||
vi.mocked(apiInstance.get).mockRejectedValue(new Error('API not available'))
|
||||
|
||||
const { fetchReportContent } = useApi()
|
||||
const result = await fetchReportContent(99999)
|
||||
|
||||
expect(result).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('loading state', () => {
|
||||
it('should toggle loading state during fetch', async () => {
|
||||
const apiInstance = axios.create()
|
||||
vi.mocked(apiInstance.get).mockImplementation(() =>
|
||||
new Promise(resolve => setTimeout(() => resolve({ data: mockProjects }), 100))
|
||||
)
|
||||
|
||||
const { loading, fetchProjects } = useApi()
|
||||
|
||||
expect(loading.value).toBe(false)
|
||||
|
||||
const fetchPromise = fetchProjects()
|
||||
// Note: loading value changes too fast in sync, check after
|
||||
const result = await fetchPromise
|
||||
|
||||
expect(result).toEqual(mockProjects)
|
||||
expect(loading.value).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,201 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createRouter, createMemoryHistory } from 'vue-router'
|
||||
import { ref } from 'vue'
|
||||
|
||||
// Mock data
|
||||
const mockProjects = [
|
||||
{ id: 1, name: '项目一', description: '主要产品线', reportCount: 15 },
|
||||
{ id: 2, name: '项目二', description: '内部工具', reportCount: 8 }
|
||||
]
|
||||
|
||||
const mockReports = [
|
||||
{ id: 101, fileName: '2026-05-22 日报.html', fileType: 'html', reportDate: '2026-05-22', size: '15KB' },
|
||||
{ id: 102, fileName: '2026-05-21 日报.md', fileType: 'md', reportDate: '2026-05-21', size: '8KB' },
|
||||
{ id: 103, fileName: '2026-05-20 周报.pptx', fileType: 'pptx', reportDate: '2026-05-20', size: '256KB' }
|
||||
]
|
||||
|
||||
// Mock the useApi composable
|
||||
vi.mock('@/composables/useApi', () => ({
|
||||
useApi: () => ({
|
||||
loading: ref(false),
|
||||
error: ref(null),
|
||||
fetchProjects: vi.fn().mockResolvedValue(mockProjects),
|
||||
fetchReports: vi.fn().mockResolvedValue(mockReports),
|
||||
fetchReportContent: vi.fn().mockResolvedValue({
|
||||
content: '<html>Test Content</html>',
|
||||
type: 'html'
|
||||
})
|
||||
})
|
||||
}))
|
||||
|
||||
// Mock components
|
||||
vi.mock('@/components/ReportCard.vue', () => ({
|
||||
default: {
|
||||
template: '<div class="report-card-mock" @click="$emit(\'select\', report)">{{ report.fileName }}</div>',
|
||||
props: ['report', 'isSelected'],
|
||||
emits: ['select']
|
||||
}
|
||||
}))
|
||||
|
||||
vi.mock('@/components/FilePreview.vue', () => ({
|
||||
default: {
|
||||
template: '<div class="file-preview-mock">{{ report?.fileName }}</div>',
|
||||
props: ['report', 'content']
|
||||
}
|
||||
}))
|
||||
|
||||
import ProjectDetail from '@/pages/ProjectDetail.vue'
|
||||
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [
|
||||
{ path: '/', component: { template: '<div>Home</div>' } },
|
||||
{ path: '/project/:id', component: ProjectDetail }
|
||||
]
|
||||
})
|
||||
|
||||
describe('ProjectDetail.vue', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
router.push('/project/1')
|
||||
await router.isReady()
|
||||
})
|
||||
|
||||
it('should render report card list', async () => {
|
||||
const wrapper = mount(ProjectDetail, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ReportCard: {
|
||||
template: '<div class="report-card-mock" @click="$emit(\'select\', report)">{{ report.fileName }}</div>',
|
||||
props: ['report', 'isSelected'],
|
||||
emits: ['select']
|
||||
},
|
||||
FilePreview: { template: '<div class="file-preview-mock"></div>' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Should render report cards
|
||||
const cards = wrapper.findAll('.report-card-mock')
|
||||
expect(cards.length).toBe(3)
|
||||
})
|
||||
|
||||
it('should show preview when report is selected', async () => {
|
||||
const wrapper = mount(ProjectDetail, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ReportCard: {
|
||||
template: '<div class="report-card-mock" @click="$emit(\'select\', report)">{{ report.fileName }}</div>',
|
||||
props: ['report', 'isSelected'],
|
||||
emits: ['select']
|
||||
},
|
||||
FilePreview: {
|
||||
template: '<div class="file-preview-mock">{{ report?.fileName }}</div>',
|
||||
props: ['report', 'content']
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Select a report
|
||||
const cards = wrapper.findAll('.report-card-mock')
|
||||
await cards[0].trigger('click')
|
||||
await wrapper.vm.$nextTick()
|
||||
|
||||
// FilePreview should show the selected report
|
||||
const preview = wrapper.find('.file-preview-mock')
|
||||
expect(preview.exists()).toBe(true)
|
||||
})
|
||||
|
||||
it('should display report types via ReportCard', async () => {
|
||||
const wrapper = mount(ProjectDetail, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ReportCard: {
|
||||
template: '<div class="report-card-mock" @click="$emit(\'select\', report)">{{ report.fileType }}</div>',
|
||||
props: ['report', 'isSelected'],
|
||||
emits: ['select']
|
||||
},
|
||||
FilePreview: { template: '<div></div>' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Check that report types are passed to ReportCard
|
||||
const cards = wrapper.findAll('.report-card-mock')
|
||||
expect(cards[0].text()).toBe('html')
|
||||
expect(cards[1].text()).toBe('md')
|
||||
expect(cards[2].text()).toBe('pptx')
|
||||
})
|
||||
|
||||
it('should show loading state', async () => {
|
||||
const wrapper = mount(ProjectDetail, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ReportCard: { template: '<div></div>' },
|
||||
FilePreview: { template: '<div></div>' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Initially no loading spinner (mocked to false)
|
||||
const spinner = wrapper.find('.animate-spin')
|
||||
expect(spinner.exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('should display project name', async () => {
|
||||
const wrapper = mount(ProjectDetail, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ReportCard: { template: '<div></div>' },
|
||||
FilePreview: { template: '<div></div>' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Should display project name from route param
|
||||
expect(wrapper.text()).toContain('项目一')
|
||||
})
|
||||
|
||||
it('should display report count from mock data', async () => {
|
||||
// Note: The actual component does not display report count text.
|
||||
// This test verifies that reports are loaded correctly
|
||||
const wrapper = mount(ProjectDetail, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ReportCard: {
|
||||
template: '<div class="report-card-mock">{{ report.fileName }}</div>',
|
||||
props: ['report', 'isSelected']
|
||||
},
|
||||
FilePreview: { template: '<div></div>' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Component should display the reports loaded from mock data
|
||||
const cards = wrapper.findAll('.report-card-mock')
|
||||
expect(cards.length).toBe(3)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,215 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { createRouter, createMemoryHistory } from 'vue-router'
|
||||
import { ref } from 'vue'
|
||||
|
||||
// Mock the useApi composable
|
||||
vi.mock('@/composables/useApi', () => ({
|
||||
useApi: () => ({
|
||||
loading: ref(false),
|
||||
error: ref(null),
|
||||
fetchProjects: vi.fn().mockResolvedValue([
|
||||
{ id: 1, name: '项目一', description: '主要产品线', reportCount: 15 },
|
||||
{ id: 2, name: '项目二', description: '内部工具', reportCount: 8 },
|
||||
{ id: 3, name: '项目三', description: '客户定制', reportCount: 12 }
|
||||
]),
|
||||
fetchReports: vi.fn(),
|
||||
fetchReportContent: vi.fn()
|
||||
})
|
||||
}))
|
||||
|
||||
// Mock ProjectCard component
|
||||
vi.mock('@/components/ProjectCard.vue', () => ({
|
||||
default: {
|
||||
template: '<div class="project-card-mock" @click="$emit(\'click\')">{{ title }}</div>',
|
||||
props: ['title', 'description', 'imageUrl', 'reportCount', 'createdAt'],
|
||||
emits: ['click']
|
||||
}
|
||||
}))
|
||||
|
||||
import ProjectList from '@/pages/ProjectList.vue'
|
||||
|
||||
const router = createRouter({
|
||||
history: createMemoryHistory(),
|
||||
routes: [
|
||||
{ path: '/', component: { template: '<div>Home</div>' } },
|
||||
{ path: '/project/:id', component: { template: '<div>Project Detail</div>' } }
|
||||
]
|
||||
})
|
||||
|
||||
describe('ProjectList.vue', () => {
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks()
|
||||
router.push('/')
|
||||
await router.isReady()
|
||||
})
|
||||
|
||||
it('should render project list', async () => {
|
||||
const wrapper = mount(ProjectList, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ProjectCard: {
|
||||
template: '<div class="project-card-mock" @click="$emit(\'click\')">{{ title }}</div>',
|
||||
props: ['title', 'description', 'imageUrl', 'reportCount', 'createdAt'],
|
||||
emits: ['click']
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Wait for onMounted to complete
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Should render project cards
|
||||
const cards = wrapper.findAll('.project-card-mock')
|
||||
expect(cards.length).toBe(3)
|
||||
})
|
||||
|
||||
it('should show loading state initially', async () => {
|
||||
const wrapper = mount(ProjectList, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ProjectCard: { template: '<div></div>' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Check loading spinner exists (initial state)
|
||||
const spinner = wrapper.find('.animate-spin')
|
||||
expect(spinner.exists()).toBe(false) // Already loaded since we mock fetchProjects
|
||||
})
|
||||
|
||||
it('should navigate to project on click', async () => {
|
||||
const pushSpy = vi.spyOn(router, 'push')
|
||||
|
||||
const wrapper = mount(ProjectList, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ProjectCard: {
|
||||
template: '<div class="project-card-mock" @click="$emit(\'click\')">{{ title }}</div>',
|
||||
props: ['title', 'description', 'imageUrl', 'reportCount', 'createdAt'],
|
||||
emits: ['click']
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Click on a project card (first project div)
|
||||
const cards = wrapper.findAll('.project-card-mock')
|
||||
expect(cards.length).toBe(3)
|
||||
|
||||
// Trigger click on first card
|
||||
await cards[0].trigger('click')
|
||||
await wrapper.vm.$nextTick()
|
||||
|
||||
// Should have navigated to project/1
|
||||
expect(pushSpy).toHaveBeenCalledWith('/project/1')
|
||||
})
|
||||
|
||||
it('should display project information', async () => {
|
||||
const wrapper = mount(ProjectList, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ProjectCard: {
|
||||
template: '<div class="project-card-mock"><span class="title">{{ title }}</span></div>',
|
||||
props: ['title', 'description', 'imageUrl', 'reportCount', 'createdAt'],
|
||||
emits: ['click']
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Check that projects are rendered
|
||||
const cards = wrapper.findAll('.project-card-mock')
|
||||
expect(cards.length).toBe(3)
|
||||
|
||||
// Check first project card content
|
||||
const firstCard = cards[0]
|
||||
expect(firstCard.text()).toContain('项目一')
|
||||
})
|
||||
|
||||
it('should display report count in stats cards', async () => {
|
||||
const wrapper = mount(ProjectList, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ProjectCard: { template: '<div></div>' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Check total reports count (15 + 8 + 12 = 35)
|
||||
const statsText = wrapper.text()
|
||||
expect(statsText).toContain('35') // total reports
|
||||
})
|
||||
|
||||
it('should display report count from backend on stats cards', async () => {
|
||||
// The stats card should show total report count from all projects
|
||||
const wrapper = mount(ProjectList, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ProjectCard: { template: '<div></div>' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
// Total is 35 (15 + 8 + 12) from default mock data
|
||||
expect(wrapper.find('.text-4xl').isVisible()).toBe(true)
|
||||
const totalReportsText = wrapper.text()
|
||||
expect(totalReportsText).toMatch(/\d+/)
|
||||
})
|
||||
|
||||
it('should render project cards with correct props structure', async () => {
|
||||
const ProjectCardStub = {
|
||||
template: '<div class="project-card-stub">{{ title }}:{{ reportCount }}:{{ imageUrl }}</div>',
|
||||
props: ['title', 'description', 'imageUrl', 'reportCount', 'createdAt']
|
||||
}
|
||||
|
||||
const wrapper = mount(ProjectList, {
|
||||
global: {
|
||||
plugins: [router],
|
||||
stubs: {
|
||||
ProjectCard: ProjectCardStub
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.$nextTick()
|
||||
await new Promise(resolve => setTimeout(resolve, 0))
|
||||
|
||||
const cards = wrapper.findAll('.project-card-stub')
|
||||
expect(cards.length).toBe(3)
|
||||
expect(cards[0].text()).toContain('项目一')
|
||||
})
|
||||
|
||||
it('should aggregate totalReports correctly', async () => {
|
||||
const { computed } = await import('vue')
|
||||
const totalReports = computed(() => {
|
||||
const projects = [
|
||||
{ id: 1, reportCount: 10 },
|
||||
{ id: 2, reportCount: 5 },
|
||||
{ id: 3, reportCount: 3 }
|
||||
]
|
||||
return projects.reduce((sum, p) => sum + (p.reportCount || 0), 0)
|
||||
})
|
||||
expect(totalReports.value).toBe(18)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user