Skip to content

Commit

Permalink
Merge pull request #73 from Dapp-Learning-DAO/feature/arc_share
Browse files Browse the repository at this point in the history
share接口文档
  • Loading branch information
arc0035 committed Dec 10, 2023
2 parents 08184ee + 40d6d05 commit 2682058
Show file tree
Hide file tree
Showing 20 changed files with 429 additions and 10 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-graphql
//implementation 'org.springframework.boot:spring-boot-starter-graphql:2.7.17'
implementation 'io.springfox:springfox-boot-starter:3.0.0'


//graphql
Expand Down
152 changes: 152 additions & 0 deletions interface/share.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
[
{
"url": "http://81.69.8.95:8080/share/usershare/create",
"method": "POST",
"body": {
"theme": "主题",
"date": "分享日期,如2023-01-01",
"time": "分享时间,如8:00",
"language": "分享语言,0-中文,1英文",
"presenter": "分享人昵称",
"org": "所属组织",
"twitter": "分享人推特",
"sharingDoc": "分享链接",
"label": "标签类别"
},
"response":
{
"code": "200",
"msg": "success",
"data": 111
}
},
{
"url": "http://81.69.8.95:8080/share/usershare/update",
"method": "POST",
"body": {
"id":"分享id,如111",
"theme": "主题",
"date": "分享日期,如2023-01-01",
"time": "分享时间,如8:00",
"language": "分享语言,0-中文,1英文",
"presenter": "分享人昵称",
"org": "所属组织",
"twitter": "分享人推特",
"sharingDoc": "分享链接",
"label": "标签类别"
},
"response":
{
"code": "200",
"msg": "success",
"data": null
}
},
{
"url": "http://81.69.8.95:8080/share/usershare/delete?shareId=111",
"method": "POST",
"response":
{
"code": "200",
"msg": "success",
"data": null
}
},
{
"url": "http://81.69.8.95:8080/share/usershare/all?pageNo=1&pageSize=10",
"method": "GET",
"response":
{
"code": "200",
"msg": "success",
"data": {
"data": [
{
"id": "分享id",
"theme": "主题",
"date": "分享日期,如2023-01-01",
"time": "分享时间,如8:00",
"language": "分享语言,0-中文,1英文",
"presenter": "分享人昵称",
"org": "所属组织",
"twitter": "分享人推特",
"sharingDoc": "分享链接",
"label": "标签类别",
"locked": "锁定状态",
"meetingType": "会议类别",
"meetingId": "会议编号",
"meetingLink": "会议链接"
}
],
"pagination": {
"totalCount": 0,
"totalPages": 0,
"currentPage": 1,
"currentPageSize": 0,
"hasNext": false
}
}
}
},
{
"url": "http://81.69.8.95:8080/share/usershare/{memberId}?pageNo=1&pageSize=10",
"method": "GET",
"response":
{
"code": "200",
"msg": "success",
"data": {
"data": [
{
"id": "分享id",
"theme": "主题",
"date": "分享日期,如2023-01-01",
"time": "分享时间,如8:00",
"language": "分享语言,0-中文,1英文",
"presenter": "分享人昵称",
"org": "所属组织",
"twitter": "分享人推特",
"sharingDoc": "分享链接",
"label": "标签类别",
"locked": "锁定状态",
"meetingType": "会议类别",
"meetingId": "会议编号",
"meetingLink": "会议链接"
}
],
"pagination": {
"totalCount": 0,
"totalPages": 0,
"currentPage": 1,
"currentPageSize": 0,
"hasNext": false
}
}
}
},
{
"url": "http://81.69.8.95:8080/share/usershare/queryByShareId?shareId=111",
"method": "GET",
"response":
{
"code": "200",
"msg": "success",
"data": {
"id": "分享id",
"theme": "主题",
"date": "分享日期,如2023-01-01",
"time": "分享时间,如8:00",
"language": "分享语言,0-中文,1英文",
"presenter": "分享人昵称",
"org": "所属组织",
"twitter": "分享人推特",
"sharingDoc": "分享链接",
"label": "标签类别",
"locked": "锁定状态",
"meetingType": "会议类别",
"meetingId": "会议编号",
"meetingLink": "会议链接"
}
}
}
]
7 changes: 7 additions & 0 deletions src/main/java/com/dl/officialsite/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.dl.officialsite.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
Expand All @@ -22,4 +28,5 @@ public void addCorsMappings(CorsRegistry registry) {
//暴露哪些原始请求头部信息
.exposedHeaders("*");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ public class LoginFilter extends OncePerRequestFilter {
add("/login/check");
add("/login/check-session");
add("/login/logout");
add("/share/usershare/all");
add("/share/usershare/queryByShareId");
}} ;

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
log.info("Login filter session id {}, request {}", request.getSession().getId(), request.getRequestURI());
try{
if (noLoginApis.contains(request.getRequestURI())) {
String uri = request.getRequestURI();
if (noLoginApis.contains(uri) || uri.contains("swagger")) {
filterChain.doFilter(request, response);
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dl.officialsite.sharing.constant;

public enum SharingPostType {

CLASSIC(0);

private int code;

SharingPostType(int code){
this.code = code;
}

public static SharingPostType codeOf(int code){
for(SharingPostType postType: SharingPostType.values()){
if(postType.code == code){
return postType;
}
}
throw new IllegalArgumentException("SharingPostType "+code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
import com.dl.officialsite.sharing.model.resp.AllSharingResp;
import com.dl.officialsite.sharing.model.resp.SharingByUserResp;
import com.dl.officialsite.sharing.service.IUserSharingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("share/v1/usershare")
@RequestMapping("share/usershare")
@Slf4j
public class UserSharingController {

Expand Down Expand Up @@ -44,7 +47,7 @@ public BaseResponse updateSharing(UpdateSharingReq req){
* 删除分享
*/
@PostMapping("delete")
public BaseResponse deleteSharing(long shareId){
public BaseResponse deleteSharing(@RequestParam("shareId") long shareId){
this.userSharingService.deleteSharing(shareId);
return BaseResponse.success();
}
Expand All @@ -55,7 +58,8 @@ public BaseResponse deleteSharing(long shareId){
* @return
*/
@GetMapping("all")
public BaseResponse<AllSharingResp> loadSharing(@Param("pageNo") int pageNo, @Param("pageSize") int pageSize){
public BaseResponse<AllSharingResp> loadSharing(@RequestParam(value = "pageNo",defaultValue = "1") int pageNo,
@RequestParam(value = "pageSize",defaultValue = "20") int pageSize){
return BaseResponse.successWithData(this.userSharingService.loadSharing(pageNo, pageSize));
}

Expand All @@ -64,16 +68,18 @@ public BaseResponse<AllSharingResp> loadSharing(@Param("pageNo") int pageNo, @Pa
* @param shareId
* @return
*/
@GetMapping("{shareId}")
public BaseResponse<SharingVo> querySharing(@PathVariable("shareId") long shareId){
@GetMapping("queryByShareId")
public BaseResponse<SharingVo> querySharing(@RequestParam("shareId") long shareId){
return BaseResponse.successWithData(this.userSharingService.querySharing(shareId));
}

/**
* 查看用户的分享
*/
@GetMapping("{memberId}")
public BaseResponse<SharingByUserResp> loadSharingByUser(@PathVariable("memberId") long memberId, @Param("pageNo") int pageNo, @Param("pageSize") int pageSize) {
public BaseResponse<SharingByUserResp> loadSharingByUser(@PathVariable("memberId") long memberId,
@RequestParam(value = "pageNo",defaultValue = "1") int pageNo,
@RequestParam(value = "pageSize",defaultValue = "20") int pageSize) {
return BaseResponse.successWithData(this.userSharingService.loadSharingByUser(memberId, pageNo, pageSize));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dl.officialsite.sharing.handler;

import com.dl.officialsite.sharing.constant.SharingPostType;
import com.dl.officialsite.sharing.model.bo.PostGenerationInput;

import java.io.IOException;
import java.io.OutputStream;

public interface IPostHandler<T extends PostGenerationInput> {

void generateOutput(T input, OutputStream os) throws IOException;

SharingPostType postType();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.dl.officialsite.sharing.handler;

import com.dl.officialsite.sharing.constant.SharingPostType;
import com.dl.officialsite.sharing.model.bo.PostClassicalGeneratorInput;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

@Component
@Slf4j
public class PostClassicHandler implements IPostHandler<PostClassicalGeneratorInput>{
@Override
public void generateOutput(PostClassicalGeneratorInput input, OutputStream os) throws IOException {
/**
* 加载模板
*/
ClassPathResource classPathResource = new ClassPathResource("post/classic.png");
try(InputStream ins = classPathResource.getInputStream()){
BufferedImage image = ImageIO.read(ins);
log.info("image load finished");
}


/**
* 画右上角组织图标
*/

/**
* Presenter
*/

/**
*
*/
}

@Override
public SharingPostType postType() {
return SharingPostType.CLASSIC;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.dl.officialsite.sharing.manager;

import com.dl.officialsite.sharing.constant.SharingPostType;
import com.dl.officialsite.sharing.handler.IPostHandler;
import com.dl.officialsite.sharing.model.bo.PostGenerationInput;
import com.dl.officialsite.sharing.model.req.PostGenerateReq;
import com.google.common.base.Preconditions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* 海报处理器
*/
@Component
public class PostImageManager {

private Map<SharingPostType, IPostHandler> handlers;

@Autowired
public PostImageManager(List<IPostHandler> handlers){
this.handlers = new HashMap<>();

for(IPostHandler handler: handlers){
this.handlers.put(handler.postType(), handler);
}
}

public void generateTemplate(PostGenerateReq req){
SharingPostType sharingPostType = SharingPostType.codeOf(req.getPostType());
IPostHandler postHandler = this.handlers.get(sharingPostType);
Preconditions.checkState(postHandler !=null, "post type not found");

try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
postHandler.generateOutput(req.getInput(), baos);
} catch (Throwable ex)
{
throw new RuntimeException(ex);
}

}

}
Loading

0 comments on commit 2682058

Please sign in to comment.