feat: no application_password

pull/376/head
textworld 1 year ago
parent 97d95406ee
commit 927be7bd76

@ -56,7 +56,7 @@ func main() {
g.GenerateModel("tag"),
g.GenerateModel("theme_setting"),
g.GenerateModel("user", gen.FieldType("mfa_type", "consts.MFAType")),
//g.GenerateModel("application_password"),
g.GenerateModel("application_password"),
g.GenerateModel("scrap_page"),
)

@ -35,7 +35,7 @@ func newScrapPage(db *gorm.DB, opts ...gen.DOOption) scrapPage {
_scrapPage.Summary = field.NewString(tableName, "summary")
_scrapPage.CreateAt = field.NewInt64(tableName, "create_at")
_scrapPage.Domain = field.NewString(tableName, "domain")
_scrapPage.Resource = field.NewString(tableName, "resource")
_scrapPage.OutLink = field.NewString(tableName, "out_link")
_scrapPage.fillFieldMap()
@ -54,7 +54,7 @@ type scrapPage struct {
Summary field.String
CreateAt field.Int64
Domain field.String
Resource field.String
OutLink field.String
fieldMap map[string]field.Expr
}
@ -79,7 +79,7 @@ func (s *scrapPage) updateTableName(table string) *scrapPage {
s.Summary = field.NewString(table, "summary")
s.CreateAt = field.NewInt64(table, "create_at")
s.Domain = field.NewString(table, "domain")
s.Resource = field.NewString(table, "resource")
s.OutLink = field.NewString(table, "out_link")
s.fillFieldMap()
@ -115,7 +115,7 @@ func (s *scrapPage) fillFieldMap() {
s.fieldMap["summary"] = s.Summary
s.fieldMap["create_at"] = s.CreateAt
s.fieldMap["domain"] = s.Domain
s.fieldMap["resource"] = s.Resource
s.fieldMap["out_link"] = s.OutLink
}
func (s scrapPage) clone(db *gorm.DB) scrapPage {

@ -3,7 +3,9 @@ package admin
import (
"github.com/gin-gonic/gin"
"github.com/go-sonic/sonic/model/param"
"github.com/go-sonic/sonic/service"
"github.com/go-sonic/sonic/util/xerr"
)
type ScrapPageHandler struct {
@ -21,4 +23,16 @@ func (handler *ScrapPageHandler) QueryMd5List(ctx *gin.Context) (interface{}, er
}
func (handler *ScrapPageHandler) Create(ctx *gin.Context) (interface{}, error) {
scrapPageParam := param.ScrapPage{}
err := ctx.ShouldBindJSON(&scrapPageParam)
if err != nil {
return nil, xerr.BadParam.Wrap(err)
}
err = handler.ScrapService.Create(ctx, &scrapPageParam)
if err != nil {
return nil, err
}
return true, nil
}

@ -14,7 +14,7 @@ const TableNameAttachment = "attachment"
// Attachment mapped from table <attachment>
type Attachment struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
FileKey string `gorm:"column:file_key;type:varchar(2047);not null" json:"file_key"`

@ -14,7 +14,7 @@ const TableNameCategory = "category"
// Category mapped from table <category>
type Category struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Description string `gorm:"column:description;type:varchar(100);not null" json:"description"`

@ -14,7 +14,7 @@ const TableNameComment = "comment"
// Comment mapped from table <comment>
type Comment struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
Type consts.CommentType `gorm:"column:type;type:bigint;not null" json:"type"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`

@ -14,7 +14,7 @@ const TableNameJournal = "journal"
// Journal mapped from table <journal>
type Journal struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Content string `gorm:"column:content;type:text;not null" json:"content"`

@ -12,7 +12,7 @@ const TableNameLink = "link"
// Link mapped from table <link>
type Link struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Description string `gorm:"column:description;type:varchar(255);not null" json:"description"`

@ -14,7 +14,7 @@ const TableNameLog = "log"
// Log mapped from table <log>
type Log struct {
ID *int64 `gorm:"column:id;type:bigint;primaryKey" json:"id"`
ID int64 `gorm:"column:id;type:bigint;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Content string `gorm:"column:content;type:varchar(1023);not null" json:"content"`

@ -12,7 +12,7 @@ const TableNameMenu = "menu"
// Menu mapped from table <menu>
type Menu struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Icon string `gorm:"column:icon;type:varchar(50);not null" json:"icon"`

@ -14,7 +14,7 @@ const TableNameMeta = "meta"
// Meta mapped from table <meta>
type Meta struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
Type consts.MetaType `gorm:"column:type;type:bigint;not null" json:"type"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`

@ -14,7 +14,7 @@ const TableNameOption = "option"
// Option mapped from table <option>
type Option struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
OptionKey string `gorm:"column:option_key;type:varchar(100);not null" json:"option_key"`

@ -14,7 +14,7 @@ const TableNamePost = "post"
// Post mapped from table <post>
type Post struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
Type consts.PostType `gorm:"column:type;type:bigint;not null" json:"type"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`

@ -9,14 +9,14 @@ const TableNameScrapPage = "scrap_page"
// ScrapPage mapped from table <scrap_page>
type ScrapPage struct {
ID *int32 `gorm:"column:id;type:INTEGER" json:"id"`
Title *string `gorm:"column:title;type:varchar(128)" json:"title"`
Md5 *string `gorm:"column:md5;type:varchar(128)" json:"md5"`
URL *string `gorm:"column:url;type:text" json:"url"`
Content *string `gorm:"column:content;type:text" json:"content"`
Title string `gorm:"column:title;type:varchar(128);not null" json:"title"`
Md5 string `gorm:"column:md5;type:varchar(128);not null" json:"md5"`
URL string `gorm:"column:url;type:text;not null" json:"url"`
Content string `gorm:"column:content;type:text;not null" json:"content"`
Summary *string `gorm:"column:summary;type:text" json:"summary"`
CreateAt *int64 `gorm:"column:create_at;type:bigint" json:"create_at"`
Domain *string `gorm:"column:domain;type:varchar(128)" json:"domain"`
Resource *string `gorm:"column:resource;type:text" json:"resource"`
Domain string `gorm:"column:domain;type:varchar(128);not null" json:"domain"`
OutLink *string `gorm:"column:out_link;type:text" json:"out_link"`
}
// TableName ScrapPage's table name

@ -12,7 +12,7 @@ const TableNameTag = "tag"
// Tag mapped from table <tag>
type Tag struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"`

@ -12,7 +12,7 @@ const TableNameThemeSetting = "theme_setting"
// ThemeSetting mapped from table <theme_setting>
type ThemeSetting struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
SettingKey string `gorm:"column:setting_key;type:varchar(255);not null" json:"setting_key"`

@ -14,7 +14,7 @@ const TableNameUser = "user"
// User mapped from table <user>
type User struct {
ID *int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
ID int32 `gorm:"column:id;type:integer;primaryKey" json:"id"`
CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"create_time"`
UpdateTime *time.Time `gorm:"column:update_time;type:datetime" json:"update_time"`
Avatar string `gorm:"column:avatar;type:varchar(1023);not null" json:"avatar"`

@ -1,11 +1,11 @@
package param
type ScrapPage struct {
Title string `json:"title"`
Summary string `json:"summary"`
URL string `json:"url"`
OriginURL string `json:"origin_url"`
AddAt int64 `json:"add_at"`
Md5 string `json:"md_5"`
Content string `json:"content"`
Title string `json:"title"`
Summary *string `json:"summary"`
URL string `json:"url"`
OriginURL string `json:"origin_url"`
AddAt *int64 `json:"add_at"`
Md5 string `json:"md_5"`
Content string `json:"content"`
}

@ -306,3 +306,19 @@ create table if not exists application_password
last_activate_ip varchar(128) default '' not null
) ENGINE = INNODB
DEFAULT charset = utf8mb4;
create table scrap_page
(
id INTEGER
constraint scrap_page_pk
primary key,
title varchar(128) not null,
md5 varchar(128) not null,
url text not null,
content text not null,
summary text,
create_at bigint,
domain varchar(128) not null,
out_link text
);

@ -2,11 +2,13 @@ package impl
import (
"context"
"net/url"
"github.com/go-sonic/sonic/dal"
"github.com/go-sonic/sonic/model/entity"
"github.com/go-sonic/sonic/model/param"
"github.com/go-sonic/sonic/service"
"github.com/go-sonic/sonic/util/xerr"
)
type scrapServiceImpl struct{}
@ -24,26 +26,42 @@ func (impl *scrapServiceImpl) QueryMd5List(ctx context.Context) ([]string, error
md5List := make([]string, len(entities))
for _, v := range entities {
md5List = append(md5List, *v.Md5)
md5List = append(md5List, v.Md5)
}
return md5List, nil
}
func (impl *scrapServiceImpl) Create(ctx context.Context, pageParam *param.ScrapPage) error {
pageEntity, err := convertToModel(pageParam)
if err != nil {
return xerr.BadParam.Wrap(err)
}
scrapPageDAL := dal.GetQueryByCtx(ctx).ScrapPage
err = scrapPageDAL.WithContext(ctx).Create(pageEntity)
if err != nil {
return WrapDBErr(err)
}
return nil
}
func convertToModel(pageParam *param.ScrapPage) *entity.ScrapPage {
pageModel := &entity.ScrapPage{
func convertToModel(pageParam *param.ScrapPage) (*entity.ScrapPage, error) {
pageURL, err := url.Parse(pageParam.URL)
if err != nil {
return nil, err
}
return &entity.ScrapPage{
ID: nil,
Title: pageParam.Title,
Md5: pageParam.Md5,
URL: pageParam.URL,
Content: pageParam.Content,
Summary: pageParam.Summary,
CreateAt: ,
Domain: nil,
Resource: nil,
}
CreateAt: pageParam.AddAt,
Domain: pageURL.Hostname(),
OutLink: nil,
}, nil
}

@ -1,7 +1,12 @@
package service
import "context"
import (
"context"
"github.com/go-sonic/sonic/model/param"
)
type ScrapService interface {
QueryMd5List(ctx context.Context) ([]string, error)
Create(ctx context.Context, pageParam *param.ScrapPage) error
}

Loading…
Cancel
Save