Skip to content

Commit

Permalink
Refactor(#529): 트랜잭션 메서드 이름 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
j-zzi committed Jun 18, 2024
1 parent f00c8ef commit 0060e47
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
8 changes: 4 additions & 4 deletions src/lecture/repositories/popular-lecture.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import { PrismaService } from '@src/prisma/prisma.service';
export class PopularLectureRepository {
constructor(private readonly prismaService: PrismaService) {}

async trxReadLectureReservationCount(lectureId: number): Promise<number> {
async readLectureReservationCount(lectureId: number): Promise<number> {
return await this.prismaService.reservation.count({
where: { lectureSchedule: { lectureId } },
});
}

async trxReadLectureLikesCount(lectureId: number): Promise<number> {
async readLectureLikesCount(lectureId: number): Promise<number> {
return await this.prismaService.likedLecture.count({
where: { lectureId },
});
}

async trxReadLectureWithUserId(
async readLectureWithUserId(
lectureId: number,
userId?: number,
): Promise<Lecture> {
Expand All @@ -44,7 +44,7 @@ export class PopularLectureRepository {
});
}

async trxReadLecture(lectureId: number): Promise<Lecture> {
async readLecture(lectureId: number): Promise<Lecture> {
return await this.prismaService.lecture.findFirst({
where: { id: lectureId, isActive: true },
include: {
Expand Down
15 changes: 6 additions & 9 deletions src/lecture/services/popular-lecture.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@ export class PopularLectureService {

for (const lecture of lectures) {
const reservationCount =
await this.popularLectureRepository.trxReadLectureReservationCount(
await this.popularLectureRepository.readLectureReservationCount(
lecture.id,
);
const likesCount =
await this.popularLectureRepository.trxReadLectureLikesCount(
lecture.id,
);
await this.popularLectureRepository.readLectureLikesCount(lecture.id);
const popularScore = this.createPopularScore(
lecture.id,
reservationCount,
Expand All @@ -47,11 +45,10 @@ export class PopularLectureService {
const popularLectures = [];

for (const popularLecture of topEightPopularScores) {
const lecture =
await this.popularLectureRepository.trxReadLectureWithUserId(
popularLecture.id,
userId,
);
const lecture = await this.popularLectureRepository.readLectureWithUserId(
popularLecture.id,
userId,
);

popularLectures.push(new LectureDto(lecture));
}
Expand Down
6 changes: 3 additions & 3 deletions src/lecturer/repositories/popular-lecturer.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import { Lecturer } from '@prisma/client';
export class PopularLecturerRepository {
constructor(private readonly prismaService: PrismaService) {}

async trxReadLecturerReservationCount(lecturerId: number): Promise<number> {
async readLecturerReservationCount(lecturerId: number): Promise<number> {
return await this.prismaService.reservation.count({
where: { lectureSchedule: { lecture: { lecturerId } } },
});
}

async trxReadLecturerLikesCount(lecturerId: number): Promise<number> {
async readLecturerLikesCount(lecturerId: number): Promise<number> {
return await this.prismaService.likedLecturer.count({
where: { lecturerId },
});
}

async trxReadLecturerWithLecturerId(lecturerId: number): Promise<Lecturer> {
async readLecturerWithLecturerId(lecturerId: number): Promise<Lecturer> {
return await this.prismaService.lecturer.findFirst({
where: { id: lecturerId },
include: { lecturerProfileImageUrl: true },
Expand Down
7 changes: 3 additions & 4 deletions src/lecturer/services/popular-lecturer.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PrismaService } from '@src/prisma/prisma.service';
import { PopularLecturerRepository } from './../repositories/popular-lecturer.repository';
import { Injectable } from '@nestjs/common';
import { PrismaTransaction } from '@src/common/interface/common-interface';
import { LecturerDto } from '@src/common/dtos/lecturer.dto';

@Injectable()
Expand All @@ -24,11 +23,11 @@ export class PopularLecturerService {

for (const lecturer of lecturers) {
const reservationCount =
await this.popularLecturerRepository.trxReadLecturerReservationCount(
await this.popularLecturerRepository.readLecturerReservationCount(
lecturer.id,
);
const likesCount =
await this.popularLecturerRepository.trxReadLecturerLikesCount(
await this.popularLecturerRepository.readLecturerLikesCount(
lecturer.id,
);
const popularScore = this.createPopularScore(
Expand All @@ -47,7 +46,7 @@ export class PopularLecturerService {

for (const popularLecturer of topTenPopularScores) {
const lecturer =
await this.popularLecturerRepository.trxReadLecturerWithLecturerId(
await this.popularLecturerRepository.readLecturerWithLecturerId(
popularLecturer.id,
);

Expand Down

0 comments on commit 0060e47

Please sign in to comment.