Skip to content

Commit

Permalink
Merge pull request #258 from GeunH/feature/be-global-final
Browse files Browse the repository at this point in the history
로그인 실패 응답 구조 변경, 상대 경로로 수정
  • Loading branch information
GeunH authored Dec 12, 2023
2 parents 59ea362 + 1e0d478 commit 9f34cd8
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 57 deletions.
5 changes: 3 additions & 2 deletions be/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import {
HttpStatus,
BadRequestException,
UnauthorizedException,
ForbiddenException,
} from "@nestjs/common";
import { UserRepository } from "../user/user.repository";
import { JwtService } from "@nestjs/jwt";
import axios from "axios";
import { LoginInfoDto } from "./dto/loginInfo.dto";
import { comparePasswords } from "src/utils/encryption.utils";
import { comparePasswords } from "../utils/encryption.utils";
import { AuthRepository } from "./auth.repository";

@Injectable()
Expand All @@ -25,7 +26,7 @@ export class AuthService {
try {
const result = await comparePasswords(loginInfoDto.password, data["password"]);
if (result) return this.signin(loginInfoDto);
else throw new UnauthorizedException();
else throw new HttpException("LOGIN FAILED", HttpStatus.FORBIDDEN);
} catch (err) {
throw new UnauthorizedException();
}
Expand Down
2 changes: 1 addition & 1 deletion be/src/aws/aws.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from "@nestjs/common";
import * as AWS from "aws-sdk";
import { awsConfig } from "objectStorage.config";
import { awsConfig } from "../../objectStorage.config";
import * as sharp from "sharp";

@Injectable()
Expand Down
5 changes: 2 additions & 3 deletions be/src/restaurant/entities/restaurant.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import {
OneToMany,
} from "typeorm";
import { Point } from "geojson";
import { ReviewInfoEntity } from "src/review/entities/review.entity";
import { User } from "src/user/entities/user.entity";
import { UserRestaurantListEntity } from "src/user/entities/user.restaurantlist.entity";
import { ReviewInfoEntity } from "../../review/entities/review.entity";
import { UserRestaurantListEntity } from "../../user/entities/user.restaurantlist.entity";

@Unique("unique_name_location", ["name", "location"])
@Entity("restaurant")
Expand Down
2 changes: 1 addition & 1 deletion be/src/restaurant/restaurant.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { RestaurantService } from "./restaurant.service";
import { SearchInfoDto } from "./dto/seachInfo.dto";
import { FilterInfoDto } from "./dto/filterInfo.dto";
import { GetUser, TokenInfo } from "src/user/user.decorator";
import { GetUser, TokenInfo } from "../user/user.decorator";
import { LocationDto } from "./dto/location.dto";

@ApiTags("Home")
Expand Down
6 changes: 3 additions & 3 deletions be/src/restaurant/restaurant.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Module } from "@nestjs/common";
import { RestaurantController } from "./restaurant.controller";
import { AuthModule } from "src/auth/auth.module";
import { AuthModule } from "../auth/auth.module";
import { RestaurantService } from "./restaurant.service";
import { RestaurantRepository } from "./restaurant.repository";
import { UserModule } from "src/user/user.module";
import { ReviewModule } from "src/review/review.module";
import { UserModule } from "../user/user.module";
import { ReviewModule } from "../review/review.module";
import { ScheduleModule } from '@nestjs/schedule';

