feat: change appType to enum

This commit is contained in:
vran 2022-03-03 09:48:21 +08:00
parent a432ade3ec
commit 3e0e0f1c8e
14 changed files with 61 additions and 31 deletions

View File

@ -1,5 +1,6 @@
package com.databasir.core.domain.app.data; package com.databasir.core.domain.app.data;
import com.databasir.dao.enums.OAuthAppType;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
@ -14,8 +15,8 @@ public class OAuthAppCreateRequest {
@NotBlank @NotBlank
private String appName; private String appName;
@NotBlank @NotNull
private String appType; private OAuthAppType appType;
private String appIcon; private String appIcon;

View File

@ -1,5 +1,6 @@
package com.databasir.core.domain.app.data; package com.databasir.core.domain.app.data;
import com.databasir.dao.enums.OAuthAppType;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -13,7 +14,7 @@ public class OAuthAppDetailResponse {
private String appIcon; private String appIcon;
private String appType; private OAuthAppType appType;
private String registrationId; private String registrationId;

View File

@ -1,6 +1,7 @@
package com.databasir.core.domain.app.data; package com.databasir.core.domain.app.data;
import com.databasir.dao.Tables; import com.databasir.dao.Tables;
import com.databasir.dao.enums.OAuthAppType;
import lombok.Data; import lombok.Data;
import org.jooq.Condition; import org.jooq.Condition;
import org.jooq.impl.DSL; import org.jooq.impl.DSL;
@ -13,7 +14,7 @@ public class OAuthAppPageCondition {
private String appNameContains; private String appNameContains;
private String appType; private OAuthAppType appType;
public Condition toCondition() { public Condition toCondition() {
List<Condition> conditions = new ArrayList<>(); List<Condition> conditions = new ArrayList<>();

View File

@ -1,5 +1,6 @@
package com.databasir.core.domain.app.data; package com.databasir.core.domain.app.data;
import com.databasir.dao.enums.OAuthAppType;
import lombok.Data; import lombok.Data;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -13,7 +14,7 @@ public class OAuthAppPageResponse {
private String appIcon; private String appIcon;
private String appType; private OAuthAppType appType;
private String registrationId; private String registrationId;

View File

@ -1,5 +1,6 @@
package com.databasir.core.domain.app.data; package com.databasir.core.domain.app.data;
import com.databasir.dao.enums.OAuthAppType;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -19,7 +20,7 @@ public class OAuthAppResponse {
private String appIcon; private String appIcon;
private String appType; private OAuthAppType appType;
private String registrationId; private String registrationId;

View File

@ -1,5 +1,6 @@
package com.databasir.core.domain.app.data; package com.databasir.core.domain.app.data;
import com.databasir.dao.enums.OAuthAppType;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
@ -17,8 +18,8 @@ public class OAuthAppUpdateRequest {
@NotBlank @NotBlank
private String appName; private String appName;
@NotBlank @NotNull
private String appType; private OAuthAppType appType;
private String appIcon; private String appIcon;

View File

@ -21,8 +21,8 @@ public class GithubOpenAuthHandler implements OpenAuthHandler {
private final GithubRemoteService githubRemoteService; private final GithubRemoteService githubRemoteService;
@Override @Override
public boolean support(String oauthAppType) { public boolean support(OAuthAppType oauthAppType) {
return OAuthAppType.GITHUB.isSame(oauthAppType); return OAuthAppType.GITHUB == oauthAppType;
} }
@Override @Override

View File

@ -19,8 +19,8 @@ public class GitlabOpenAuthHandler implements OpenAuthHandler {
private final GitlabRemoteService gitlabRemoteService; private final GitlabRemoteService gitlabRemoteService;
@Override @Override
public boolean support(String oauthAppType) { public boolean support(OAuthAppType oauthAppType) {
return OAuthAppType.GITLAB.isSame(oauthAppType); return OAuthAppType.GITLAB == oauthAppType;
} }
@Override @Override

View File

@ -1,12 +1,13 @@
package com.databasir.core.domain.app.handler; package com.databasir.core.domain.app.handler;
import com.databasir.dao.enums.OAuthAppType;
import com.databasir.dao.tables.pojos.OauthAppPojo; import com.databasir.dao.tables.pojos.OauthAppPojo;
import java.util.Map; import java.util.Map;
public interface OpenAuthHandler { public interface OpenAuthHandler {
boolean support(String oauthAppType); boolean support(OAuthAppType oauthAppType);
String authorizationUrl(OauthAppPojo app, Map<String, String[]> requestParams); String authorizationUrl(OauthAppPojo app, Map<String, String[]> requestParams);

View File

@ -60,6 +60,12 @@ jooq {
includeExpression = '.*' includeExpression = '.*'
includeTypes = 'INET' includeTypes = 'INET'
} }
forcedType {
userType = 'com.databasir.dao.enums.OAuthAppType'
converter = 'com.databasir.dao.converter.OAuthAppTypeConverter'
includeExpression = 'app_type'
includeTypes = '.*'
}
} }
} }
generate { generate {

View File

@ -6,6 +6,8 @@ package com.databasir.dao.tables;
import com.databasir.dao.Databasir; import com.databasir.dao.Databasir;
import com.databasir.dao.Keys; import com.databasir.dao.Keys;
import com.databasir.dao.converter.OAuthAppTypeConverter;
import com.databasir.dao.enums.OAuthAppType;
import com.databasir.dao.tables.records.OauthAppRecord; import com.databasir.dao.tables.records.OauthAppRecord;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -72,7 +74,7 @@ public class OauthApp extends TableImpl<OauthAppRecord> {
/** /**
* The column <code>databasir.oauth_app.app_type</code>. github, gitlab * The column <code>databasir.oauth_app.app_type</code>. github, gitlab
*/ */
public final TableField<OauthAppRecord, String> APP_TYPE = createField(DSL.name("app_type"), SQLDataType.VARCHAR(64).nullable(false), this, "github, gitlab"); public final TableField<OauthAppRecord, OAuthAppType> APP_TYPE = createField(DSL.name("app_type"), SQLDataType.VARCHAR(64).nullable(false), this, "github, gitlab", new OAuthAppTypeConverter());
/** /**
* The column <code>databasir.oauth_app.client_id</code>. * The column <code>databasir.oauth_app.client_id</code>.
@ -193,7 +195,7 @@ public class OauthApp extends TableImpl<OauthAppRecord> {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
@Override @Override
public Row12<Integer, String, String, String, String, String, String, String, String, String, LocalDateTime, LocalDateTime> fieldsRow() { public Row12<Integer, String, String, String, OAuthAppType, String, String, String, String, String, LocalDateTime, LocalDateTime> fieldsRow() {
return (Row12) super.fieldsRow(); return (Row12) super.fieldsRow();
} }
} }

View File

@ -4,6 +4,8 @@
package com.databasir.dao.tables.pojos; package com.databasir.dao.tables.pojos;
import com.databasir.dao.enums.OAuthAppType;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -20,7 +22,7 @@ public class OauthAppPojo implements Serializable {
private String registrationId; private String registrationId;
private String appName; private String appName;
private String appIcon; private String appIcon;
private String appType; private OAuthAppType appType;
private String clientId; private String clientId;
private String clientSecret; private String clientSecret;
private String authUrl; private String authUrl;
@ -51,7 +53,7 @@ public class OauthAppPojo implements Serializable {
String registrationId, String registrationId,
String appName, String appName,
String appIcon, String appIcon,
String appType, OAuthAppType appType,
String clientId, String clientId,
String clientSecret, String clientSecret,
String authUrl, String authUrl,
@ -133,14 +135,14 @@ public class OauthAppPojo implements Serializable {
/** /**
* Getter for <code>databasir.oauth_app.app_type</code>. github, gitlab * Getter for <code>databasir.oauth_app.app_type</code>. github, gitlab
*/ */
public String getAppType() { public OAuthAppType getAppType() {
return this.appType; return this.appType;
} }
/** /**
* Setter for <code>databasir.oauth_app.app_type</code>. github, gitlab * Setter for <code>databasir.oauth_app.app_type</code>. github, gitlab
*/ */
public void setAppType(String appType) { public void setAppType(OAuthAppType appType) {
this.appType = appType; this.appType = appType;
} }

View File

@ -4,6 +4,7 @@
package com.databasir.dao.tables.records; package com.databasir.dao.tables.records;
import com.databasir.dao.enums.OAuthAppType;
import com.databasir.dao.tables.OauthApp; import com.databasir.dao.tables.OauthApp;
import com.databasir.dao.tables.pojos.OauthAppPojo; import com.databasir.dao.tables.pojos.OauthAppPojo;
@ -20,7 +21,7 @@ import org.jooq.impl.UpdatableRecordImpl;
* oauth app info * oauth app info
*/ */
@SuppressWarnings({ "all", "unchecked", "rawtypes" }) @SuppressWarnings({ "all", "unchecked", "rawtypes" })
public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implements Record12<Integer, String, String, String, String, String, String, String, String, String, LocalDateTime, LocalDateTime> { public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implements Record12<Integer, String, String, String, OAuthAppType, String, String, String, String, String, LocalDateTime, LocalDateTime> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -83,15 +84,15 @@ public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implemen
/** /**
* Setter for <code>databasir.oauth_app.app_type</code>. github, gitlab * Setter for <code>databasir.oauth_app.app_type</code>. github, gitlab
*/ */
public void setAppType(String value) { public void setAppType(OAuthAppType value) {
set(4, value); set(4, value);
} }
/** /**
* Getter for <code>databasir.oauth_app.app_type</code>. github, gitlab * Getter for <code>databasir.oauth_app.app_type</code>. github, gitlab
*/ */
public String getAppType() { public OAuthAppType getAppType() {
return (String) get(4); return (OAuthAppType) get(4);
} }
/** /**
@ -206,12 +207,12 @@ public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implemen
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
@Override @Override
public Row12<Integer, String, String, String, String, String, String, String, String, String, LocalDateTime, LocalDateTime> fieldsRow() { public Row12<Integer, String, String, String, OAuthAppType, String, String, String, String, String, LocalDateTime, LocalDateTime> fieldsRow() {
return (Row12) super.fieldsRow(); return (Row12) super.fieldsRow();
} }
@Override @Override
public Row12<Integer, String, String, String, String, String, String, String, String, String, LocalDateTime, LocalDateTime> valuesRow() { public Row12<Integer, String, String, String, OAuthAppType, String, String, String, String, String, LocalDateTime, LocalDateTime> valuesRow() {
return (Row12) super.valuesRow(); return (Row12) super.valuesRow();
} }
@ -236,7 +237,7 @@ public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implemen
} }
@Override @Override
public Field<String> field5() { public Field<OAuthAppType> field5() {
return OauthApp.OAUTH_APP.APP_TYPE; return OauthApp.OAUTH_APP.APP_TYPE;
} }
@ -296,7 +297,7 @@ public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implemen
} }
@Override @Override
public String component5() { public OAuthAppType component5() {
return getAppType(); return getAppType();
} }
@ -356,7 +357,7 @@ public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implemen
} }
@Override @Override
public String value5() { public OAuthAppType value5() {
return getAppType(); return getAppType();
} }
@ -420,7 +421,7 @@ public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implemen
} }
@Override @Override
public OauthAppRecord value5(String value) { public OauthAppRecord value5(OAuthAppType value) {
setAppType(value); setAppType(value);
return this; return this;
} }
@ -468,7 +469,7 @@ public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implemen
} }
@Override @Override
public OauthAppRecord values(Integer value1, String value2, String value3, String value4, String value5, String value6, String value7, String value8, String value9, String value10, LocalDateTime value11, LocalDateTime value12) { public OauthAppRecord values(Integer value1, String value2, String value3, String value4, OAuthAppType value5, String value6, String value7, String value8, String value9, String value10, LocalDateTime value11, LocalDateTime value12) {
value1(value1); value1(value1);
value2(value2); value2(value2);
value3(value3); value3(value3);
@ -498,7 +499,7 @@ public class OauthAppRecord extends UpdatableRecordImpl<OauthAppRecord> implemen
/** /**
* Create a detached, initialised OauthAppRecord * Create a detached, initialised OauthAppRecord
*/ */
public OauthAppRecord(Integer id, String registrationId, String appName, String appIcon, String appType, String clientId, String clientSecret, String authUrl, String resourceUrl, String scope, LocalDateTime updateAt, LocalDateTime createAt) { public OauthAppRecord(Integer id, String registrationId, String appName, String appIcon, OAuthAppType appType, String clientId, String clientSecret, String authUrl, String resourceUrl, String scope, LocalDateTime updateAt, LocalDateTime createAt) {
super(OauthApp.OAUTH_APP); super(OauthApp.OAUTH_APP);
setId(id); setId(id);

View File

@ -0,0 +1,12 @@
package com.databasir.dao.converter;
import com.databasir.dao.enums.OAuthAppType;
import org.jooq.impl.EnumConverter;
public class OAuthAppTypeConverter extends EnumConverter<String, OAuthAppType> {
public OAuthAppTypeConverter() {
super(String.class, OAuthAppType.class);
}
}