Skip to content

Commit

Permalink
Merge pull request #263 from mash-up-kr/feature/auto-recruit-team-id
Browse files Browse the repository at this point in the history
Feat: 지원서 생성, 조회에 필요한 teamId를 api를 통해 응답받도록 개선한다
  • Loading branch information
HaJunRyu authored Jan 27, 2024
2 parents 4480869 + af56625 commit 8d34dbe
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 50 deletions.
44 changes: 27 additions & 17 deletions pages/apply/[platformName].tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { applicationApiService } from '@/api/services';
import { applicationApiService, teamApiService } from '@/api/services';
import { ApplyLayout } from '@/components';
import {
PlatformHeadings,
Expand All @@ -10,11 +10,10 @@ import {
ERROR_PAGE,
HOME_PAGE,
NOT_FOUND_PAGE,
teamIds,
teamNames,
Teams,
} from '@/constants';
import { Application } from '@/types/dto';
import { Application, TeamName } from '@/types/dto';
import { GetServerSideProps } from 'next';
import { getSession } from 'next-auth/react';
import { useRouter } from 'next/router';
Expand Down Expand Up @@ -50,17 +49,6 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
};
}

const currentApplyPlatform = teamNames[context.params?.platformName as Teams];

if (!currentApplyPlatform) {
return {
redirect: {
permanent: false,
destination: NOT_FOUND_PAGE,
},
};
}

const session = await getSession(context);

if (!session) {
Expand All @@ -73,6 +61,28 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
}

try {
const teams = (
await teamApiService.getTeams({
accessToken: session?.accessToken,
generationNumber: CURRENT_GENERATION,
})
).data;

const teamIds = teams.reduce<Record<TeamName, number>>((acc, { name, teamId }) => {
return { ...acc, [name]: teamId };
}, {} as Record<TeamName, number>);

const currentApplyPlatform = teamNames[context.params?.platformName as Teams];

if (!currentApplyPlatform) {
return {
redirect: {
permanent: false,
destination: NOT_FOUND_PAGE,
},
};
}

const applications = (
await applicationApiService.getApplications({
accessToken: session?.accessToken,
Expand All @@ -86,15 +96,15 @@ export const getServerSideProps: GetServerSideProps = async (context) => {

const currentApplication = applications.find(
({ team, generationResponse: { generationNumber } }) =>
team.teamId === teamIds[CURRENT_GENERATION][currentApplyPlatform] &&
generationNumber === CURRENT_GENERATION,
team.teamId === teamIds[currentApplyPlatform] && generationNumber === CURRENT_GENERATION,
);

if (!currentApplication) {
const application = await applicationApiService.createMyApplication({
accessToken: session.accessToken,
teamId: teamIds[CURRENT_GENERATION][currentApplyPlatform],
teamId: teamIds[currentApplyPlatform],
});

return {
props: {
application: application?.data,
Expand Down
11 changes: 8 additions & 3 deletions src/api/services/team.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { TeamsResponse } from '@/types/dto';
import { TeamsRequest, TeamsResponse } from '@/types/dto';
import BaseApiService from './base';

class TeamApiService extends BaseApiService {
public constructor() {
super('teams');
}

public getTeams(): Promise<TeamsResponse> {
return this.http.get('').then(BaseApiService.handleResponse).catch(BaseApiService.handleError);
public getTeams({ accessToken, generationNumber }: TeamsRequest): Promise<TeamsResponse> {
return this.http
.get(`?generationNumber=${generationNumber}`, {
headers: { Authorization: `Bearer ${accessToken}` },
})
.then(BaseApiService.handleResponse)
.catch(BaseApiService.handleError);
}
}

Expand Down
29 changes: 0 additions & 29 deletions src/constants/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,6 @@ export const teamNames = {
spring: 'Spring',
} as const;

export const teamIds = {
12: {
[teamNames.design]: 5,
[teamNames.web]: 6,
[teamNames.android]: 7,
[teamNames.ios]: 8,
[teamNames.node]: 9,
[teamNames.spring]: 10,
},
13: {
[teamNames.design]: 11,
[teamNames.web]: 12,
[teamNames.android]: 13,
[teamNames.ios]: 14,
[teamNames.node]: 15,
[teamNames.spring]: 16,
},
// TODO: 14기 팀 id 확정되면 수정
14: {
[teamNames.design]: 17,
[teamNames.web]: 18,
[teamNames.android]: 19,
[teamNames.ios]: 20,
[teamNames.node]: 21,
[teamNames.spring]: 22,
},
} as const;

export const TEAM_NICK_NAME: Record<TeamName, string> = {
Design: 'Product Design Team',
Android: 'Android Team',
Expand All @@ -58,4 +30,3 @@ export const TEAM_NICK_NAME: Record<TeamName, string> = {

export type Teams = ValueOf<typeof teamUrls>;
export type TeamNames = ValueOf<typeof teamNames>;
export type TeamIds = ValueOf<typeof teamIds>;
5 changes: 4 additions & 1 deletion src/types/dto/team.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseResponse } from '@/types/dto/base';
import { BaseRequest, BaseResponse } from '@/types/dto/base';

export type TeamName = 'Design' | 'Web' | 'Android' | 'iOS' | 'Node' | 'Spring';
export interface Team {
Expand All @@ -8,4 +8,7 @@ export interface Team {

export interface TeamsResponseData extends Array<Team> {}

export interface TeamsRequest extends BaseRequest {
generationNumber: number;
}
export interface TeamsResponse extends BaseResponse<TeamsResponseData> {}

0 comments on commit 8d34dbe

Please sign in to comment.