Skip to content

Commit

Permalink
Fix setting site active to false
Browse files Browse the repository at this point in the history
  • Loading branch information
rupinr committed Nov 1, 2024
1 parent f82eaec commit dad59bd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
5 changes: 3 additions & 2 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func main() {

r.POST("/admin/sites/update", auth.AuthMiddleware(auth.ValidateAdminToken), func(c *gin.Context) {
var sites []dto.Site

if c.ShouldBindJSON(&sites) == nil {
repository.UpdateSites(sites)
} else {
Expand All @@ -78,7 +79,7 @@ func main() {
siteData := []dto.Site{}

for _, site := range sites {
siteData = append(siteData, dto.Site{Url: site.Url, Name: site.Name, Active: site.Active, Language: site.Language})
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 Expand Up @@ -117,7 +118,7 @@ func main() {
sites := repository.GetActiveSites()
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})
}
jsonData, _ := json.Marshal(siteData)
c.Data(http.StatusOK, "application/json", jsonData)
Expand Down
2 changes: 1 addition & 1 deletion datamodels/dto/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type TopicUpdate struct {
type Site struct {
Url string `json:"url" binding:"required"`
Name string `json:"name" binding:"required"`
Active bool `json:"active"`
Active *bool `json:"active"`
Language string `json:"language"`
}
type Sites struct {
Expand Down
13 changes: 6 additions & 7 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func CreateSite(siteData dto.Site) {
db().Where(entity.Site{Url: siteData.Url}).Assign(entity.Site{
Name: siteData.Name,
Language: siteData.Language,
Active: siteData.Active,
Active: *siteData.Active,
}).FirstOrCreate(&siteDb)
}

Expand All @@ -43,12 +43,11 @@ func UpdateSites(siteData []dto.Site) {
}
}
for _, v := range siteData {
db().Where(entity.Site{
Url: v.Url,
}).UpdateColumns(entity.Site{
Name: v.Name,
Active: v.Active,
Language: v.Language,

db().Model(&entity.Site{}).Where(&entity.Site{Url: v.Url}).UpdateColumns(map[string]interface{}{
"Name": v.Name,
"Active": *v.Active,
"Language": v.Language,
})
}
}
Expand Down

0 comments on commit dad59bd

Please sign in to comment.