Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cafe/cafe.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ export class CafeRepository {
async getSwipeCafeList(
userUuid: string,
query: GetSwipeCafeListDto,
page: number,
take = 20,
): Promise<{ data: GeneralCafeResDto[]; hasNextPage: boolean }> {
const page = query.page;
const take = query.take;

const skip = (page - 1) * take;
const limit = take + 1; // +1 to check for the next page
const DISLIKE_EXPIRE_DAYS = 7;
Expand Down Expand Up @@ -145,7 +146,6 @@ export class CafeRepository {

return {
data: rawResult,

hasNextPage,
};
}
Expand Down
22 changes: 10 additions & 12 deletions src/cafe/cafe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,33 +106,31 @@ export class CafeService {
async getSwipeCafeList(
user: User,
query: GetSwipeCafeListDto,
page = 1,
take = 20,
): Promise<SwipeCafeListResDto> {
// GPS coordinates Validation
if (!this.isValidKoreanGPS(query.latitude, query.longitude)) {
throw new BadRequestException(
'Wrong GPS coordinates (out of South Korea)',
);
}

const { data, hasNextPage } = await this.cafeRepository.getSwipeCafeList(
user.uuid,
query,
page,
take,
);

if (page < 1) {
// Pagination values Validation
if (query.page < 1) {
throw new BadRequestException('Page must be greater than 0');
}

if (take < 1 || take > 20) {
if (query.take < 1 || query.take > 20) {
throw new BadRequestException('Take must be between 1 and 20');
}

const { data, hasNextPage } = await this.cafeRepository.getSwipeCafeList(
user.uuid,
query,
);

const result: SwipeCafeListResDto = {
data,
nextPage: page + 1,
nextPage: query.page + 1,
cafeCount: data.length,
hasNextPage,
};
Expand Down
2 changes: 1 addition & 1 deletion src/cafe/dto/req/getSwipeCafeList.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class GetSwipeCafeListDto extends GetNearCafeListDto {
@IsNumber()
@IsOptional()
@Type(() => Number)
page: number;
page: number = 1;

@ApiProperty({
example: 20,
Expand Down