添加关卡结算接口

This commit is contained in:
Ethereal 2024-04-11 23:13:12 +08:00
parent baef746aff
commit 312f9c4ad8
3 changed files with 24 additions and 2 deletions

View File

@ -68,7 +68,7 @@ public class LevelController {
@ApiOperation(value = "关卡结算游戏结束时提交一定要鉴别token") @ApiOperation(value = "关卡结算游戏结束时提交一定要鉴别token")
@PostMapping("/settle") @PostMapping("/settle")
public R settle(@RequestBody ScoreInfo scoreInfo) { public R<ScoreInfo> settle(@RequestBody ScoreInfo scoreInfo, @RequestHeader("token")String token) {
return null; return levelService.settle(scoreInfo, token);
} }
} }

View File

@ -1,6 +1,7 @@
package com.example.catchTheLetters.service; package com.example.catchTheLetters.service;
import com.example.catchTheLetters.entity.Level; import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.entity.ScoreInfo;
import com.example.catchTheLetters.utils.R; import com.example.catchTheLetters.utils.R;
import java.util.List; import java.util.List;
@ -16,4 +17,6 @@ public interface LevelService {
R<Level> levelDetail(Long id); R<Level> levelDetail(Long id);
R<List<Level>> list(); R<List<Level>> list();
R<ScoreInfo> settle(ScoreInfo scoreInfo, String token);
} }

View File

@ -1,7 +1,9 @@
package com.example.catchTheLetters.service.impl; package com.example.catchTheLetters.service.impl;
import com.example.catchTheLetters.entity.Level; import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.entity.ScoreInfo;
import com.example.catchTheLetters.service.LevelService; import com.example.catchTheLetters.service.LevelService;
import com.example.catchTheLetters.utils.JwtUtil;
import com.example.catchTheLetters.utils.R; import com.example.catchTheLetters.utils.R;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.data.annotation.QueryAnnotation; import org.springframework.data.annotation.QueryAnnotation;
@ -40,4 +42,21 @@ public class LevelServiceImpl implements LevelService {
List<Level> levels = mongoTemplate.find(query, Level.class); List<Level> levels = mongoTemplate.find(query, Level.class);
return R.ok(levels); return R.ok(levels);
} }
@Override
public R<ScoreInfo> settle(ScoreInfo scoreInfo, String token) {
var map = JwtUtil.getPayload(token);
String id = null;
if (map != null) {
id = map.get("id").asString().replaceAll("\"", "");
}
if (id == null){
return R.fail("token解析失败");
}
if (id.equals(scoreInfo.getUserId().toString())){
ScoreInfo insert = mongoTemplate.insert(scoreInfo);
return R.ok(insert);
}
return R.fail("添加失败,请重试");
}
} }