Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a usage-order selection of common spaces #674

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import apiCms004 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms0
import apiCms005 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms005";
import apiCms006 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms006";
import apiCms007 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms007";
import apiCms008 from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms008";

import { ZodPipe } from "@sparcs-clubs/api/common/pipe/zod-pipe";
import { Public } from "@sparcs-clubs/api/common/util/decorators/method-decorator";
Expand Down Expand Up @@ -48,6 +49,10 @@ import type {
ApiCms007RequestQuery,
ApiCms007ResponseOk,
} from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms007";
import type {
ApiCms008RequestParam,
ApiCms008ResponseOk,
} from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms008";

@Controller()
export class CommonSpaceController {
Expand Down Expand Up @@ -162,4 +167,16 @@ export class CommonSpaceController {
);
return result;
}

@Get("student/common-spaces/common-space/usage-order/:orderId")
@UsePipes(new ZodPipe(apiCms008))
async getStudentCommonSpacesUsageOrderDetail(
@Param() param: ApiCms008RequestParam,
): Promise<ApiCms008ResponseOk> {
const result =
await this.commonspaceService.getStudentCommonSpacesUsageOrderDetail(
param.orderId,
);
return result;
}
Comment on lines +171 to +181
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗ CMS-008은 사용자가 해당 신청의 신청자이거나 신청 동아리의 대표자+대의원인지 검사합니다. 이를 위해 토큰으로부터 유저 정보를 가져와야해요. GetStudent의 사용 예시를 보고 적용해주세요

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { MySql2Database } from "drizzle-orm/mysql2";

import { takeUnique } from "@sparcs-clubs/api/common/util/util";
import { DrizzleAsyncProvider } from "@sparcs-clubs/api/drizzle/drizzle.provider";
import { CommonSpaceUsageOrderD } from "@sparcs-clubs/api/drizzle/schema/common-space.schema";
import {
CommonSpace,
CommonSpaceUsageOrderD,
} from "@sparcs-clubs/api/drizzle/schema/common-space.schema";
import { Student } from "@sparcs-clubs/api/drizzle/schema/user.schema";

import { TermList } from "../dto/common-space.dto";

Expand Down Expand Up @@ -85,6 +89,28 @@ export class CommonSpaceUsageOrderDRepository {
return result;
}

async findCommonSpaceUsageOrderById(orderId: number) {
const result = await this.db
.select({
orderId: CommonSpaceUsageOrderD.id,
statusEnum: CommonSpace.commonSpaceEnum,
spaceName: CommonSpace.spaceName,
chargeStudentName: Student.name,
startTerm: CommonSpaceUsageOrderD.startTerm,
endTerm: CommonSpaceUsageOrderD.endTerm,
createdAt: CommonSpaceUsageOrderD.createdAt,
})
.from(CommonSpaceUsageOrderD)
.leftJoin(
CommonSpace,
eq(CommonSpaceUsageOrderD.commonSpaceId, CommonSpace.id),
)
.leftJoin(Student, eq(CommonSpaceUsageOrderD.chargeStudentId, Student.id))
.where(and(eq(CommonSpaceUsageOrderD.id, orderId)))
.then(takeUnique);
return result;
}

async deleteCommonSpaceUsageOrderD(orderId: number) {
await this.db
.update(CommonSpaceUsageOrderD)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { HttpException, HttpStatus, Injectable } from "@nestjs/common";

import logger from "@sparcs-clubs/api/common/util/logger";

import { getKSTDate, isEmptyObject } from "@sparcs-clubs/api/common/util/util";
import ClubStudentTRepository from "@sparcs-clubs/api/feature/club/repository/club.club-student-t.repository";

Expand All @@ -25,6 +27,7 @@ import type { ApiCms004ResponseOK } from "@sparcs-clubs/interface/api/common-spa
import type { ApiCms005ResponseCreated } from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms005";
import type { ApiCms006ResponseOk } from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms006";
import type { ApiCms007ResponseOk } from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms007";
import type { ApiCms008ResponseOk } from "@sparcs-clubs/interface/api/common-space/endpoint/apiCms008";

@Injectable()
export class CommonSpaceService {
Expand Down Expand Up @@ -237,4 +240,25 @@ export class CommonSpaceService {
);
return result;
}

async getStudentCommonSpacesUsageOrderDetail(
orderId: number,
): Promise<ApiCms008ResponseOk> {
const order =
await this.commonSpaceUsageOrderDRepository.findCommonSpaceUsageOrderById(
orderId,
);
// const { id } = order;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❗ 아마 요근처에서 권한 확인이 들어가야 할 것 같네요

logger.debug(order);
const result = {
orderId,
statusEnum: order.statusEnum,
spaceName: order.spaceName,
chargeStudentName: order.chargeStudentName,
startTerm: order.startTerm,
endTerm: order.endTerm,
createdAt: order.createdAt,
};
return result;
}
}
59 changes: 59 additions & 0 deletions packages/interface/src/api/common-space/endpoint/apiCms008.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { HttpStatusCode } from "axios";
import { z } from "zod";

import { CommonSpaceUsageOrderStatusEnum } from "@sparcs-clubs/interface/common/enum/commonSpace.enum";

/**
* @version v0.1
* @description 개별 공용공간 사용신청 내역을 가져옵니다.
*/

const url = (orderId: number) =>
`/student/common-spaces/common-space/usage-order/${orderId}`;
const method = "GET";

const requestParam = z.object({
orderId: z.coerce.number().int().min(1), // orderId는 양의 정수여야 합니다.
});

const requestQuery = z.object({});

const requestBody = z.object({});

const responseBodyMap = {
[HttpStatusCode.Ok]: z.object({
orderId: z.number().int().min(1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 Reponse는 coerce가 필요 없는지 확인이 필요합니다

statusEnum: z.nativeEnum(CommonSpaceUsageOrderStatusEnum),
spaceName: z.string(),
chargeStudentName: z.string().max(255),
startTerm: z.coerce.date(), // Assuming startTerm is a datetime
endTerm: z.coerce.date(), // Assuming endTerm is a datetime
createdAt: z.coerce.date(), // Assuming createdAt is a datetime
}),
};

const responseErrorMap = {};

const apiCms008 = {
url,
method,
requestParam,
requestQuery,
requestBody,
responseBodyMap,
responseErrorMap,
};

type ApiCms008RequestParam = z.infer<typeof apiCms008.requestParam>;
type ApiCms008RequestQuery = z.infer<typeof apiCms008.requestQuery>;
type ApiCms008RequestBody = z.infer<typeof apiCms008.requestBody>;
type ApiCms008ResponseOk = z.infer<(typeof apiCms008.responseBodyMap)[200]>;

export default apiCms008;

export type {
ApiCms008RequestParam,
ApiCms008RequestQuery,
ApiCms008RequestBody,
ApiCms008ResponseOk,
};