Feature/favorite project (#25)
* feat: add project favorite api * feat:update frontend resources
This commit is contained in:
parent
496534843a
commit
decd76dd42
|
@ -25,6 +25,15 @@ public interface Routes {
|
|||
String ADD_OR_REMOVE_SYS_OWNER = BASE + "/users/{userId}/sys_owners";
|
||||
}
|
||||
|
||||
interface UserProject {
|
||||
|
||||
String LIST = BASE + "/user_projects/favorites";
|
||||
|
||||
String ADD = BASE + "/user_projects/favorites/{projectId}";
|
||||
|
||||
String REMOVE = BASE + "/user_projects/favorites/{projectId}";
|
||||
}
|
||||
|
||||
interface Group {
|
||||
|
||||
String LIST = BASE + "/groups";
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.databasir.api;
|
||||
|
||||
import com.databasir.api.config.security.DatabasirUserDetails;
|
||||
import com.databasir.common.JsonData;
|
||||
import com.databasir.core.domain.user.data.FavoriteProjectPageCondition;
|
||||
import com.databasir.core.domain.user.data.FavoriteProjectPageResponse;
|
||||
import com.databasir.core.domain.user.service.UserProjectService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Validated
|
||||
public class UserProjectController {
|
||||
|
||||
private final UserProjectService userProjectService;
|
||||
|
||||
@GetMapping(Routes.UserProject.LIST)
|
||||
public JsonData<Page<FavoriteProjectPageResponse>> listFavorites(
|
||||
@PageableDefault(sort = "id", direction = DESC) Pageable pageable,
|
||||
FavoriteProjectPageCondition condition) {
|
||||
DatabasirUserDetails user = (DatabasirUserDetails) SecurityContextHolder.getContext()
|
||||
.getAuthentication()
|
||||
.getPrincipal();
|
||||
Integer userId = user.getUserPojo().getId();
|
||||
return JsonData.ok(userProjectService.listFavorites(pageable, userId, condition));
|
||||
}
|
||||
|
||||
@PostMapping(Routes.UserProject.ADD)
|
||||
public JsonData<Void> addFavorite(@PathVariable Integer projectId) {
|
||||
DatabasirUserDetails user = (DatabasirUserDetails) SecurityContextHolder.getContext()
|
||||
.getAuthentication()
|
||||
.getPrincipal();
|
||||
Integer userId = user.getUserPojo().getId();
|
||||
userProjectService.addFavorites(projectId, userId);
|
||||
return JsonData.ok();
|
||||
}
|
||||
|
||||
@DeleteMapping(Routes.UserProject.REMOVE)
|
||||
public JsonData<Void> removeFavorite(@PathVariable Integer projectId) {
|
||||
DatabasirUserDetails user = (DatabasirUserDetails) SecurityContextHolder.getContext()
|
||||
.getAuthentication()
|
||||
.getPrincipal();
|
||||
Integer userId = user.getUserPojo().getId();
|
||||
userProjectService.removeFavorites(projectId, userId);
|
||||
return JsonData.ok();
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir-frontend</title><link href="/css/chunk-04ac1c26.a5cbc9e6.css" rel="prefetch"><link href="/css/chunk-0888fe78.ab54ac4c.css" rel="prefetch"><link href="/css/chunk-2c1a91f8.a5b9f9ad.css" rel="prefetch"><link href="/css/chunk-39c5c064.a79c1787.css" rel="prefetch"><link href="/js/chunk-04ac1c26.b03a6105.js" rel="prefetch"><link href="/js/chunk-0888fe78.b8350bfc.js" rel="prefetch"><link href="/js/chunk-2c1a91f8.3e538e1a.js" rel="prefetch"><link href="/js/chunk-2d0cc811.feb081c8.js" rel="prefetch"><link href="/js/chunk-39c5c064.54e382a6.js" rel="prefetch"><link href="/js/chunk-48cebeac.b43a95b4.js" rel="prefetch"><link href="/js/chunk-abb10c56.c3ae63ee.js" rel="prefetch"><link href="/js/chunk-fffb1b64.df1e960f.js" rel="prefetch"><link href="/css/app.df19208c.css" rel="preload" as="style"><link href="/css/chunk-vendors.d4aa889d.css" rel="preload" as="style"><link href="/js/app.26339c44.js" rel="preload" as="script"><link href="/js/chunk-vendors.8b5336af.js" rel="preload" as="script"><link href="/css/chunk-vendors.d4aa889d.css" rel="stylesheet"><link href="/css/app.df19208c.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but databasir-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.8b5336af.js"></script><script src="/js/app.26339c44.js"></script></body></html>
|
||||
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/favicon.ico"><title>databasir-frontend</title><link href="/css/chunk-03c4dbde.00ac37b1.css" rel="prefetch"><link href="/css/chunk-0888fe78.e51aa148.css" rel="prefetch"><link href="/css/chunk-39c5c064.80a92238.css" rel="prefetch"><link href="/css/chunk-566612f0.06814884.css" rel="prefetch"><link href="/js/chunk-03c4dbde.fc870883.js" rel="prefetch"><link href="/js/chunk-0888fe78.b3edc7bf.js" rel="prefetch"><link href="/js/chunk-2d0cc811.c5d1ef9e.js" rel="prefetch"><link href="/js/chunk-39c5c064.54a7dd3b.js" rel="prefetch"><link href="/js/chunk-48cebeac.162363c9.js" rel="prefetch"><link href="/js/chunk-566612f0.8a0bf91d.js" rel="prefetch"><link href="/js/chunk-76185686.f269c8f3.js" rel="prefetch"><link href="/js/chunk-e421509c.b47034f5.js" rel="prefetch"><link href="/js/chunk-fffb1b64.1ffb9f27.js" rel="prefetch"><link href="/css/app.36ecf611.css" rel="preload" as="style"><link href="/css/chunk-vendors.d4aa889d.css" rel="preload" as="style"><link href="/js/app.eed3d895.js" rel="preload" as="script"><link href="/js/chunk-vendors.ec0aa4ac.js" rel="preload" as="script"><link href="/css/chunk-vendors.d4aa889d.css" rel="stylesheet"><link href="/css/app.36ecf611.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but databasir-frontend doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.ec0aa4ac.js"></script><script src="/js/app.eed3d895.js"></script></body></html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,2 +1,2 @@
|
|||
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-0888fe78"],{"0625":function(e,t,n){"use strict";n("191d")},"191d":function(e,t,n){},a55b:function(e,t,n){"use strict";n.r(t);var o=n("7a23"),r={class:"login-card"},c=Object(o["createElementVNode"])("h1",null,"Databasir",-1),a=Object(o["createTextVNode"])(" 登录 "),u=Object(o["createTextVNode"])(" 忘记密码? ");function i(e,t,n,i,l,d){var s=Object(o["resolveComponent"])("el-header"),f=Object(o["resolveComponent"])("el-link"),b=Object(o["resolveComponent"])("el-divider"),m=Object(o["resolveComponent"])("el-form-item"),j=Object(o["resolveComponent"])("el-button"),p=Object(o["resolveComponent"])("el-tooltip"),O=Object(o["resolveComponent"])("el-space"),h=Object(o["resolveComponent"])("el-form"),w=Object(o["resolveComponent"])("el-main"),C=Object(o["resolveComponent"])("el-footer"),v=Object(o["resolveComponent"])("el-container");return Object(o["openBlock"])(),Object(o["createBlock"])(v,null,{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(s),Object(o["createVNode"])(w,{class:"login-main"},{default:Object(o["withCtx"])((function(){return[Object(o["createElementVNode"])("div",r,[Object(o["createVNode"])(h,{ref:"formRef",rules:l.formRule,model:l.form,style:{border:"none"}},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(m,null,{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(b,{"content-position":"left"},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(f,{href:"https://github.com/vran-dev/databasir",target:"_blank",underline:!1,type:"info"},{default:Object(o["withCtx"])((function(){return[c]})),_:1})]})),_:1})]})),_:1}),Object(o["createVNode"])(m,{prop:"username"},{default:Object(o["withCtx"])((function(){return[Object(o["withDirectives"])(Object(o["createElementVNode"])("input",{type:"text",class:"login-input",placeholder:"用户名或邮箱","onUpdate:modelValue":t[0]||(t[0]=function(e){return l.form.username=e}),onKeyup:t[1]||(t[1]=Object(o["withKeys"])((function(e){return d.onLogin("formRef")}),["enter"]))},null,544),[[o["vModelText"],l.form.username]])]})),_:1}),Object(o["createVNode"])(m,{prop:"password"},{default:Object(o["withCtx"])((function(){return[Object(o["withDirectives"])(Object(o["createElementVNode"])("input",{type:"password",class:"login-input",placeholder:"密码","onUpdate:modelValue":t[2]||(t[2]=function(e){return l.form.password=e}),onKeyup:t[3]||(t[3]=Object(o["withKeys"])((function(e){return d.onLogin("formRef")}),["enter"]))},null,544),[[o["vModelText"],l.form.password]])]})),_:1}),Object(o["createVNode"])(m,null,{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(O,{size:32},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(j,{style:{width:"120px","margin-top":"10px"},color:"#000",onClick:t[4]||(t[4]=function(e){return d.onLogin("formRef")}),plain:"",round:""},{default:Object(o["withCtx"])((function(){return[a]})),_:1}),Object(o["createVNode"])(p,{content:"请联系管理员为您重置密码"},{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(f,{target:"_blank",underline:!1,type:"info"},{default:Object(o["withCtx"])((function(){return[u]})),_:1})]})),_:1})]})),_:1})]})),_:1})]})),_:1},8,["rules","model"])])]})),_:1}),Object(o["createVNode"])(C,null,{default:Object(o["withCtx"])((function(){return[Object(o["createVNode"])(O)]})),_:1})]})),_:1})}var l=n("b0af"),d=n("5f87"),s={data:function(){return{form:{username:null,password:null},formRule:{username:[{required:!0,message:"请输入用户名或邮箱",trigger:"blur"}],password:[{required:!0,message:"请输入密码",trigger:"blur"}]}}},methods:{toIndexPage:function(){this.$router.push({path:"/groups"})},onLogin:function(){var e=this;this.$refs.formRef.validate((function(t){t&&Object(l["a"])(e.form).then((function(t){t.errCode||(d["b"].saveUserLoginData(t.data),e.$store.commit("userUpdate",{nickname:t.data.nickname,username:t.data.username,email:t.data.email}),e.toIndexPage())}))}))}}},f=(n("0625"),n("6b0d")),b=n.n(f);const m=b()(s,[["render",i]]);t["default"]=m}}]);
|
||||
//# sourceMappingURL=chunk-0888fe78.b8350bfc.js.map
|
||||
//# sourceMappingURL=chunk-0888fe78.b3edc7bf.js.map
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -1,2 +1,2 @@
|
|||
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-2d0cc811"],{"4de0":function(e,t,r){"use strict";r.r(t);var n=r("7a23"),o=Object(n["createTextVNode"])(" : "),u=Object(n["createTextVNode"])("保存");function l(e,t,r,l,a,c){var s=Object(n["resolveComponent"])("el-input"),i=Object(n["resolveComponent"])("el-form-item"),d=Object(n["resolveComponent"])("el-col"),m=Object(n["resolveComponent"])("el-button"),f=Object(n["resolveComponent"])("el-form"),p=Object(n["resolveComponent"])("el-card"),b=Object(n["resolveComponent"])("el-main"),j=Object(n["resolveComponent"])("el-container");return Object(n["openBlock"])(),Object(n["createBlock"])(j,null,{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(b,null,{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(p,null,{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(f,{model:a.form,"label-position":"top",rules:a.formRule,ref:"formRef",style:{"max-width":"900px"}},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(i,{label:"邮箱账号",prop:"username"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(s,{modelValue:a.form.username,"onUpdate:modelValue":t[0]||(t[0]=function(e){return a.form.username=e})},null,8,["modelValue"])]})),_:1}),Object(n["createVNode"])(i,{label:"邮箱密码",prop:"password"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(s,{modelValue:a.form.password,"onUpdate:modelValue":t[1]||(t[1]=function(e){return a.form.password=e}),type:"password",placeholder:"请输入密码","show-password":""},null,8,["modelValue"])]})),_:1}),Object(n["createVNode"])(i,{label:"SMTP",prop:"smtpHost"},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(d,{span:12},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(s,{modelValue:a.form.smtpHost,"onUpdate:modelValue":t[2]||(t[2]=function(e){return a.form.smtpHost=e}),placeholder:"SMTP Host"},null,8,["modelValue"])]})),_:1}),Object(n["createVNode"])(d,{span:1,style:{"text-align":"center"}},{default:Object(n["withCtx"])((function(){return[o]})),_:1}),Object(n["createVNode"])(d,{span:6},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(s,{modelValue:a.form.smtpPort,"onUpdate:modelValue":t[3]||(t[3]=function(e){return a.form.smtpPort=e}),placeholder:"SMTP Port"},null,8,["modelValue"])]})),_:1})]})),_:1}),Object(n["createVNode"])(i,{style:{"margin-top":"38px"}},{default:Object(n["withCtx"])((function(){return[Object(n["createVNode"])(m,{type:"primary",onClick:t[4]||(t[4]=function(e){return c.onSubmit("formRef")})},{default:Object(n["withCtx"])((function(){return[u]})),_:1})]})),_:1})]})),_:1},8,["model","rules"])]})),_:1})]})),_:1})]})),_:1})}var a=r("1da1"),c=(r("96cf"),r("1c1e")),s="/api/v1.0/settings",i=function(){return c["a"].get(s+"/sys_email")},d=function(e){return c["a"].post(s+"/sys_email",e)},m={data:function(){return{form:{smtpHost:null,smtpPort:null,username:null,password:null},formRule:{username:[this.requiredInputValidRule("请输入邮箱账号"),{type:"email",message:"邮箱格式不正确",trigger:"blur"}],password:[this.requiredInputValidRule("请输入邮箱密码")],smtpHost:[this.requiredInputValidRule("请输入 SMTP 地址")],smtpPort:[this.requiredInputValidRule("请输入 SMTP 端口"),{min:1,max:65535,message:"端口有效值为 1~65535",trigger:"blur"}]}}},mounted:function(){this.fetchSysMail()},methods:{requiredInputValidRule:function(e){return{required:!0,message:e,trigger:"blur"}},fetchSysMail:function(){var e=this;return Object(a["a"])(regeneratorRuntime.mark((function t(){var r;return regeneratorRuntime.wrap((function(t){while(1)switch(t.prev=t.next){case 0:return t.next=2,i().then((function(e){return e.data}));case 2:r=t.sent,r&&(e.form=r);case 4:case"end":return t.stop()}}),t)})))()},onSubmit:function(){var e=this;this.$refs.formRef.validate((function(t){return t?(d(e.form).then((function(t){t.errCode||e.$message.success("更新成功")})),!0):(e.$message.error("请完善表单相关信息!"),!1)}))}}},f=r("6b0d"),p=r.n(f);const b=p()(m,[["render",l]]);t["default"]=b}}]);
|
||||
//# sourceMappingURL=chunk-2d0cc811.feb081c8.js.map
|
||||
//# sourceMappingURL=chunk-2d0cc811.c5d1ef9e.js.map
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,2 @@
|
|||
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([["chunk-e421509c"],{9633:function(e,t,o){"use strict";o.d(t,"a",(function(){return r}));var a=o("1c1e"),n="/api/v1.0/operation_logs",r=function(e){return a["a"].get(n,{params:e})}},efd7:function(e,t,o){"use strict";o.r(t);var a=o("7a23"),n={key:0},r=Object(a["createTextVNode"])("成功"),c={key:1},l=Object(a["createTextVNode"])("失败"),p={key:0},u={key:1};function i(e,t,o,i,j,s){var O=Object(a["resolveComponent"])("el-row"),b=Object(a["resolveComponent"])("el-header"),g=Object(a["resolveComponent"])("el-table-column"),d=Object(a["resolveComponent"])("el-option"),f=Object(a["resolveComponent"])("el-select"),h=Object(a["resolveComponent"])("el-tag"),m=Object(a["resolveComponent"])("el-table"),C=Object(a["resolveComponent"])("el-main"),P=Object(a["resolveComponent"])("el-pagination"),v=Object(a["resolveComponent"])("el-footer"),V=Object(a["resolveComponent"])("el-container");return Object(a["openBlock"])(),Object(a["createBlock"])(V,null,{default:Object(a["withCtx"])((function(){return[Object(a["createVNode"])(b,null,{default:Object(a["withCtx"])((function(){return[Object(a["createVNode"])(O,{gutter:10})]})),_:1}),Object(a["createVNode"])(C,null,{default:Object(a["withCtx"])((function(){return[Object(a["createVNode"])(m,{data:j.projectOperationLogPageData.data},{default:Object(a["withCtx"])((function(){return[Object(a["createVNode"])(g,{prop:"id",label:""}),Object(a["createVNode"])(g,{prop:"operationModule",label:"系统模块"}),Object(a["createVNode"])(g,{prop:"operatorNickname",label:"操作人"}),Object(a["createVNode"])(g,{prop:"operationName",label:"操作"}),Object(a["createVNode"])(g,{label:"状态"},{header:Object(a["withCtx"])((function(){return[Object(a["createVNode"])(f,{modelValue:j.projectOperationLogPageQuery.isSuccess,"onUpdate:modelValue":t[0]||(t[0]=function(e){return j.projectOperationLogPageQuery.isSuccess=e}),placeholder:"状态",onChange:s.onQuery,clearable:"",size:"small","tag-type":"success"},{default:Object(a["withCtx"])((function(){return[(Object(a["openBlock"])(),Object(a["createElementBlock"])(a["Fragment"],null,Object(a["renderList"])([!0,!1],(function(e){return Object(a["createVNode"])(d,{key:e,label:e?"成功":"失败",value:e},null,8,["label","value"])})),64))]})),_:1},8,["modelValue","onChange"])]})),default:Object(a["withCtx"])((function(e){return[e.row.isSuccess?(Object(a["openBlock"])(),Object(a["createElementBlock"])("span",n,[Object(a["createVNode"])(h,{type:"success"},{default:Object(a["withCtx"])((function(){return[r]})),_:1})])):(Object(a["openBlock"])(),Object(a["createElementBlock"])("span",c,[Object(a["createVNode"])(h,{type:"danger"},{default:Object(a["withCtx"])((function(){return[l]})),_:1})]))]})),_:1}),Object(a["createVNode"])(g,{label:"错误信息"},{default:Object(a["withCtx"])((function(e){return[e.row.isSuccess?(Object(a["openBlock"])(),Object(a["createElementBlock"])("span",p)):(Object(a["openBlock"])(),Object(a["createElementBlock"])("span",u,Object(a["toDisplayString"])(e.row.operationResponse.errMessage),1))]})),_:1}),Object(a["createVNode"])(g,{prop:"involvedGroupId",label:"涉及分组"}),Object(a["createVNode"])(g,{prop:"involvedProjectId",label:"涉及项目"}),Object(a["createVNode"])(g,{prop:"involvedUserId",label:"涉及用户"}),Object(a["createVNode"])(g,{prop:"createAt",label:"记录时间"})]})),_:1},8,["data"])]})),_:1}),Object(a["createVNode"])(v,null,{default:Object(a["withCtx"])((function(){return[Object(a["createVNode"])(P,{layout:"prev, pager, next","hide-on-single-page":!1,currentPage:j.projectOperationLogPageData.number,"page-size":j.projectOperationLogPageData.size,"page-count":j.projectOperationLogPageData.totalPages,onCurrentChange:s.onProjectOperationLogCurrentPageChange},null,8,["currentPage","page-size","page-count","onCurrentChange"])]})),_:1})]})),_:1})}var j=o("9633"),s={data:function(){return{projectOperationLogPageData:{data:[],number:1,size:10,totalElements:0,totalPages:1},projectOperationLogPageQuery:{page:0,size:10,isSuccess:null,involveProjectId:null,module:null}}},created:function(){this.fetchProjectOperationLogs()},methods:{fetchProjectOperationLogs:function(e){var t=this;this.projectOperationLogPageQuery.page=e?e-1:null,Object(j["a"])(this.projectOperationLogPageQuery).then((function(e){e.errCode||(t.projectOperationLogPageData.data=e.data.content,t.projectOperationLogPageData.number=e.data.number+1,t.projectOperationLogPageData.size=e.data.size,t.projectOperationLogPageData.totalPages=e.data.totalPages,t.projectOperationLogPageData.totalElements=e.data.totalElements)}))},onProjectOperationLogCurrentPageChange:function(e){e&&e-1!=this.projectOperationLogPageQuery.page&&(this.projectOperationLogPageQuery.page=e-1,this.fetchProjectOperationLogs(e))},onQuery:function(){this.fetchProjectOperationLogs()}}},O=o("6b0d"),b=o.n(O);const g=b()(s,[["render",i]]);t["default"]=g}}]);
|
||||
//# sourceMappingURL=chunk-e421509c.b47034f5.js.map
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,22 @@
|
|||
package com.databasir.core.domain.user.converter;
|
||||
|
||||
import com.databasir.core.domain.user.data.FavoriteProjectPageResponse;
|
||||
import com.databasir.dao.tables.pojos.*;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface FavoriteProjectPageResponseConverter {
|
||||
|
||||
@Mapping(target = "projectId", source = "project.id")
|
||||
@Mapping(target = "projectName", source = "project.name")
|
||||
@Mapping(target = "projectDescription", source = "project.description")
|
||||
@Mapping(target = "groupId", source = "group.id")
|
||||
@Mapping(target = "groupName", source = "group.name")
|
||||
@Mapping(target = "createAt", source = "favoriteProject.createAt")
|
||||
FavoriteProjectPageResponse to(UserFavoriteProjectPojo favoriteProject,
|
||||
ProjectPojo project,
|
||||
DataSourcePojo dataSource,
|
||||
ProjectSyncRulePojo projectSyncRule,
|
||||
GroupPojo group);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.databasir.core.domain.user.data;
|
||||
|
||||
public class FavoriteProjectCreateRequest {
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.databasir.core.domain.user.data;
|
||||
|
||||
import com.databasir.dao.Tables;
|
||||
import lombok.Data;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.impl.DSL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class FavoriteProjectPageCondition {
|
||||
|
||||
private String projectNameContains;
|
||||
|
||||
public Condition toCondition(Integer userId) {
|
||||
List<Condition> conditions = new ArrayList<>();
|
||||
conditions.add(Tables.USER_FAVORITE_PROJECT.USER_ID.eq(userId));
|
||||
if (projectNameContains != null && !projectNameContains.trim().equals("")) {
|
||||
conditions.add(Tables.PROJECT.NAME.contains(projectNameContains));
|
||||
}
|
||||
return conditions.stream()
|
||||
.reduce(Condition::and)
|
||||
.orElse(DSL.trueCondition());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.databasir.core.domain.user.data;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class FavoriteProjectPageResponse {
|
||||
|
||||
private Integer projectId;
|
||||
|
||||
private String projectName;
|
||||
|
||||
private String projectDescription;
|
||||
|
||||
private Boolean isAutoSync;
|
||||
|
||||
private String autoSyncCron;
|
||||
|
||||
private Integer groupId;
|
||||
|
||||
private String groupName;
|
||||
|
||||
private String databaseType;
|
||||
|
||||
private String databaseName;
|
||||
|
||||
private LocalDateTime createAt;
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.databasir.core.domain.user.service;
|
||||
|
||||
import com.databasir.core.domain.DomainErrors;
|
||||
import com.databasir.core.domain.user.converter.FavoriteProjectPageResponseConverter;
|
||||
import com.databasir.core.domain.user.data.FavoriteProjectPageCondition;
|
||||
import com.databasir.core.domain.user.data.FavoriteProjectPageResponse;
|
||||
import com.databasir.dao.impl.*;
|
||||
import com.databasir.dao.tables.pojos.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserProjectService {
|
||||
|
||||
private final UserFavoriteProjectDao userFavoriteProjectDao;
|
||||
|
||||
private final ProjectDao projectDao;
|
||||
|
||||
private final ProjectSyncRuleDao projectSyncRuleDao;
|
||||
|
||||
private final DataSourceDao dataSourceDao;
|
||||
|
||||
private final GroupDao groupDao;
|
||||
|
||||
private final FavoriteProjectPageResponseConverter favoriteProjectPageResponseConverter;
|
||||
|
||||
public Page<FavoriteProjectPageResponse> listFavorites(Pageable pageable,
|
||||
Integer userId,
|
||||
FavoriteProjectPageCondition condition) {
|
||||
var data = userFavoriteProjectDao.selectByCondition(pageable, condition.toCondition(userId));
|
||||
// project data
|
||||
var projectIdList = data.map(UserFavoriteProjectPojo::getProjectId).toList();
|
||||
var projectPojos = projectDao.selectInIds(projectIdList);
|
||||
var projectMapById = projectPojos.stream()
|
||||
.collect(Collectors.toMap(ProjectPojo::getId, Function.identity()));
|
||||
// dataSource data
|
||||
var dataSourceMapByProjectId = dataSourceDao.selectInProjectIds(projectIdList)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(DataSourcePojo::getProjectId, Function.identity()));
|
||||
// project sync rule data
|
||||
var projectSyncRuleMapByProjectId = projectSyncRuleDao.selectInProjectIds(projectIdList)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(ProjectSyncRulePojo::getProjectId, Function.identity()));
|
||||
// group data
|
||||
var groupIdList = projectPojos.stream().map(ProjectPojo::getGroupId).collect(Collectors.toList());
|
||||
var groupMapById = groupDao.selectInIds(groupIdList)
|
||||
.stream()
|
||||
.collect(Collectors.toMap(GroupPojo::getId, Function.identity()));
|
||||
// response data
|
||||
return data.map(favorite -> {
|
||||
ProjectPojo project = projectMapById.get(favorite.getProjectId());
|
||||
DataSourcePojo dataSource = dataSourceMapByProjectId.get(favorite.getProjectId());
|
||||
ProjectSyncRulePojo projectSyncRule = projectSyncRuleMapByProjectId.get(favorite.getProjectId());
|
||||
GroupPojo group = null;
|
||||
if (project != null) {
|
||||
group = groupMapById.get(project.getGroupId());
|
||||
}
|
||||
return favoriteProjectPageResponseConverter.to(favorite, project, dataSource, projectSyncRule, group);
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void addFavorites(Integer projectId, Integer userId) {
|
||||
if (!projectDao.existsById(projectId)) {
|
||||
throw DomainErrors.PROJECT_NOT_FOUND.exception();
|
||||
}
|
||||
if (!userFavoriteProjectDao.exists(userId, projectId)) {
|
||||
userFavoriteProjectDao.insert(userId, projectId);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeFavorites(Integer projectId, Integer userId) {
|
||||
if (userFavoriteProjectDao.exists(userId, projectId)) {
|
||||
userFavoriteProjectDao.delete(userId, projectId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@ import com.databasir.dao.tables.TableDocument;
|
|||
import com.databasir.dao.tables.TableIndexDocument;
|
||||
import com.databasir.dao.tables.TableTriggerDocument;
|
||||
import com.databasir.dao.tables.User;
|
||||
import com.databasir.dao.tables.UserFavoriteProject;
|
||||
import com.databasir.dao.tables.UserRole;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -129,6 +130,11 @@ public class Databasir extends SchemaImpl {
|
|||
*/
|
||||
public final User USER = User.USER;
|
||||
|
||||
/**
|
||||
* The table <code>databasir.user_favorite_project</code>.
|
||||
*/
|
||||
public final UserFavoriteProject USER_FAVORITE_PROJECT = UserFavoriteProject.USER_FAVORITE_PROJECT;
|
||||
|
||||
/**
|
||||
* The table <code>databasir.user_role</code>.
|
||||
*/
|
||||
|
@ -167,6 +173,7 @@ public class Databasir extends SchemaImpl {
|
|||
TableIndexDocument.TABLE_INDEX_DOCUMENT,
|
||||
TableTriggerDocument.TABLE_TRIGGER_DOCUMENT,
|
||||
User.USER,
|
||||
UserFavoriteProject.USER_FAVORITE_PROJECT,
|
||||
UserRole.USER_ROLE
|
||||
);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.databasir.dao.tables.TableColumnDocument;
|
|||
import com.databasir.dao.tables.TableDocument;
|
||||
import com.databasir.dao.tables.TableIndexDocument;
|
||||
import com.databasir.dao.tables.TableTriggerDocument;
|
||||
import com.databasir.dao.tables.UserFavoriteProject;
|
||||
|
||||
import org.jooq.Index;
|
||||
import org.jooq.OrderField;
|
||||
|
@ -38,4 +39,5 @@ public class Indexes {
|
|||
public static final Index TABLE_COLUMN_DOCUMENT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), TableColumnDocument.TABLE_COLUMN_DOCUMENT, new OrderField[] { TableColumnDocument.TABLE_COLUMN_DOCUMENT.TABLE_DOCUMENT_ID }, false);
|
||||
public static final Index TABLE_INDEX_DOCUMENT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), TableIndexDocument.TABLE_INDEX_DOCUMENT, new OrderField[] { TableIndexDocument.TABLE_INDEX_DOCUMENT.TABLE_DOCUMENT_ID }, false);
|
||||
public static final Index TABLE_TRIGGER_DOCUMENT_IDX_TABLE_DOCUMENT_ID = Internal.createIndex(DSL.name("idx_table_document_id"), TableTriggerDocument.TABLE_TRIGGER_DOCUMENT, new OrderField[] { TableTriggerDocument.TABLE_TRIGGER_DOCUMENT.TABLE_DOCUMENT_ID }, false);
|
||||
public static final Index USER_FAVORITE_PROJECT_IDX_USER_ID = Internal.createIndex(DSL.name("idx_user_id"), UserFavoriteProject.USER_FAVORITE_PROJECT, new OrderField[] { UserFavoriteProject.USER_FAVORITE_PROJECT.USER_ID }, false);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.databasir.dao.tables.TableDocument;
|
|||
import com.databasir.dao.tables.TableIndexDocument;
|
||||
import com.databasir.dao.tables.TableTriggerDocument;
|
||||
import com.databasir.dao.tables.User;
|
||||
import com.databasir.dao.tables.UserFavoriteProject;
|
||||
import com.databasir.dao.tables.UserRole;
|
||||
import com.databasir.dao.tables.records.DataSourcePropertyRecord;
|
||||
import com.databasir.dao.tables.records.DataSourceRecord;
|
||||
|
@ -38,6 +39,7 @@ import com.databasir.dao.tables.records.TableColumnDocumentRecord;
|
|||
import com.databasir.dao.tables.records.TableDocumentRecord;
|
||||
import com.databasir.dao.tables.records.TableIndexDocumentRecord;
|
||||
import com.databasir.dao.tables.records.TableTriggerDocumentRecord;
|
||||
import com.databasir.dao.tables.records.UserFavoriteProjectRecord;
|
||||
import com.databasir.dao.tables.records.UserRecord;
|
||||
import com.databasir.dao.tables.records.UserRoleRecord;
|
||||
|
||||
|
@ -83,6 +85,7 @@ public class Keys {
|
|||
public static final UniqueKey<UserRecord> KEY_USER_PRIMARY = Internal.createUniqueKey(User.USER, DSL.name("KEY_user_PRIMARY"), new TableField[] { User.USER.ID }, true);
|
||||
public static final UniqueKey<UserRecord> KEY_USER_UK_EMAIL = Internal.createUniqueKey(User.USER, DSL.name("KEY_user_uk_email"), new TableField[] { User.USER.EMAIL }, true);
|
||||
public static final UniqueKey<UserRecord> KEY_USER_UK_USERNAME = Internal.createUniqueKey(User.USER, DSL.name("KEY_user_uk_username"), new TableField[] { User.USER.USERNAME }, true);
|
||||
public static final UniqueKey<UserFavoriteProjectRecord> KEY_USER_FAVORITE_PROJECT_PRIMARY = Internal.createUniqueKey(UserFavoriteProject.USER_FAVORITE_PROJECT, DSL.name("KEY_user_favorite_project_PRIMARY"), new TableField[] { UserFavoriteProject.USER_FAVORITE_PROJECT.ID }, true);
|
||||
public static final UniqueKey<UserRoleRecord> KEY_USER_ROLE_PRIMARY = Internal.createUniqueKey(UserRole.USER_ROLE, DSL.name("KEY_user_role_PRIMARY"), new TableField[] { UserRole.USER_ROLE.ID }, true);
|
||||
public static final UniqueKey<UserRoleRecord> KEY_USER_ROLE_UK_USER_ID_GROUP_ID_ROLE = Internal.createUniqueKey(UserRole.USER_ROLE, DSL.name("KEY_user_role_uk_user_id_group_id_role"), new TableField[] { UserRole.USER_ROLE.USER_ID, UserRole.USER_ROLE.GROUP_ID, UserRole.USER_ROLE.ROLE }, true);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.databasir.dao.tables.TableDocument;
|
|||
import com.databasir.dao.tables.TableIndexDocument;
|
||||
import com.databasir.dao.tables.TableTriggerDocument;
|
||||
import com.databasir.dao.tables.User;
|
||||
import com.databasir.dao.tables.UserFavoriteProject;
|
||||
import com.databasir.dao.tables.UserRole;
|
||||
|
||||
|
||||
|
@ -115,6 +116,11 @@ public class Tables {
|
|||
*/
|
||||
public static final User USER = User.USER;
|
||||
|
||||
/**
|
||||
* The table <code>databasir.user_favorite_project</code>.
|
||||
*/
|
||||
public static final UserFavoriteProject USER_FAVORITE_PROJECT = UserFavoriteProject.USER_FAVORITE_PROJECT;
|
||||
|
||||
/**
|
||||
* The table <code>databasir.user_role</code>.
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.databasir.dao.tables;
|
||||
|
||||
|
||||
import com.databasir.dao.Databasir;
|
||||
import com.databasir.dao.Indexes;
|
||||
import com.databasir.dao.Keys;
|
||||
import com.databasir.dao.tables.records.UserFavoriteProjectRecord;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.jooq.Field;
|
||||
import org.jooq.ForeignKey;
|
||||
import org.jooq.Identity;
|
||||
import org.jooq.Index;
|
||||
import org.jooq.Name;
|
||||
import org.jooq.Record;
|
||||
import org.jooq.Row4;
|
||||
import org.jooq.Schema;
|
||||
import org.jooq.Table;
|
||||
import org.jooq.TableField;
|
||||
import org.jooq.TableOptions;
|
||||
import org.jooq.UniqueKey;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.jooq.impl.SQLDataType;
|
||||
import org.jooq.impl.TableImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||
public class UserFavoriteProject extends TableImpl<UserFavoriteProjectRecord> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* The reference instance of <code>databasir.user_favorite_project</code>
|
||||
*/
|
||||
public static final UserFavoriteProject USER_FAVORITE_PROJECT = new UserFavoriteProject();
|
||||
|
||||
/**
|
||||
* The class holding records for this type
|
||||
*/
|
||||
@Override
|
||||
public Class<UserFavoriteProjectRecord> getRecordType() {
|
||||
return UserFavoriteProjectRecord.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* The column <code>databasir.user_favorite_project.id</code>.
|
||||
*/
|
||||
public final TableField<UserFavoriteProjectRecord, Integer> ID = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false).identity(true), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>databasir.user_favorite_project.user_id</code>.
|
||||
*/
|
||||
public final TableField<UserFavoriteProjectRecord, Integer> USER_ID = createField(DSL.name("user_id"), SQLDataType.INTEGER.nullable(false), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>databasir.user_favorite_project.project_id</code>.
|
||||
*/
|
||||
public final TableField<UserFavoriteProjectRecord, Integer> PROJECT_ID = createField(DSL.name("project_id"), SQLDataType.INTEGER.nullable(false), this, "");
|
||||
|
||||
/**
|
||||
* The column <code>databasir.user_favorite_project.create_at</code>.
|
||||
*/
|
||||
public final TableField<UserFavoriteProjectRecord, LocalDateTime> CREATE_AT = createField(DSL.name("create_at"), SQLDataType.LOCALDATETIME(0).nullable(false).defaultValue(DSL.field("CURRENT_TIMESTAMP", SQLDataType.LOCALDATETIME)), this, "");
|
||||
|
||||
private UserFavoriteProject(Name alias, Table<UserFavoriteProjectRecord> aliased) {
|
||||
this(alias, aliased, null);
|
||||
}
|
||||
|
||||
private UserFavoriteProject(Name alias, Table<UserFavoriteProjectRecord> aliased, Field<?>[] parameters) {
|
||||
super(alias, null, aliased, parameters, DSL.comment(""), TableOptions.table());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an aliased <code>databasir.user_favorite_project</code> table
|
||||
* reference
|
||||
*/
|
||||
public UserFavoriteProject(String alias) {
|
||||
this(DSL.name(alias), USER_FAVORITE_PROJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an aliased <code>databasir.user_favorite_project</code> table
|
||||
* reference
|
||||
*/
|
||||
public UserFavoriteProject(Name alias) {
|
||||
this(alias, USER_FAVORITE_PROJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>databasir.user_favorite_project</code> table reference
|
||||
*/
|
||||
public UserFavoriteProject() {
|
||||
this(DSL.name("user_favorite_project"), null);
|
||||
}
|
||||
|
||||
public <O extends Record> UserFavoriteProject(Table<O> child, ForeignKey<O, UserFavoriteProjectRecord> key) {
|
||||
super(child, key, USER_FAVORITE_PROJECT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Schema getSchema() {
|
||||
return aliased() ? null : Databasir.DATABASIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Index> getIndexes() {
|
||||
return Arrays.asList(Indexes.USER_FAVORITE_PROJECT_IDX_USER_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identity<UserFavoriteProjectRecord, Integer> getIdentity() {
|
||||
return (Identity<UserFavoriteProjectRecord, Integer>) super.getIdentity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UniqueKey<UserFavoriteProjectRecord> getPrimaryKey() {
|
||||
return Keys.KEY_USER_FAVORITE_PROJECT_PRIMARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserFavoriteProject as(String alias) {
|
||||
return new UserFavoriteProject(DSL.name(alias), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserFavoriteProject as(Name alias) {
|
||||
return new UserFavoriteProject(alias, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public UserFavoriteProject rename(String name) {
|
||||
return new UserFavoriteProject(DSL.name(name), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename this table
|
||||
*/
|
||||
@Override
|
||||
public UserFavoriteProject rename(Name name) {
|
||||
return new UserFavoriteProject(name, null);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Row4 type methods
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Row4<Integer, Integer, Integer, LocalDateTime> fieldsRow() {
|
||||
return (Row4) super.fieldsRow();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.databasir.dao.tables.pojos;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||
public class UserFavoriteProjectPojo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Integer id;
|
||||
private Integer userId;
|
||||
private Integer projectId;
|
||||
private LocalDateTime createAt;
|
||||
|
||||
public UserFavoriteProjectPojo() {}
|
||||
|
||||
public UserFavoriteProjectPojo(UserFavoriteProjectPojo value) {
|
||||
this.id = value.id;
|
||||
this.userId = value.userId;
|
||||
this.projectId = value.projectId;
|
||||
this.createAt = value.createAt;
|
||||
}
|
||||
|
||||
public UserFavoriteProjectPojo(
|
||||
Integer id,
|
||||
Integer userId,
|
||||
Integer projectId,
|
||||
LocalDateTime createAt
|
||||
) {
|
||||
this.id = id;
|
||||
this.userId = userId;
|
||||
this.projectId = projectId;
|
||||
this.createAt = createAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>databasir.user_favorite_project.id</code>.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>databasir.user_favorite_project.id</code>.
|
||||
*/
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>databasir.user_favorite_project.user_id</code>.
|
||||
*/
|
||||
public Integer getUserId() {
|
||||
return this.userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>databasir.user_favorite_project.user_id</code>.
|
||||
*/
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>databasir.user_favorite_project.project_id</code>.
|
||||
*/
|
||||
public Integer getProjectId() {
|
||||
return this.projectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>databasir.user_favorite_project.project_id</code>.
|
||||
*/
|
||||
public void setProjectId(Integer projectId) {
|
||||
this.projectId = projectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>databasir.user_favorite_project.create_at</code>.
|
||||
*/
|
||||
public LocalDateTime getCreateAt() {
|
||||
return this.createAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>databasir.user_favorite_project.create_at</code>.
|
||||
*/
|
||||
public void setCreateAt(LocalDateTime createAt) {
|
||||
this.createAt = createAt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("UserFavoriteProjectPojo (");
|
||||
|
||||
sb.append(id);
|
||||
sb.append(", ").append(userId);
|
||||
sb.append(", ").append(projectId);
|
||||
sb.append(", ").append(createAt);
|
||||
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,235 @@
|
|||
/*
|
||||
* This file is generated by jOOQ.
|
||||
*/
|
||||
package com.databasir.dao.tables.records;
|
||||
|
||||
|
||||
import com.databasir.dao.tables.UserFavoriteProject;
|
||||
import com.databasir.dao.tables.pojos.UserFavoriteProjectPojo;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import org.jooq.Field;
|
||||
import org.jooq.Record1;
|
||||
import org.jooq.Record4;
|
||||
import org.jooq.Row4;
|
||||
import org.jooq.impl.UpdatableRecordImpl;
|
||||
|
||||
|
||||
/**
|
||||
* This class is generated by jOOQ.
|
||||
*/
|
||||
@SuppressWarnings({ "all", "unchecked", "rawtypes" })
|
||||
public class UserFavoriteProjectRecord extends UpdatableRecordImpl<UserFavoriteProjectRecord> implements Record4<Integer, Integer, Integer, LocalDateTime> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Setter for <code>databasir.user_favorite_project.id</code>.
|
||||
*/
|
||||
public void setId(Integer value) {
|
||||
set(0, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>databasir.user_favorite_project.id</code>.
|
||||
*/
|
||||
public Integer getId() {
|
||||
return (Integer) get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>databasir.user_favorite_project.user_id</code>.
|
||||
*/
|
||||
public void setUserId(Integer value) {
|
||||
set(1, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>databasir.user_favorite_project.user_id</code>.
|
||||
*/
|
||||
public Integer getUserId() {
|
||||
return (Integer) get(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>databasir.user_favorite_project.project_id</code>.
|
||||
*/
|
||||
public void setProjectId(Integer value) {
|
||||
set(2, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>databasir.user_favorite_project.project_id</code>.
|
||||
*/
|
||||
public Integer getProjectId() {
|
||||
return (Integer) get(2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for <code>databasir.user_favorite_project.create_at</code>.
|
||||
*/
|
||||
public void setCreateAt(LocalDateTime value) {
|
||||
set(3, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for <code>databasir.user_favorite_project.create_at</code>.
|
||||
*/
|
||||
public LocalDateTime getCreateAt() {
|
||||
return (LocalDateTime) get(3);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Primary key information
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Record1<Integer> key() {
|
||||
return (Record1) super.key();
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Record4 type implementation
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public Row4<Integer, Integer, Integer, LocalDateTime> fieldsRow() {
|
||||
return (Row4) super.fieldsRow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Row4<Integer, Integer, Integer, LocalDateTime> valuesRow() {
|
||||
return (Row4) super.valuesRow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field<Integer> field1() {
|
||||
return UserFavoriteProject.USER_FAVORITE_PROJECT.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field<Integer> field2() {
|
||||
return UserFavoriteProject.USER_FAVORITE_PROJECT.USER_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field<Integer> field3() {
|
||||
return UserFavoriteProject.USER_FAVORITE_PROJECT.PROJECT_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field<LocalDateTime> field4() {
|
||||
return UserFavoriteProject.USER_FAVORITE_PROJECT.CREATE_AT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer component1() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer component2() {
|
||||
return getUserId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer component3() {
|
||||
return getProjectId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDateTime component4() {
|
||||
return getCreateAt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer value1() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer value2() {
|
||||
return getUserId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer value3() {
|
||||
return getProjectId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDateTime value4() {
|
||||
return getCreateAt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserFavoriteProjectRecord value1(Integer value) {
|
||||
setId(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserFavoriteProjectRecord value2(Integer value) {
|
||||
setUserId(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserFavoriteProjectRecord value3(Integer value) {
|
||||
setProjectId(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserFavoriteProjectRecord value4(LocalDateTime value) {
|
||||
setCreateAt(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserFavoriteProjectRecord values(Integer value1, Integer value2, Integer value3, LocalDateTime value4) {
|
||||
value1(value1);
|
||||
value2(value2);
|
||||
value3(value3);
|
||||
value4(value4);
|
||||
return this;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Constructors
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Create a detached UserFavoriteProjectRecord
|
||||
*/
|
||||
public UserFavoriteProjectRecord() {
|
||||
super(UserFavoriteProject.USER_FAVORITE_PROJECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a detached, initialised UserFavoriteProjectRecord
|
||||
*/
|
||||
public UserFavoriteProjectRecord(Integer id, Integer userId, Integer projectId, LocalDateTime createAt) {
|
||||
super(UserFavoriteProject.USER_FAVORITE_PROJECT);
|
||||
|
||||
setId(id);
|
||||
setUserId(userId);
|
||||
setProjectId(projectId);
|
||||
setCreateAt(createAt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a detached, initialised UserFavoriteProjectRecord
|
||||
*/
|
||||
public UserFavoriteProjectRecord(UserFavoriteProjectPojo value) {
|
||||
super(UserFavoriteProject.USER_FAVORITE_PROJECT);
|
||||
|
||||
if (value != null) {
|
||||
setId(value.getId());
|
||||
setUserId(value.getUserId());
|
||||
setProjectId(value.getProjectId());
|
||||
setCreateAt(value.getCreateAt());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,6 +28,10 @@ public abstract class BaseDao<R> {
|
|||
return getDslContext().fetchExists(table, identity().eq(id));
|
||||
}
|
||||
|
||||
public boolean exists(Condition condition) {
|
||||
return getDslContext().fetchExists(table, condition);
|
||||
}
|
||||
|
||||
public <T> T insertAndReturnId(R pojo) {
|
||||
Record record = getDslContext().newRecord(table, pojo);
|
||||
UpdatableRecord<?> updatableRecord = (UpdatableRecord<?>) record;
|
||||
|
@ -46,6 +50,12 @@ public abstract class BaseDao<R> {
|
|||
return Arrays.stream(getDslContext().batchInsert(records).execute()).sum();
|
||||
}
|
||||
|
||||
public int delete(Condition condition) {
|
||||
return getDslContext()
|
||||
.deleteFrom(table).where(condition)
|
||||
.execute();
|
||||
}
|
||||
|
||||
public <T extends Serializable> int deleteById(T id) {
|
||||
return getDslContext()
|
||||
.deleteFrom(table).where(identity().eq(id))
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package com.databasir.dao.impl;
|
||||
|
||||
import com.databasir.dao.tables.pojos.UserFavoriteProjectPojo;
|
||||
import lombok.Getter;
|
||||
import org.jooq.Condition;
|
||||
import org.jooq.DSLContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.databasir.dao.Tables.*;
|
||||
|
||||
@Repository
|
||||
public class UserFavoriteProjectDao extends BaseDao<UserFavoriteProjectPojo> {
|
||||
|
||||
@Autowired
|
||||
@Getter
|
||||
private DSLContext dslContext;
|
||||
|
||||
public UserFavoriteProjectDao() {
|
||||
super(USER_FAVORITE_PROJECT, UserFavoriteProjectPojo.class);
|
||||
}
|
||||
|
||||
public boolean exists(Integer userId, Integer projectId) {
|
||||
return exists(USER_FAVORITE_PROJECT.USER_ID.eq(userId)
|
||||
.and(USER_FAVORITE_PROJECT.PROJECT_ID.eq(projectId)));
|
||||
}
|
||||
|
||||
public void insert(Integer userId, Integer projectId) {
|
||||
UserFavoriteProjectPojo pojo = new UserFavoriteProjectPojo();
|
||||
pojo.setUserId(userId);
|
||||
pojo.setProjectId(projectId);
|
||||
this.insertAndReturnId(pojo);
|
||||
}
|
||||
|
||||
public void delete(Integer userId, Integer projectId) {
|
||||
this.delete(USER_FAVORITE_PROJECT.USER_ID.eq(userId)
|
||||
.and(USER_FAVORITE_PROJECT.PROJECT_ID.eq(projectId)));
|
||||
}
|
||||
|
||||
public Page<UserFavoriteProjectPojo> selectByCondition(Pageable request, Condition condition) {
|
||||
int total = getDslContext()
|
||||
.selectCount().from(USER_FAVORITE_PROJECT)
|
||||
.innerJoin(USER).on(USER.ID.eq(USER_FAVORITE_PROJECT.USER_ID))
|
||||
.innerJoin(PROJECT).on(PROJECT.ID.eq(USER_FAVORITE_PROJECT.PROJECT_ID))
|
||||
.where(PROJECT.DELETED.eq(false).and(condition))
|
||||
.fetchOne(0, int.class);
|
||||
List<UserFavoriteProjectPojo> data = getDslContext()
|
||||
.select(USER_FAVORITE_PROJECT.fields()).from(USER_FAVORITE_PROJECT)
|
||||
.innerJoin(USER).on(USER.ID.eq(USER_FAVORITE_PROJECT.USER_ID))
|
||||
.innerJoin(PROJECT).on(PROJECT.ID.eq(USER_FAVORITE_PROJECT.PROJECT_ID))
|
||||
.where(PROJECT.DELETED.eq(false).and(condition))
|
||||
.orderBy(getSortFields(request.getSort()))
|
||||
.offset(request.getOffset()).limit(request.getPageSize())
|
||||
.fetchInto(UserFavoriteProjectPojo.class);
|
||||
return new PageImpl<>(data, request, total);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
CREATE TABLE IF NOT EXISTS user_favorite_project
|
||||
(
|
||||
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
|
||||
user_id INT NOT NULL,
|
||||
project_id INT NOT NULL,
|
||||
create_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE uk_user_id_project_id (user_id, project_id)
|
||||
) CHARSET utf8mb4
|
||||
COLLATE utf8mb4_unicode_ci;
|
Loading…
Reference in New Issue