Skip to content

Commit

Permalink
fix(be): remove redundant problem controller handler (#1198)
Browse files Browse the repository at this point in the history
* fix(be): remove redundant problem controller handler

* fix(be): remove unused function

* fix: include problem tags in problem list

* docs: remove useless endpoint

---------

Co-authored-by: Jaemin Choi <[email protected]>
  • Loading branch information
Jaehyeon1020 and dotoleeoak authored Jan 17, 2024
1 parent d26897f commit d4854fc
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export class ProblemsResponseDto {
@Expose() difficulty: Level
@Expose() submissionCount: number
@Expose() acceptedRate: number
@Expose() tags: Partial<Tag>
@Expose() tags: Partial<Tag>[]
}
9 changes: 0 additions & 9 deletions backend/apps/client/src/problem/problem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@ export class ProblemController {
private readonly logger = new Logger(ProblemController.name)

constructor(private readonly problemService: ProblemService) {}
@Get()
async searchProblemTitle(@Query('search') search: string) {
try {
return await this.problemService.searchProblemTitle(search)
} catch (error) {
this.logger.error(error)
throw new InternalServerErrorException()
}
}

@Get()
async getProblems(
Expand Down
23 changes: 6 additions & 17 deletions backend/apps/client/src/problem/problem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ export class ProblemRepository {
where: {
groupId,
title: {
// TODO/FIXME: postgreSQL의 full text search를 사용하여 검색하려 했으나
// 그럴 경우 띄어쓰기를 기준으로 나눠진 단어 단위로만 검색이 가능하다
// ex) "hello world"를 검색하면 "hello"와 "world"로 검색이 된다.
// 글자 단위로 검색하기 위해서, 성능을 희생하더라도 contains를 사용하여 구현했다.
// 추후에 검색 성능을 개선할 수 있는 방법을 찾아보자
// 아니면 텍스트가 많은 field에서는 full-text search를 사용하고, 텍스트가 적은 field에서는 contains를 사용하는 방법도 고려해보자.
contains: search
}
},
Expand All @@ -105,23 +111,6 @@ export class ProblemRepository {
})
}

// TODO/FIXME: postgreSQL의 full text search를 사용하여 검색하려 했으나
// 그럴 경우 띄어쓰기를 기준으로 나눠진 단어 단위로만 검색이 가능하다
// ex) "hello world"를 검색하면 "hello"와 "world"로 검색이 된다.
// 글자 단위로 검색하기 위해서, 성능을 희생하더라도 contains를 사용하여 구현했다.
// 추후에 검색 성능을 개선할 수 있는 방법을 찾아보자
// 아니면 텍스트가 많은 field에서는 full-text search를 사용하고, 텍스트가 적은 field에서는 contains를 사용하는 방법도 고려해보자.
async searchProblemTitle(search: string): Promise<Partial<Problem>[]> {
return await this.prisma.problem.findMany({
where: {
title: {
contains: search
}
},
select: this.problemsSelectOption
})
}

async getProblemTags(problemId: number): Promise<Partial<Tag>[]> {
return (
await this.prisma.problemTag.findMany({
Expand Down
4 changes: 0 additions & 4 deletions backend/apps/client/src/problem/problem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ export class ProblemService {

return plainToInstance(ProblemsResponseDto, await Promise.all(problems))
}
async searchProblemTitle(search: string) {
const data = await this.problemRepository.searchProblemTitle(search)
return plainToInstance(ProblemsResponseDto, data)
}

async getProblem(problemId: number, groupId = OPEN_SPACE_ID) {
const data = await this.problemRepository.getProblem(problemId, groupId)
Expand Down
23 changes: 0 additions & 23 deletions collection/client/Problem/Search Problem Title/Succeed.bru

This file was deleted.

0 comments on commit d4854fc

Please sign in to comment.