Skip to content

Commit 512ca26

Browse files
committed
멤버 추가 로직 생성
1 parent 56549cb commit 512ca26

File tree

3 files changed

+70
-7
lines changed

3 files changed

+70
-7
lines changed

polling-app-client/src/components/Dashboard/GroupCreateModal.jsx

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
2-
import { Modal, Input, message } from 'antd';
3-
import { createGroup } from '../../util/APIUtils';
2+
import { createGroup, getAllUsers } from '../../util/APIUtils';
3+
import { Modal, Input, message, Checkbox, Spin } from 'antd';
44

55

66
class GroupCreateModal extends Component {
@@ -9,19 +9,42 @@ class GroupCreateModal extends Component {
99
this.state = {
1010
name: '',
1111
description: '',
12-
imageUrl: ''
12+
imageUrl: '',
13+
users: [],
14+
selectedUserIds: [],
15+
loading: false
1316
};
1417
}
1518

19+
componentDidMount() {
20+
this.setState({ loading: true });
21+
getAllUsers()
22+
.then(users => {
23+
this.setState({ users, loading: false });
24+
})
25+
.catch(() => {
26+
message.error('유저 목록을 불러오는 데 실패했습니다.');
27+
this.setState({ loading: false });
28+
});
29+
}
30+
1631
handleChange = (field, value) => {
1732
this.setState({ [field]: value });
1833
}
1934

35+
handleUserSelect = userId => {
36+
const { selectedUserIds } = this.state;
37+
const newList = selectedUserIds.includes(userId)
38+
? selectedUserIds.filter(id => id !== userId)
39+
: [...selectedUserIds, userId];
40+
this.setState({ selectedUserIds: newList });
41+
}
42+
2043
handleSubmit = () => {
2144

22-
const { name, description, imageUrl } = this.state;
45+
const { name, description, imageUrl, selectedUserIds } = this.state;
2346

24-
createGroup({ name, description, imageUrl })
47+
createGroup({ name, description, imageUrl, memberIds : selectedUserIds })
2548
.then(data => {
2649
if (!data || !data.name) {
2750
throw new Error("응답에 그룹 이름이 없습니다.");
@@ -46,7 +69,7 @@ class GroupCreateModal extends Component {
4669

4770
render() {
4871
const { visible, onClose } = this.props;
49-
const { name, description, imageUrl } = this.state;
72+
const { name, description, imageUrl, users, selectedUserIds, loading } = this.state;
5073

5174
return (
5275
<Modal
@@ -75,6 +98,20 @@ class GroupCreateModal extends Component {
7598
value={imageUrl}
7699
onChange={e => this.handleChange('imageUrl', e.target.value)}
77100
/>
101+
<div style={{ maxHeight: 150, overflowY: 'auto', border: '1px solid #eee', padding: 8 }}>
102+
{loading ? (
103+
<Spin />
104+
) : users.map(user => (
105+
<Checkbox
106+
key={user.id}
107+
checked={selectedUserIds.includes(user.id)}
108+
onChange={() => this.handleUserSelect(user.id)}
109+
style={{ display: 'block', marginBottom: 6 }}
110+
>
111+
{user.name} ({user.username})
112+
</Checkbox>
113+
))}
114+
</div>
78115
</Modal>
79116
);
80117
}

polling-app-client/src/util/APIUtils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,12 @@ export function createGroup(groupData) {
137137
method: "POST",
138138
body: JSON.stringify(groupData),
139139
});
140-
}
140+
}
141+
142+
export function getAllUsers(){
143+
return request({
144+
url : API_BASE_URL + "/users/all",
145+
method : "GET"
146+
})
147+
}
148+

polling-app-server/src/main/java/com/example/polls/controller/UserController.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import org.springframework.security.access.prepost.PreAuthorize;
1919
import org.springframework.web.bind.annotation.*;
2020

21+
import java.util.List;
22+
import java.util.stream.Collectors;
23+
2124
@RestController
2225
@RequestMapping("/api")
2326
public class UserController {
@@ -84,4 +87,19 @@ public PagedResponse<PollResponse> getPollsVotedBy(@PathVariable(value = "userna
8487
return pollService.getPollsVotedBy(username, currentUser, page, size);
8588
}
8689

90+
91+
@GetMapping("/users/all")
92+
public List<UserSummary> getAllUsers(@CurrentUser UserPrincipal currentUser) {
93+
List<User> users = userRepository.findAll();
94+
95+
return users.stream()
96+
.filter(user -> !user.getId().equals(currentUser.getId()))
97+
.map(user -> new UserSummary(
98+
user.getId(),
99+
user.getUsername(),
100+
user.getName()
101+
))
102+
.collect(Collectors.toList());
103+
104+
}
87105
}

0 commit comments

Comments
 (0)