Skip to content

Commit 604cc6d

Browse files
committed
fix service, request dto
1 parent d86b75e commit 604cc6d

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

models/patch_items_id_request.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
package models
22

33
type PatchItemsIdRequest struct {
4-
Body string `json:"body"`
5-
Coediting bool `json:"coediting"`
6-
GroupURLName string `json:"group_url_name"`
7-
Private bool `json:"private"`
8-
Tags []struct {
9-
Name string `json:"name"`
10-
Versions []string `json:"versions"`
11-
} `json:"tags"`
124
Title string `json:"title"`
5+
Body string `json:"body"`
136
}

services/qiita_service.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/uskey512/qiita-url-replace/clients"
9+
"github.com/uskey512/qiita-url-replace/models"
910
)
1011

1112
const getPerPage = 100
@@ -52,16 +53,24 @@ func ReplaceBodyUrlDomain(qc *clients.QiitaClient, r ReplaceSetting) {
5253
os.Exit(1)
5354
}
5455

55-
for i := 0; i < len(*items); i++ {
56+
for i := 0; i < len((*items).Response); i++ {
5657
itemCount++
57-
if strings.Index((*items)[i].Body, r.SrcDomain) != -1 {
58-
// ここに置換 & PATCH する実装を追加
58+
if strings.Index((*items).Response[i].Body, r.SrcDomain) != -1 {
59+
item := (*items).Response[i]
5960

60-
fmt.Println((*items)[i].URL)
61+
replacedBody := strings.Replace(item.Body, r.SrcDomain, r.DstDomain, -1)
62+
replacedPatchRequest := models.PatchItemsIdRequest{
63+
Title: item.Title,
64+
Body: replacedBody,
65+
}
66+
67+
qc.PatchItemById(item.ID, &replacedPatchRequest)
6168
replacedItemCount++
69+
70+
fmt.Printf("replace done. url : %s ", item.URL)
6271
}
6372
}
64-
if len(*items) != getPerPage {
73+
if len((*items).Response) != getPerPage {
6574
break
6675
}
6776
page++

0 commit comments

Comments
 (0)