Skip to content

Commit

Permalink
feat: Activity Api 연결 (#33)
Browse files Browse the repository at this point in the history
* fix(api): 백엔드 서버 시그니처와 동기화

* feat(api): activity/study api 추가

* feat(api): activity/project, social api 추가
  • Loading branch information
son-daehyeon committed Sep 14, 2024
1 parent 8bec525 commit da8e599
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 79 deletions.
8 changes: 4 additions & 4 deletions src/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,19 @@ const MemberList = async () => {
}
```

## User Store
## Member Store

```tsx
const MyPage = () => {
const { user } = useUserStore();
const { member } = useMemberStore();

return (
<div>
<h1>My Info</h1>

<div>
<span>Name: {user.name}</span>
<span>Email: {user.email}</span>
<span>Name: {member.name}</span>
<span>Email: {member.email}</span>
</div>
</div>
);
Expand Down
43 changes: 40 additions & 3 deletions src/api/domain/Activity.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
import { WinkApiRequest } from '@/api';
import {
Project,
ProjectAdmin,
Social,
SocialAdmin,
Study,
StudyAdmin,
WinkApiRequest,
} from '@/api';

export class Activity {
constructor(private readonly request: WinkApiRequest) {}
}

//////////////////////////////////////////////////////////////////////////
private readonly project: Project = new Project(this.request);
private readonly projectAdmin: ProjectAdmin = new ProjectAdmin(this.request);
private readonly study: Study = new Study(this.request);
private readonly studyAdmin: StudyAdmin = new StudyAdmin(this.request);
private readonly social: Social = new Social(this.request);
private readonly socialAdmin: SocialAdmin = new SocialAdmin(this.request);

public get Project() {
return this.project;
}

public get ProjectAdmin() {
return this.projectAdmin;
}

public get Study() {
return this.study;
}

public get StudyAdmin() {
return this.studyAdmin;
}

public get Social() {
return this.social;
}

public get SocialAdmin() {
return this.socialAdmin;
}
}
14 changes: 2 additions & 12 deletions src/api/domain/Auth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MyInfoLinks, RoleString, WinkApiRequest } from '@/api';
import { MemberType, WinkApiRequest } from '@/api';

export class Auth {
constructor(private readonly request: WinkApiRequest) {}
Expand Down Expand Up @@ -72,15 +72,5 @@ export interface VerifyCodeResponseDto {
}

export interface MyInfoResponseDto {
memberId: string;
createdAt: Date;
updatedAt: Date;
name: string;
studentId: string;
email: string;
avatar: string | null;
description: string | null;
link: MyInfoLinks;
role: RoleString | null;
fee: boolean;
member: MemberType;
}
6 changes: 3 additions & 3 deletions src/api/domain/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface UpdateMyPasswordRequestDto {
//////////////////////////////////////////////////////////////////////////

export interface EachGetMembersResponseDto {
memberId: string;
_id: string;
createdAt: Date;
updatedAt: Date;
name: string;
Expand All @@ -116,7 +116,7 @@ export interface GetMembersForAdminResponseDto {
}

export interface EachGetWaitingMembersResponseDto {
memberId: string;
_id: string;
name: string;
studentId: string;
}
Expand Down Expand Up @@ -152,4 +152,4 @@ export enum Role {

export type RoleString = keyof typeof Role;

export type User = MyInfoResponseDto;
export type MemberType = MyInfoResponseDto;
94 changes: 94 additions & 0 deletions src/api/domain/activity/Project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { MemberType, WinkApiRequest } from '@/api';

export class Project {
constructor(private readonly request: WinkApiRequest) {}

public async getProject(data: GetProjectRequestDto): Promise<GetProjectResponseDto> {
return this.request.get('/activity/project/detail', data);
}

public async getProjectsPage(): Promise<GetProjectsPageResponseDto> {
return this.request.get('/activity/project/max');
}

public async getProjects(data: GetProjectsRequestDto): Promise<GetProjectsResponseDto> {
return this.request.get('/activity/project', data);
}
}

export class ProjectAdmin {
constructor(private readonly request: WinkApiRequest) {}

public async createProject(data: CreateProjectRequestDto): Promise<CreateProjectResponseDto> {
return this.request.put('/admin/activity/project', data);
}

public async updateProject(data: UpdateProjectRequestDto): Promise<void> {
return this.request.patch('/admin/activity/project', data);
}

public async deleteProject(data: DeleteProjectRequestDto): Promise<void> {
return this.request.delete('/admin/activity/project', data);
}
}

//////////////////////////////////////////////////////////////////////////

export interface CreateProjectRequestDto {
title: string;
content: string;
tags: string[];
image: string;
}

export interface DeleteProjectRequestDto {
projectId: string;
}

export interface GetProjectRequestDto {
projectId: string;
}

export interface GetProjectsRequestDto {
page: number;
}

export interface UpdateProjectRequestDto {
projectId: string;
title: string;
content: string;
tags: string[];
image: string;
}

//////////////////////////////////////////////////////////////////////////

export interface CreateProjectResponseDto {
project: ProjectType;
}

export interface GetProjectResponseDto {
project: ProjectType;
}

export interface GetProjectsResponseDto {
projects: ProjectType[];
}

export interface GetProjectsPageResponseDto {
page: number;
}

//////////////////////////////////////////////////////////////////////////

export interface ProjectType {
_id: string;
createdAt: Date;
updatedAt: Date;
type: 'Project' | 'Study' | 'Social';
author: MemberType;
title: string;
content: string;
tags: string[];
image: string;
}
80 changes: 80 additions & 0 deletions src/api/domain/activity/Social.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { WinkApiRequest } from '@/api';

export class Social {
constructor(private readonly request: WinkApiRequest) {}

public async getSocial(data: GetSocialRequestDto): Promise<GetSocialResponseDto> {
return this.request.get('/activity/social/detail', data);
}

public async getSocials(): Promise<GetSocialsResponseDto> {
return this.request.get('/activity/social');
}
}

export class SocialAdmin {
constructor(private readonly request: WinkApiRequest) {}

public async createSocial(data: CreateSocialRequestDto): Promise<CreateSocialResponseDto> {
return this.request.put('/admin/activity/social', data);
}

public async updateSocial(data: UpdateSocialRequestDto): Promise<void> {
return this.request.patch('/admin/activity/social', data);
}

public async deleteSocial(data: DeleteSocialRequestDto): Promise<void> {
return this.request.delete('/admin/activity/social', data);
}
}

//////////////////////////////////////////////////////////////////////////

export interface CreateSocialRequestDto {
title: string;
contents: Content[];
}

export interface DeleteSocialRequestDto {
socialId: string;
}

export interface GetSocialRequestDto {
socialId: string;
}

export interface UpdateSocialRequestDto {
socialId: string;
title: string;
contents: Content[];
}

//////////////////////////////////////////////////////////////////////////

export interface CreateSocialResponseDto {
social: SocialType;
}

export interface GetSocialResponseDto {
social: SocialType;
}

export interface GetSocialsResponseDto {
socials: SocialType[];
}

//////////////////////////////////////////////////////////////////////////

export interface SocialType {
_id: string;
createdAt: Date;
updatedAt: Date;
type: 'Project' | 'Study' | 'Social';
title: string;
contents: Content[];
}

export interface Content {
content: string;
image: string;
}
Loading

0 comments on commit da8e599

Please sign in to comment.