feat(irc): improve list view (#466)

* feat(irc): add irc status examples

* feat(irc): add dropdown menu to list

* feat(irc): update heroicons and add expand button

* feat(irc): update heroicons and add expand button
This commit is contained in:
ze0s 2022-09-22 16:39:05 +02:00 committed by GitHub
parent f5faf066a9
commit 300418b9f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 478 additions and 258 deletions

View file

@ -19,6 +19,7 @@ type ircService interface {
StoreNetwork(ctx context.Context, network *domain.IrcNetwork) error
UpdateNetwork(ctx context.Context, network *domain.IrcNetwork) error
StoreChannel(networkID int64, channel *domain.IrcChannel) error
RestartNetwork(ctx context.Context, id int64) error
}
type ircHandler struct {
@ -38,6 +39,7 @@ func (h ircHandler) Routes(r chi.Router) {
r.Post("/", h.storeNetwork)
r.Put("/network/{networkID}", h.updateNetwork)
r.Post("/network/{networkID}/channel", h.storeChannel)
r.Get("/network/{networkID}/restart", h.restartNetwork)
r.Get("/network/{networkID}", h.getNetworkByID)
r.Delete("/network/{networkID}", h.deleteNetwork)
}
@ -69,6 +71,21 @@ func (h ircHandler) getNetworkByID(w http.ResponseWriter, r *http.Request) {
h.encoder.StatusResponse(ctx, w, network, http.StatusOK)
}
func (h ircHandler) restartNetwork(w http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
networkID = chi.URLParam(r, "networkID")
)
id, _ := strconv.Atoi(networkID)
if err := h.service.RestartNetwork(ctx, int64(id)); err != nil {
h.encoder.Error(w, err)
}
h.encoder.NoContent(w)
}
func (h ircHandler) storeNetwork(w http.ResponseWriter, r *http.Request) {
var data domain.IrcNetwork

View file

@ -20,6 +20,7 @@ type Service interface {
StartHandlers()
StopHandlers()
StopNetwork(key handlerKey) error
RestartNetwork(ctx context.Context, id int64) error
ListNetworks(ctx context.Context) ([]domain.IrcNetwork, error)
GetNetworksWithHealth(ctx context.Context) ([]domain.IrcNetworkWithHealth, error)
GetNetworkByID(ctx context.Context, id int64) (*domain.IrcNetwork, error)
@ -279,6 +280,15 @@ func (s *service) checkIfNetworkRestartNeeded(network *domain.IrcNetwork) error
return nil
}
func (s *service) RestartNetwork(ctx context.Context, id int64) error {
network, err := s.repo.GetNetworkByID(ctx, id)
if err != nil {
return err
}
return s.restartNetwork(*network)
}
func (s *service) restartNetwork(network domain.IrcNetwork) error {
// look if we have the network in handlers, if so restart it
if existingHandler, found := s.handlers[handlerKey{network.Server, network.NickServ.Account}]; found {