添加关卡列表、关卡详情接口

This commit is contained in:
Ethereal 2024-04-11 00:05:24 +08:00
parent 6e61ffd198
commit 38a35aefed
3 changed files with 51 additions and 4 deletions

View File

@ -3,13 +3,17 @@ package com.example.catchTheLetters.controller;
import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.model.vo.RankVo;
import com.example.catchTheLetters.entity.ScoreInfo;
import com.example.catchTheLetters.service.LevelService;
import com.example.catchTheLetters.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 关卡控制器
*
@ -20,17 +24,21 @@ import org.springframework.web.bind.annotation.*;
@Api(tags = "关卡API")
@RequestMapping("/level")
public class LevelController {
@Resource
private LevelService levelService;
@ApiOperation(value = "关卡列表只返回ID、名称和类型")
@GetMapping("/list")
public R<Level> list() {
return null;
public R<List<Level>> list() {
return levelService.list();
}
@ApiOperation(value = "关卡详情")
@GetMapping("/detail")
@ApiParam(name = "id", value = "关卡ID")
public R<Level> detail(Long id) {
return null;
return levelService.levelDetail(id);
}
@ApiOperation(value = "关卡创建web前端管理员提交")

View File

@ -1,5 +1,10 @@
package com.example.catchTheLetters.service;
import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.utils.R;
import java.util.List;
/**
* @author 慕华
* @date 2024/4/10
@ -7,4 +12,8 @@ package com.example.catchTheLetters.service;
* @description
*/
public interface LevelService {
R<Level> levelDetail(Long id);
R<List<Level>> list();
}

View File

@ -1,7 +1,17 @@
package com.example.catchTheLetters.service.impl;
import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.service.LevelService;
import com.example.catchTheLetters.utils.R;
import jakarta.annotation.Resource;
import org.springframework.data.annotation.QueryAnnotation;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author 慕华
* @date 2024/4/10
@ -9,5 +19,25 @@ import org.springframework.stereotype.Service;
* @description
*/
@Service
public class LevelServiceImpl {
public class LevelServiceImpl implements LevelService {
@Resource
private MongoTemplate mongoTemplate;
@Override
public R<Level> levelDetail(Long id) {
Level level = mongoTemplate.findOne(new Query(Criteria.where("id").is(id)), Level.class);
if (level == null){
return R.fail("查询失败,请重试");
}
return R.ok(level);
}
@Override
public R<List<Level>> list() {
Query query = new Query();
query.fields().include("id").include("name").include("type");
List<Level> levels = mongoTemplate.find(query, Level.class);
return R.ok(levels);
}
}