Skip to content

Commit

Permalink
Add language param
Browse files Browse the repository at this point in the history
  • Loading branch information
rupinr committed Oct 28, 2024
1 parent 2b41543 commit 85fd34e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func main() {
siteData := []dto.Site{}

for _, site := range sites {
siteData = append(siteData, dto.Site{Url: site.Url, Name: site.Name, Active: site.Active})
siteData = append(siteData, dto.Site{Url: site.Url, Name: site.Name, Active: site.Active, Language: site.Language})
}
jsonData, _ := json.Marshal(siteData)
c.Data(http.StatusOK, "application/json", jsonData)
Expand Down
7 changes: 4 additions & 3 deletions datamodels/dto/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ type TopicUpdate struct {
}

type Site struct {
Url string `json:"url" binding:"required"`
Name string `json:"name" binding:"required"`
Active bool `json:"active"`
Url string `json:"url" binding:"required"`
Name string `json:"name" binding:"required"`
Active bool `json:"active"`
Language string `json:"language"`
}
type Sites struct {
Sites []Site `json:"sites,omitempty"`
Expand Down
7 changes: 4 additions & 3 deletions datamodels/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ type Topic struct {
}
type Site struct {
gorm.Model
Url string `gorm:"index:idx_url"`
Name string
Active bool `gorm:"index:"`
Url string `gorm:"index:idx_url"`
Name string
Language string
Active bool `gorm:"index:"`
}
type User struct {
gorm.Model
Expand Down
9 changes: 6 additions & 3 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ func UpdateTopic(name string, visibility bool) error {
func CreateSite(siteData dto.Site) {
var siteDb entity.Site
db().Where(entity.Site{Url: siteData.Url}).Assign(entity.Site{
Name: siteData.Name,
Name: siteData.Name,
Language: siteData.Language,
Active: siteData.Active,
}).FirstOrCreate(&siteDb)
}

Expand All @@ -68,8 +70,9 @@ func UpdateSites(siteData []dto.Site) {
db().Where(entity.Site{
Url: v.Url,
}).UpdateColumns(entity.Site{
Name: v.Name,
Active: v.Active,
Name: v.Name,
Active: v.Active,
Language: v.Language,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions tasks/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func FetchNewsTask() {

for _, site := range sites {
params.Set("domainurl", site.Url)
params.Set("language", site.Language)
apiRequest.RawQuery = params.Encode()

logger.Log.Debug("Fetching", "url", apiRequest.String())
Expand Down

0 comments on commit 85fd34e

Please sign in to comment.