Compare commits

...

4 Commits

Author SHA1 Message Date
石皮幼鸟 289fe1c009 格式化 2024-04-12 11:15:43 +08:00
石皮幼鸟 baa889f73b Merge branch 'refs/heads/dev-01'
# Conflicts:
#	src/main/java/com/example/catchTheLetters/controller/LevelController.java
#	src/main/java/com/example/catchTheLetters/service/LevelService.java
#	src/main/java/com/example/catchTheLetters/service/impl/LevelServiceImpl.java
2024-04-12 11:12:50 +08:00
石皮幼鸟 4af5dae371 关卡删除和修改 2024-04-12 11:09:04 +08:00
Ch3nGO a7442babbe 2024年4月12日
关卡修改、删除
2024-04-12 11:05:15 +08:00
3 changed files with 37 additions and 7 deletions

View File

@ -24,7 +24,6 @@ import java.util.List;
@Api(tags = "关卡API") @Api(tags = "关卡API")
@RequestMapping("/level") @RequestMapping("/level")
public class LevelController { public class LevelController {
@Resource @Resource
private LevelService levelService; private LevelService levelService;
@ -49,14 +48,15 @@ public class LevelController {
@ApiOperation(value = "关卡修改web前端管理员提交") @ApiOperation(value = "关卡修改web前端管理员提交")
@PostMapping("/update") @PostMapping("/update")
public R update(@RequestBody Level level) { public R update(@RequestBody Level level)
return null; {
return levelService.update(level) ? R.ok() : R.fail();
} }
@ApiOperation(value = "关卡删除web前端管理员提交") @ApiOperation(value = "关卡删除web前端管理员提交")
@PostMapping("/delete") @PostMapping("/delete")
public R delete(String id) { public R delete(String id) {
return null; return levelService.delete(id) ? R.ok() : R.fail();
} }
@ApiOperation(value = "获取某个关卡排行榜数据") @ApiOperation(value = "获取某个关卡排行榜数据")

View File

@ -55,4 +55,19 @@ public interface LevelService {
*/ */
boolean levelCreate(Level level); boolean levelCreate(Level level);
/**
* 删除关卡
* @param id 关卡id
* @return 是否成功
*/
boolean delete(String id);
/**
* 更新关卡
* @param level 关卡
* @return 是否成功
*/
boolean update(Level level);
} }

View File

@ -10,6 +10,7 @@ import jakarta.annotation.Resource;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import com.mongodb.client.result.DeleteResult;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -29,7 +30,7 @@ public class LevelServiceImpl implements LevelService {
@Override @Override
public R<Level> levelDetail(String id) { public R<Level> levelDetail(String id) {
Level level = mongoTemplate.findOne(new Query(Criteria.where("id").is(id)), Level.class); Level level = mongoTemplate.findOne(new Query(Criteria.where("id").is(id)), Level.class);
if (level == null){ if (level == null) {
return R.fail("查询失败,请重试"); return R.fail("查询失败,请重试");
} }
return R.ok(level); return R.ok(level);
@ -50,10 +51,10 @@ public class LevelServiceImpl implements LevelService {
if (map != null) { if (map != null) {
id = map.get("id").asString().replaceAll("\"", ""); id = map.get("id").asString().replaceAll("\"", "");
} }
if (id == null){ if (id == null) {
return R.fail("token解析失败"); return R.fail("token解析失败");
} }
if (id.equals(scoreInfo.getUserId().toString())){ if (id.equals(scoreInfo.getUserId())) {
ScoreInfo insert = mongoTemplate.insert(scoreInfo); ScoreInfo insert = mongoTemplate.insert(scoreInfo);
return R.ok(insert); return R.ok(insert);
} }
@ -90,4 +91,18 @@ public class LevelServiceImpl implements LevelService {
var insert = mongoTemplate.insert(level); var insert = mongoTemplate.insert(level);
return insert.getId() != null; return insert.getId() != null;
} }
@Override
public boolean delete(String id) {
Level level = new Level();
level.setId(id);
DeleteResult deleteRequest = mongoTemplate.remove(level);
return deleteRequest.getDeletedCount() > 0;
}
@Override
public boolean update(Level level) {
var save = mongoTemplate.save(level);
return save.getId() != null;
}
} }