Code cleanup
This commit is contained in:
parent
f76f9e42d6
commit
7bc82447cc
4 changed files with 186 additions and 186 deletions
|
@ -24,14 +24,14 @@ type application struct {
|
|||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
func (app *application) getCurrentNotebok_id(r *http.Request) int64 {
|
||||
func (app *application) getCurrentNotebookId(r *http.Request) int64 {
|
||||
session, _ := app.sessionStore.Get(r, "session")
|
||||
current_notebook_id := session.Values["current_notebook_id"]
|
||||
var notebook_id int64 = -1
|
||||
if current_notebook_id != nil {
|
||||
notebook_id, _ = strconv.ParseInt(current_notebook_id.(string), 10, 64)
|
||||
currentNotebookId := session.Values["current_notebook_id"]
|
||||
var notebookId int64 = -1
|
||||
if currentNotebookId != nil {
|
||||
notebookId, _ = strconv.ParseInt(currentNotebookId.(string), 10, 64)
|
||||
}
|
||||
return notebook_id
|
||||
return notebookId
|
||||
}
|
||||
|
||||
func (app *application) saveSessionValue(w http.ResponseWriter, r *http.Request, name string, value any) {
|
||||
|
@ -91,7 +91,7 @@ func (app *application) getCategoriesAsMap() map[string]string {
|
|||
func (app *application) getTypesAsOptions(r *http.Request) []funcs.WidgetOption {
|
||||
typeModel := &models.TypeModel{DB: app.db}
|
||||
criteria := map[string]any{
|
||||
"notebook_id": app.getCurrentNotebok_id(r),
|
||||
"notebook_id": app.getCurrentNotebookId(r),
|
||||
}
|
||||
return typeModel.FindAsOptions(criteria)
|
||||
}
|
||||
|
|
|
@ -15,24 +15,24 @@ import (
|
|||
)
|
||||
|
||||
type itemForm struct {
|
||||
Id int64 `form:"Id"`
|
||||
Type_id int64 `form:"Type_id"`
|
||||
Title string `form:"Title"`
|
||||
Summary string `form:"Summary"`
|
||||
Description string `form:"Description"`
|
||||
Notebooks []string `form:"Notebooks"`
|
||||
Tags string `form:"Tags"`
|
||||
On_dashboard int `form:"On_dashboard"`
|
||||
Categories []string `form:"Categories"`
|
||||
Type_icon string
|
||||
Type_title string
|
||||
Type_show_summary int
|
||||
Type_show_description int
|
||||
FieldsSection map[string][]models.Field
|
||||
FieldsValues map[int64]map[int]string
|
||||
Relations []models.ItemRelation
|
||||
Shares []models.ItemShare
|
||||
Validator validator.Validator `form:"-"`
|
||||
Id int64 `form:"Id"`
|
||||
TypeId int64 `form:"Type_id"`
|
||||
Title string `form:"Title"`
|
||||
Summary string `form:"Summary"`
|
||||
Description string `form:"Description"`
|
||||
Notebooks []string `form:"Notebooks"`
|
||||
Tags string `form:"Tags"`
|
||||
OnDashboard int `form:"On_dashboard"`
|
||||
Categories []string `form:"Categories"`
|
||||
TypeIcon string
|
||||
TypeTitle string
|
||||
TypeShowSummary int
|
||||
TypeShowDescription int
|
||||
FieldsSection map[string][]models.Field
|
||||
FieldsValues map[int64]map[int]string
|
||||
Relations []models.ItemRelation
|
||||
Shares []models.ItemShare
|
||||
Validator validator.Validator `form:"-"`
|
||||
}
|
||||
|
||||
type itemShareForm struct {
|
||||
|
@ -105,9 +105,9 @@ func (app *application) itemsRelationAdd(w http.ResponseWriter, r *http.Request)
|
|||
itemModel := models.NewItemModel(app.db)
|
||||
categoryModel := &models.CategoryModel{DB: app.db}
|
||||
var fullBuf = new(bytes.Buffer)
|
||||
related_item_id, _ := strconv.ParseInt(flow.Param(r.Context(), "related_item_id"), 10, 64)
|
||||
relatedItemId, _ := strconv.ParseInt(flow.Param(r.Context(), "related_item_id"), 10, 64)
|
||||
|
||||
relatedItem, _, _ := itemModel.One(related_item_id)
|
||||
relatedItem, _, _ := itemModel.One(relatedItemId)
|
||||
data["relatedItem"] = relatedItem
|
||||
data["categoriesMap"] = categoryModel.AllAsMap()
|
||||
|
||||
|
@ -199,11 +199,11 @@ func (app *application) items(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
params := r.URL.Query()
|
||||
|
||||
offset_str := r.URL.Query().Get("offset")
|
||||
if len(offset_str) == 0 {
|
||||
offset_str = "0"
|
||||
offsetStr := r.URL.Query().Get("offset")
|
||||
if len(offsetStr) == 0 {
|
||||
offsetStr = "0"
|
||||
}
|
||||
offset, _ := strconv.ParseInt(offset_str, 10, 64)
|
||||
offset, _ := strconv.ParseInt(offsetStr, 10, 64)
|
||||
data["offset"] = offset
|
||||
|
||||
switch r.Method {
|
||||
|
@ -217,9 +217,9 @@ func (app *application) items(w http.ResponseWriter, r *http.Request) {
|
|||
criteriaParam := r.URL.Query()["criteriaName"]
|
||||
if len(criteriaParam) > 0 {
|
||||
if criteriaParam[0] == criteriaName {
|
||||
criteria_values := app.getSessionValue(w, r, criteriaName)
|
||||
if criteria_values != nil {
|
||||
criteria = criteria_values.(map[string]any)
|
||||
criteriaValues := app.getSessionValue(w, r, criteriaName)
|
||||
if criteriaValues != nil {
|
||||
criteria = criteriaValues.(map[string]any)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -267,11 +267,11 @@ func (app *application) items(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
category_id, _ := strconv.ParseInt(r.PostForm.Get("category_id"), 10, 64)
|
||||
categoryId, _ := strconv.ParseInt(r.PostForm.Get("category_id"), 10, 64)
|
||||
criteria := map[string]any{
|
||||
"Title": r.PostForm.Get("Title"),
|
||||
"Tags": r.PostForm.Get("Tags"),
|
||||
"category_id": category_id,
|
||||
"category_id": categoryId,
|
||||
}
|
||||
|
||||
criteriaName := "itemsSearch"
|
||||
|
@ -300,14 +300,14 @@ func (app *application) items(w http.ResponseWriter, r *http.Request) {
|
|||
func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
||||
data := app.newTemplateData(r)
|
||||
|
||||
type_id, _ := strconv.ParseInt(flow.Param(r.Context(), "type_id"), 10, 64)
|
||||
typeId, _ := strconv.ParseInt(flow.Param(r.Context(), "type_id"), 10, 64)
|
||||
|
||||
itemModel := models.NewItemModel(app.db)
|
||||
typeModel := &models.TypeModel{DB: app.db}
|
||||
aType, _, _ := typeModel.One(type_id)
|
||||
aType, _, _ := typeModel.One(typeId)
|
||||
fieldModel := &models.FieldModel{DB: app.db}
|
||||
|
||||
fields, _, _ := fieldModel.ByTypeOnList(type_id)
|
||||
fields, _, _ := fieldModel.ByTypeOnList(typeId)
|
||||
data["type"] = &aType
|
||||
data["Fields"] = fields
|
||||
|
||||
|
@ -316,11 +316,11 @@ func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
params := r.URL.Query()
|
||||
|
||||
offset_str := params.Get("offset")
|
||||
if len(offset_str) == 0 {
|
||||
offset_str = "0"
|
||||
offsetStr := params.Get("offset")
|
||||
if len(offsetStr) == 0 {
|
||||
offsetStr = "0"
|
||||
}
|
||||
offset, _ := strconv.ParseInt(offset_str, 10, 64)
|
||||
offset, _ := strconv.ParseInt(offsetStr, 10, 64)
|
||||
data["offset"] = offset
|
||||
|
||||
var fullBuf = new(bytes.Buffer)
|
||||
|
@ -330,22 +330,22 @@ func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
criteria := make(map[string]any)
|
||||
|
||||
criteriaName := fmt.Sprintf("itemsTypeSearch_%d", type_id)
|
||||
criteriaName := fmt.Sprintf("itemsTypeSearch_%d", typeId)
|
||||
data["criteriaName"] = criteriaName
|
||||
|
||||
criteriaParam := r.URL.Query()["criteriaName"]
|
||||
if len(criteriaParam) > 0 {
|
||||
if criteriaParam[0] == criteriaName {
|
||||
criteria_values := app.getSessionValue(w, r, criteriaName)
|
||||
if criteria_values != nil {
|
||||
criteria = criteria_values.(map[string]any)
|
||||
criteriaValues := app.getSessionValue(w, r, criteriaName)
|
||||
if criteriaValues != nil {
|
||||
criteria = criteriaValues.(map[string]any)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
app.removeSessionValue(w, r, criteriaName)
|
||||
}
|
||||
|
||||
criteria["type_id"] = type_id
|
||||
criteria["type_id"] = typeId
|
||||
criteria["notebook_id"] = app.getCurrentNotebok_id(r)
|
||||
|
||||
rows, _, _ := itemModel.Find(criteria, offset)
|
||||
|
@ -389,15 +389,15 @@ func (app *application) itemsType(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
category_id, _ := strconv.ParseInt(r.PostForm.Get("category_id"), 10, 64)
|
||||
categoryId, _ := strconv.ParseInt(r.PostForm.Get("category_id"), 10, 64)
|
||||
criteria := map[string]any{
|
||||
"Title": r.PostForm.Get("Title"),
|
||||
"Tags": r.PostForm.Get("Tags"),
|
||||
"category_id": category_id,
|
||||
"type_id": type_id,
|
||||
"category_id": categoryId,
|
||||
"type_id": typeId,
|
||||
}
|
||||
|
||||
criteriaName := fmt.Sprintf("itemsTypeSearch_%d", type_id)
|
||||
criteriaName := fmt.Sprintf("itemsTypeSearch_%d", typeId)
|
||||
data["criteriaName"] = criteriaName
|
||||
app.saveSessionValue(w, r, criteriaName, criteria)
|
||||
|
||||
|
@ -422,13 +422,13 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
|||
categoryModel := &models.CategoryModel{DB: app.db}
|
||||
typeModel := &models.TypeModel{DB: app.db}
|
||||
|
||||
type_id, _ := strconv.ParseInt(flow.Param(r.Context(), "type_id"), 10, 64)
|
||||
typeId, _ := strconv.ParseInt(flow.Param(r.Context(), "type_id"), 10, 64)
|
||||
|
||||
aType, _, _ := typeModel.One(type_id)
|
||||
aType, _, _ := typeModel.One(typeId)
|
||||
|
||||
data := app.newTemplateData(r)
|
||||
data["type"] = aType
|
||||
data["formAction"] = fmt.Sprint("/item/create/", type_id)
|
||||
data["formAction"] = fmt.Sprint("/item/create/", typeId)
|
||||
data["formTarget"] = "#page-content"
|
||||
data["categories"] = categoryModel.AllAsOptions()
|
||||
data["categoriesMap"] = categoryModel.AllAsMap()
|
||||
|
@ -444,26 +444,26 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
|||
var fullBuf = new(bytes.Buffer)
|
||||
var categories []string
|
||||
|
||||
fieldsSection, _, _ := fieldModel.ByTypeSection(int64(type_id))
|
||||
fieldsSection, _, _ := fieldModel.ByTypeSection(typeId)
|
||||
fieldsValues := make(map[int64]map[int]string)
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
notebooks := []string{strconv.FormatInt(app.getCurrentNotebok_id(r), 10)}
|
||||
|
||||
data["item"] = itemForm{
|
||||
Title: "",
|
||||
Type_id: type_id,
|
||||
Type_show_summary: aType.Show_summary,
|
||||
Type_show_description: aType.Show_description,
|
||||
Summary: "",
|
||||
Description: "",
|
||||
Tags: "",
|
||||
FieldsSection: fieldsSection,
|
||||
FieldsValues: fieldsValues,
|
||||
Categories: categories,
|
||||
Notebooks: notebooks,
|
||||
Relations: nil,
|
||||
Shares: nil,
|
||||
Title: "",
|
||||
TypeId: typeId,
|
||||
TypeShowSummary: aType.Show_summary,
|
||||
TypeShowDescription: aType.Show_description,
|
||||
Summary: "",
|
||||
Description: "",
|
||||
Tags: "",
|
||||
FieldsSection: fieldsSection,
|
||||
FieldsValues: fieldsValues,
|
||||
Categories: categories,
|
||||
Notebooks: notebooks,
|
||||
Relations: nil,
|
||||
Shares: nil,
|
||||
}
|
||||
|
||||
if r.Header.Get("HX-Request") == "true" {
|
||||
|
@ -489,7 +489,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
case http.MethodPost:
|
||||
var itemFromForm itemForm
|
||||
var item_id int64
|
||||
var itemId int64
|
||||
|
||||
err := request.DecodePostForm(r, &itemFromForm)
|
||||
if err != nil {
|
||||
|
@ -501,19 +501,19 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
item := &models.Item{
|
||||
Type_id: itemFromForm.Type_id,
|
||||
TypeId: itemFromForm.TypeId,
|
||||
Title: itemFromForm.Title,
|
||||
Summary: itemFromForm.Summary,
|
||||
Description: itemFromForm.Description,
|
||||
Tags: itemFromForm.Tags,
|
||||
On_dashboard: itemFromForm.On_dashboard,
|
||||
On_dashboard: itemFromForm.OnDashboard,
|
||||
}
|
||||
|
||||
notebooks_str := strings.Join(itemFromForm.Notebooks, "|")
|
||||
if len(notebooks_str) > 0 {
|
||||
notebooks_str = "|" + notebooks_str + "|"
|
||||
notebooksStr := strings.Join(itemFromForm.Notebooks, "|")
|
||||
if len(notebooksStr) > 0 {
|
||||
notebooksStr = "|" + notebooksStr + "|"
|
||||
}
|
||||
item.Notebooks = notebooks_str
|
||||
item.Notebooks = notebooksStr
|
||||
|
||||
categories_str := strings.Join(itemFromForm.Categories, "|")
|
||||
if len(categories_str) > 0 {
|
||||
|
@ -521,8 +521,8 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
item.Categories = categories_str
|
||||
|
||||
item_id, err = itemModel.Create(item)
|
||||
item.Id = item_id
|
||||
itemId, err = itemModel.Create(item)
|
||||
item.Id = itemId
|
||||
if err != nil {
|
||||
app.badRequest(w, err)
|
||||
return
|
||||
|
@ -555,7 +555,7 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
item.Type_title = aType.Title
|
||||
fields, _, _ := fieldModel.ByType(int64(type_id))
|
||||
fields, _, _ := fieldModel.ByType(type_id)
|
||||
itemModel.SaveKeywords(item, &fields, fieldsValues)
|
||||
|
||||
data["formAction"] = fmt.Sprint("/item/update/", item_id)
|
||||
|
@ -567,22 +567,22 @@ func (app *application) itemCreate(w http.ResponseWriter, r *http.Request) {
|
|||
shares, _, _ := itemModel.GetShares(item.Id)
|
||||
|
||||
data["item"] = itemForm{
|
||||
Id: item_id,
|
||||
Type_id: type_id,
|
||||
Type_show_summary: aType.Show_summary,
|
||||
Type_show_description: aType.Show_description,
|
||||
Title: item.Title,
|
||||
Summary: item.Summary,
|
||||
Description: item.Description,
|
||||
Tags: item.Tags,
|
||||
Type_icon: item.Type_icon,
|
||||
Type_title: item.Type_title,
|
||||
FieldsSection: fieldsSection,
|
||||
FieldsValues: fieldsValues,
|
||||
Notebooks: notebooks,
|
||||
Categories: categories,
|
||||
Relations: relations,
|
||||
Shares: shares,
|
||||
Id: item_id,
|
||||
TypeId: type_id,
|
||||
TypeShowSummary: aType.Show_summary,
|
||||
TypeShowDescription: aType.Show_description,
|
||||
Title: item.Title,
|
||||
Summary: item.Summary,
|
||||
Description: item.Description,
|
||||
Tags: item.Tags,
|
||||
TypeIcon: item.Type_icon,
|
||||
TypeTitle: item.Type_title,
|
||||
FieldsSection: fieldsSection,
|
||||
FieldsValues: fieldsValues,
|
||||
Notebooks: notebooks,
|
||||
Categories: categories,
|
||||
Relations: relations,
|
||||
Shares: shares,
|
||||
}
|
||||
|
||||
err = response.HXFragment(fullBuf, []string{"items/form.tmpl", "items/fields.tmpl", "items/relations.tmpl"}, "page:content", data)
|
||||
|
@ -713,23 +713,23 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
|||
shares, _, _ := itemModel.GetShares(item.Id)
|
||||
|
||||
data["item"] = itemForm{
|
||||
Id: item.Id,
|
||||
Type_id: item.Type_id,
|
||||
Type_show_summary: item.Type_show_summary,
|
||||
Type_show_description: item.Type_show_description,
|
||||
Title: item.Title,
|
||||
Summary: item.Summary,
|
||||
Description: item.Description,
|
||||
Tags: item.Tags,
|
||||
On_dashboard: item.On_dashboard,
|
||||
Type_icon: item.Type_icon,
|
||||
Type_title: item.Type_title,
|
||||
FieldsSection: fieldsSection,
|
||||
FieldsValues: fieldsValues,
|
||||
Categories: categories,
|
||||
Notebooks: notebooks,
|
||||
Relations: relations,
|
||||
Shares: shares,
|
||||
Id: item.Id,
|
||||
TypeId: item.Type_id,
|
||||
TypeShowSummary: item.Type_show_summary,
|
||||
TypeShowDescription: item.Type_show_description,
|
||||
Title: item.Title,
|
||||
Summary: item.Summary,
|
||||
Description: item.Description,
|
||||
Tags: item.Tags,
|
||||
OnDashboard: item.On_dashboard,
|
||||
TypeIcon: item.Type_icon,
|
||||
TypeTitle: item.Type_title,
|
||||
FieldsSection: fieldsSection,
|
||||
FieldsValues: fieldsValues,
|
||||
Categories: categories,
|
||||
Notebooks: notebooks,
|
||||
Relations: relations,
|
||||
Shares: shares,
|
||||
}
|
||||
|
||||
data["categories"] = categoryModel.AllAsOptions()
|
||||
|
@ -774,11 +774,11 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
item.Title = itemFromForm.Title
|
||||
item.Type_id = itemFromForm.Type_id
|
||||
item.Type_id = itemFromForm.TypeId
|
||||
item.Summary = itemFromForm.Summary
|
||||
item.Description = itemFromForm.Description
|
||||
item.Tags = itemFromForm.Tags
|
||||
item.On_dashboard = itemFromForm.On_dashboard
|
||||
item.On_dashboard = itemFromForm.OnDashboard
|
||||
|
||||
notebooks_str := strings.Join(itemFromForm.Notebooks, "|")
|
||||
if len(notebooks_str) > 0 {
|
||||
|
@ -854,11 +854,11 @@ func (app *application) itemUpdate(w http.ResponseWriter, r *http.Request) {
|
|||
shares, _, _ := itemModel.GetShares(item.Id)
|
||||
|
||||
data["item"] = itemForm{
|
||||
Title: item.Title,
|
||||
Type_icon: item.Type_icon,
|
||||
Type_title: item.Type_title,
|
||||
Relations: relations,
|
||||
Shares: shares,
|
||||
Title: item.Title,
|
||||
TypeIcon: item.Type_icon,
|
||||
TypeTitle: item.Type_title,
|
||||
Relations: relations,
|
||||
Shares: shares,
|
||||
}
|
||||
|
||||
data["FieldsSection"] = fieldsSection
|
||||
|
|
124
models/item.go
124
models/item.go
|
@ -11,39 +11,39 @@ import (
|
|||
)
|
||||
|
||||
type Item struct {
|
||||
Id int64 `db:"id"`
|
||||
Title string `db:"title"`
|
||||
Summary string `db:"summary"`
|
||||
Summary_rendered string `db:"summary_rendered"`
|
||||
Description string `db:"description"`
|
||||
Description_rendered string `db:"description_rendered"`
|
||||
Active int `db:"active"`
|
||||
Tags string `db:"tags"`
|
||||
Type_id int64 `db:"type_id"`
|
||||
Categories string `db:"categories"`
|
||||
Notebooks string `db:"notebooks"`
|
||||
Crypted int `db:"crypted"`
|
||||
Hidden int `db:"hidden"`
|
||||
On_dashboard int `db:"on_dashboard"`
|
||||
On_dashboard_position int `db:"on_dashboard_position"`
|
||||
Type_title string `db:"type_title"`
|
||||
Type_icon string `db:"type_icon"`
|
||||
Type_show_summary int `db:"type_show_summary"`
|
||||
Type_show_description int `db:"type_show_description"`
|
||||
FieldsOnList []Field
|
||||
FieldsValues []FieldValue
|
||||
FieldsValuesMap map[int64]map[int]string
|
||||
Id int64 `db:"id"`
|
||||
Title string `db:"title"`
|
||||
Summary string `db:"summary"`
|
||||
SummaryRendered string `db:"summary_rendered"`
|
||||
Description string `db:"description"`
|
||||
DescriptionRendered string `db:"description_rendered"`
|
||||
Active int `db:"active"`
|
||||
Tags string `db:"tags"`
|
||||
TypeId int64 `db:"type_id"`
|
||||
Categories string `db:"categories"`
|
||||
Notebooks string `db:"notebooks"`
|
||||
Crypted int `db:"crypted"`
|
||||
Hidden int `db:"hidden"`
|
||||
OnDashboard int `db:"on_dashboard"`
|
||||
OnDashboardPosition int `db:"on_dashboard_position"`
|
||||
TypeTitle string `db:"type_title"`
|
||||
TypeIcon string `db:"type_icon"`
|
||||
TypeShowSummary int `db:"type_show_summary"`
|
||||
TypeShowDescription int `db:"type_show_description"`
|
||||
FieldsOnList []Field
|
||||
FieldsValues []FieldValue
|
||||
FieldsValuesMap map[int64]map[int]string
|
||||
}
|
||||
|
||||
type ItemRelation struct {
|
||||
Item_id int64 `db:"item_id"`
|
||||
Related_item_id int64 `db:"related_item_id"`
|
||||
Relation_type string `db:"relation_type"`
|
||||
Title string `db:"title"`
|
||||
Categories string `db:"categories"`
|
||||
Tags string `db:"tags"`
|
||||
Type_title string `db:"type_title"`
|
||||
Type_icon string `db:"type_icon"`
|
||||
ItemId int64 `db:"item_id"`
|
||||
RelatedItemId int64 `db:"related_item_id"`
|
||||
RelationType string `db:"relation_type"`
|
||||
Title string `db:"title"`
|
||||
Categories string `db:"categories"`
|
||||
Tags string `db:"tags"`
|
||||
TypeTitle string `db:"type_title"`
|
||||
TypeIcon string `db:"type_icon"`
|
||||
}
|
||||
|
||||
type ItemModel struct {
|
||||
|
@ -103,8 +103,8 @@ func (model *ItemModel) Search(searchText string, criteria map[string]any) ([]It
|
|||
var conditions []string
|
||||
var cond string
|
||||
|
||||
var conditions_criteria []string
|
||||
var cond_criteria string
|
||||
var conditionsCriteria []string
|
||||
var condCriteria string
|
||||
|
||||
query := `SELECT DISTINCT bmi.*, bmt.title AS type_title, bmt.icon AS type_icon FROM bm_item bmi
|
||||
INNER JOIN bm_type bmt ON bmi.type_id=bmt.id
|
||||
|
@ -118,7 +118,7 @@ func (model *ItemModel) Search(searchText string, criteria map[string]any) ([]It
|
|||
if valint > 0 {
|
||||
valstr := "|" + strconv.FormatInt(valint, 10) + "|"
|
||||
params = append(params, valstr)
|
||||
conditions_criteria = append(conditions_criteria, "INSTR(bmi.notebooks, ?) > 0 ")
|
||||
conditionsCriteria = append(conditionsCriteria, "INSTR(bmi.notebooks, ?) > 0 ")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -144,27 +144,27 @@ func (model *ItemModel) Search(searchText string, criteria map[string]any) ([]It
|
|||
cond = cond + condition
|
||||
}
|
||||
|
||||
for _, condition := range conditions_criteria {
|
||||
if len(cond_criteria) > 0 {
|
||||
cond_criteria = cond_criteria + " AND "
|
||||
for _, condition := range conditionsCriteria {
|
||||
if len(condCriteria) > 0 {
|
||||
condCriteria = condCriteria + " AND "
|
||||
}
|
||||
cond_criteria = cond_criteria + condition
|
||||
condCriteria = condCriteria + condition
|
||||
}
|
||||
|
||||
len_cond := len(cond)
|
||||
len_cond_criteria := len(cond_criteria)
|
||||
lenCond := len(cond)
|
||||
lenCondCriteria := len(condCriteria)
|
||||
|
||||
if len_cond_criteria > 0 || len_cond > 0 {
|
||||
if lenCondCriteria > 0 || lenCond > 0 {
|
||||
query = query + "WHERE "
|
||||
}
|
||||
|
||||
if len_cond_criteria > 0 {
|
||||
query = query + cond_criteria
|
||||
if len_cond > 0 {
|
||||
if lenCondCriteria > 0 {
|
||||
query = query + condCriteria
|
||||
if lenCond > 0 {
|
||||
query = query + " AND (" + cond + ")"
|
||||
}
|
||||
} else {
|
||||
if len_cond > 0 {
|
||||
if lenCond > 0 {
|
||||
query = query + " (" + cond + ")"
|
||||
}
|
||||
}
|
||||
|
@ -273,11 +273,11 @@ func (model *ItemModel) Create(Item *Item) (int64, error) {
|
|||
|
||||
var bufSummary bytes.Buffer
|
||||
markdown.Convert([]byte(Item.Summary), &bufSummary)
|
||||
Item.Summary_rendered = bufSummary.String()
|
||||
Item.SummaryRendered = bufSummary.String()
|
||||
|
||||
var bufDescription bytes.Buffer
|
||||
markdown.Convert([]byte(Item.Description), &bufDescription)
|
||||
Item.Description_rendered = bufDescription.String()
|
||||
Item.DescriptionRendered = bufDescription.String()
|
||||
|
||||
query := `INSERT INTO bm_item (type_id, title, summary, summary_rendered, description, description_rendered, on_dashboard, tags, notebooks, categories)
|
||||
VALUES (:type_id, :title, :summary, :summary_rendered, :description, :description_rendered, :on_dashboard, :tags, :notebooks, :categories)`
|
||||
|
@ -303,11 +303,11 @@ func (model *ItemModel) Update(Item *Item) error {
|
|||
|
||||
var bufSummary bytes.Buffer
|
||||
markdown.Convert([]byte(Item.Summary), &bufSummary)
|
||||
Item.Summary_rendered = bufSummary.String()
|
||||
Item.SummaryRendered = bufSummary.String()
|
||||
|
||||
var bufDescription bytes.Buffer
|
||||
markdown.Convert([]byte(Item.Description), &bufDescription)
|
||||
Item.Description_rendered = bufDescription.String()
|
||||
Item.DescriptionRendered = bufDescription.String()
|
||||
|
||||
query := `UPDATE bm_item SET title=:title, type_id=:type_id, summary=:summary, summary_rendered=:summary_rendered,
|
||||
description=:description, description_rendered=:description_rendered, tags=:tags, on_dashboard=:on_dashboard,
|
||||
|
@ -354,17 +354,17 @@ func (model *ItemModel) SaveKeywords(Item *Item, fields *[]Field, fieldsValues m
|
|||
defer cancel()
|
||||
|
||||
var keywords []string
|
||||
keywords = append(keywords, Item.Type_title)
|
||||
keywords = append(keywords, Item.TypeTitle)
|
||||
|
||||
var categories_int []int64
|
||||
categories_str := strings.Split(strings.Trim(Item.Categories, "|"), "|")
|
||||
for _, category_str := range categories_str {
|
||||
category_int, _ := strconv.ParseInt(category_str, 10, 64)
|
||||
categories_int = append(categories_int, category_int)
|
||||
var categoriesInt []int64
|
||||
categoriesStr := strings.Split(strings.Trim(Item.Categories, "|"), "|")
|
||||
for _, categoryStr := range categoriesStr {
|
||||
categoryInt, _ := strconv.ParseInt(categoryStr, 10, 64)
|
||||
categoriesInt = append(categoriesInt, categoryInt)
|
||||
}
|
||||
|
||||
categoryModel := &CategoryModel{DB: model.DB}
|
||||
categories, _, _ := categoryModel.Find(categories_int)
|
||||
categories, _, _ := categoryModel.Find(categoriesInt)
|
||||
for _, category := range categories {
|
||||
keywords = append(keywords, category.Name)
|
||||
}
|
||||
|
@ -405,12 +405,12 @@ func (model *ItemModel) SaveKeywords(Item *Item, fields *[]Field, fieldsValues m
|
|||
return nil
|
||||
}
|
||||
|
||||
func (model *ItemModel) AddRelation(id int64, related_id int64, relation_type string) error {
|
||||
func (model *ItemModel) AddRelation(id int64, relatedId int64, relationType string) error {
|
||||
ctx, cancel := database.GetContext()
|
||||
defer cancel()
|
||||
|
||||
query := `INSERT INTO bm_item_relations (item_id, related_item_id, relation_type) VALUES($1, $2, $3)`
|
||||
_, err := model.DB.ExecContext(ctx, query, id, related_id, relation_type)
|
||||
query := `INSERT INTO bm_item_relations (itemId, relatedItemId, relationType) VALUES($1, $2, $3)`
|
||||
_, err := model.DB.ExecContext(ctx, query, id, relatedId, relationType)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -418,12 +418,12 @@ func (model *ItemModel) AddRelation(id int64, related_id int64, relation_type st
|
|||
return nil
|
||||
}
|
||||
|
||||
func (model *ItemModel) UpdateRelation(id int64, related_id int64, relation_type string) error {
|
||||
func (model *ItemModel) UpdateRelation(id int64, relatedId int64, relationType string) error {
|
||||
ctx, cancel := database.GetContext()
|
||||
defer cancel()
|
||||
|
||||
query := `UPDATE bm_item_relations SET relation_type=$1 WHERE item_id=$2 AND related_item_id=$3`
|
||||
_, err := model.DB.ExecContext(ctx, query, relation_type, id, related_id)
|
||||
_, err := model.DB.ExecContext(ctx, query, relationType, id, relatedId)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -431,12 +431,12 @@ func (model *ItemModel) UpdateRelation(id int64, related_id int64, relation_type
|
|||
return nil
|
||||
}
|
||||
|
||||
func (model *ItemModel) DeleteRelation(id int64, related_id int64) error {
|
||||
func (model *ItemModel) DeleteRelation(id int64, relatedId int64) error {
|
||||
ctx, cancel := database.GetContext()
|
||||
defer cancel()
|
||||
|
||||
query := `DELETE FROM bm_item_relations WHERE item_id=$1 AND related_item_id=$2`
|
||||
_, err := model.DB.ExecContext(ctx, query, id, related_id)
|
||||
_, err := model.DB.ExecContext(ctx, query, id, relatedId)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -13,9 +13,9 @@ type QuicknoteModel struct {
|
|||
}
|
||||
|
||||
type Quicknote struct {
|
||||
Id int64 `db:"id"`
|
||||
Note string `db:"note"`
|
||||
Note_rendered string `db:"note_rendered"`
|
||||
Id int64 `db:"id"`
|
||||
Note string `db:"note"`
|
||||
NoteRendered string `db:"note_rendered"`
|
||||
}
|
||||
|
||||
func (model *QuicknoteModel) One(id int64) (*Quicknote, bool, error) {
|
||||
|
@ -133,7 +133,7 @@ func (model *QuicknoteModel) Create(Quicknote *Quicknote) (int64, error) {
|
|||
|
||||
var bufNote bytes.Buffer
|
||||
markdown.Convert([]byte(Quicknote.Note), &bufNote)
|
||||
Quicknote.Note_rendered = bufNote.String()
|
||||
Quicknote.NoteRendered = bufNote.String()
|
||||
|
||||
query := `INSERT INTO bm_quicknote (note, note_rendered) VALUES (:note, :note_rendered)`
|
||||
|
||||
|
@ -158,7 +158,7 @@ func (model *QuicknoteModel) Update(Quicknote *Quicknote) error {
|
|||
|
||||
var bufNote bytes.Buffer
|
||||
markdown.Convert([]byte(Quicknote.Note), &bufNote)
|
||||
Quicknote.Note_rendered = bufNote.String()
|
||||
Quicknote.NoteRendered = bufNote.String()
|
||||
|
||||
query := `UPDATE bm_quicknote SET note=:note, note_rendered=:note_rendered WHERE id = :id`
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue