Skip to content

Commit 7dd89d5

Browse files
committed
Fix user detailed routes
1 parent 6fd82c8 commit 7dd89d5

File tree

7 files changed

+14
-13
lines changed

7 files changed

+14
-13
lines changed

backend/app/controller/common/controllerCommon.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class controllerCommon {
2121

2222
findSuccess(res) {
2323
return (result) => {
24+
console.log(result)
2425
res.status(200); // Found
2526
res.json(result);
2627
}

backend/app/controller/userController.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class UserController {
3232
*/
3333
findById(req, res) {
3434
let userId = req.params.userId;
35+
console.log(userId)
3536
this.userDao.findById(userId)
3637
.then(this.common.findSuccess(res))
3738
.catch(this.common.findError(res));

backend/app/dao/userDao.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class UserDao {
3535
* @return entity
3636
*/
3737
findById(userId) {
38-
let sqlRequest = "SELECT id, username, password, firstName, lastName, age, imageURL, comment FROM User WHERE id like '%'||$userId||'%' ";
38+
let sqlRequest = "SELECT id, username, password, firstName, lastName, age, imageURL, comment FROM User WHERE id=$userId";
3939
let sqlParams = {$userId: userId};
4040
return this.common.findOne(sqlRequest, sqlParams).then(rows =>{
4141
let users = [];

frontend/src/actions/userActions/userActions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ function getUserDetailed(userId) {
6666
};
6767

6868
function request(userId) { return { type: userConstants.DETAILED_REQUEST, userId } }
69-
function success(userId) { return { type: userConstants.DETAILED_SUCCESS, userId } }
69+
function success(userDetailed) { return { type: userConstants.DETAILED_SUCCESS, userDetailed } }
7070
function failure(error) { return { type: userConstants.DETAILED_FAILURE, error } }
7171
}

frontend/src/containers/UserDetailedPage/UserDetailedPage.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { connect } from "react-redux";
33
import { userActions } from "../../actions";
44

55
class UserDetailedPage extends Component {
6-
// componentDidMount() {
7-
// this.props.dispatch(userActions.getUserDetailed(this.props.match.params.id));
8-
// }
6+
componentDidMount() {
7+
this.props.dispatch(userActions.getUserDetailed(this.props.match.params.id));
8+
9+
}
910
render() {
1011
const {userDetailed} = this.props;
12+
console.log(this.props)
1113
return (
1214
<div>
1315
{userDetailed}
@@ -17,10 +19,11 @@ class UserDetailedPage extends Component {
1719
}
1820

1921
function mapStateToProps(state) {
20-
const { userDetailed, authentication } = state;
22+
const { users, userDetailed, authentication } = state;
2123
const { user } = authentication;
2224
return {
2325
user,
26+
users,
2427
userDetailed
2528
};
2629
}

frontend/src/reducers/usersReducer/usersReducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function users(state = {}, action) {
2121
};
2222
case userConstants.DETAILED_SUCCESS:
2323
return {
24-
userId: action.userId
24+
userDetailed: action.userDetailed
2525
};
2626
case userConstants.DETAILED_FAILURE:
2727
return {

frontend/src/services/userService/userService.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,22 @@ function getAll() {
4040
};
4141

4242
return fetch('http://localhost:7777/user/all', requestOptions).then(handleResponse);
43-
// return fetch('http://localhost:3000/users', requestOptions).then(handleResponse);
4443
}
4544

4645
function getUserDetailed(userId) {
4746
const requestOptions = {
4847
method: 'GET',
49-
headers: authHeader(),
50-
body: JSON.stringify({ userId })
48+
headers: authHeader()
5149
};
5250

53-
return fetch('http://localhost:7777/user/:userId', requestOptions).then(handleResponse);
54-
// return fetch('http://localhost:3000/users/:userId', requestOptions).then(handleResponse);
51+
return fetch(`http://localhost:7777/user/find/${userId}`, requestOptions).then(handleResponse);
5552
}
5653

5754
function handleResponse(response) {
5855
return response.text().then(text => {
5956
const data = text && JSON.parse(text);
6057
if (!response.ok) {
6158
if (response.status === 21) {
62-
// auto logout if 401 response returned from api
6359
logout();
6460
Location.reload(true);
6561
}

0 commit comments

Comments
 (0)