Skip to content

Commit

Permalink
团队管理增、删、查、UI优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Moujuruo committed Jun 15, 2024
1 parent f2e6497 commit 2d68cf7
Show file tree
Hide file tree
Showing 8 changed files with 548 additions and 342 deletions.
35 changes: 34 additions & 1 deletion backend/run_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,8 @@ def getAllTeams():
for member in members:
team_info["members"].append({
"member_id": member[0],
"is_captain": member[1]
"is_captain": member[1],
"username": member[2],
})

team_list.append(team_info)
Expand Down Expand Up @@ -546,6 +547,38 @@ def disagreeinvitation():
return jsonify({"data": "Failed to disagree invitation", "status": 500}), 500
return jsonify({"data": "Success to disagree invitation", "status": 200}), 200

@app.route(apiPrefix + 'deleteTeam', methods=['POST'])
def deleteTeam():
data = request.get_json()
print(data)
teamID = data['teamID']
userID = data['userID']
userID = int(userID)
captainID = Team.get_team_captain(teamID)[0]

if captainID != userID:
return jsonify({"data": "You are not the captain", "status": 400}), 400
result = Team.delete_team(teamID)
if result is False:
return jsonify({"data": "Failed to delete team", "status": 500}), 500
return jsonify({"data": "Success to delete team", "status": 200}), 200

# deleteMember
@app.route(apiPrefix + 'deleteMember', methods=['POST'])
def deleteMember():
data = request.get_json()
teamID = data['teamID']
userID = data['userID']
userID = int(userID)
memberID = data['memberID']
captainID = Team.get_team_captain(teamID)[0]
if captainID != userID:
return jsonify({"data": "You are not the captain", "status": 400}), 400
result = Team.deleteTeamMember(teamID, memberID)
if result is False:
return jsonify({"data": "Failed to delete member", "status": 500}), 500
return jsonify({"data": "Success to delete member", "status": 200}), 200


################## Note接口 ##################
@app.route(apiPrefix + 'updateNote', methods=['POST'])
Expand Down
31 changes: 30 additions & 1 deletion backend/sqlite_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_team_members_with_details(team_id):
try:
lock_threading.acquire()
cursor.execute('''
SELECT u.id, tm.if_captain
SELECT u.id, tm.if_captain, u.username
FROM team_member tm
JOIN users u ON tm.member_id = u.id
WHERE tm.team_id = ?
Expand All @@ -191,4 +191,33 @@ def search_in_team_invitation(member_id):
finally:
lock_threading.release()

def delete_team(team_id):
try:
lock_threading.acquire()
# 先删 team_member
cursor.execute('''DELETE FROM team_member WHERE team_id = ?''', (team_id,))
conn.commit()
# 再删 team_invitation
cursor.execute('''DELETE FROM team_invitation WHERE team_id = ?''', (team_id,))
conn.commit()
# 最后删 team
cursor.execute('''DELETE FROM team WHERE id = ?''', (team_id,))
conn.commit()
return True
except sqlite3.Error as e:
print(e)
return False
finally:
lock_threading.release()

def get_captain_teams(captain_id):
try:
lock_threading.acquire()
cursor.execute('''SELECT * FROM team WHERE captain_id = ?''', (captain_id,))
return cursor.fetchall()
except sqlite3.Error as e:
print(e)
return False
finally:
lock_threading.release()

2 changes: 1 addition & 1 deletion frontend/src/pages/MainLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const MainLayout: React.FC = () => {
message: '团队邀请',
description: `你被邀请加入团队 ${team_id}`,
btn: (
<div>
<div>
<Button type='primary' onClick={() => acceptInvitation(team_id, captain_id, key)}>接受</Button>
<Button onClick={() => rejectInvitation(team_id, captain_id, key)} style={{ marginLeft: '8px' }}>拒绝</Button>
</div>
Expand Down
53 changes: 45 additions & 8 deletions frontend/src/pages/Reservation/ReservationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ import { Modal, Form, Select, DatePicker, Input, Slider, message } from 'antd';
import moment from 'moment';
import HttpUtil from '../../utils/HttpUtil';
import ApiUtil from '../../utils/ApiUtil';
import { ApiResponse } from '../../utils/ApiUtil';

const { Option } = Select;

interface ApiResponse<T> {
status: number;
data: T;
}

interface Room {
id: number;
name: string;
Expand All @@ -27,6 +23,20 @@ interface Reservation {
subject: string;
}

interface Member {
member_id: number;
is_captain: string;
avatar: string;
}

interface Team {
team_id: number;
team_name: string;
is_captain: number;
members: Member[];
}


interface ReservationModalProps {
visible: boolean;
onOk: () => void;
Expand Down Expand Up @@ -78,6 +88,32 @@ const ReservationModal: React.FC<ReservationModalProps> = ({
message.error('获取预定信息失败');
}
};

const fetchTeams = async () => {
try {
const response = await HttpUtil.post(ApiUtil.API_GET_ALL_TEAMS,
{
userID: localStorage.getItem('userID')
}
) as ApiResponse<Team[]>;
if (response.status === 200) {
const teamsWithAvatar = await Promise.all(
response.data.map(async (team) => {
const membersWithAvatar = await Promise.all(
team.members.map(async (member) => {
return { ...member };
})
);
return { ...team, members: membersWithAvatar };
})
);
} else {
message.error('获取团队列表失败');
}
} catch (error) {
message.error('获取团队列表失败');
}
};


const marks = {
Expand Down Expand Up @@ -118,7 +154,7 @@ const ReservationModal: React.FC<ReservationModalProps> = ({
try {
const newReservation = {
room_id: values.room_id,
user_id: localStorage.getItem('userID') || 1, // Assuming user_id is stored in localStorage or a default value
user_id: localStorage.getItem('userID') || 1,
start_time: moment().startOf('day').add(values.time[0], 'hours').format('HH:mm'),
end_time: moment().startOf('day').add(values.time[1], 'hours').format('HH:mm'),
date: values.date.format('YYYY-MM-DD'),
Expand All @@ -139,6 +175,8 @@ const ReservationModal: React.FC<ReservationModalProps> = ({
return (
<Modal title="创建预约" open={visible} onOk={form.submit} onCancel={onCancel}>
<Form form={form} layout="vertical" onFinish={handleSubmit}>
<Form.Item name="title" label="会议主题" rules={[{ required: true, message: '请输入会议主题' }]}>
<Input />
<Form.Item name="room_id" label="会议室" rules={[{ required: true, message: '请选择会议室' }]}>
<Select onChange={(value: number) => setRoom(value)} value={room}>
{meetingRooms.map(room => (
Expand All @@ -162,8 +200,7 @@ const ReservationModal: React.FC<ReservationModalProps> = ({
tooltip={{ formatter: formatSliderTooltip }}
/>
</Form.Item>
<Form.Item name="title" label="会议主题" rules={[{ required: true, message: '请输入会议主题' }]}>
<Input />

</Form.Item>
</Form>
</Modal>
Expand Down
Loading

0 comments on commit 2d68cf7

Please sign in to comment.