Skip to content

Commit 482ec93

Browse files
committed
feat: reformat users and auth apis
1 parent 8bef76e commit 482ec93

File tree

12 files changed

+100
-39
lines changed

12 files changed

+100
-39
lines changed

src/api/answersApi.js

Whitespace-only changes.

src/api/authApi.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import axios from 'axios';
2+
3+
import {loadUserData as _loadUserData, registerUser as _registerUser, loginUser as _loginUser} from './urls';
4+
5+
export const loadUserData = () => {
6+
return axios.get(_loadUserData);
7+
};
8+
9+
export const registerUser = (username, password) => {
10+
const config_headers = {
11+
headers: {
12+
'Content-Type': 'application/json',
13+
Accept: "application/json",
14+
},
15+
};
16+
17+
const body = JSON.stringify({ username, password });
18+
19+
return axios.post(_registerUser, body, config_headers);
20+
};
21+
22+
export const loginUser = (username, password) => {
23+
const config_headers = {
24+
headers: {
25+
'Content-Type': 'application/json',
26+
Accept: "application/json",
27+
},
28+
};
29+
30+
const body = JSON.stringify({username, password});
31+
32+
return axios.post(_loginUser, body, config_headers);
33+
};

src/api/commentsApi.js

Whitespace-only changes.

src/api/postsApis.js

Whitespace-only changes.

src/api/tagsApi.js

Whitespace-only changes.

src/api/urls.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import config from "../config";
2+
3+
// Users
4+
export const usersData = config.BASE_URL + '/api/users';
5+
export const profileData = config.BASE_URL + '/api/users/{id}';
6+
7+
// Auth
8+
export const loadUserData = config.BASE_URL + '/api/auth';
9+
export const registerUser = config.BASE_URL + '/api/users';
10+
export const loginUser = config.BASE_URL + '/api/auth';
11+
12+
// Posts
13+
export const allPostsData = config.BASE_URL + '/api/posts';
14+
export const singlePostData = config.BASE_URL + '/api/posts/{id}';
15+
export const allTopPostsData = config.BASE_URL + '/api/posts/top';
16+
export const allTagPostsData = config.BASE_URL + '/api/posts/tag/{tagName}';
17+
export const createSinglePost = config.BASE_URL + '/api/posts';
18+
export const deleteSinglePost = config.BASE_URL + '/api/posts/{id}';
19+
20+
// Answers
21+
export const allAnswersData = config.BASE_URL + '/api/posts/answers/{id}';
22+
export const createSingleAnswer = config.BASE_URL + '/api/posts/answers/{postId}';
23+
export const deleteSingleAnswer = config.BASE_URL + '/api/posts/answers/{AnswerId}';
24+
25+
// Comments
26+
export const allCommentsData = config.BASE_URL + '/api/posts/comments/{id}';
27+
export const createSingleComment = config.BASE_URL + '/api/posts/comments/{postId}';
28+
export const deleteSingleComment = config.BASE_URL + '/api/posts/comments/{CommentId}';
29+
30+
// Tags
31+
export const allTagsData = config.BASE_URL + '/api/tags';
32+
export const singleTagData = config.BASE_URL + '/api/tags/{tagName}';

src/api/usersApi.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import axios from 'axios';
2+
3+
import {usersData as _usersData, profileData as _profileData} from './urls';
4+
5+
export const usersData = () => {
6+
return axios.get(_usersData);
7+
};
8+
9+
export const profileData = (id) => {
10+
return axios.get(_profileData.replace('{id}', id));
11+
};

src/modules/Post/Post.component.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect, Fragment } from "react";
22
import moment from "moment";
3+
import { useParams } from "react-router-dom";
34
import { connect } from "react-redux";
45
import PropTypes from "prop-types";
56
import { getPost } from "../../redux/posts/posts.actions";
@@ -12,9 +13,11 @@ import QuestionSection from "./QuestionSection/QuestionSection.component";
1213
import "./Post.styles.scss";
1314
import censorBadWords from "../../services/censorBadWords";
1415

15-
const Post = ({ getPost, post: { post, loading }, match }) => {
16+
const Post = ({ getPost, post: { post, loading } }) => {
17+
const { id } = useParams();
18+
1619
useEffect(() => {
17-
getPost(match.params.id);
20+
getPost(id);
1821
// eslint-disable-next-line
1922
}, [getPost]);
2023

src/modules/ProfilePage/ProfilePage.component.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useEffect, Fragment} from 'react';
22
import { connect } from 'react-redux';
3-
import { Link } from "react-router-dom";
3+
import { Link, useParams } from "react-router-dom";
44
import PropTypes from 'prop-types';
55
import { getProfile } from '../../redux/users/users.actions';
66

@@ -11,9 +11,11 @@ import UserActivity from "./UserActivity/UserActivity.component";
1111

1212
import './ProfilePage.styles.scss';
1313

14-
const ProfilePage = ({getProfile, user: {user, loading}, match}) => {
14+
const ProfilePage = ({getProfile, user: {user, loading}}) => {
15+
const { id } = useParams();
16+
1517
useEffect(() => {
16-
getProfile(match.params.id);
18+
getProfile(id);
1719
// eslint-disable-next-line
1820
}, [getProfile]);
1921

src/modules/TagPage/TagPage.component.jsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, {useEffect, Fragment, useState} from 'react';
22
import {connect} from 'react-redux';
3-
import {Redirect} from 'react-router-dom';
3+
import {Redirect, useParams} from 'react-router-dom';
44
import PropTypes from 'prop-types';
55
import {getTagPosts} from '../../redux/posts/posts.actions';
66
import {getTag} from '../../redux/tags/tags.actions';
@@ -13,10 +13,12 @@ import ButtonGroup from '../../components/molecules/ButtonGroup/ButtonGroup.comp
1313

1414
import './TagPage.styles.scss';
1515

16-
const TagPage = ({getTag, getTagPosts, tag, post: {posts, loading}, match}) => {
16+
const TagPage = ({getTag, getTagPosts, tag, post: {posts, loading}}) => {
17+
const { tagname } = useParams();
18+
1719
useEffect(() => {
18-
getTagPosts(match.params.tagname);
19-
getTag(match.params.tagname);
20+
getTagPosts(tagname);
21+
getTag(tagname);
2022
// eslint-disable-next-line
2123
}, [getTag, getTagPosts]);
2224

0 commit comments

Comments
 (0)