|
|
@@ -31,23 +31,29 @@ export class RecordsController {
|
|
|
const filename = data.filename
|
|
|
const mimeType = data.mimetype
|
|
|
|
|
|
- // 从表单字段中获取描述
|
|
|
+ // 从表单字段中获取描述和 fishId
|
|
|
const description = (data.fields?.description as any)?.value || ''
|
|
|
+ const fishId = (data.fields?.fishId as any)?.value || ''
|
|
|
+
|
|
|
+ if (!fishId) {
|
|
|
+ return reply.code(400).send({ message: 'FishId 不能为空' })
|
|
|
+ }
|
|
|
|
|
|
// 上传文件到OSS
|
|
|
const uploadResult = await this.fileService.uploadFile(buffer, filename, mimeType, {
|
|
|
folder: 'tweb',
|
|
|
- maxSize: 50 * 1024 * 1024 // 50MB
|
|
|
+ maxSize: 500 * 1024 * 1024 // 500MB
|
|
|
})
|
|
|
|
|
|
// 创建记录
|
|
|
- const record = await this.recordsService.create(uploadResult.url, description)
|
|
|
+ const record = await this.recordsService.create(fishId, uploadResult.url, description)
|
|
|
|
|
|
return reply.code(201).send({
|
|
|
message: '文件上传并创建记录成功',
|
|
|
data: {
|
|
|
record: {
|
|
|
id: record.id,
|
|
|
+ fishId: record.fishId,
|
|
|
url: record.url,
|
|
|
description: record.description,
|
|
|
createdAt: record.createdAt,
|
|
|
@@ -74,17 +80,18 @@ export class RecordsController {
|
|
|
|
|
|
async create(request: FastifyRequest<{ Body: CreateRecordsBody }>, reply: FastifyReply) {
|
|
|
try {
|
|
|
- const { url, description } = request.body
|
|
|
+ const { fishId, url, description } = request.body
|
|
|
|
|
|
- if (!url || !description) {
|
|
|
- return reply.code(400).send({ message: 'URL和描述不能为空' })
|
|
|
+ if (!fishId || !url || !description) {
|
|
|
+ return reply.code(400).send({ message: 'FishId、URL和描述不能为空' })
|
|
|
}
|
|
|
|
|
|
- const record = await this.recordsService.create(url, description)
|
|
|
+ const record = await this.recordsService.create(fishId, url, description)
|
|
|
|
|
|
return reply.code(201).send({
|
|
|
record: {
|
|
|
id: record.id,
|
|
|
+ fishId: record.fishId,
|
|
|
url: record.url,
|
|
|
description: record.description,
|
|
|
createdAt: record.createdAt,
|
|
|
@@ -98,9 +105,9 @@ export class RecordsController {
|
|
|
|
|
|
async list(request: FastifyRequest<{ Querystring: ListRecordsQuery }>, reply: FastifyReply) {
|
|
|
try {
|
|
|
- const { page, size, url, description } = request.query
|
|
|
+ const { page, size, fishId, url, description } = request.query
|
|
|
|
|
|
- const result = await this.recordsService.findAll(page, size, url, description)
|
|
|
+ const result = await this.recordsService.findAll(page, size, fishId, url, description)
|
|
|
|
|
|
return reply.send(result)
|
|
|
} catch (error) {
|
|
|
@@ -121,6 +128,7 @@ export class RecordsController {
|
|
|
return reply.send({
|
|
|
record: {
|
|
|
id: record.id,
|
|
|
+ fishId: record.fishId,
|
|
|
url: record.url,
|
|
|
description: record.description,
|
|
|
createdAt: record.createdAt,
|
|
|
@@ -137,7 +145,7 @@ export class RecordsController {
|
|
|
|
|
|
async update(request: FastifyRequest<{ Body: UpdateRecordsBody }>, reply: FastifyReply) {
|
|
|
try {
|
|
|
- const { id, url, description } = request.body
|
|
|
+ const { id, fishId, url, description } = request.body
|
|
|
|
|
|
if (!id) {
|
|
|
return reply.code(400).send({ message: 'ID不能为空' })
|
|
|
@@ -149,11 +157,12 @@ export class RecordsController {
|
|
|
return reply.code(404).send({ message: '记录不存在' })
|
|
|
}
|
|
|
|
|
|
- const updatedRecord = await this.recordsService.updateRecord(id, { url, description })
|
|
|
+ const updatedRecord = await this.recordsService.updateRecord(id, { fishId, url, description })
|
|
|
|
|
|
return reply.send({
|
|
|
record: {
|
|
|
id: updatedRecord.id,
|
|
|
+ fishId: updatedRecord.fishId,
|
|
|
url: updatedRecord.url,
|
|
|
description: updatedRecord.description,
|
|
|
createdAt: updatedRecord.createdAt,
|