Skip to content

Commit

Permalink
[FE][Feat] #241 : createChannelAPI ์—ฐ๋™
Browse files Browse the repository at this point in the history
  • Loading branch information
leedongyull committed Nov 26, 2024
1 parent 0e0d50c commit 19c7c43
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
10 changes: 9 additions & 1 deletion frontend/src/api/dto/channel.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export class locationEntity {
title: string | undefined;

lat: number | undefined;

lng: number | undefined;
}

export class pathLocationEntity {
lat: number | undefined;

lng: number | undefined;
Expand All @@ -15,7 +23,7 @@ export class guestEntity {

end_location: locationEntity | undefined;

path: locationEntity[] | undefined;
path: pathLocationEntity[] | undefined;

marker_style: guestMarkerStyleEntity | undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/component/routebutton/RouteResultButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const RouteResultButton = (props: IRouteResultButtonProps) => {
)}
>
<div className="h-full w-24 overflow-hidden text-ellipsis whitespace-nowrap rounded border-2 px-2 py-[16px] text-start text-xs font-normal">
{props.user.end_location.title}
{props.user.start_location.title}
</div>
<GoArrowRight className="mx-2 h-8 w-8" />
<div className="h-full w-24 overflow-hidden text-ellipsis whitespace-nowrap rounded border-2 px-2 py-[16px] text-start text-xs font-normal">
Expand Down
44 changes: 43 additions & 1 deletion frontend/src/pages/AddChannel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Outlet } from 'react-router-dom';
import { RouteResultButton } from '@/component/routebutton/RouteResultButton';
import { IUser, UserContext } from '@/context/UserContext';
import { buttonActiveType } from '@/component/layout/enumTypes';
import { createChannelReqEntity } from '@/api/dto/channel.dto';
import { createChannel } from '@/api/channel.api';
import { InputBox } from '../component/common/InputBox';

/**
Expand Down Expand Up @@ -35,7 +37,8 @@ const Divider = () => <hr className="my-6 w-full border-gray-300" />;
export const AddChannel = () => {
const [channelName, setChannelName] = useState<string>('');
const { users, setUsers } = useContext(UserContext);
const { setFooterTitle, setFooterTransparency, setFooterActive } = useContext(FooterContext);
const { setFooterTitle, setFooterTransparency, setFooterActive, footerOption, setFooterOnClick } =
useContext(FooterContext);

/**
* ์‚ฌ์šฉ์ž ์ถ”๊ฐ€ ํ•จ์ˆ˜
Expand Down Expand Up @@ -127,6 +130,45 @@ export const AddChannel = () => {
}
}, [users, setFooterActive]); // users๊ฐ€ ๋ณ€๊ฒฝ๋  ๋•Œ๋งˆ๋‹ค ์‹คํ–‰

const createChannelAPI = async () => {
try {
const channelData: createChannelReqEntity = {
name: channelName,
host_id: 'jhi2359',
guests: users.map(user => ({
name: user.name,
start_location: {
title: user.start_location.title,
lat: user.start_location.lat,
lng: user.start_location.lng,
},
end_location: {
title: user.end_location.title,
lat: user.end_location.lat,
lng: user.end_location.lng,
},
path: user.path.map(p => ({
lat: p.lat,
lng: p.lng,
})),
marker_style: user.marker_style,
})),
};

// createChannel ํ˜ธ์ถœ
const response = await createChannel(channelData);
console.log('์ฑ„๋„ ์ƒ์„ฑ ์„ฑ๊ณต:', response);
} catch (error) {
console.error('์ฑ„๋„ ์ƒ์„ฑ ์‹คํŒจ:', error);
}
};

useEffect(() => {
setFooterOnClick(() => {
createChannelAPI();
});
}, [footerOption.active, channelName]); // channelName์ด ๋ณ€๊ฒฝ๋  ๋•Œ๋งˆ๋‹ค ์‹คํ–‰

return (
<main className="flex h-full w-full flex-col items-center px-8 py-16">
<Outlet />
Expand Down

0 comments on commit 19c7c43

Please sign in to comment.