目录
1:交友项目【通用设置】
1.1:查询通用设置
1.1.1:接口地址
1.1.2:流程分析
1.1.3:代码实现
1.2:设置陌生人问题
1.2.1:接口地址
1.2.2:流程分析
1.2.3:代码实现
1.3:通知设置
1.3.1:接口地址
1.3.2:流程分析
1.3.3:代码实现
1:交友项目【通用设置】
1.1:查询通用设置
1.1.1:接口地址
接口地址:http://192.168.136.160:3000/project/19/interface/api/268
1.1.2:流程分析
根据定义的文档接口,请求头需要接收,token信息,响应ResponseEntity<SettingVo>,创建SettingVo进行封装数据,
根据需求需要查询tb_question和tb_settings表中的信息,进行汇总到Vo中。
1.1.3:代码实现
与前端交互的app-server模块
controller层实现
/**
* @Author 爱吃豆的土豆、
* @Date 2023/4/4 11:29
*/
@RequestMapping("/users")
@RestController
public class UserController {
@Resource
private UserService userService;
@GetMapping("/settings")
public ResponseEntity findUsersettings(){
SettingsVo usersettings = userService.findUsersettings(UserHolder.getUserId());
usersettings.setPhone(UserHolder.getMobile());
return ResponseEntity.ok(usersettings);
}
}
service层实现
public SettingsVo findUsersettings(Long userId) {
return userApi.findUsersettings(userId);
}
统一封装接口的模块
SettingsVo findUsersettings(Long userId);
提供者模块(提供相关接口的实现)
@Override
public SettingsVo findUsersettings(Long userId) {
Settings setting = setMapper.findSetting(userId);
SettingsVo settingsVo = new SettingsVo();
Long numberLong = new Long(userId);
Integer id = numberLong.intValue();
settingsVo.setId(id);
if (setting.getGonggaoNotification() == 1){
settingsVo.setGonggaoNotification(true);
}else {
settingsVo.setGonggaoNotification(false);
}
if (setting.getLikeNotification() == 1){
settingsVo.setLikeNotification(true);
}else {
settingsVo.setLikeNotification(false);
}
if (setting.getPinglunNotification() == 1){
settingsVo.setPinglunNotification(true);
}else {
settingsVo.setPinglunNotification(false);
}
Question question = questionMapper.findQuestion(userId);
settingsVo.setStrangerQuestion(question.getTxt());
return settingsVo;
}
1.2:设置陌生人问题
1.2.1:接口地址
接口地址:http://192.168.136.160:3000/project/19/interf
1.2.3:代码实现
与前端交互的app-server模块
controller层实现
@PostMapping("/questions")
public ResponseEntity editquestion(@RequestBody Map content){
userService.editquestion(String.valueOf(content.get("content")), UserHolder.getUserId());
return ResponseEntity.ok(null);
}
service层实现
public void editquestion(String content, Long id) {
userApi.editquestion(content,id);
}
统一封装接口的模块
void editquestion(String content, Long id);
提供者模块(提供相关接口的实现)
@Override
public void editquestion(String content, Long id) {
//查询对应的数据
Question question = questionMapper.findQuestion(id);
//重新设置
question.setTxt(content);
questionMapper.updateById(question);
}
1.3:通知设置
1.3.1:接口地址
通知管理:对通知进行保存或者更新的操作
http://192.168.136.160:3000/project/19/interface/api/280
1.3.2:流程分析
1.3.3:代码实现
与前端交互的app-server模块
controller层实现
@PostMapping("/notifications/setting")
public ResponseEntity editsetting(@RequestBody SettingsVo settingsVo){
userService.editsetting(settingsVo,UserHolder.getUserId());
return ResponseEntity.ok(null);
}
service层实现
public void editsetting(SettingsVo settingsVo, Long userId) {
userApi.editsetting(settingsVo,userId);
}
统一封装接口的模块
void editsetting(SettingsVo settingsVo, Long userId);
提供者模块(提供相关接口的实现)
@Override
public void editsetting(SettingsVo settingsVo, Long userId) {
Settings settings = setMapper.findSetting(userId);
if (settingsVo.getGonggaoNotification()){
settings.setGonggaoNotification(1);
}else {
settings.setGonggaoNotification(0);
}
if (settingsVo.getLikeNotification()){
settings.setLikeNotification(1);
}else {
settings.setLikeNotification(0);
}
if (settingsVo.getPinglunNotification()){
settings.setPinglunNotification(1);
}else {
settings.setPinglunNotification(0);
}
setMapper.updateById(settings);
}