Skip to content

Commit

Permalink
Merge pull request #109 from CodeVac513/fix/login-feed-bugfix
Browse files Browse the repository at this point in the history
🐛 fix: 올바른 ID가 아닌 경우 예외 처리 추가, swagger 적용 오류 수정, feed 전송 개수 수정
  • Loading branch information
CodeVac513 authored Nov 18, 2024
2 parents d229888 + f9564af commit 6975055
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion server/src/admin/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { RegisterAdminDto } from './dto/register-admin.dto';
import { ApiTags } from '@nestjs/swagger';
import { ApiPostLoginAdmin, ApiPostRegisterAdmin } from './admin.api-docs';
import { ApiResponse } from '../common/response/common.response';
import type { LoginAdminDto } from './dto/login-admin.dto';
import { LoginAdminDto } from './dto/login-admin.dto';

@ApiTags('Admin')
@Controller('admin')
Expand Down
2 changes: 1 addition & 1 deletion server/src/admin/admin.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class AdminService {
where: { loginId },
});

if (!(await bcrypt.compare(password, admin.password))) {
if (!admin || !(await bcrypt.compare(password, admin.password))) {
throw new UnauthorizedException('아이디 혹은 비밀번호가 잘못되었습니다.');
}

Expand Down
10 changes: 3 additions & 7 deletions server/src/feed/feed.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@ export class FeedController {
}),
)
async getFeedList(@Query() queryFeedDto: QueryFeedDto) {
const feedList = await this.feedService.getFeedList(queryFeedDto);
const hasMore = this.feedService.existNextFeed(
feedList,
queryFeedDto.limit,
return ApiResponse.responseWithData(
'피드 조회 완료',
await this.feedService.getFeedData(queryFeedDto),
);
const lastId = this.feedService.getLastIdFromFeedList(feedList);
const data = { result: feedList, lastId, hasMore };
return ApiResponse.responseWithData('피드 조회 완료', data);
}
}
12 changes: 8 additions & 4 deletions server/src/feed/feed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ import { Feed } from './feed.entity';
@Injectable()
export class FeedService {
constructor(private readonly feedRepository: FeedRepository) {}
async getFeedList(queryFeedDto: QueryFeedDto) {

async getFeedData(queryFeedDto: QueryFeedDto) {
const result = await this.feedRepository.findFeed(queryFeedDto);
return result;
const hasMore = this.existNextFeed(result, queryFeedDto.limit);
if (hasMore) result.pop();
const lastId = this.getLastIdFromFeedList(result);
return { result, lastId, hasMore };
}

existNextFeed(feedList: Feed[], limit: number) {
private existNextFeed(feedList: Feed[], limit: number) {
return feedList.length > limit;
}

getLastIdFromFeedList(feedList: Feed[]) {
private getLastIdFromFeedList(feedList: Feed[]) {
if (feedList.length === 0) return 0;
const lastFeed = feedList[feedList.length - 1];
return lastFeed.id;
Expand Down

0 comments on commit 6975055

Please sign in to comment.