Skip to content

Commit

Permalink
v2.1.3
Browse files Browse the repository at this point in the history
v2.1.3
  • Loading branch information
hoonyworld authored Sep 29, 2024
2 parents 318d1ce + b7a2593 commit e54f318
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 83 deletions.
8 changes: 7 additions & 1 deletion main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'

// lombok
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'

developmentOnly 'org.springframework.boot:spring-boot-devtools'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.6.0'
implementation 'org.springframework.boot:spring-boot-starter-validation'
Expand Down
5 changes: 0 additions & 5 deletions main/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,3 @@ management:
metrics:
export:
enabled: true

logging:
level:
org.hibernate.SQL: DEBUG # Hibernate의 SQL 쿼리 로그 레벨 설정
org.hibernate.type: TRACE # SQL 파라미터 바인딩을 보기 위한 타입 정보 로그 출력
7 changes: 7 additions & 0 deletions main/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>

<springProfile name="test">
<include resource="console-appender.xml"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</springProfile>
</configuration>
137 changes: 60 additions & 77 deletions server/src/auth/v0/auth-v0.service.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,80 @@
import {
HttpException,
HttpStatus,
Injectable,
UnauthorizedException,
} from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { JwtService } from '@nestjs/jwt';
import { PlaygroundService } from 'src/internal-api/playground/playground.service';
import { UserActivity } from 'src/entity/user/interface/user-activity.interface';
import { AuthV0TokenDto } from './dto/auth-v0-token.dto';
import { UserRepository } from 'src/entity/user/user.repository';
import { UserPart } from 'src/entity/user/enum/user-part.enum';
import {HttpException, HttpStatus, Injectable, UnauthorizedException,} from '@nestjs/common';
import {InjectRepository} from '@nestjs/typeorm';
import {JwtService} from '@nestjs/jwt';
import {PlaygroundService} from 'src/internal-api/playground/playground.service';
import {UserActivity} from 'src/entity/user/interface/user-activity.interface';
import {AuthV0TokenDto} from './dto/auth-v0-token.dto';
import {UserRepository} from 'src/entity/user/user.repository';
import {UserPart} from 'src/entity/user/enum/user-part.enum';

@Injectable()
export class AuthV0Service {
constructor(
@InjectRepository(UserRepository)
private userRepository: UserRepository,

private playgroundService: PlaygroundService,
private jwtService: JwtService,
) {}
constructor(
@InjectRepository(UserRepository)
private userRepository: UserRepository,
private playgroundService: PlaygroundService,
private jwtService: JwtService,
) {
}

async loginUser(authTokenDTO: AuthV0TokenDto) {
const { authToken } = authTokenDTO;
async loginUser(authTokenDTO: AuthV0TokenDto) {
const {authToken} = authTokenDTO;

try {
const { id, name, profileImage } = await this.playgroundService.getUser(
authToken,
);
const user = await this.userRepository.getUserByOrgId(id);
const userId: number = await (async () => {
if (!user) {
const newUser = await this.userRepository.save({
orgId: id,
name,
profileImage,
});
try {
const {id, name, profileImage} = await this.playgroundService.getUser(authToken);

return newUser.id;
}
let user = await this.userRepository.getUserByOrgId(id);

return user.id;
})();
if (!user) {
user = await this.userRepository.save({
orgId: id,
name,
profileImage,
});
}

const playgroundUserProfile = await this.playgroundService.getUserProfile(
authToken,
);
const playgroundUserProfile = await this.playgroundService.getUserProfile(authToken);
const playgroundUserActivities = await this.playgroundService.getUserActivities(authToken, user.orgId);


const playgroundUserActivities = await this.playgroundService.getUserActivities(
authToken, user.orgId
);
const activities: UserActivity[] = playgroundUserActivities[0].activities.flatMap((activity) => {
const [generationString, partString] = activity.cardinalInfo.split(',');
const generation = parseInt(generationString);
const partKey = getKeyByValue(UserPart, partString);
const part = UserPart[partKey];

const activities: UserActivity[] = playgroundUserActivities[0].activities.flatMap((activity) => {
const [generationString, partString] = activity.cardinalInfo.split(',');
const generation = parseInt(generationString);
const partKey = getKeyByValue(UserPart, partString);
const part = UserPart[partKey];
return {
generation: generation,
part: part,
};
});

return {
generation: generation,
part: part
};
});

const phone = playgroundUserProfile.phone
? playgroundUserProfile.phone
: null;
const phone = playgroundUserProfile.phone
? playgroundUserProfile.phone
: null;

await this.userRepository.update(
{ id: userId },
{ activities, profileImage, name, phone },
);
await this.userRepository.update(
{id: user.id},
{activities, profileImage, name, phone},
);

const payload = { name, id: userId };
const accessToken = this.jwtService.sign(payload);
const payload = {name, id: user.id};
const accessToken = this.jwtService.sign(payload);

return { accessToken };
} catch (error) {
console.log(error);
if (error.response?.status === HttpStatus.UNAUTHORIZED) {
throw new UnauthorizedException({ message: '유효하지 않은 토큰' });
}
return {accessToken};
} catch (error) {
console.log(error);
if (error.response?.status === HttpStatus.UNAUTHORIZED) {
throw new UnauthorizedException({message: '유효하지 않은 토큰'});
}

throw new HttpException(
{ message: '로그인 서버 에러' },
HttpStatus.INTERNAL_SERVER_ERROR,
);
throw new HttpException(
{message: '로그인 서버 에러'},
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}
}

function getKeyByValue(object: any, value: string) {
return Object.keys(object).find(key => object[key] === value);
return Object.keys(object).find(key => object[key] === value);
}

0 comments on commit e54f318

Please sign in to comment.