@Module({
Expand Down
8 changes: 4 additions & 4 deletions be/src/restaurant/restaurant.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { DataSource, Repository, Like } from "typeorm";
import { Injectable } from "@nestjs/common";
import { RestaurantInfoEntity } from "./entities/restaurant.entity";
import { SearchInfoDto } from "./dto/seachInfo.dto";
import { TokenInfo } from "src/user/user.decorator";
import { UserRestaurantListEntity } from "src/user/entities/user.restaurantlist.entity";
import { TokenInfo } from "../user/user.decorator";
import { UserRestaurantListEntity } from "../user/entities/user.restaurantlist.entity";
import { FilterInfoDto } from "./dto/filterInfo.dto";
import { User } from "src/user/entities/user.entity";
import { User } from "../user/entities/user.entity";
import { LocationDto } from "./dto/location.dto";
import { UserWishRestaurantListEntity } from "src/user/entities/user.wishrestaurantlist.entity";
import { UserWishRestaurantListEntity } from "../user/entities/user.wishrestaurantlist.entity";

@Injectable()
export class RestaurantRepository extends Repository<RestaurantInfoEntity> {
Expand Down
8 changes: 4 additions & 4 deletions be/src/restaurant/restaurant.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { SearchInfoDto } from "./dto/seachInfo.dto";
import * as proj4 from "proj4";
import axios from "axios";
import { FilterInfoDto } from "./dto/filterInfo.dto";
import { TokenInfo } from "src/user/user.decorator";
import { UserRepository } from "src/user/user.repository";
import { ReviewRepository } from "src/review/review.repository";
import { TokenInfo } from "../user/user.decorator";
import { UserRepository } from "../user/user.repository";
import { ReviewRepository } from "../review/review.repository";
import { LocationDto } from "./dto/location.dto";
import { AwsService } from "src/aws/aws.service";
import { AwsService } from "../aws/aws.service";
import { Cron } from "@nestjs/schedule";

const key = process.env.API_KEY;
Expand Down
6 changes: 3 additions & 3 deletions be/src/review/entities/review.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import {
OneToOne,
OneToMany,
} from "typeorm";
import { User } from "src/user/entities/user.entity";
import { RestaurantInfoEntity } from "src/restaurant/entities/restaurant.entity";
import { UserRestaurantListEntity } from "src/user/entities/user.restaurantlist.entity";
import { User } from "../../user/entities/user.entity";
import { RestaurantInfoEntity } from "../../restaurant/entities/restaurant.entity";
import { UserRestaurantListEntity } from "../../user/entities/user.restaurantlist.entity";
import { ReviewLikeEntity } from "./review.like.entity";

@Entity("review")
Expand Down
2 changes: 1 addition & 1 deletion be/src/review/entities/review.like.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
JoinColumn,
DeleteDateColumn,
} from "typeorm";
import { User } from "src/user/entities/user.entity";
import { User } from "../../user/entities/user.entity";
import { ReviewInfoEntity } from "./review.entity";

@Entity("reviewLike")
Expand Down
4 changes: 2 additions & 2 deletions be/src/review/review.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Controller, Get, Param, Post, Query, UseGuards, UsePipes, ValidationPip
import { ReviewService } from './review.service';
import { ApiBearerAuth, ApiOperation, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
import { AuthGuard } from '@nestjs/passport';
import { GetUser, TokenInfo } from 'src/user/user.decorator';
import { SortInfoDto } from 'src/utils/sortInfo.dto';
import { GetUser, TokenInfo } from '../user/user.decorator';
import { SortInfoDto } from '../utils/sortInfo.dto';

@ApiTags("Review")
@Controller('review')
Expand Down
2 changes: 0 additions & 2 deletions be/src/review/review.like.repository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { DataSource, IsNull, Repository, Not } from "typeorm";
import { ConflictException, Injectable } from "@nestjs/common";
import { ReviewInfoEntity } from "./entities/review.entity";
import { ReviewLikeEntity } from "./entities/review.like.entity";
import { String } from "aws-sdk/clients/cloudhsm";

@Injectable()
export class ReviewLikeRepository extends Repository<ReviewLikeEntity> {
Expand Down
6 changes: 3 additions & 3 deletions be/src/review/review.repository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { DataSource, IsNull, Repository, Not } from "typeorm";
import { ConflictException, Injectable } from "@nestjs/common";
import { ReviewInfoEntity } from "./entities/review.entity";
import { TokenInfo } from "src/user/user.decorator";
import { SortInfoDto } from "src/utils/sortInfo.dto";
import { TokenInfo } from "../user/user.decorator";
import { SortInfoDto } from "../utils/sortInfo.dto";

@Injectable()
export class ReviewRepository extends Repository<ReviewInfoEntity> {
Expand Down Expand Up @@ -33,7 +33,7 @@ export class ReviewRepository extends Repository<ReviewInfoEntity> {
}
}
async getSortedReviews(getSortedReviewsDto: SortInfoDto, restaurantId: number, id: TokenInfo["id"], sortedReviewIds: number[]) {
const pageNumber = parseInt(getSortedReviewsDto.page as unknown as string)|| 1;
const pageNumber = parseInt(getSortedReviewsDto.page as unknown as string) || 1;
const limitNumber = parseInt(getSortedReviewsDto.limit as unknown as string) || 10;
const skipNumber = (pageNumber - 1) * limitNumber;
if (getSortedReviewsDto && getSortedReviewsDto.sort === "TIME_DESC") {
Expand Down
6 changes: 3 additions & 3 deletions be/src/review/review.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { ReviewRepository } from './review.repository';
import { TokenInfo } from 'src/user/user.decorator';
import { TokenInfo } from '../user/user.decorator';
import { ReviewLikeRepository } from './review.like.repository';
import { SortInfoDto } from 'src/utils/sortInfo.dto';
import { AwsService } from 'src/aws/aws.service';
import { SortInfoDto } from '../utils/sortInfo.dto';
import { AwsService } from '../aws/aws.service';

@Injectable()
export class ReviewService {
Expand Down
2 changes: 1 addition & 1 deletion be/src/user/entities/user.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from "typeorm";
import { FollowEntity } from "./user.followList.entity";
import { UserRestaurantListEntity } from "./user.restaurantlist.entity";
import { ReviewInfoEntity } from "src/review/entities/review.entity";
import { ReviewInfoEntity } from "../../review/entities/review.entity";

@Entity()
export class User {
Expand Down
6 changes: 3 additions & 3 deletions be/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import { UserService } from "./user.service";
import { GetUser, TokenInfo } from "./user.decorator";
import { AuthGuard } from "@nestjs/passport";
import { SearchInfoDto } from "../restaurant/dto/seachInfo.dto";
import { LocationDto } from "src/restaurant/dto/location.dto";
import { ReviewInfoDto } from "src/review/dto/reviewInfo.dto";
import { LocationDto } from "../restaurant/dto/location.dto";
import { ReviewInfoDto } from "../review/dto/reviewInfo.dto";
import { ParseArrayPipe } from "../utils/parsearraypipe";
import { FileInterceptor } from "@nestjs/platform-express";
import { memoryStorage } from 'multer';
import { plainToClass } from "class-transformer";
import { validate } from "class-validator";
import { SortInfoDto } from "src/utils/sortInfo.dto";
import { SortInfoDto } from "../utils/sortInfo.dto";

const multerOptions = {
storage: memoryStorage(),
Expand Down
6 changes: 3 additions & 3 deletions be/src/user/user.restaurantList.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { DataSource, IsNull, Repository, Not } from "typeorm";
import { ConflictException, Injectable } from "@nestjs/common";
import { UserRestaurantListEntity } from "./entities/user.restaurantlist.entity";
import { TokenInfo } from "./user.decorator";
import { SearchInfoDto } from "src/restaurant/dto/seachInfo.dto";
import { ReviewInfoEntity } from "src/review/entities/review.entity";
import { SearchInfoDto } from "../restaurant/dto/seachInfo.dto";
import { ReviewInfoEntity } from "../review/entities/review.entity";
import { UserWishRestaurantListEntity } from "./entities/user.wishrestaurantlist.entity";
import { SortInfoDto } from "src/utils/sortInfo.dto";
import { SortInfoDto } from "../utils/sortInfo.dto";

@Injectable()
export class UserRestaurantListRepository extends Repository<UserRestaurantListEntity> {
Expand Down
23 changes: 11 additions & 12 deletions be/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import { UserRestaurantListRepository } from "./user.restaurantList.repository";
import { UserFollowListRepository } from "./user.followList.repository";
import { Equal, In, Like, Not } from "typeorm";
import { BadRequestException, ConflictException } from "@nestjs/common/exceptions";
import { ReviewInfoDto } from "src/review/dto/reviewInfo.dto";
import { ReviewRepository } from "src/review/review.repository";
import { ReviewInfoDto } from "../review/dto/reviewInfo.dto";
import { ReviewRepository } from "../review/review.repository";
import { UserWishRestaurantListRepository } from "./user.wishrestaurantList.repository";
import { AwsService } from "src/aws/aws.service";
import { AwsService } from "../aws/aws.service";
import { v4 } from "uuid";
import { User } from "./entities/user.entity";
import { RestaurantInfoEntity } from "src/restaurant/entities/restaurant.entity";
import { AuthService } from "src/auth/auth.service";
import { SortInfoDto } from "src/utils/sortInfo.dto";
import { JwtService } from "@nestjs/jwt";
import { RestaurantInfoEntity } from "../restaurant/entities/restaurant.entity";
import { AuthService } from "../auth/auth.service";
import { SortInfoDto } from "../utils/sortInfo.dto";

@Injectable()
export class UserService {
Expand Down Expand Up @@ -96,7 +95,7 @@ export class UserService {
tokenInfo.id
);
if (restaurantList) result["restaurants"] = restaurantList;
else result["restaurants"] = [];
else result["restaurants"] = [];
result.profileImage = this.awsService.getImageURL(result.profileImage);
return result;
} catch (err) {
Expand Down Expand Up @@ -218,9 +217,9 @@ export class UserService {
const result = await this.usersRepository.getRecommendUserListInfo(userIdValues, tokenInfo.id);

function getRandomInts(min: number, max: number, count: number): number[] {
if(max === -1){
if (max === -1) {
return [];
} else if(max === 0){
} else if (max === 0) {
return [0];
}

Expand All @@ -233,8 +232,8 @@ export class UserService {
}

const randomIndexes = getRandomInts(0, result.length - 1, 2);
if(randomIndexes.length === 0) return [];
if (randomIndexes.length === 0) return [];

const selectedUsers = randomIndexes.map(index => result[index]);
return selectedUsers.map((user) => ({
...user,
Expand Down
28 changes: 22 additions & 6 deletions be/test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test, TestingModule } from "@nestjs/testing";
import { INestApplication } from "@nestjs/common";
import * as request from "supertest";
import { AppModule } from "./../src/app.module";
import { AppModule } from "../src/app.module";

describe("AppController (e2e)", () => {
let app: INestApplication;
Expand All @@ -15,10 +15,26 @@ describe("AppController (e2e)", () => {
await app.init();
});

it("/ (GET)", () => {
return request(app.getHttpServer())
.get("/")
.expect(200)
.expect("Hello World!");
it('/api/user', async () => {
const userData = {
email: "[email protected]",
password: "1234",
provider: "site",
nickName: "test",
region: "강남구",
birthdate: "1234/56/78",
isMale: true
};

const response = await request(app.getHttpServer())
.post('/user')
.send(userData)
.expect(201);

expect(response.statusCode).toBe(201);
});

afterAll(async () => {
await app.close();
});
});

0 comments on commit 9f34cd8

Please sign in to comment.