Skip to content

Commit

Permalink
fix: home other profile format
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeahxx19 committed Sep 11, 2024
1 parent 5f78975 commit 33256f6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
16 changes: 15 additions & 1 deletion src/decorators/swagger/home.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import {
ApiBody,
ApiOkResponse,
ApiOperation,
ApiParam,
ApiResponse,
} from '@nestjs/swagger';
import { UserProfileDto } from 'src/domain/dtos/user.dto';
import { HomeInfoResponseDto, likeHomeAnswerDto } from 'src/domain/home/dtos';
import { RandomUserDto } from 'src/domain/home/dtos/homInfoResponse.dto';

type HomeEndPoints = 'default' | 'like' | 'version' | 'random';
type HomeEndPoints = 'default' | 'like' | 'version' | 'random' | 'otherProfile';
export function Docs(endpoint: HomeEndPoints) {
switch (endpoint) {
case 'default':
Expand Down Expand Up @@ -45,5 +47,17 @@ export function Docs(endpoint: HomeEndPoints) {
}),
ApiResponse({ type: RandomUserDto, isArray: true }),
);
case 'otherProfile':
return applyDecorators(
ApiOperation({
summary: '다른 사용자 프로필 정보',
}),
ApiParam({
name: 'other',
description: '다른 사람 id',
type: Number,
}),
ApiResponse({ type: UserProfileDto }),
);
}
}
16 changes: 5 additions & 11 deletions src/domain/home/home.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@ import { JwtPayload } from 'src/interfaces/auth';
import { HomeInfoResponseDto, likeHomeAnswerDto } from './dtos';
import { User } from 'src/decorators/accessUser.decorator';
import { Docs } from 'src/decorators/swagger/home.decorator';
import { OtherProfileDocs } from 'src/decorators/swagger/blurting.decorator';
import { BlurtingProfileDto } from '../blurting/dtos';
import { BlurtingService } from '../blurting/blurting.service';
import { UserProfileDto } from '../dtos/user.dto';

@Controller('home')
@ApiTags('home')
export class HomeController {
constructor(
private readonly homeService: HomeService,
private readonly blurtingService: BlurtingService,
) {}
constructor(private readonly homeService: HomeService) {}

@Get('/')
@UseGuards(AuthGuard('access'))
Expand All @@ -30,13 +25,12 @@ export class HomeController {

@Get('/profile/:other')
@UseGuards(AuthGuard('access'))
@OtherProfileDocs()
@Docs('otherProfile')
async getBlurtingProfile(
@User() userPayload: JwtPayload,
@Param('other') other: number,
): Promise<BlurtingProfileDto> {
const { id } = userPayload;
return this.blurtingService.getProfile(id, other);
): Promise<UserProfileDto> {
return this.homeService.getOtherProfile(other);
}

@Put('/like')
Expand Down
2 changes: 0 additions & 2 deletions src/domain/home/home.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ import {
UserRepository,
} from 'src/domain/repositories';
import { UserModule } from 'src/domain/user/user.module';
import { BlurtingModule } from '../blurting/blurting.module';

@Module({
imports: [
UserModule,
BlurtingModule,
TypeOrmModule.forFeature([
LikeEntity,
BlurtingArrowEntity,
Expand Down
10 changes: 10 additions & 0 deletions src/domain/home/home.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { compareDateGroupExist, getDateTimeOfNow } from 'src/common/util/time';
import { AnswerWithQuestionDto } from './dtos';
import { UserService } from 'src/domain/user/user.service';
import { Sex, SexOrient } from 'src/common/enums';
import { UserProfileDto } from '../dtos/user.dto';

@Injectable()
export class HomeService {
Expand Down Expand Up @@ -130,6 +131,15 @@ export class HomeService {
);
}

async getOtherProfile(userId: number): Promise<UserProfileDto> {
const userImages = await this.userService.getUserImages(userId);
const userProfile = await this.userService.getUserProfile(
userId,
userImages,
);
return userProfile;
}

async updateProfile(userId: number) {
const user = await this.userRepository.findOneById(userId);
if (user.birth == null) return true;
Expand Down

0 comments on commit 33256f6

Please sign in to comment.