Skip to content

Commit 834254b

Browse files
committed
feat: remove blacklist api
1 parent fdcf7f4 commit 834254b

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

db/db.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,4 +756,7 @@ func (c *client) AddTorrent2Blacklist(hash, name string, mediaId int) error {
756756

757757
func (c *client) GetTorrentBlacklist() (ent.Blacklists, error) {
758758
return c.ent.Blacklist.Query().Where(blacklist.TypeEQ(blacklist.TypeTorrent)).All(context.Background())
759+
}
760+
func (c *client) DeleteTorrentBlacklist(id int) error {
761+
return c.ent.Blacklist.DeleteOneID(id).Exec(context.Background())
759762
}

db/interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type Database interface {
4242

4343
AddTorrent2Blacklist(hash, name string, mediaId int) error
4444
GetTorrentBlacklist() (ent.Blacklists, error)
45+
DeleteTorrentBlacklist(id int) error
4546
}
4647

4748
type Settings interface {

server/activity.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ func (s *Server) GetAllBlacklistItems(c *gin.Context) (interface{}, error) {
135135
}
136136
return list, nil
137137
}
138+
func (s *Server) RemoveBlacklistItem(c *gin.Context) (interface{}, error) {
139+
id := c.Param("id")
140+
if id == "" {
141+
return nil, fmt.Errorf("id is empty")
142+
}
143+
idInt, err := strconv.Atoi(id)
144+
if err!= nil {
145+
return nil, fmt.Errorf("id is not int: %v", id)
146+
}
147+
if err := s.db.DeleteTorrentBlacklist(idInt); err!= nil {
148+
return nil, errors.Wrap(err, "db")
149+
}
150+
return nil, nil
151+
}
138152

139153
func (s *Server) GetMediaDownloadHistory(c *gin.Context) (interface{}, error) {
140154
var ids = c.Param("id")

server/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (s *Server) Serve() error {
8787
activity.POST("/delete", HttpHandler(s.RemoveActivity))
8888
activity.GET("/media/:id", HttpHandler(s.GetMediaDownloadHistory))
8989
activity.GET("/blacklist", HttpHandler(s.GetAllBlacklistItems))
90+
activity.DELETE("/blacklist/:id", HttpHandler(s.RemoveBlacklistItem))
9091
//activity.GET("/torrents", HttpHandler(s.GetAllTorrents))
9192
}
9293

0 commit comments

Comments
 (0)