Skip to content

Commit

Permalink
Merge pull request #4 from carolcoral/v1.6.0
Browse files Browse the repository at this point in the history
V1.6.0
  • Loading branch information
carolcoral authored Jun 7, 2024
2 parents 84bf08b + ce81eeb commit b7b4192
Show file tree
Hide file tree
Showing 14 changed files with 337 additions and 147 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.5.2
version=1.6.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.xindu.afdian.service;
package site.xindu.afdian.component;

import org.pf4j.PluginWrapper;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.xindu.afdian.service;
package site.xindu.afdian.config;

import java.util.HashMap;
import lombok.RequiredArgsConstructor;
Expand All @@ -23,8 +23,6 @@ public class AfdianRouter {

private final ReactiveSettingFetcher settingFetcher;

private static final String BASIC = "basic";

private static final String THEME_SETTING = "themeSetting";

@Bean
Expand All @@ -50,12 +48,12 @@ Mono<ServerResponse> renderPage(ServerRequest request) {

private void defaultModel(HashMap<String, Object> model) {
Mono<String> sponsorUrl =
this.settingFetcher.get(BASIC).map(setting ->
this.settingFetcher.get(THEME_SETTING).map(setting ->
setting.get("sponsorUrl").asText()
).defaultIfEmpty("https://afdian.net/a/carolcoral");
model.put("sponsorUrl", sponsorUrl);
Mono<Double> sponsorNumber =
this.settingFetcher.get(BASIC).map(setting ->
this.settingFetcher.get(THEME_SETTING).map(setting ->
setting.get("sponsorNumber").asDouble()
).defaultIfEmpty(66.00);
model.put("sponsorNumber", sponsorNumber);
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/site/xindu/afdian/config/BaseSettingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ public class BaseSettingConfig {
private String userId = "";

/**
* 赞助地址
* 登录用户名
*/
private String sponsorUrl = "";
private String username;

/**
* 切换赞助金额显示颜色值
* 登录用户密码
*/
private Double sponsorNumber = 66.00;

private String password;

}
10 changes: 10 additions & 0 deletions src/main/java/site/xindu/afdian/config/ThemeSettingConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public class ThemeSettingConfig {
public static final String CONFIG_MAP_NAME = "plugin-afdian-config";
public static final String GROUP = "themeSetting";

/**
* 赞助地址
*/
private String sponsorUrl = "";

/**
* 切换赞助金额显示颜色值
*/
private Double sponsorNumber = 66.00;

/**
* 赞助展示页面
*/
Expand Down
38 changes: 26 additions & 12 deletions src/main/java/site/xindu/afdian/controller/AfdianController.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package site.xindu.afdian.controller;

import com.fasterxml.jackson.databind.JsonNode;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;
import run.halo.app.plugin.ApiVersion;
import site.xindu.afdian.service.ConfigService;
import site.xindu.afdian.service.SponsorService;
import site.xindu.afdian.service.AfdianConfigService;
import site.xindu.afdian.service.AfdianService;

@ApiVersion("v1alpha1")
@RequestMapping("/afdian")
Expand All @@ -19,29 +18,44 @@
public class AfdianController {


private final SponsorService sponsorService;
private final AfdianService afdianService;

private final ConfigService configService;
private final AfdianConfigService configService;

public AfdianController(SponsorService sponsorService, ConfigService configService) {
this.sponsorService = sponsorService;
public AfdianController(AfdianService afdianService, AfdianConfigService configService) {
this.afdianService = afdianService;
this.configService = configService;
}


@GetMapping("/getSponsorList")
public Mono<JsonNode> listAllSponsor(){
return sponsorService.listAllSponsor();
public Mono<JsonNode> listAllSponsor() {
return afdianService.listAllSponsor();
}

@GetMapping("/getSponsorList/{pageNumber}")
public Mono<JsonNode> listSponsor(@PathVariable("pageNumber") int pageNumber){
return sponsorService.getSponsorList(pageNumber);
public Mono<JsonNode> listSponsor(@PathVariable("pageNumber") int pageNumber) {
return afdianService.getSponsorList(pageNumber);
}

@GetMapping("/config")
public Mono<JsonNode> getConfig(){
public Mono<JsonNode> getConfig() {
return configService.getConfig();
}

@GetMapping("/listAllSponsorship")
public Mono<JsonNode> listAllSponsorship() {
return afdianService.listAllSponsorship();
}

@GetMapping("/listPlansAndSales")
public Mono<JsonNode> listPlansAndSales() {
return afdianService.listPlansAndSales();
}

@GetMapping("/listAlbum")
public Mono<JsonNode> listAlbum() {
return afdianService.listAlbum();
}

}
17 changes: 17 additions & 0 deletions src/main/java/site/xindu/afdian/service/AfdianConfigService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package site.xindu.afdian.service;

import com.fasterxml.jackson.databind.JsonNode;
import reactor.core.publisher.Mono;

/**
* 配置信息服务
*/
public interface AfdianConfigService {

/**
* 获取插件配置信息
* @return 插件配置信息(敏感信息已处理)
*/
Mono<JsonNode> getConfig();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package site.xindu.afdian.finder;
package site.xindu.afdian.service;

import com.fasterxml.jackson.databind.JsonNode;
import reactor.core.publisher.Mono;
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/site/xindu/afdian/service/AfdianService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package site.xindu.afdian.service;

import com.fasterxml.jackson.databind.JsonNode;
import reactor.core.publisher.Mono;

/**
* 爱发电APP相关服务
*/
public interface AfdianService {

/**
* 获取token
* @return token对象
*/
Mono<JsonNode> getAuthToken();

/**
* 分页获取爱发电赞助用户
* @param pageNumber 页码
* @return 赞助用户集合
*/
Mono<JsonNode> getSponsorList(int pageNumber);

/**
* 获取全部爱发电赞助用户
* @return 全部赞助用户
*/
Mono<JsonNode> listAllSponsor();

/**
* 获取全部赞助方案、商品、VIP服务
* @return 全部赞助方案、商品、VIP服务
*/
Mono<JsonNode> listAllSponsorship();


/**
* 获取全部赞助方案、商品列表
* @return 全部赞助方案、商品列表
*/
Mono<JsonNode> listPlansAndSales();

/**
* 获取全部作品集
* @return 全部作品集
*/
Mono<JsonNode> listAlbum();



}
90 changes: 0 additions & 90 deletions src/main/java/site/xindu/afdian/service/SponsorService.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
package site.xindu.afdian.service;
package site.xindu.afdian.service.impl;

import java.time.Duration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Predicate;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.JsonSerializable;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import reactor.core.Disposable;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import run.halo.app.infra.utils.JsonUtils;
import run.halo.app.plugin.ReactiveSettingFetcher;
import site.xindu.afdian.config.BaseSettingConfig;
import site.xindu.afdian.service.AfdianConfigService;

@Service
@Slf4j
public class ConfigService {
public class AfdianConfigServiceImpl implements AfdianConfigService {

private final ReactiveSettingFetcher settingFetcher;

public ConfigService(ReactiveSettingFetcher settingFetcher) {
public AfdianConfigServiceImpl(ReactiveSettingFetcher settingFetcher) {
this.settingFetcher = settingFetcher;
}

private static final String BASIC = "basic";
private static final String THEME_SETTING = "themeSetting";

/**
* 获取插件配置信息
*
* @return 插件配置信息(敏感信息已处理)
*/
@Override
public Mono<JsonNode> getConfig() {
return this.settingFetcher.get(BASIC).map(res -> {
return this.settingFetcher.get(THEME_SETTING).map(res -> {
var fields = res.fields();
while (fields.hasNext()) {
var next = fields.next();
Expand All @@ -52,5 +49,4 @@ public Mono<JsonNode> getConfig() {
return res;
});
}

}
Loading

0 comments on commit b7b4192

Please sign in to comment.