Skip to content
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
41 changes: 36 additions & 5 deletions src/api/routes/v1/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import asyncHandler from "@/api/middlewares/asyncHandler";
import {
GroupPostDTO,
GroupPostInputDTO

GroupPostInputDTO,
GroupPostEmojiDTO,

} from "@/interfaces/GroupPost";

import GroupService from "@/services/group";
Expand All @@ -15,7 +18,7 @@ const route = Router();
export default (app: Router) => {
app.use("/groups", route);

// 개인 롤링페이퍼 포스트 생성
// 롤링페이퍼 포스트 생성
route.post(
"/posts",
asyncHandler(async (req: Request, res: Response) => {
Expand Down Expand Up @@ -49,13 +52,18 @@ export default (app: Router) => {
asyncHandler(async (req: Request, res: Response) => {
logger.debug(req.body);
const groupServiceInstance = Container.get(GroupService);
const { groupUadatedPostResult} = await groupServiceInstance.updateGroupPost(

const { groupUpdatedPostResult} = await groupServiceInstance.updateGroupPost(
req.body as GroupPostInputDTO,
req.body as GroupPostDTO,
);
// ! 수정한 후 디테일 뷰로 이동!
// 포스트 수정을 성공했다면 디테일 뷰
const { groupPostDetail} = await groupServiceInstance.getDetailGroupPost(
req.body as GroupPostInputDTO,
);
// 수정한 포스트 결과
return res.status(201).json({ result: groupUadatedPostResult });
return res.status(201).json({ result: groupUpdatedPostResult, post: groupPostDetail});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

응답 시 result에 배열을 그대로 담아서 주는데, true or false값만 전달해주는게 어떤가요?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

groupUpdatedPostResult와 groupPostDetail 차이점이 뭔가요? 좀 헷갈려서..

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

groupUp0datedPostResult는 수정 성공 여부이고 groupPostDetail은 수정 후 포스트의 정보를 전달하기 위한 해당 포스트의 디테일 정보입니다.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

result에 true false 값으로 수정하겠습니다.


}),
);

Expand All @@ -72,4 +80,27 @@ export default (app: Router) => {
return res.status(200).json({ result: groupDeletedPostResult });
}),
);

// 그룹 포스트 이모지 수정
route.put(
"/posts/emoji",
asyncHandler(async (req: Request, res: Response) => {
logger.debug(req.body);
const groupServiceInstance = Container.get(GroupService);
const { groupUpdatedEmojiResult} = await groupServiceInstance.updateEmojiForPost(
req.body as GroupPostInputDTO,
req.body as GroupPostEmojiDTO,
);

// 이모지 수정을 성공했다면 디테일 뷰
const { groupPostDetail} = await groupServiceInstance.getDetailGroupPost(
req.body as GroupPostInputDTO,
);

// ! 수정한 후 디테일 뷰로 이동!
// 수정한 포스트 결과
return res.status(201).json({ result: groupUpdatedEmojiResult , post: groupPostDetail});
}),
);

};
34 changes: 34 additions & 0 deletions src/interfaces/Group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

export interface Group {
groupId: string;
userId: string;
groupName: string;
inviteUrl: string;

}

export interface GroupMember{
groupMemberId: string;
groupId: string;
userId: string;
groupRollingPaperId: string;
}
export interface GroupInputDTO{
groupId: string;
}

export interface GroupMemberInputDTO{
groupMemberId: string;
}

export interface GroupDTO {
userId: string;
groupName: string;
inviteUrl: string;
}

export interface GroupMemberDTO{
groupId: string;
userId: string;
groupRollingPaperId: string;
}
6 changes: 6 additions & 0 deletions src/interfaces/GroupPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ export interface GroupPostDTO {
anonymousType: AnonymousType | null;
postColor: string;
}


export interface GroupPostEmojiDTO {
emojiType: string | null;
}

13 changes: 13 additions & 0 deletions src/interfaces/GroupRollingPaper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export interface GroupRollingPaper {
groupRollingPaperId: string;
title: string | null;
}


export interface GroupRollingPaperInputDTO {
groupRollingPaperId: string;
}

export interface GroupRollingPaperDTO {
title: string | null;
}
24 changes: 12 additions & 12 deletions src/interfaces/PersonalPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ enum AnonymousType {
}

export interface PersonalPost {
personal_post_id: string;
personal_rolling_paper_id: string;
user_id: string | null;
personalPostId: string;
personalRollingPaperId: string;
userId: string | null;
content: string | null;
anonymous_type: AnonymousType | null;
post_color: string;
emoji_type: string | null;
non_member_password: string | null;
anonymousType: AnonymousType | null;
postColor: string;
emojiType: string | null;
nonMemberPassword: string | null;
}

export interface PersonalPostInputDTO {
personalPostId: string;
}

export interface PersonalPostDTO {
personal_rolling_paper_id: string;
user_id: string | null;
personalRollingPaperId: string;
userId: string | null;
content: string | null;
anonymous_type: AnonymousType | null;
post_color: string;
non_member_password: string | null;
anonymousType: AnonymousType | null;
postColor: string;
nonMemberPassword: string | null;
}
45 changes: 41 additions & 4 deletions src/services/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
GroupPost,
GroupPostInputDTO,
GroupPostDTO,

GroupPostEmojiDTO,

} from "@/interfaces/GroupPost";
import { group } from "console";

Expand Down Expand Up @@ -65,13 +68,17 @@ export default class GroupService {
public async updateGroupPost(
groupPostInputDTO: GroupPostInputDTO,
groupPostDTO: GroupPostDTO,
): Promise<{ groupUadatedPostResult: GroupPost }> {

): Promise<{ groupUpdatedPostResult: GroupPost }> {

try {
const groupPostId = groupPostInputDTO.groupPostId;

// ! 수정한 사람 누구인지 확인 로직 필요, 비로그인 유저면 비밀번호 확인해줘야해!
// 이건 로그인 회원
const groupUadatedPostResult= await this.groupPostModel.update(

const groupUpdatedPostResult= await this.groupPostModel.update(

{
content:groupPostDTO.content,
post_color:groupPostDTO.postColor,
Expand All @@ -81,11 +88,13 @@ export default class GroupService {
);
// 비로그인 회원은 필요한 거- 비밀번호 확인

if (!groupUadatedPostResult) {

if (groupUpdatedPostResult[0]===0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sequelize UPDATE 시 return type이 [영향 받은 행 개수]니까 업데이트 수행 시 리턴값이 [0]이면 업데이트 할 포스트가 없다고 보고 이러한 조건식을 걸어두신건가요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

throw new Error("Unable to update post");
}

return { groupUadatedPostResult };
return { groupUpdatedPostResult };

} catch (error) {
this.logger.error(error);
throw error;
Expand Down Expand Up @@ -113,4 +122,32 @@ export default class GroupService {
throw error;
}
}


// TODO: 롤링페이퍼 주인만 이모지 수정 가능!
public async updateEmojiForPost(
groupPostInputDTO: GroupPostInputDTO,
groupPostEmojiDTO: GroupPostEmojiDTO,
): Promise<{ groupUpdatedEmojiResult: GroupPost}> {
try {
const groupPostId = groupPostInputDTO.groupPostId;

const groupUpdatedEmojiResult= await this.groupPostModel.update(
{
emoji_type : groupPostEmojiDTO.emojiType,
},
{ where: { group_post_id: groupPostId } },
);

if (groupUpdatedEmojiResult[0]=== 0) {
throw new Error("Unable to update emoji for a post");
}

return { groupUpdatedEmojiResult};
} catch (error) {
this.logger.error(error);
throw error;
}
}

}