-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User service #38
Merged
Merged
User service #38
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
707b428
Add mappers to UserResponse and PageResponse
moustaphastar 4f165ed
Add service methods, pass granted authorities to User object.
moustaphastar 25a2358
Add new derived queries.
moustaphastar decd56c
Add UserResponse class.
moustaphastar 5f8cf74
Add request/response classes for user image actions.
moustaphastar 1f28905
Add list, user and delete endpoints with access rule.
moustaphastar d5548a0
Add User page
moustaphastar 778f36f
Add user service file for api requests
moustaphastar e04d4ed
Add user details view modal
moustaphastar b134f45
Add route link for user page.
moustaphastar ad32c63
Add route link for user page.
moustaphastar File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import React, {useEffect, useState} from "react"; | ||
import CssBaseline from "@material-ui/core/CssBaseline"; | ||
import Container from "@material-ui/core/Container"; | ||
import CustomTable from "../../components/CustomTable"; | ||
import {pageUsers, getUserById, deleteUserById} from "./UserService"; | ||
import {createConfirmAlert, createErrorAlert, createSuccessAlert} from "../../components/Alert"; | ||
import ViewUserModal from "./modal/ViewUserModal"; | ||
|
||
|
||
const columns = [ | ||
"id", "Ad", "Email", "Telefon", "Lokasyon", "İşlemler" | ||
] | ||
|
||
const deleteDialogText = "Kullanıcıyı silmek istediğinizden emin misiniz?" | ||
const deleteSuccessDialogText = "Ürünü güncelleme işlemi başarılı" | ||
const deleteErrorDialogText = "Ürünü güncelleme işlemi başarısız" | ||
|
||
function User(props) { | ||
|
||
const [viewModalOpen, setViewModalOpen] = React.useState(false); | ||
const [page, setPage] = useState(0); | ||
const [size, setSize] = useState(5); | ||
const [count, setCount] = useState(0); | ||
const [users, setUsers] = useState([]); | ||
const [userDeleteSuccess, setUserDeleteSuccess] = useState(false); | ||
const [userDeleteError, setUserDeleteError] = useState(false); | ||
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false); | ||
const [idToDelete, setIdToDelete] = useState(null); | ||
const [viewUserData, setViewUserData] = useState([]); | ||
|
||
useEffect(() => { | ||
pageUsers(page, size).then(response => { | ||
setUsers(response.data.content); | ||
setCount(response.data.totalElements); | ||
}).catch(e => { | ||
console.log(e); | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
pageUsers(page, size).then(response => { | ||
setUsers(response.data.content); | ||
setCount(response.data.totalElements); | ||
}).catch(e => { | ||
console.log(e); | ||
}); | ||
}, [page, size]); | ||
|
||
function pageUsersDefault() { | ||
pageUsers(0, 5).then(response => { | ||
setPage(0); | ||
setUsers(response.data.content); | ||
setCount(response.data.totalElements); | ||
}).catch(e => { | ||
console.log(e); | ||
}); | ||
} | ||
|
||
useEffect(() => { | ||
if (userDeleteSuccess) { | ||
setTimeout(function () { | ||
setUserDeleteSuccess(false); | ||
}, 3000); | ||
} | ||
}, [userDeleteSuccess]); | ||
|
||
useEffect(() => { | ||
if (userDeleteError) { | ||
setTimeout(function () { | ||
setUserDeleteError(false); | ||
}, 3000); | ||
} | ||
}, [userDeleteError]); | ||
|
||
const handleDelete = (id) => { | ||
setDeleteDialogOpen(true); | ||
setIdToDelete(id); | ||
} | ||
|
||
const handleDeleteAfterConfirm = () => { | ||
|
||
deleteUserById(idToDelete).then(response => { | ||
pageUsersDefault(); | ||
setUserDeleteSuccess(true); | ||
}).catch(e => { | ||
console.log(e); | ||
setUserDeleteError(true); | ||
}) | ||
setDeleteDialogOpen(false); | ||
} | ||
|
||
const handleDeleteDialogClose = () => { | ||
setDeleteDialogOpen(false); | ||
} | ||
|
||
const handleVisible = (id) => { | ||
setViewModalOpen(true); | ||
getUserById(id).then(response => { | ||
setViewUserData(response.data); | ||
}).catch(e => { | ||
console.log(e); | ||
}) | ||
} | ||
|
||
const handleViewModalClose = () => { | ||
setViewModalOpen(false); | ||
} | ||
|
||
const handlePageChange = page => { | ||
setPage(page); | ||
} | ||
|
||
const handleRowsPerPageChange = rowsPerPage => { | ||
setSize(rowsPerPage); | ||
} | ||
|
||
return ( | ||
<React.Fragment> | ||
<CssBaseline/> | ||
{createConfirmAlert(deleteDialogOpen, deleteDialogText, handleDeleteDialogClose, handleDeleteAfterConfirm)} | ||
{userDeleteSuccess && <div> {createSuccessAlert(deleteSuccessDialogText)} <br/><br/></div>} | ||
{userDeleteError && <div> {createErrorAlert(deleteErrorDialogText)} <br/><br/></div>} | ||
<Container maxWidth="xl"> | ||
<div> | ||
<ViewUserModal open={viewModalOpen} | ||
userData={viewUserData} | ||
categoryData={viewUserData.category} | ||
handleClose={handleViewModalClose}/> | ||
|
||
</div> | ||
<div> | ||
<h2>Kullanıcılar</h2> | ||
</div> | ||
<CustomTable rows={users} | ||
columns={columns} | ||
handlePageChange={handlePageChange} | ||
handleRowsPerPageChange={handleRowsPerPageChange} | ||
isOperation={true} | ||
previewImageUrlField={"previewImageUrl"} | ||
activePage={page} | ||
count={count} | ||
handleDelete={handleDelete} | ||
handleVisible={handleVisible} | ||
hiddenIndexes={[2,3,7,8,9,10,11,12,13,14,15,16,17,18]} | ||
/> | ||
</Container> | ||
</React.Fragment> | ||
) | ||
|
||
} | ||
|
||
export default User; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import request from "../../common/request"; | ||
|
||
/** | ||
* Retrieves paged list of users. | ||
* @param page Page number. | ||
* @param size Page size. | ||
* @returns {Promise<* | void>} Http status code returned from the server. | ||
*/ | ||
export const pageUsers = (page, size) => { | ||
let options = { | ||
method: "GET", | ||
path: "/api/v1/users", | ||
params: ["page", "size"], | ||
values: [page, size], | ||
} | ||
|
||
return request(options); | ||
} | ||
|
||
/** | ||
* Retrieves user data from API. | ||
* @param userId Id of the user. | ||
* @returns {Promise<* | void>} User data as JSON. | ||
*/ | ||
export const getUserById = (userId) => { | ||
let options = { | ||
method: "GET", | ||
path: "/api/v1/users/" + userId, | ||
} | ||
|
||
return request(options); | ||
} | ||
|
||
/** | ||
* Requests a user status change from API. | ||
* @param id Id of the user. | ||
* @returns {Promise<* | void>} Http status code returned from API. | ||
*/ | ||
export const deleteUserById = (id) => { | ||
let options = { | ||
method: "DELETE", | ||
path: "/api/v1/users/" + id, | ||
} | ||
|
||
return request(options) | ||
} | ||
|
||
/** | ||
* Sends a user image addition request to API. | ||
* @param data Image data. | ||
* @returns {Promise<* | void>} Http status code returned from API. | ||
*/ | ||
export const addUserImage= data => { | ||
const formData = new FormData(); | ||
formData.append('file', data); | ||
|
||
const addUserImageRequest = { | ||
method: "POST", | ||
path: "/api/v1/file", | ||
data: formData, | ||
params: ["firebasePath"], | ||
values: ["product-images"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Value should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, do we have the implementation to add a user image? |
||
} | ||
return request(addUserImageRequest); | ||
} |
61 changes: 61 additions & 0 deletions
61
petshop-admin-panel/src/containers/user/modal/ViewUserModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, {useEffect} from "react"; | ||
import Dialog from "@material-ui/core/Dialog"; | ||
import DialogTitle from "@material-ui/core/DialogTitle"; | ||
import {DialogContentText} from "@material-ui/core"; | ||
import DialogContent from "@material-ui/core/DialogContent"; | ||
import Button from "@material-ui/core/Button"; | ||
import DialogActions from "@material-ui/core/DialogActions"; | ||
|
||
|
||
function ViewUserModal(props) { | ||
|
||
const {userData, open, handleClose} = props; | ||
|
||
useEffect(() => { | ||
if (open) { | ||
} | ||
}, [open]); | ||
|
||
return ( | ||
<React.Fragment> | ||
<Dialog open={open} onClose={handleClose} | ||
aria-labelledby="form-dialog-title" | ||
aria-describedby="alert-dialog-description" | ||
PaperProps={{ | ||
style: { | ||
minHeight: '40vh', | ||
minWidth: '40vw', | ||
}, | ||
}}> | ||
<DialogTitle id="view-user">Kullanıcı Detay</DialogTitle> | ||
<DialogContent> | ||
<div> | ||
<h4>Ad</h4> | ||
<DialogContentText>{userData.name}</DialogContentText> | ||
<h4>Soyad</h4> | ||
<DialogContentText>{userData.lastName}</DialogContentText> | ||
<h4>İlçe</h4> | ||
<DialogContentText>{userData.town}</DialogContentText> | ||
<h4>Şehir</h4> | ||
<DialogContentText>{userData.city}</DialogContentText> | ||
<h4>Cinsiyet</h4> | ||
<DialogContentText>{userData.gender}</DialogContentText> | ||
</div> | ||
<div style={{clear: "both"}}> | ||
<h4>Son giriş</h4> | ||
<DialogContentText>{userData.lastLoggedIn}</DialogContentText> | ||
<h4>Kayıt Tarihi</h4> | ||
<DialogContentText>{userData.createdAt}</DialogContentText> | ||
</div> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={handleClose} color="primary"> | ||
İptal | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
export default ViewUserModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...e/domain/src/main/java/com/turkninja/petshop/api/request/user/UserImageInsertRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.turkninja.petshop.api.request.user; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Request object for user image creation. | ||
* | ||
* @author mstar | ||
* @version 1.0 | ||
* @since 1.0, 2021-09-24 | ||
*/ | ||
@Data | ||
public class UserImageInsertRequest { | ||
private Long userId; | ||
private String imageUrl; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
UserImageInsertRequest that = (UserImageInsertRequest) o; | ||
return Objects.equals(userId, that.userId) && Objects.equals(imageUrl, that.imageUrl); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(userId, imageUrl); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...domain/src/main/java/com/turkninja/petshop/api/response/user/UserImageInsertResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.turkninja.petshop.api.response.user; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* Response object for user image insert request. | ||
* | ||
* @author mstar | ||
* @version 1.0 | ||
* @since 1.0, 2021-09-24 | ||
*/ | ||
@Data | ||
public class UserImageInsertResponse { | ||
private String url; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What columns to show/hide?