Skip to content

Commit

Permalink
style: 코드 포맷팅
Browse files Browse the repository at this point in the history
  • Loading branch information
Miensoap committed Nov 5, 2024
1 parent c2c84ab commit 791001c
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 62 deletions.
3 changes: 1 addition & 2 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ import { PlaceModule } from './place/place.module';
controllers: [AppController],
providers: [AppService],
})
export class AppModule {
}
export class AppModule {}
7 changes: 6 additions & 1 deletion backend/src/common/BaseEntity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, DeleteDateColumn } from 'typeorm';
import {
PrimaryGeneratedColumn,
CreateDateColumn,
UpdateDateColumn,
DeleteDateColumn,
} from 'typeorm';

export abstract class BaseEntity {
@PrimaryGeneratedColumn()
Expand Down
5 changes: 4 additions & 1 deletion backend/src/common/SoftDeleteRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { SoftDeletableEntity } from './SoftDeletableEntity.interface';
* Soft Delete 를 지원
* 기본적으로 deletedAt 이 null 인 것만 조회
*/
export abstract class SoftDeleteRepository<T extends SoftDeletableEntity<K>, K> extends Repository<T> {
export abstract class SoftDeleteRepository<
T extends SoftDeletableEntity<K>,
K,
> extends Repository<T> {
find(options: FindManyOptions<T> = {}) {
return super.find({
...options,
Expand Down
3 changes: 1 addition & 2 deletions backend/src/config/TypeOrmConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { CustomNamingStrategy } from './CustomNamingStrategy';

@Injectable()
export class TypeOrmConfigService implements TypeOrmOptionsFactory {
constructor(private configService: ConfigService) {
}
constructor(private configService: ConfigService) {}

createTypeOrmOptions(): TypeOrmModuleOptions {
return {
Expand Down
6 changes: 2 additions & 4 deletions backend/src/map/dto/MapDetailResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ import { UserIconResponse } from '../../user/dto/UserIconResponse';
import { PlaceResponse } from '../../place/dto/PlaceResponse';
import { DEFAULT_THUMBNAIL_URL } from './MapListResponse';


export class MapDetailResponse {
constructor(
readonly id: number,
readonly user: { id: number, nickname: string, profileImageUrl: string },
readonly user: { id: number; nickname: string; profileImageUrl: string },
readonly title: string,
readonly isPublic: boolean,
readonly thumbnailUrl: string,
Expand All @@ -16,8 +15,7 @@ export class MapDetailResponse {
readonly places: PlaceResponse[],
readonly createdAt: Date,
readonly updatedAt: Date,
) {
}
) {}

static async from(map: Map) {
const places = (await map.getPlaces()).map((place) => {
Expand Down
8 changes: 4 additions & 4 deletions backend/src/map/dto/MapListResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import { Map } from '../entity/map.entity';
import { UserIconResponse } from '../../user/dto/UserIconResponse';

// Todo. 오브젝트 스토리지에 실제 이미지 저장 후 수정
export const DEFAULT_THUMBNAIL_URL = 'https://avatars.githubusercontent.com/u/87180146?v=4';
export const DEFAULT_THUMBNAIL_URL =
'https://avatars.githubusercontent.com/u/87180146?v=4';

export class MapListResponse {
constructor(
readonly id: number,
readonly user: { id: number, nickname: string, profileImageUrl: string },
readonly user: { id: number; nickname: string; profileImageUrl: string },
readonly title: string,
readonly isPublic: boolean,
readonly thumbnailUrl: string,
readonly description: string,
readonly pinCount: number,
readonly createdAt: Date,
readonly updatedAt: Date,
) {
}
) {}

static async from(map: Map) {
return new MapListResponse(
Expand Down
10 changes: 5 additions & 5 deletions backend/src/map/entity/map.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { BaseEntity } from '../../common/BaseEntity';
import { User } from '../../user/user.entity';
import { MapPlace } from './map-place.entity';
import { Place } from '../../place/place.entity';
import { map } from 'rxjs';

@Entity()
export class Map extends BaseEntity {
Expand Down Expand Up @@ -46,9 +45,10 @@ export class Map extends BaseEntity {
}

async getPlaces(): Promise<Place[]> {
return Promise.all(this.mapPlaces.map(async (mapPlace) => {
console.log(mapPlace);
return await mapPlace.place;
}));
return Promise.all(
this.mapPlaces.map(async (mapPlace) => {
return await mapPlace.place;
}),
);
}
}
12 changes: 3 additions & 9 deletions backend/src/map/map.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { INestApplication, ValidationPipe } from '@nestjs/common';

describe('MapController', () => {
let app: INestApplication;
let mapService = {
const mapService = {
searchMap: jest.fn(),
getOwnMaps: jest.fn(),
createMap: jest.fn(),
Expand Down Expand Up @@ -34,18 +34,12 @@ describe('MapController', () => {

it('/GET maps', () => {
mapService.searchMap.mockResolvedValue([]);
return request(app.getHttpServer())
.get('/maps')
.expect(200)
.expect([]);
return request(app.getHttpServer()).get('/maps').expect(200).expect([]);
});

it('/GET maps/my', () => {
mapService.getOwnMaps.mockResolvedValue([]);
return request(app.getHttpServer())
.get('/maps/my')
.expect(200)
.expect([]);
return request(app.getHttpServer()).get('/maps/my').expect(200).expect([]);
});

it('/POST maps - success', () => {
Expand Down
17 changes: 12 additions & 5 deletions backend/src/map/map.controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Controller, Get, Post, Body, Query, Delete, Param } from '@nestjs/common';
import {
Controller,
Get,
Post,
Body,
Query,
Delete,
Param,
} from '@nestjs/common';
import { MapService } from './map.service';
import { CreateMapForm } from './dto/CreateMapForm';

@Controller('/maps')
export class MapController {
constructor(private readonly appService: MapService) {
}
constructor(private readonly appService: MapService) {}

@Get()
async getMapList(@Query('query') query?: string) {
Expand All @@ -26,11 +33,11 @@ export class MapController {
@Post()
async createMap(@Body() createMapForm: CreateMapForm) {
const userId = 1; // Todo. 로그인 기능 완성 후 수정
return (await this.appService.createMap(userId, createMapForm));
return await this.appService.createMap(userId, createMapForm);
}

@Delete('/:id')
async deleteMap(@Param('id') id: number) {
return (await this.appService.deleteMap(id));
return await this.appService.deleteMap(id);
}
}
3 changes: 1 addition & 2 deletions backend/src/map/map.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ import { MapRepository } from './map.repository';
controllers: [MapController],
providers: [MapService, MapRepository],
})
export class MapModule {
}
export class MapModule {}
30 changes: 18 additions & 12 deletions backend/src/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ import { MapDetailResponse } from './dto/MapDetailResponse';

@Injectable()
export class MapService {
constructor(private readonly mapRepository: MapRepository,
@InjectRepository(User) private readonly userRepository: Repository<User>) {

constructor(
private readonly mapRepository: MapRepository,
@InjectRepository(User) private readonly userRepository: Repository<User>,
) {
// Todo. 로그인 기능 완성 후 제거
const testUser = new User('test', 'test', 'test', 'test');
testUser.id = 1;
userRepository.upsert(
testUser,
{ conflictPaths: ['id'] },
);
userRepository.upsert(testUser, { conflictPaths: ['id'] });
}

// Todo. 작성자명 등 ... 검색 조건 추가
Expand All @@ -27,7 +25,9 @@ export class MapService {
? await this.mapRepository.searchByTitleQuery(query, page, pageSize)
: await this.mapRepository.findAll(page, pageSize);

const totalCount = await this.mapRepository.count({ where: { title: query, isPublic: true } });
const totalCount = await this.mapRepository.count({
where: { title: query, isPublic: true },
});

const publicMaps = maps.filter((map) => map.isPublic);

Expand All @@ -40,13 +40,19 @@ export class MapService {

async getOwnMaps(userId: number, page: number = 1, pageSize: number = 10) {
// Todo. 그룹 기능 추가
const totalCount = await this.mapRepository.count({ where: { user: { id: userId } } });
const totalCount = await this.mapRepository.count({
where: { user: { id: userId } },
});

const ownMaps = await this.mapRepository.findByUserId(userId, page, pageSize);
const ownMaps = await this.mapRepository.findByUserId(
userId,
page,
pageSize,
);

return {
maps: await Promise.all(ownMaps.map(MapListResponse.from)),
totalPages: Math.ceil((totalCount / pageSize)),
totalPages: Math.ceil(totalCount / pageSize),
currentPage: page,
};
}
Expand All @@ -55,7 +61,7 @@ export class MapService {
const map = await this.mapRepository.findById(id);
if (map) return await MapDetailResponse.from(map);

throw new Error("커스텀에러로수정예정 404")
throw new Error('커스텀에러로수정예정 404');
}

async createMap(userId: number, createMapForm: CreateMapForm) {
Expand Down
3 changes: 1 addition & 2 deletions backend/src/place/dto/PlaceResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ export class PlaceResponse {
readonly thumbnail_url?: string,
readonly rating?: number,
readonly formed_address?: string,
) {
}
) {}

static from(place: Place): PlaceResponse {
return new PlaceResponse(
Expand Down
19 changes: 12 additions & 7 deletions backend/src/user/dto/UserIconResponse.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { User } from '../user.entity';

export const DEFAULT_PROFILE_IMAGE_URL = 'https://avatars.githubusercontent.com/u/87180146?v=4';

export const DEFAULT_PROFILE_IMAGE_URL =
'https://avatars.githubusercontent.com/u/87180146?v=4';

export class UserIconResponse {
constructor(readonly id: number,
readonly nickname: string,
readonly profileImageUrl: string) {
}
constructor(
readonly id: number,
readonly nickname: string,
readonly profileImageUrl: string,
) {}

static from(user: User) {
return new UserIconResponse(user.id, user.nickname, user.profileImageUrl ?? DEFAULT_PROFILE_IMAGE_URL);
return new UserIconResponse(
user.id,
user.nickname,
user.profileImageUrl ?? DEFAULT_PROFILE_IMAGE_URL,
);
}
}
11 changes: 7 additions & 4 deletions backend/src/user/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ export class User extends BaseEntity {
@OneToMany(() => Course, (course) => course.user)
courses: Promise<Course[]>;

constructor(provider: string,
nickname: string,
oauthId: string, role: string,
profileImageUrl?: string) {
constructor(
provider: string,
nickname: string,
oauthId: string,
role: string,
profileImageUrl?: string,
) {
super();
this.provider = provider;
this.nickname = nickname;
Expand Down
3 changes: 1 addition & 2 deletions backend/src/user/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ import { Module } from '@nestjs/common';
imports: [TypeOrmModule.forFeature([User])],
exports: [TypeOrmModule.forFeature([User])],
})
export class UserModule {
}
export class UserModule {}

0 comments on commit 791001c

Please sign in to comment.