Skip to content

Commit

Permalink
add version to the message
Browse files Browse the repository at this point in the history
  • Loading branch information
ross96D committed Sep 18, 2024
1 parent 682d891 commit c8305dc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
5 changes: 2 additions & 3 deletions cmd/client/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type Session struct {
token []byte
}

func (session Session) List() (apps []user_handler.App, err error) {
func (session Session) List() (server user_handler.Server, err error) {
defer func() {
if err != nil {
err = ErrNetworkMsg{
Expand Down Expand Up @@ -129,8 +129,7 @@ func (session Session) List() (apps []user_handler.App, err error) {
err = fmt.Errorf("status: %d - %s", resp.StatusCode, string(b))
return
}
apps = make([]user_handler.App, 0)
err = json.Unmarshal(b, &apps)
err = json.Unmarshal(b, &server)
return
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/client/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ross96D/updater/cmd/client/components/list"
"github.com/ross96D/updater/server/user_handler"
"github.com/ross96D/updater/share"
)

type Password string
Expand Down Expand Up @@ -46,6 +47,7 @@ type Server struct {
Url *url.URL `json:"url"`
UserName string `json:"username"`
Password Password `json:"password"`
Version share.VersionData `json:"version"`
Apps []user_handler.App `json:"apps"`
Status list.Status `json:"-"`
}
6 changes: 3 additions & 3 deletions cmd/client/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func NewState(servers []models.Server) *GlobalState {

type FetchResultMsg struct {
ServerName string
Apps []user_handler.App
Server user_handler.Server
}

type ErrFetchFailMsg struct {
Expand Down Expand Up @@ -140,11 +140,11 @@ func (gs *GlobalState) FetchCmd() tea.Cmd {
if err != nil {
return ErrFetchFailCmd(server.ServerName, err)
}
apps, err := session.List()
s, err := session.List()
if err != nil {
return ErrFetchFailCmd(server.ServerName, err)
}
return FetchResultMsg{ServerName: server.ServerName, Apps: apps}
return FetchResultMsg{ServerName: server.ServerName, Server: s}
}
}
for _, server := range *gs.servers {
Expand Down
3 changes: 2 additions & 1 deletion cmd/client/views/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (model *app) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return model, nil
}
server := model.state.Get(index)
server.Apps = msg.Apps
server.Apps = msg.Server.Apps
server.Version = msg.Server.Version
server.Status = listcomp.Ready
model.state.Set(index, server)
return model, tea.Batch(state.GlobalStateSyncCmd, state.SaveCmd)
Expand Down
4 changes: 3 additions & 1 deletion cmd/client/views/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ func (hv *HomeView) init() {
for i := 0; i < length; i++ {
server := hv.State.GetRef(i)
items = append(items, list.Item[*models.Server]{
Message: server.ServerName + " " + (*url.URL)(server.Url).String(),
Message: server.Version.String() + " " +
server.ServerName + " " +
(*url.URL)(server.Url).String(),
Value: server,
StatusValue: server.Status,
})
Expand Down
8 changes: 7 additions & 1 deletion server/user_handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ func HandlerUserUpdate(ctx context.Context, payload []byte, dryRun bool) error {

}

type Server struct {
Apps []App `json:"apps"`
Version share.VersionData `json:"version"`
}

type App struct {
configuration.Application
Index int `json:"index"`
Expand All @@ -156,5 +161,6 @@ func HandleUserAppsList(w io.Writer) error {

enc := json.NewEncoder(w)
enc.SetIndent("", "\t")
return enc.Encode(apps)

return enc.Encode(Server{Apps: apps, Version: share.Version()})
}

0 comments on commit c8305dc

Please sign in to comment.