Add create date on history items

This commit is contained in:
2023-05-23 16:00:59 +09:00
parent 7adfb6e294
commit 712c08303a
5 changed files with 63 additions and 37 deletions

View File

@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "SearchHistory" ADD COLUMN "searchDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
-- AlterTable
ALTER TABLE "SongHistory" ADD COLUMN "playDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;

View File

@@ -10,38 +10,39 @@ datasource db {
}
model User {
id Int @id @default(autoincrement())
username String @unique
password String
email String
isGuest Boolean @default(false)
partyPlayed Int @default(0)
LessonHistory LessonHistory[]
SongHistory SongHistory[]
searchHistory SearchHistory[]
settings UserSettings?
id Int @id @default(autoincrement())
username String @unique
password String
email String
isGuest Boolean @default(false)
partyPlayed Int @default(0)
LessonHistory LessonHistory[]
SongHistory SongHistory[]
searchHistory SearchHistory[]
settings UserSettings?
}
model UserSettings {
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int @unique
pushNotification Boolean @default(true)
emailNotification Boolean @default(true)
trainingNotification Boolean @default(true)
newSongNotification Boolean @default(true)
recommendations Boolean @default(true)
weeklyReport Boolean @default(true)
leaderBoard Boolean @default(true)
showActivity Boolean @default(true)
id Int @id @default(autoincrement())
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId Int @unique
pushNotification Boolean @default(true)
emailNotification Boolean @default(true)
trainingNotification Boolean @default(true)
newSongNotification Boolean @default(true)
recommendations Boolean @default(true)
weeklyReport Boolean @default(true)
leaderBoard Boolean @default(true)
showActivity Boolean @default(true)
}
model SearchHistory {
id Int @id @default(autoincrement())
query String
type String
userId Int?
user User? @relation(fields: [userId], references: [id])
id Int @id @default(autoincrement())
query String
type String
userId Int?
user User? @relation(fields: [userId], references: [id])
searchDate DateTime @default(now())
}
model Song {
@@ -60,13 +61,14 @@ model Song {
}
model SongHistory {
id Int @id @default(autoincrement())
song Song @relation(fields: [songID], references: [id], onDelete: Cascade, onUpdate: Cascade)
id Int @id @default(autoincrement())
song Song @relation(fields: [songID], references: [id], onDelete: Cascade, onUpdate: Cascade)
songID Int
user User @relation(fields: [userID], references: [id], onDelete: Cascade, onUpdate: Cascade)
user User @relation(fields: [userID], references: [id], onDelete: Cascade, onUpdate: Cascade)
userID Int
score Int
difficulties Json
playDate DateTime @default(now())
}
model Genre {

View File

@@ -1,4 +1,15 @@
import { Body, Controller, DefaultValuePipe, Get, HttpCode, ParseIntPipe, Post, Query, Request, UseGuards } from '@nestjs/common';
import {
Body,
Controller,
DefaultValuePipe,
Get,
HttpCode,
ParseIntPipe,
Post,
Query,
Request,
UseGuards,
} from '@nestjs/common';
import { ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger';
import { SearchHistory, SongHistory } from '@prisma/client';
import { JwtAuthGuard } from 'src/auth/jwt-auth.guard';
@@ -6,9 +17,9 @@ import { SongHistoryDto } from './dto/SongHistoryDto';
import { HistoryService } from './history.service';
@Controller('history')
@ApiTags("history")
@ApiTags('history')
export class HistoryController {
constructor(private readonly historyService: HistoryService) {}
constructor(private readonly historyService: HistoryService) { }
@Get()
@HttpCode(200)
@@ -22,7 +33,7 @@ export class HistoryController {
return this.historyService.getHistory(req.user.id, { skip, take });
}
@Get("search")
@Get('search')
@HttpCode(200)
@UseGuards(JwtAuthGuard)
@ApiUnauthorizedResponse({ description: 'Invalid token' })

View File

@@ -6,7 +6,7 @@ import { SongHistoryDto } from './dto/SongHistoryDto';
@Injectable()
export class HistoryService {
constructor(private prisma: PrismaService) {}
constructor(private prisma: PrismaService) { }
async createSongHistoryRecord({
songID,
@@ -46,6 +46,7 @@ export class HistoryService {
): Promise<SongHistory[]> {
return this.prisma.songHistory.findMany({
where: { user: { id: playerId } },
orderBy: { playDate: 'asc' },
skip,
take,
});
@@ -75,6 +76,7 @@ export class HistoryService {
): Promise<SearchHistory[]> {
return this.prisma.searchHistory.findMany({
where: { user: { id: playerId } },
orderBy: { searchDate: 'asc' },
skip,
take,
});

View File

@@ -63,10 +63,10 @@ Create and get a duplicated history record
Array response body
Integer $[0].userID ${userID}
Integer $[0].songID ${song.body.id}
Integer $[0].score 55
Integer $[0].score 65
Integer $[1].userID ${userID}
Integer $[1].songID ${song.body.id}
Integer $[1].score 65
Integer $[1].score 55
[Teardown] Run Keywords DELETE /users/${userID}
... AND DELETE /song/${song.body.id}
@@ -79,11 +79,17 @@ Create and get a search history record
Output
Integer response status 404
GET /search/song/tata
Output
Integer response status 404
&{res}= GET /history/search
Output
Integer response status 200
Array response body
String $[0].type "song"
String $[0].query "toto"
String $[0].query "tata"
String $[1].type "song"
String $[1].query "toto"
[Teardown] DELETE /users/${userID}