增加添加联系人接口,未完成

This commit is contained in:
2025-08-25 21:42:16 +08:00
parent fd196c5917
commit a3d5df25c0
2 changed files with 63 additions and 1 deletions

View File

@@ -0,0 +1,61 @@
package com.onekeycall.videotablet.controller;
import com.onekeycall.videotablet.entity.Contact;
import com.onekeycall.videotablet.entity.DeviceInfo;
import com.onekeycall.videotablet.entity.User;
import com.onekeycall.videotablet.result.Result;
import com.onekeycall.videotablet.service.DeviceSnService;
import com.onekeycall.videotablet.service.UserService;
import com.onekeycall.videotablet.utils.JwtUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/contact")
public class ContactController {
@Autowired
private JwtUtil jwtUtil;
@Autowired
private UserService userService;
@Autowired
private DeviceSnService deviceSnService;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
Logger logger = LoggerFactory.getLogger(ContactController.class);
@PostMapping("/user_add_contact")
public Result userAddContact(
@RequestHeader("Authorization") String authHeader, @RequestHeader("Device-ID") String deviceId,
@RequestParam(value = "user_id") String userId, @RequestParam(value = "sn") String sn
, @RequestBody Contact contact) {
if (!authHeader.startsWith("Bearer ")) {
return Result.error().message("Invalid Authorization header");
}
String token = authHeader.substring(7); // 去掉 "Bearer " 前缀
if (!jwtUtil.validateAccessToken(userId, token, deviceId)) {
return Result.error().message("Invalid token");
}
User user = userService.getUserByUserId(userId);
if (user == null) {
return Result.error().message("user not found");
}
DeviceInfo deviceInfo = deviceSnService.findBySn(sn);
if (deviceInfo == null) {
return Result.error().message("device not found");
}
if (!deviceInfo.getUserId().equals(userId)) {
return Result.error().message("device not belong to user");
}
return Result.ok();
}
}

View File

@@ -6,11 +6,12 @@ import lombok.Data;
@Data @Data
@Entity @Entity
@Table(name = "tablet_default_settings") @Table(name = "tablet_default_settings")
public class Contacts { public class Contact {
@Id @Id
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id",unique = true, nullable = false) @Column(name = "id",unique = true, nullable = false)
private Long id; private Long id;
} }