Skip to content

Commit

Permalink
Merge pull request #10 from joog-lim/feature/join_algorithm
Browse files Browse the repository at this point in the history
Feature/join algorithm
  • Loading branch information
sunrabbit123 authored Dec 25, 2021
2 parents c5496b9 + 48eef1b commit aa86cab
Show file tree
Hide file tree
Showing 11 changed files with 544 additions and 102 deletions.
16 changes: 8 additions & 8 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,63 +44,63 @@ functions:
handler: src/handler.getAlgorithmCountAtAll
events:
- http:
path: algoirthm/count
path: algorithm/count
method: get
cors: true

getAlgorithmRules:
handler: src/handler.getAlgorithmRules
events:
- http:
path: algoirthm/rule
path: algorithm/rule
method: get
cors: true

getAlgorithmRulesForWeb:
handler: src/handler.getAlgorithmRulesForWeb
events:
- http:
path: algoirthm/rule/web
path: algorithm/rule/web
method: get
cors: true

getAlgorithmList:
handler: src/handler.getAlgorithmList
events:
- http:
path: algoirthm/list
path: algorithm/list
method: get
cors: true

getAlgorithmPage:
handler: src/handler.getAlgorithmListAtPages
events:
- http:
path: algoirthm/page
path: algorithm/page
method: get
cors: true

deleteAlgorithm:
handler: src/handler.deleteAlgorithm
events:
- http:
path: algoirthm/{id}
path: algorithm/{id}
method: delete
cors: true

modifyAlgorithm:
handler: src/handler.modifyAlogirithemContent
events:
- http:
path: algoirthm/{id}
path: algorithm/{id}
method: patch
cors: true

changeStatusAlgorithm:
handler: src/handler.setAlgorithmStatus
events:
- http:
path: algoirthm/{id}/status
path: algorithm/{id}/status
method: patch
cors: true

Expand Down
37 changes: 24 additions & 13 deletions src/DTO/algorithm.dto.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
export interface BaseAlgorithmDTO {
title: string;
content: string;
tag: string;
}

export type AlgorithmStatusType =
| "PENDING"
| "ACCEPTED"
| "REJECTED"
| "REPORTED";

export interface ModifyAlgorithmDTO extends BaseAlgorithmDTO {}
export interface BaseAlgorithmDTO {
title: string;
content: string;
tag: string;
}

export interface GeneratedAlgorithmDTO extends BaseAlgorithmDTO {
number: number;
}
export type AlgorithmStatusType =
| "PENDING"
| "ACCEPTED"
| "REJECTED"
| "REPORTED";

export interface JoinAlgorithmDTO {
count: number;
cursor?: number;
page?: number;
status: AlgorithmStatusType;
isAdmin: boolean;
}

export interface ModifyAlgorithmDTO extends BaseAlgorithmDTO {}
201 changes: 201 additions & 0 deletions src/DTO/discord.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import { BaseAlgorithmDTO } from "./algorithm.dto";

export interface DiscordObject {
id: string;
}
export interface DiscordWebhook extends DiscordObject {
type: number;
name: string;
avatar: string;
application_id: string;

guild_id?: string | null;
channel_id: string | null;
}

export interface DiscordIncomingWebhook extends DiscordWebhook {
token?: string;
user?: DiscordUser;
}
export interface DiscordChannelFollowerWebhook extends DiscordWebhook {
user?: DiscordUser;
source_guild?: DiscordGuild;
source_channel?: DiscordChannel;
url?: string;
}
export interface DiscordApplicationWebhook extends DiscordWebhook {}

interface DiscordGuild extends DiscordObject {} // TODO
interface DiscordChannel extends DiscordObject {} // TODO

export interface DiscordUser extends DiscordObject {
username: string;
discriminator: string;
avatar?: string;
bot?: boolean;
system?: boolean;
mfa_enabled?: boolean;
banner?: string;
accent_color?: number;
locale?: string;
verified?: boolean;
email?: string;
flags?: number;
premium_type?: number;
public_flags?: number;
}

export interface SendDiscordWebhookMessage {
content?: string; // content, file, embeds ์…‹ ์ค‘ ํ•˜๋‚˜๋Š” ํ•„์ˆ˜
username?: string;
avatar_url?: string;
tts?: boolean;
file?: File; // content, file, embeds ์…‹ ์ค‘ ํ•˜๋‚˜๋Š” ํ•„์ˆ˜
embeds?: DiscordEmbed[]; // content, file, embeds ์…‹ ์ค‘ ํ•˜๋‚˜๋Š” ํ•„์ˆ˜
payload_json?: string; // multipart/form-data only
allowed_mentions?: DiscordAllowedMentions;
components?: DiscordComponent[];
}

