交友项目【通用设置】三个功能实现

╰半橙微兮° 2023-10-09 00:29 64阅读 0赞

目录

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:查询通用设置

f1e0eaaeb0a540c0a8358beec779a29e.png

1b87f3ba2a09407a8d175bb3b50c1e7f.png

0100e8e2a39f40de96e544fd1f923e64.png

1.1.1:接口地址

接口地址:http://192.168.136.160:3000/project/19/interface/api/268

1c551104ecb149079de2c00fee57acea.png

1.1.2:流程分析

根据定义的文档接口,请求头需要接收,token信息,响应ResponseEntity,创建SettingVo进行封装数据,

根据需求需要查询tb_question和tb_settings表中的信息,进行汇总到Vo中。

1.1.3:代码实现

与前端交互的app-server模块

d3d2dd3eea9c4377b9470fc1bf54113f.png

controller层实现

  1. /**
  2. * @Author 爱吃豆的土豆、
  3. * @Date 2023/4/4 11:29
  4. */
  5. @RequestMapping("/users")
  6. @RestController
  7. public class UserController {
  8. @Resource
  9. private UserService userService;
  10. @GetMapping("/settings")
  11. public ResponseEntity findUsersettings(){
  12. SettingsVo usersettings = userService.findUsersettings(UserHolder.getUserId());
  13. usersettings.setPhone(UserHolder.getMobile());
  14. return ResponseEntity.ok(usersettings);
  15. }
  16. }

service层实现

  1. public SettingsVo findUsersettings(Long userId) {
  2. return userApi.findUsersettings(userId);
  3. }

统一封装接口的模块

  1. SettingsVo findUsersettings(Long userId);

提供者模块(提供相关接口的实现)

  1. @Override
  2. public SettingsVo findUsersettings(Long userId) {
  3. Settings setting = setMapper.findSetting(userId);
  4. SettingsVo settingsVo = new SettingsVo();
  5. Long numberLong = new Long(userId);
  6. Integer id = numberLong.intValue();
  7. settingsVo.setId(id);
  8. if (setting.getGonggaoNotification() == 1){
  9. settingsVo.setGonggaoNotification(true);
  10. }else {
  11. settingsVo.setGonggaoNotification(false);
  12. }
  13. if (setting.getLikeNotification() == 1){
  14. settingsVo.setLikeNotification(true);
  15. }else {
  16. settingsVo.setLikeNotification(false);
  17. }
  18. if (setting.getPinglunNotification() == 1){
  19. settingsVo.setPinglunNotification(true);
  20. }else {
  21. settingsVo.setPinglunNotification(false);
  22. }
  23. Question question = questionMapper.findQuestion(userId);
  24. settingsVo.setStrangerQuestion(question.getTxt());
  25. return settingsVo;
  26. }

1.2:设置陌生人问题

1.2.1:接口地址

接口地址:http://192.168.136.160:3000/project/19/interf![6747353fe23d46769e4fee71749ae429.png][]

1.2.3:代码实现

与前端交互的app-server模块

f48260455315440481c2c633c67a0830.png

controller层实现

  1. @PostMapping("/questions")
  2. public ResponseEntity editquestion(@RequestBody Map content){
  3. userService.editquestion(String.valueOf(content.get("content")), UserHolder.getUserId());
  4. return ResponseEntity.ok(null);
  5. }

service层实现

  1. public void editquestion(String content, Long id) {
  2. userApi.editquestion(content,id);
  3. }

统一封装接口的模块

2ff27cd0666045b0ab7435e8d0c2404e.png

  1. void editquestion(String content, Long id);

提供者模块(提供相关接口的实现)

126919a695564a0c9a6345f68a9b9cab.png

  1. @Override
  2. public void editquestion(String content, Long id) {
  3. //查询对应的数据
  4. Question question = questionMapper.findQuestion(id);
  5. //重新设置
  6. question.setTxt(content);
  7. questionMapper.updateById(question);
  8. }

1.3:通知设置

1.3.1:接口地址

通知管理:对通知进行保存或者更新的操作

http://192.168.136.160:3000/project/19/interface/api/280

ab89227a0e224661803a2dc8a007c5ed.png

1.3.2:流程分析

ab5fb84c64fc4998b8b5a26e391ee80a.png

1.3.3:代码实现

与前端交互的app-server模块

d3d2dd3eea9c4377b9470fc1bf54113f.png

controller层实现

  1. @PostMapping("/notifications/setting")
  2. public ResponseEntity editsetting(@RequestBody SettingsVo settingsVo){
  3. userService.editsetting(settingsVo,UserHolder.getUserId());
  4. return ResponseEntity.ok(null);
  5. }

service层实现

  1. public void editsetting(SettingsVo settingsVo, Long userId) {
  2. userApi.editsetting(settingsVo,userId);
  3. }

统一封装接口的模块

  1. void editsetting(SettingsVo settingsVo, Long userId);

提供者模块(提供相关接口的实现)

  1. @Override
  2. public void editsetting(SettingsVo settingsVo, Long userId) {
  3. Settings settings = setMapper.findSetting(userId);
  4. if (settingsVo.getGonggaoNotification()){
  5. settings.setGonggaoNotification(1);
  6. }else {
  7. settings.setGonggaoNotification(0);
  8. }
  9. if (settingsVo.getLikeNotification()){
  10. settings.setLikeNotification(1);
  11. }else {
  12. settings.setLikeNotification(0);
  13. }
  14. if (settingsVo.getPinglunNotification()){
  15. settings.setPinglunNotification(1);
  16. }else {
  17. settings.setPinglunNotification(0);
  18. }
  19. setMapper.updateById(settings);
  20. }

发表评论

表情:
评论列表 (有 0 条评论,64人围观)

还没有评论,来说两句吧...

相关阅读