Skip to content

Commit

Permalink
commit to change branch
Browse files Browse the repository at this point in the history
  • Loading branch information
taeju-moon committed Aug 11, 2022
1 parent d1582b5 commit e23aa07
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 165 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

158 changes: 29 additions & 129 deletions src/api/auth.js
Original file line number Diff line number Diff line change
@@ -1,142 +1,42 @@
import axios from 'axios';
import { userValidation } from './validations';
import axios from "axios";

axios.defaults.withCredentials = true;

export const login = async (studentId, password) => {
try {
const result = await axios.post(
`${process.env.REACT_APP_API_URL}/auth/login`,
try {
const result = await axios.post(
`${process.env.REACT_APP_API_URL}/auth/login`,

{
studentId: studentId,
password: password,
}
);
{
studentId: studentId,
password: password,
}
);

return result;
} catch (error) {
throw new Error(error.message);
}
return result;
} catch (error) {
throw new Error(error.message);
}
};

export const logout = async () => {
try {
const result = await axios.post(
`${process.env.REACT_APP_API_URL}/auth/logout`
);
return result;
} catch (error) {
throw new Error(error.message);
}
try {
const result = await axios.post(
`${process.env.REACT_APP_API_URL}/auth/logout`
);
return result;
} catch (error) {
throw new Error(error.message);
}
};

export const verify = async () => {
try {
const result = await axios.get(
`${process.env.REACT_APP_API_URL}/auth/verify`
);
return result;
} catch (error) {
throw new Error(error.message);
}
};

export const getAllUsers = async () => {
try {
const result = await axios.get(`${process.env.REACT_APP_API_URL}/auth`);
return result.data.data.users;
} catch (error) {
throw new Error(error.message);
}
};

export const getOneUser = async (studentId) => {
try {
const result = await axios.get(
`${process.env.REACT_APP_API_URL}/auth/${studentId}`
);
console.log(result)
return result.data.data.user;
} catch (error) {
throw new Error(error.message);
}
};

export const addUser = async (
studentId,
password,
major,
name,
role,
degree
) => {
try {
const body = {
studentId,
password,
major,
name,
role,
degree,
isCheckedIn: false,
};
if (!userValidation(body))
throw Error('유효성 검사에서 통과하지 못했습니다.');
const result = axios.post(
`${process.env.REACT_APP_API_URL}/auth/register`,

body
);
return result;
} catch (error) {
throw new Error(error);
}
};

export const getUser = async (studentId) => {
try {
const result = await axios.get(
`${process.env.REACT_APP_API_URL}/auth/${studentId}`
);
return result.data.data.user;
} catch (error) {
throw new Error(error.message);
}
};

export const updateUser = async (id, properties) => {
try {
const body = properties;
const result = axios.patch(
`${process.env.REACT_APP_API_URL}/auth/${id}`,

body
);
return result;
} catch (error) {
throw new Error(error.message);
}
};

export const resetCheckInAll = async () => {
try {
const result = await axios.patch(
`${process.env.REACT_APP_API_URL}/auth/checkin`
);
return result;
} catch (error) {
throw new Error(error.message);
}
};

export const resetCheckInOne = async (id) => {
try {
const result = await axios.patch(
`${process.env.REACT_APP_API_URL}/auth/checkin/${id}`
);
return result;
} catch (error) {
throw new Error(error.message);
}
try {
const result = await axios.get(
`${process.env.REACT_APP_API_URL}/auth/verify`
);
return result;
} catch (error) {
throw new Error(error.message);
}
};
79 changes: 79 additions & 0 deletions src/api/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { userValidation } from "./validations";
import axios from "axios";

export const getAllUsers = async () => {
try {
const result = await axios.get(`${process.env.REACT_APP_API_URL}/users`);
return result.data.data.users;
} catch (error) {
throw new Error(error.message);
}
};

export const getOneUser = async (studentId) => {
try {
const result = await axios.get(
`${process.env.REACT_APP_API_URL}/users/${studentId}`
);
console.log(result);
return result.data.data.user;
} catch (error) {
throw new Error(error.message);
}
};

export const addUser = async (
studentId,
password,
major,
name,
role,
degree,
comment
) => {
try {
const body = {
studentId,
password,
major,
name,
role,
degree,
comment,
};
if (!userValidation(body))
throw Error("유효성 검사에서 통과하지 못했습니다.");
const result = axios.post(
`${process.env.REACT_APP_API_URL}/users/register`,
body
);
return result;
} catch (error) {
throw new Error(error);
}
};

export const getUser = async (studentId) => {
try {
const result = await axios.get(
`${process.env.REACT_APP_API_URL}/users/${studentId}`
);
return result.data.data.user;
} catch (error) {
throw new Error(error.message);
}
};

export const updateUser = async (id, properties) => {
try {
const body = properties;
const result = axios.patch(
`${process.env.REACT_APP_API_URL}/users/${id}`,

body
);
return result;
} catch (error) {
throw new Error(error.message);
}
};
2 changes: 1 addition & 1 deletion src/api/validations.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getAllUsers } from "./auth";
import { getAllUsers } from "./users";

export const userValidation = async (body) => {
//1. 학번이 유일한지 확인
Expand Down
36 changes: 3 additions & 33 deletions src/components/admin/AdminTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,8 @@ import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import Paper from "@mui/material/Paper";
import Button from "@mui/material/Button";
import styled from "@emotion/styled";

import { getAllUsers, resetCheckInAll, resetCheckInOne } from "../../api/auth";

const FlexBox = styled.div`
display: flex;
margin-top: 10px;
justify-content: flex-end;
`;
import { getAllUsers } from "../../api/users";

export default function UserTable() {
const [users, setUsers] = useState([]);
Expand All @@ -39,8 +32,7 @@ export default function UserTable() {
<TableCell align="right">전공</TableCell>
<TableCell align="right">학위</TableCell>
<TableCell align="right">권한</TableCell>
<TableCell align="right">체크인 여부</TableCell>
<TableCell align="right">체크인 초기화</TableCell>
<TableCell align="right">코멘트</TableCell>
<TableCell align="right">수정</TableCell>
</TableRow>
</TableHead>
Expand All @@ -51,19 +43,8 @@ export default function UserTable() {
<TableCell align="right">{row.name}</TableCell>
<TableCell align="right">{row.major}</TableCell>
<TableCell align="right">{row.degree}</TableCell>
<TableCell align="right">{row.comment}</TableCell>
<TableCell align="right">{row.role}</TableCell>
<TableCell align="right">{row.isCheckedIn ? 1 : 0}</TableCell>
<TableCell align="right">
<Button
variant="contained"
onClick={async () => {
await resetCheckInOne(row.studentId);
fillTable();
}}
>
Reset
</Button>
</TableCell>
<TableCell align="right">
<Button
variant="contained"
Expand All @@ -77,17 +58,6 @@ export default function UserTable() {
</TableBody>
</Table>
</TableContainer>
<FlexBox>
<Button
variant="contained"
onClick={async () => {
await resetCheckInAll();
fillTable();
}}
>
모든 체크인 초기화
</Button>
</FlexBox>
</div>
);
}
2 changes: 1 addition & 1 deletion src/components/admin/UserForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
import Container from "@mui/material/Container";
import Box from "@mui/material/Box";
import { addUser, updateUser, getOneUser } from "../../api/auth";
import { addUser, updateUser, getOneUser } from "../../api/users";
import styled from "@emotion/styled";
import SelectLabels from "./UserForm_SelectBox";

Expand Down

0 comments on commit e23aa07

Please sign in to comment.