export interface DiscordEmbed {
title?: string;
type: DiscordEmbedType; // webhook ์‚ฌ์šฉ์‹œ ํ•ญ์ƒ rich
description?: string;
url?: string;
timestamp?: string; // ISO8601 timestamp
color?: number;
footer?: DiscordEmbedFooter;
image?: DiscordEmbedImage;
thumbnail?: DiscordEmbedThumbnail;
video?: DiscordEmbedVideo;
provider?: DiscordEmbedProvider;
author?: DiscordEmbedAuthor;
fields?: DiscordEmbedFields[];
}
interface DiscordEmbedLinkedComponent {
url?: string;
}
interface DiscordEmbedLinkedMediaContent extends DiscordEmbedLinkedComponent {
proxy_url?: string;
height?: number;
width?: number;
}
export interface DiscordEmbedFooter {
text: string;
icon_url?: string;
proxy_icon_url?: string;
}
export interface DiscordEmbedImage extends DiscordEmbedLinkedMediaContent {}
export interface DiscordEmbedThumbnail extends DiscordEmbedLinkedMediaContent {}
export interface DiscordEmbedVideo extends DiscordEmbedLinkedMediaContent {}
export interface DiscordEmbedProvider extends DiscordEmbedLinkedComponent {
name?: string;
}
export interface DiscordEmbedAuthor extends DiscordEmbedLinkedComponent {
name?: string;
icon_url?: string;
proxy_icon_url?: string;
}
export interface DiscordEmbedFields {
name: string;
value: string;
inline?: boolean;
}

export const DiscordEmbedType = {
rich: "rich",
image: "image",
video: "video",
gifv: "gifv",
article: "article",
link: "link",
} as const;
export type DiscordEmbedType =
typeof DiscordEmbedType[keyof typeof DiscordEmbedType];

export interface DiscordAllowedMentions {
parse?: AllowedMentionTypes[];
roles?: string[];
users?: string[];
replied_user?: boolean;
}

export type AllowedMentionTypes = "roles" | "users" | "everyone";

export type DiscordButtonsComponentType = {
type: DiscordEmbedComponentType;
custom_id?: string;
disabled?: boolean;
style?: number;
label?: string;
emoji?: DiscordEmoji;
url?: string;
};
export type DiscordSelectMenusComponentType = {
type: DiscordEmbedComponentType;
custom_id?: string;
disabled?: boolean;

options: SelectOptions[];
placeholder?: string;
min_values?: number;
max_values?: number;
};
export type DiscordActionRowsComponentType = {
type: DiscordEmbedComponentType;
components?: DiscordComponent[];
};
export type DiscordComponent =
| DiscordButtonsComponentType
| DiscordSelectMenusComponentType
| DiscordActionRowsComponentType;

export const DiscordEmbedComponentType = {
Action_Row: 1,
Button: 2,
Select_Menu: 3,
} as const;
export type DiscordEmbedComponentType =
typeof DiscordEmbedComponentType[keyof typeof DiscordEmbedComponentType];

export interface SelectOptions {
label: string;
value: string;
description?: string;
emoji?: DiscordEmoji;
default?: boolean;
}
export interface DiscordEmoji {
id: string | null;
name: string | null;
roles?: DiscordRoles[];
user?: DiscordUser;
require_colons?: boolean;
managed?: boolean;
animatd?: boolean;
available?: boolean;
}

export interface DiscordRoles {
id: string;
name: string;
color: number;
hoist: boolean;
position: number;
permissions: string;
managed: boolean;
mentionalbe: boolean;
tags?: DiscordRoleTags;
}
export interface DiscordRoleTags {
bot_id?: string;
integration_id?: string;
premium_subscriber?: null;
}

export interface GenerateMessage {
form: BaseAlgorithmDTO;
coment: string;
color: number;
description: string;
}
4 changes: 3 additions & 1 deletion src/middleware/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export class DBMiddleware {
// run function
const result = await originMethod.apply(this, args);

await connection.close();
if (result) {
await connection.close();
}

return result;
};
Expand Down
38 changes: 36 additions & 2 deletions src/repository/algorithm.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
import { EntityRepository, Repository } from "typeorm";
import { ModifyAlgorithmDTO } from "../DTO/algorithm.dto";
import { EntityRepository, Repository, SelectQueryBuilder } from "typeorm";

import { JoinAlgorithmDTO, ModifyAlgorithmDTO } from "../DTO/algorithm.dto";
import { Algorithm } from "../entity";

@EntityRepository(Algorithm)
export class AlgorithmRepository extends Repository<Algorithm> {
getListByCursor({ count, cursor, status, isAdmin }: JoinAlgorithmDTO) {
function addOptions(algorithmList: SelectQueryBuilder<Algorithm>) {
return algorithmList.take(count).orderBy("postNumber", "DESC").getMany();
}

const base = this.createQueryBuilder("algorithm").where(
"algorithm.algorithmStatus = :status",
{
status: isAdmin ? status : "PENDING",
}
);

return addOptions(
!!cursor
? base.andWhere("algorithm.postNumber <= :cursor", { cursor })
: base
);
}

getListByPage({ count, page, status, isAdmin }: JoinAlgorithmDTO) {
function addOptions(algorithmList: SelectQueryBuilder<Algorithm>) {
return algorithmList.take(count).orderBy("postNumber", "DESC").getMany();
}

const base = this.createQueryBuilder("algorithm").where(
"algorithm.algorithmStatus = :status",
{
status: isAdmin ? status : "PENDING",
}
);

return addOptions(!!page ? base.skip((page - 1) * count) : base);
}

async getAlgorithmCountAtAll() {
return this.createQueryBuilder("algorithm")
.select("algorithm.algorithmStatus AS status")
Expand Down
Loading

0 comments on commit aa86cab

Please sign in to comment.