Skip to content

Commit

Permalink
Merge pull request #59 from jiphyeonjeon-42/parkj12b/issue58
Browse files Browse the repository at this point in the history
feat: users api 명세 작성
  • Loading branch information
parkj12b authored Sep 27, 2024
2 parents 024f4f8 + 168fb44 commit b173e2f
Show file tree
Hide file tree
Showing 7 changed files with 615 additions and 0 deletions.
42 changes: 42 additions & 0 deletions backend/src/users/dto/users.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { createZodDto } from '@anatine/zod-nestjs';
import {
createUsersRequestSchema,
getAPIVersionResponseSchema,
getMyUserInfoResponseSchema,
getUsersRequestSchema,
getUsersResponseSchema,
myUpdateUsersRequestSchema,
updateUsersParamSchema,
updateUsersRequestSchema,
updateUsersResponseSchema,
} from '../schema/users.schema';

export class GetUsersRequestDto extends createZodDto(getUsersRequestSchema) {}

export class GetUsersResponseDto extends createZodDto(getUsersResponseSchema) {}

export class CreateUsersRequestDto extends createZodDto(
createUsersRequestSchema,
) {}

export class UpdateUsersParamDto extends createZodDto(updateUsersParamSchema) {}

export class UpdateUsersRequestDto extends createZodDto(
updateUsersRequestSchema,
) {}

export class UpdateUsersResponseDto extends createZodDto(
updateUsersResponseSchema,
) {}

export class MyUpddateUsersRequestDto extends createZodDto(
myUpdateUsersRequestSchema,
) {}

export class GetAPIVersionResponseDto extends createZodDto(
getAPIVersionResponseSchema,
) {}

export class GetMyUserInfoResponseDto extends createZodDto(
getMyUserInfoResponseSchema,
) {}
115 changes: 115 additions & 0 deletions backend/src/users/schema/users.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { extendApi } from '@anatine/zod-openapi';
import { z } from 'zod';

export const getUsersRequestSchema = z.object({
nicknameOrEmail: z.string().describe('검색할 유저의 nickname or email'),
page: z.coerce.number().int().describe('페이지').min(1),
limit: z.coerce
.number()
.int()
.describe(' 한 페이지에 들어올 검색결과 수 ')
.min(1),
id: z.coerce.number().int().describe('유저의 id').min(0),
});

const lending = z.object({
userId: z.coerce.number(),
bookInfoId: z.coerce.number(),
lendDate: z.coerce.date(),
lendingCondition: z.string(),
image: z.string(),
author: z.string(),
title: z.string(),
duedate: z.coerce.date(),
overDueDay: z.coerce.number(),
reservedNum: z.coerce.number().min(0),
});

const VUserReservations = z.object({
reservationId: z.coerce.number().min(0),
reservedBookInfoId: z.coerce.number().min(0),
reservationDate: z.coerce.date(),
endAt: z.coerce.date(),
ranking: z.coerce.number().min(0),
title: z.string(),
author: z.string(),
image: z.string(),
userId: z.coerce.number().min(0),
});

const getUsersResponseInnerSchema = z.object({
id: z.coerce.number().int().describe('유저 번호').min(0),
email: z.string().describe('이메일'),
nickname: z.string().describe('닉네임'),
intraId: z.coerce.number().int().describe('인트라 고유 번호').min(0),
slack: z.string().describe('slack 멤버 Id'),
penaltyEndDate: z.string().describe('패널티 끝나는 날짜'),
overDueDay: z.coerce.number().describe('현재 연체된 날수').min(0),
role: z.coerce.number().int().describe('권한'),
reservations: z.array(VUserReservations).describe('해당 유저의 예약 정보'),
lendings: z.array(lending).describe('해당 유저의 대출 정보'),
});

const getUsersResponseMetaSchema = z.object({
totalItems: z.coerce.number().int().describe('전체 검색 결과 수'),
itemCount: z.coerce.number().int().describe('현재 페이지 검색 결과 수'),
itemsPerPage: z.coerce.number().int().describe('페이지 당 검색 결과 수'),
totalPages: z.coerce.number().int().describe('전체 결과 페이지 수'),
currentPage: z.coerce.number().int().describe('현재 페이지'),
});

export const getUsersResponseSchema = z.object({
items: z.array(getUsersResponseInnerSchema).describe('유저 정보 목록'),
meta: getUsersResponseMetaSchema.describe('유저 수와 관련된 정보'),
});

export const createUsersRequestSchema = z.object({
email: z.string().describe('이메일'),
password: z.string().describe('비밀번호'),
});

export const updateUsersParamSchema = z.object({
id: z.coerce.number().int().describe('변경할 유저의 id 값').min(0),
});

export const updateUsersRequestSchema = z.object({
nickname: z.string(),
intraId: z.coerce.number().int().min(0).describe('인트라 ID'),
slack: z.string().describe('slack 멤버 변수'),
role: z.coerce.number().int().describe('유저의 권한'),
penaltyEndDate: z.date().describe('패널티 끝나는 날짜'),
});

export const updateUsersResponseSchema = updateUsersRequestSchema;

export const myUpdateUsersRequestSchema = createUsersRequestSchema;

export const getAPIVersionResponseSchema = z.object({
version: extendApi(z.string().describe('API 버전'), {
example: 'gshim.v1',
}),
});

export const getMyUserInfoResponseSchema = z.object({
nickname: extendApi(z.string().describe('닉네임'), { example: 'jimin' }),
intraId: extendApi(z.number().describe('인트라 ID'), { example: 10035 }),
slack: extendApi(z.string().describe('slack 멤버 변수'), {
example: 'U02LNNDRC9F',
}),
role: extendApi(z.coerce.number().describe('유저의 권한'), { example: 2 }),
penaltyEndDate: extendApi(z.date().describe('패널티 끝나는 날짜'), {
example: '2021-08-01',
}),
overDueDay: extendApi(z.coerce.number().describe('현재 연체된 날수'), {
example: 0,
}),
reservations: extendApi(
z.array(VUserReservations).describe('해당 유저의 예약 정보'),
{
example: [],
},
),
lendings: extendApi(z.array(lending).describe('해당 유저의 대출 정보'), {
example: [],
}),
});
18 changes: 18 additions & 0 deletions backend/src/users/users.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersController } from './users.controller';

describe('UsersController', () => {
let controller: UsersController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UsersController],
}).compile();

controller = module.get<UsersController>(UsersController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
Loading

0 comments on commit b173e2f

Please sign in to comment.