Skip to content

Commit

Permalink
fix: bugs fix
Browse files Browse the repository at this point in the history
- visited ondelete cascade
- visited count
  • Loading branch information
hongloans committed Jun 28, 2022
1 parent 771c432 commit 4418d45
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
4 changes: 3 additions & 1 deletion back/src/landmarks/landmarks.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class Landmark {
@Column({ nullable: true })
latitude: string;

@OneToMany(() => Visited, (visited) => visited.landmark)
@OneToMany(() => Visited, (visited) => visited.landmark, {
cascade: true,
})
visited: Visited[];
}
14 changes: 14 additions & 0 deletions back/src/landmarks/landmarks.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,18 @@ export class LandmarksService {
console.log(error);
}
}

async getLandmarkByLandmarkName(param): Promise<any> {
try {
const landmark = await this.landmarksRepository
.createQueryBuilder('landmark')
.select('landmark_id')
.where('landmark.name = :name', { name: param.landmark_name })
.getRawOne();

return landmark;
} catch (error) {
console.log(error);
}
}
}
4 changes: 3 additions & 1 deletion back/src/users/users.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export class Users extends BaseEntity {
@Exclude() // 민감한 데이터는 응답에서 제외 가능
hashedRefreshToken?: string;

@OneToMany(() => Visited, (visited) => visited.user)
@OneToMany(() => Visited, (visited) => visited.user, {
cascade: true,
})
visited: Visited[];

@OneToMany(() => Boards, (board) => board.user_id, {
Expand Down
20 changes: 20 additions & 0 deletions back/src/visited/visited.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ export class VisitedController {
res.status(HttpStatus.OK).json(result);
}

@Get('/count/:landmark_name')
@ApiOperation({ summary: '방문지 조회 with landmark_name' })
@ApiResponse({
status: 200,
description: 'Return visited by landmark_name',
})
async getVisitedByLandmarkName(
@Res() res: any,
@Param()
landmark_name: string,
): Promise<void> {
const landmark = await this.landmarksService.getLandmarkByLandmarkName(
landmark_name,
);

const result = await this.visitedService.getCount(landmark.landmark_id);

res.status(HttpStatus.OK).json(result);
}

@Get('/images/:imageId')
@ApiOperation({ summary: '방문지 사진 받아오기' })
@ApiResponse({
Expand Down
4 changes: 2 additions & 2 deletions back/src/visited/visited.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export class Visited {

@ManyToOne(() => Landmark, (landmark) => landmark.visited, {
eager: true,
// onDelete: 'CASCADE',
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'landmark_id' })
landmark: Landmark;

@ManyToOne(() => Users, (user) => user.visited, {
eager: true,
// onDelete: 'CASCADE',
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'user_id' })
user: Users;
Expand Down

0 comments on commit 4418d45

Please sign in to comment.