Skip to content

Commit 4d4d3a7

Browse files
authored
Merge pull request #338 from boostcampwm-2022/develop
v0.2.6 배포
2 parents fce0ffa + 97bc703 commit 4d4d3a7

File tree

48 files changed

+559
-427
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+559
-427
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# <img src="https://user-images.githubusercontent.com/79798443/206173852-a4baafe3-5de7-4afa-b494-f630d5170d54.svg"/> Devrank <img src="https://user-images.githubusercontent.com/79798443/206173852-a4baafe3-5de7-4afa-b494-f630d5170d54.svg"/>
1+
<div align="center">
2+
<h1> <img src="https://user-images.githubusercontent.com/79798443/206173852-a4baafe3-5de7-4afa-b494-f630d5170d54.svg"/> Devrank <img src="https://user-images.githubusercontent.com/79798443/206173852-a4baafe3-5de7-4afa-b494-f630d5170d54.svg"/></h1>
23

34
[![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fboostcampwm-2022%2Fweb21-devrank&count_bg=%23C455F9&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)
45

@@ -7,6 +8,11 @@
78
![redis](https://img.shields.io/badge/redis-6.2.5-%23DC382D?style=flat&logo=Redis)
89
![mongoDB](https://img.shields.io/badge/mongoDB-5.0.14-%2347A248?style=flat&logo=MongoDB)
910
![docker](https://img.shields.io/badge/docker-20.10.21-%232496ED?style=flat&logo=Docker)
11+
![React](https://img.shields.io/badge/react-18.2.0-%2361DAFB?style=flat&logo=React)
12+
![Next.js](https://img.shields.io/badge/next-13.0.3-%23000000?style=flat&logo=Next.js)
13+
14+
</div>
15+
1016

1117
![Frame 12023](https://user-images.githubusercontent.com/79798443/206137429-5cb1d269-4bec-4aaa-85ad-053ae564c625.png)
1218

backend/libs/consts/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ export const PAGE_UNIT_COUNT = 10;
1313
export const RANK_CACHE_DELAY = 12 * HOUR;
1414

1515
export const GITHUB_API_DELAY = 1500; // ms
16+
17+
export const KR_TIME_DIFF = 9 * HOUR * 1000; // ms

backend/src/app.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export class AppController {
77

88
@Get()
99
getHello(): string {
10-
return this.appService.getHello();
10+
return this.appService.healthCheck();
1111
}
1212
}

backend/src/app.service.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
import { Injectable } from '@nestjs/common';
1+
import { logger } from '@libs/utils';
2+
import { Injectable, OnApplicationBootstrap } from '@nestjs/common';
3+
import { UserRepository } from './user/user.repository';
24

35
@Injectable()
4-
export class AppService {
5-
getHello(): string {
6-
return 'Hello World!';
6+
export class AppService implements OnApplicationBootstrap {
7+
constructor(private readonly userRepository: UserRepository) {}
8+
9+
async onApplicationBootstrap() {
10+
const allUsers = await this.userRepository.findAll({}, false, ['lowerUsername', 'score', 'tier', 'history']);
11+
await Promise.all(
12+
allUsers
13+
.filter((user) => user.history)
14+
.map(({ lowerUsername, score, tier }) => this.userRepository.updateCachedUserRank(tier, score, lowerUsername)),
15+
);
16+
logger.log('all user score loaded in Redis.');
17+
}
18+
19+
healthCheck(): string {
20+
return 'devrank server is listening!';
721
}
822
}

backend/src/auth/auth.service.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,6 @@ export class AuthService {
7474
await this.authRepository.create(id, refreshToken);
7575
}
7676

77-
// async replaceRefreshToken(id: string, refreshToken: string, githubToken: string): Promise<string> {
78-
// const storedRefreshToken = await this.authRepository.findRefreshTokenById(id);
79-
// if (refreshToken !== storedRefreshToken) {
80-
// throw new UnauthorizedException('invalid token.');
81-
// }
82-
// const newRefreshToken = this.issueRefreshToken(id, githubToken);
83-
// await this.authRepository.create(id, newRefreshToken);
84-
// return newRefreshToken;
85-
// }
86-
8777
async deleteRefreshToken(id: string): Promise<void> {
8878
await this.authRepository.delete(id);
8979
}

backend/src/ranking/dto/ranking-user.dto.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,26 @@ export class RankingUserDto {
2323
@ApiProperty()
2424
tier: string;
2525

26+
@ApiProperty()
27+
totalRank?: number;
28+
29+
@ApiProperty()
30+
tierRank?: number;
31+
2632
@ApiProperty()
2733
primaryLanguages: string[];
2834

2935
of(user: UserDto): RankingUserDto {
3036
this.id = user.id;
3137
this.username = user.username;
3238
this.avatarUrl = user.avatarUrl;
33-
this.score = user.commitsScore + user.followersScore + user.issuesScore;
39+
this.score = user.score;
3440
this.tier = user.tier;
3541
this.dailyViews = user.dailyViews;
3642
this.scoreDifference = user.scoreDifference;
3743
this.primaryLanguages = user.primaryLanguages;
44+
this.totalRank = user.totalRank;
45+
this.tierRank = user.tierRank;
3846
return this;
3947
}
4048
}

backend/src/ranking/ranking.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export class RankingService {
1919
if (!paginationResult?.metadata || paginationResult?.users.length === 0) {
2020
throw new NotFoundException('user not found.');
2121
}
22+
for (const user of paginationResult.users) {
23+
const [totalRank, tierRank] = await this.userRepository.findCachedUserRank(user.tier, user.lowerUsername);
24+
user.totalRank = totalRank;
25+
user.tierRank = tierRank;
26+
}
27+
2228
const lastPage = Math.ceil(paginationResult.metadata.total / limit);
2329
const lastPageGroupNumber = Math.ceil(lastPage / PAGE_UNIT_COUNT);
2430
const pageGroupNumber = Math.ceil(page / PAGE_UNIT_COUNT);

backend/src/user/dto/rank.dto.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

backend/src/user/dto/user.dto.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export class UserDto {
7878
@ApiProperty({ type: History })
7979
history?: History;
8080

81+
@ApiProperty()
82+
totalRank?: number;
83+
84+
@ApiProperty()
85+
tierRank?: number;
86+
8187
@ApiProperty({ isArray: true, type: PinnedRepositoryDto })
8288
pinnedRepositories?: PinnedRepositoryDto[];
8389

backend/src/user/user.controller.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
Controller,
77
DefaultValuePipe,
88
Get,
9-
NotFoundException,
109
Param,
1110
ParseIntPipe,
1211
Patch,

0 commit comments

Comments
 (0)