|
|
@@ -3,12 +3,14 @@ package com.etotem.cfc.controller.family;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.dto.*;
|
|
|
+import com.etotem.cfc.entity.FamilyJoinRequest;
|
|
|
import com.etotem.cfc.entity.FamilyMember;
|
|
|
import com.etotem.cfc.entity.Family;
|
|
|
import com.etotem.cfc.entity.User;
|
|
|
import com.etotem.cfc.mapper.FamilyMemberMapper;
|
|
|
import com.etotem.cfc.mapper.FamilyMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
|
+import com.etotem.cfc.service.FamilyJoinRequestService;
|
|
|
import com.etotem.cfc.service.UserService;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
@@ -38,6 +40,9 @@ public class FamilyUserController {
|
|
|
@Resource
|
|
|
private FamilyMemberMapper familyMemberMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private FamilyJoinRequestService familyJoinRequestService;
|
|
|
+
|
|
|
@Operation(summary = "获取用户信息")
|
|
|
@PostMapping("/info")
|
|
|
public Result<User> getUserInfo(@RequestAttribute("userId") Long userId) {
|
|
|
@@ -55,12 +60,24 @@ public class FamilyUserController {
|
|
|
|
|
|
@Operation(summary = "加入家庭(通过邀请码)")
|
|
|
@PostMapping("/join-family")
|
|
|
- public Result<Boolean> joinFamily(@RequestAttribute("userId") Long userId,
|
|
|
- @RequestBody Map<String, String> body) {
|
|
|
+ public Result<Map<String, Object>> joinFamily(@RequestAttribute("userId") Long userId,
|
|
|
+ @RequestBody Map<String, String> body) {
|
|
|
String inviteCode = body.get("inviteCode");
|
|
|
- boolean success = userService.joinFamily(userId, inviteCode);
|
|
|
- return Result.success(success);
|
|
|
- }
|
|
|
+ if (inviteCode == null || inviteCode.trim().isEmpty()) {
|
|
|
+ return Result.error("邀请码不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ FamilyJoinRequest request = familyJoinRequestService.createJoinRequest(userId, inviteCode);
|
|
|
+ Family family = familyMapper.selectById(request.getTargetFamilyId());
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("requestId", request.getId());
|
|
|
+ result.put("familyName", family != null ? family.getName() : "");
|
|
|
+ return Result.success("申请已提交,等待家庭管理员审批", result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return Result.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Operation(summary = "创建新家庭")
|
|
|
@PostMapping("/create-family")
|