添加获取最新5个版本接口

This commit is contained in:
ETHEREAL 2024-06-09 14:17:54 +08:00
parent 157894a8a6
commit b9ffbdb088
8 changed files with 120 additions and 4 deletions

View File

@ -152,6 +152,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.4.5</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,26 @@
package com.example.catchTheLetters.config;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
//@Data
//@Configuration
//@ConfigurationProperties(prefix = "minio")
//public class MinioConfig {
// private String endpoint;
// private String bucket;
// private String accessKey;
// private String secretKey;
//
// @Bean
// public MinioClient minioClient(){
// return MinioClient.builder()
// .endpoint(endpoint)
// .credentials(accessKey, secretKey)
// .build();
// }
//
//}

View File

@ -1,10 +1,7 @@
package com.example.catchTheLetters.controller;
import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.entity.Page;
import com.example.catchTheLetters.entity.ScoreInfoPage;
import com.example.catchTheLetters.entity.*;
import com.example.catchTheLetters.model.vo.RankVo;
import com.example.catchTheLetters.entity.ScoreInfo;
import com.example.catchTheLetters.service.LevelService;
import com.example.catchTheLetters.service.VersionService;
import com.example.catchTheLetters.utils.R;
@ -107,4 +104,8 @@ public class LevelController {
public R<ScoreInfoPage> getScores(@RequestBody Page page) {
return R.ok(levelService.getScoreInfo( page.getLevelId(),page.getPage(), page.getSize()));
}
public R<List<VersionDownload>> getNewVersion(){
return versionService.getNewDownloads();
}
}

View File

@ -0,0 +1,17 @@
package com.example.catchTheLetters.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VersionDownload implements Serializable {
private String id;
private Long time;
private String version;
private String url;
}

View File

@ -1,5 +1,10 @@
package com.example.catchTheLetters.service;
import com.example.catchTheLetters.entity.VersionDownload;
import com.example.catchTheLetters.utils.R;
import java.util.List;
/**
* 版本服务接口
*
@ -21,4 +26,18 @@ public interface VersionService {
* @param version 版本号
*/
void setVersion(String tableName, Long version);
/**
* 添加下载文件版本
* @param time 时间
* @param version 版本号
* @param url 地址
*/
R<String> addVersionDownload(Long time, String version, String url);
/**
* 获取最新的5个版本
* @return 版本集合
*/
R<List<VersionDownload>> getNewDownloads();
}

View File

@ -1,13 +1,18 @@
package com.example.catchTheLetters.service.impl;
import com.example.catchTheLetters.entity.Version;
import com.example.catchTheLetters.entity.VersionDownload;
import com.example.catchTheLetters.service.VersionService;
import com.example.catchTheLetters.utils.R;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Sort;
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;
@Service
public class VersionServiceImpl implements VersionService {
@ -30,4 +35,27 @@ public class VersionServiceImpl implements VersionService {
mongoTemplate.save(res);
}
}
@Override
public R<String> addVersionDownload(Long time, String version, String url) {
VersionDownload versionDownload = new VersionDownload();
versionDownload.setUrl(url);
versionDownload.setTime(time);
versionDownload.setVersion(version);
VersionDownload insert = mongoTemplate.insert(versionDownload);
if (insert.getId() == null){
return R.fail("添加数据库失败");
}
//TODO
return R.ok(insert.getId());
}
@Override
public R<List<VersionDownload>> getNewDownloads() {
Query query = new Query()
.with(Sort.by(Sort.Direction.DESC,"time"))
.limit(5);
List<VersionDownload> list = mongoTemplate.find(query, VersionDownload.class);
return R.ok(list);
}
}

View File

@ -21,5 +21,11 @@ spring:
host: 1.14.105.160
port: 6379
password: spynsql
server:
port: 3536
#minio:
# endpoint: http://1.14.105.160:9000
# bucketName:
# accessKey:
# secretKey:

View File

@ -3,12 +3,15 @@ package com.example.catchTheLetters;
import com.example.catchTheLetters.controller.LevelController;
import com.example.catchTheLetters.entity.Level;
import com.example.catchTheLetters.entity.ScoreInfo;
import com.example.catchTheLetters.entity.VersionDownload;
import com.example.catchTheLetters.utils.R;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
@ -101,4 +104,14 @@ class TestInsertLevel {
List<ScoreInfo> scores = mongoTemplate.find(new Query(Criteria.where("levelId").is("0")).with(pageable), ScoreInfo.class);
System.out.println(scores);
}
@Test
@Disabled
void newTest(){
Query query = new Query()
.with(Sort.by(Sort.Direction.DESC,"time"))
.limit(5);
var list = mongoTemplate.find(query, VersionDownload.class);
System.out.println(list);
}
}