Skip to content

Commit a6d0c7b

Browse files
committed
clean user func impl
1 parent abdb95e commit a6d0c7b

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed

rsa-backend/src/main/java/com/example/rsa/controller/UserController.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.example.rsa.model.User;
44
import com.example.rsa.service.UserService;
5+
import io.swagger.v3.oas.annotations.Operation;
56
import org.springframework.beans.factory.annotation.Autowired;
67
import org.springframework.http.ResponseEntity;
78
import org.springframework.web.bind.annotation.*;
@@ -32,5 +33,22 @@ public ResponseEntity<String> deleteUser(@PathVariable Integer id) {
3233
return ResponseEntity.status(500).body("Kullanıcı silinirken hata: " + e.getMessage());
3334
}
3435
}
36+
37+
@PutMapping("/{id}/{field}/{newValue}")
38+
public ResponseEntity<String> updateUser(@PathVariable Integer id, @PathVariable String field, @PathVariable boolean newValue) {
39+
try {
40+
userService.updateUser(id, field,newValue);
41+
return ResponseEntity.ok("Kullanıcı başarıyla güncellendi.");
42+
} catch (Exception e) {
43+
return ResponseEntity.status(500).body("Kullanıcı güncellenirken hata oluştu: " + e.getMessage());
44+
}
45+
}
46+
47+
@Operation(summary = "Delete all users")
48+
@GetMapping("/clean")
49+
public void cleanUsers() {
50+
userService.cleanAllUsers();
51+
}
52+
3553
}
3654

rsa-backend/src/main/java/com/example/rsa/service/UserService.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,49 @@ public class UserService {
1313

1414
public void saveUser(User user) {
1515
users.add(user);
16-
System.out.println(users);
16+
System.out.println(getAllUsers());
1717
}
1818

1919
public void deleteUser(Integer id) {
2020
users.removeIf(user -> user.getId().equals(id));
21-
System.out.println(users);
21+
System.out.println(getAllUsers());
2222
}
23+
24+
public List<User> getAllUsers() {
25+
return users;
26+
}
27+
28+
public void cleanAllUsers() {
29+
users.clear();
30+
System.out.println(getAllUsers());
31+
}
32+
2333
public User getUserById(Integer id) {
2434
return users.stream()
2535
.filter(user -> user.getId().equals(id))
2636
.findFirst()
2737
.orElse(null);
2838
}
39+
40+
public void updateUser(Integer id, String field ,boolean newValue) {
41+
System.out.println(id);
42+
System.out.println(field);
43+
System.out.println(newValue);
44+
for (User user : users) {
45+
if (user.getId().equals(id)) {
46+
switch (field) {
47+
case "publicKey" -> user.setPublicKey(newValue);
48+
case "privateKey" -> user.setPrivateKey(newValue);
49+
case "fileUpload" -> user.setFileUpload(newValue);
50+
case "fileRead" -> user.setFileRead(newValue);
51+
case "fileSend" -> user.setFileSend(newValue);
52+
case "fileReceive" -> user.setFileReceive(newValue);
53+
}
54+
break;
55+
}
56+
}
57+
System.out.println(getAllUsers());
58+
}
59+
2960
}
3061

rsa-frontend/src/routes/components/FileExplorer.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import axios from "axios";
23

