-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from boostcampwm2023/server/feature/287
Recent_Played 테이블 생성 + API 수정
- Loading branch information
Showing
19 changed files
with
264 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
BaseEntity, | ||
Column, | ||
Entity, | ||
JoinColumn, | ||
ManyToOne, | ||
PrimaryGeneratedColumn, | ||
} from 'typeorm'; | ||
import { Music } from './music.entity'; | ||
import { User } from './user.entity'; | ||
|
||
@Entity({ name: 'recent_played' }) | ||
export class Recent_Played extends BaseEntity { | ||
@PrimaryGeneratedColumn() | ||
recent_played_id: number; | ||
|
||
@ManyToOne(() => Music, (music) => music.recent_played) | ||
@JoinColumn({ name: 'music_id' }) | ||
music: Music; | ||
|
||
@ManyToOne(() => User, (user) => user.recent_played) | ||
@JoinColumn({ name: 'user_id' }) | ||
user: User; | ||
|
||
@Column() | ||
played_at: Date; | ||
|
||
static async getRecentPlayedMusicByUserId( | ||
user_id: string, | ||
count: number, | ||
): Promise<Music[]> { | ||
return await this.find({ | ||
relations: { | ||
music: { user: true }, | ||
user: true, | ||
}, | ||
where: { | ||
user: { | ||
user_id, | ||
}, | ||
}, | ||
select: { | ||
recent_played_id: false, | ||
music: { | ||
music_id: true, | ||
title: true, | ||
music_file: true, | ||
cover: true, | ||
genre: true, | ||
user: { user_id: true, nickname: true }, | ||
}, | ||
}, | ||
order: { | ||
played_at: 'DESC', | ||
}, | ||
take: count, | ||
}).then((recent_played: Recent_Played[]) => | ||
recent_played.map((recent) => recent.music), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.