34
const FileContainer = ({ owner, fileName, size, id }) => (
45
<div className={"file-container custom-row"} style={{justifyContent:"space-between",alignItems:"center"}}>
@@ -20,6 +21,18 @@ const FileContainer = ({ owner, fileName, size, id }) => (
2021

2122
const FileExplorer = () => {
2223

24+
const clean = () => {
25+
axios.get(`http://localhost:8080/user/clean`)
26+
.then(response => {
27+
console.log("Kullanıcılar başarıyla silindi:", response.data);
28+
})
29+
.catch(error => {
30+
console.error("Kullanıcılar silinirken hata oluştu:", error);
31+
});
32+
window.location.reload();
33+
};
34+
35+
2336
return (
2437
<div className="file-explorer">
2538
<p className={"title-text"}><span>Dosya</span> Gezgini</p>
@@ -42,7 +55,7 @@ const FileExplorer = () => {
4255

4356
<FileContainer owner="Alice" fileName="abc.txt" size="148 kb" id="1" />
4457

45-
<div className={"remove-button"}>
58+
<div className={"remove-button"} onClick={clean}>
4659
<img src="/icon/bin.png" alt="Clear System" className={"mini-icon"}/>
4760
<p className={"small-text"}>Sistemi Temizle</p>
4861
</div>

rsa-frontend/src/routes/components/ScenarioArea.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import React, { useState } from 'react';
22
import Switch from "./Switch";
33
import axios from 'axios';
4-
import endpoints from "../../contants/endpoints";
54
import Endpoints from "../../contants/endpoints";
65

76
const initialUsers = [
8-
{ id: 1, name: 'Alice', publicKey: false, privateKey: false, fileUpload: false, readFiles: false, eKey: "...", dKey:"..." },
9-
{ id: 2, name: 'Bob', publicKey: false, privateKey: false, fileUpload: false, readFiles: false,eKey: "...", dKey:"..." },
10-
{ id: 3, name: 'Charlie', publicKey: false, privateKey: false, fileUpload: false, readFiles: false,eKey: "...", dKey:"..." },
7+
{ id: 1, name: 'Alice', publicKey: false, privateKey: false, fileUpload: false, readFiles: false, fileSend: false,fileReceive: false, eKey: "...", dKey:"..." },
8+
{ id: 2, name: 'Bob', publicKey: false, privateKey: false, fileUpload: false, readFiles: false,fileSend: false,fileReceive: false, eKey: "...", dKey:"..." },
9+
{ id: 3, name: 'Charlie', publicKey: false, privateKey: false, fileUpload: false, readFiles: false,fileSend: false,fileReceive: false, eKey: "...", dKey:"..." },
1110
];
1211

1312
const UserContainer = ({ user, handleUserToggle }) => {
14-
const handleToggle = (field) => {
15-
handleUserToggle(user.id, field);
13+
const handleToggle = (field,newValue) => {
14+
handleUserToggle(user.id, field,newValue);
1615
};
1716

1817
return (
@@ -22,7 +21,7 @@ const UserContainer = ({ user, handleUserToggle }) => {
2221
<div className={"custom-row"} style={{gap:0}}>
2322
<Switch
2423
isOn={user.publicKey}
25-
handleToggle={() => handleToggle('publicKey')}
24+
handleToggle={() => handleToggle('publicKey',!user.publicKey)}
2625
id={user.id+"publicKey"}
2726
/>
2827
<div>
@@ -35,7 +34,7 @@ const UserContainer = ({ user, handleUserToggle }) => {
3534
<div className={"custom-row"} style={{gap:0}}>
3635
<Switch
3736
isOn={user.privateKey}
38-
handleToggle={() => handleToggle('privateKey')}
37+
handleToggle={() => handleToggle('privateKey',!user.privateKey)}
3938
id={user.id+"privateKey"}
4039
/>
4140
<div>
@@ -49,7 +48,7 @@ const UserContainer = ({ user, handleUserToggle }) => {
4948
<div className={"custom-row"} style={{gap:0}}>
5049
<Switch
5150
isOn={user.fileUpload}
52-
handleToggle={() => handleToggle('fileUpload')}
51+
handleToggle={() => handleToggle('fileUpload',!user.fileUpload)}
5352
id={user.id+"fileUpload"}
5453
/>
5554
<div>
@@ -61,7 +60,7 @@ const UserContainer = ({ user, handleUserToggle }) => {
6160
<div className={"custom-row"} style={{gap:0}}>
6261
<Switch
6362
isOn={user.readFiles}
64-
handleToggle={() => handleToggle('readFiles')}
63+
handleToggle={() => handleToggle('readFiles',!user.readFiles)}
6564
id={user.id+"readFiles"}
6665
/>
6766
<div>
@@ -105,8 +104,8 @@ const ScenarioArea = () => {
105104
privateKey: user.privateKey,
106105
fileUpload: user.fileUpload,
107106
fileRead: user.readFiles,
108-
fileSend: false,
109-
fileReceive: false,
107+
fileSend: user.fileSend,
108+
fileReceive: user.readFiles,
110109
eKey: user.eKey,
111110
dKey: user.dKey
112111
})
@@ -120,12 +119,20 @@ const ScenarioArea = () => {
120119
}
121120
};
122121

123-
const handleUserToggle = (userId, field) => {
122+
const handleUserToggle = (userId, field,newValue) => {
124123
setUsers(users.map(user =>
125124
user.id === userId
126125
? { ...user, [field]: !user[field] }
127126
: user
128127
));
128+
129+
axios.put(`http://localhost:8080/user/${userId}/${field}/${newValue}`)
130+
.then(response => {
131+
console.log("Kullanıcı başarıyla güncellendi:", response.data);
132+
})
133+
.catch(error => {
134+
console.error("Kullanıcı güncellenirken hata oluştu:", error);
135+
});
129136
};
130137

131138
return (

0 commit comments

Comments
 (0)