Showing
2 changed files
with
109 additions
and
0 deletions
| ... | @@ -63,10 +63,21 @@ func NewApp(config Config) *App { | ... | @@ -63,10 +63,21 @@ func NewApp(config Config) *App { |
| 63 | app.echo.POST("/extractions", app.PostExtractions, auth) | 63 | app.echo.POST("/extractions", app.PostExtractions, auth) |
| 64 | 64 | ||
| 65 | extraction := app.echo.Group("/extractions/:no") | 65 | extraction := app.echo.Group("/extractions/:no") |
| 66 | + | ||
| 66 | extraction.GET("/calls", app.GetCalls) | 67 | extraction.GET("/calls", app.GetCalls) |
| 68 | + extraction.POST("/calls", app.PostCall) | ||
| 69 | + extraction.DELETE("/calls/:id", app.DeleteCall) | ||
| 70 | + | ||
| 67 | extraction.GET("/messages", app.GetMessages) | 71 | extraction.GET("/messages", app.GetMessages) |
| 72 | + extraction.POST("/messages", app.PostMessage) | ||
| 73 | + extraction.DELETE("/messages/:id", app.DeleteMessage) | ||
| 74 | + | ||
| 68 | extraction.GET("/calls/analyses", app.GetCallsAnalyses) | 75 | extraction.GET("/calls/analyses", app.GetCallsAnalyses) |
| 76 | + | ||
| 69 | extraction.GET("/apps/analyses", app.GetAppsAnalyses) | 77 | extraction.GET("/apps/analyses", app.GetAppsAnalyses) |
| 78 | + extraction.POST("/apps/analyses", app.PostAppAnalysis) | ||
| 79 | + extraction.DELETE("/apps/analyses/:package", app.DeleteAppAnalysis) | ||
| 80 | + | ||
| 70 | extraction.GET("/messages/analyses", app.GetMessagesAnalyses) | 81 | extraction.GET("/messages/analyses", app.GetMessagesAnalyses) |
| 71 | extraction.GET("/processes", app.GetProcesses) | 82 | extraction.GET("/processes", app.GetProcesses) |
| 72 | extraction.GET("/alarms", app.GetAlarms) | 83 | extraction.GET("/alarms", app.GetAlarms) | ... | ... |
| ... | @@ -33,6 +33,37 @@ func (app *App) GetCalls(c echo.Context) error { | ... | @@ -33,6 +33,37 @@ func (app *App) GetCalls(c echo.Context) error { |
| 33 | return c.JSON(http.StatusOK, calls) | 33 | return c.JSON(http.StatusOK, calls) |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | +func (app *App) PostCall(c echo.Context) error { | ||
| 37 | + call := Call{} | ||
| 38 | + if err := c.Bind(&call); err != nil { | ||
| 39 | + return err | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + query := "INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?)" | ||
| 43 | + _, err := app.db.Exec(query, c.Param("no"), call.ID, call.Type, call.Name, call.Number, call.Duration, call.Date) | ||
| 44 | + if err != nil { | ||
| 45 | + return nil | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + return c.NoContent(http.StatusNoContent) | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +func (app *App) DeleteCall(c echo.Context) error { | ||
| 52 | + query := "DELETE FROM calls WHERE `extraction_no`=? AND `id`=?" | ||
| 53 | + res, err := app.db.Exec(query, c.Param("no"), c.Param("id")) | ||
| 54 | + if err != nil { | ||
| 55 | + return err | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + if rows, err := res.RowsAffected(); err != nil { | ||
| 59 | + return err | ||
| 60 | + } else if rows == 0 { | ||
| 61 | + return echo.NewHTTPError(http.StatusNotFound, "Can not find the call") | ||
| 62 | + } else { | ||
| 63 | + return c.NoContent(http.StatusNoContent) | ||
| 64 | + } | ||
| 65 | +} | ||
| 66 | + | ||
| 36 | type CallStats struct { | 67 | type CallStats struct { |
| 37 | Number string `json:"number" db:"number"` | 68 | Number string `json:"number" db:"number"` |
| 38 | Name *string `json:"name" db:"name"` | 69 | Name *string `json:"name" db:"name"` |
| ... | @@ -73,6 +104,41 @@ func (app *App) GetAppsAnalyses(c echo.Context) error { | ... | @@ -73,6 +104,41 @@ func (app *App) GetAppsAnalyses(c echo.Context) error { |
| 73 | return c.JSON(http.StatusOK, apps) | 104 | return c.JSON(http.StatusOK, apps) |
| 74 | } | 105 | } |
| 75 | 106 | ||
| 107 | +func (app *App) PostAppAnalysis(c echo.Context) error { | ||
| 108 | + info := AppInfo{} | ||
| 109 | + if err := c.Bind(&info); err != nil { | ||
| 110 | + return err | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + query := "INSERT INTO apps VALUES (?, ?, ?, ?, ?, ?, ?, ?)" | ||
| 114 | + _, err := app.db.Exec( | ||
| 115 | + query, | ||
| 116 | + c.Param("no"), info.PackageName, info.Name, info.Version, | ||
| 117 | + info.WifiUsage, info.CellularUsage, info.LastUsed, info.ForegroundTime, | ||
| 118 | + ) | ||
| 119 | + if err != nil { | ||
| 120 | + return err | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + return c.NoContent(http.StatusNoContent) | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +func (app *App) DeleteAppAnalysis(c echo.Context) error { | ||
| 127 | + query := "DELETE FROM apps WHERE `extraction_no`=? AND `package_name`=?" | ||
| 128 | + res, err := app.db.Exec(query, c.Param("no"), c.Param("package")) | ||
| 129 | + if err != nil { | ||
| 130 | + return err | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + if rows, err := res.RowsAffected(); err != nil { | ||
| 134 | + return err | ||
| 135 | + } else if rows == 0 { | ||
| 136 | + return echo.NewHTTPError(http.StatusNotFound, "Can not find the app") | ||
| 137 | + } else { | ||
| 138 | + return c.NoContent(http.StatusNoContent) | ||
| 139 | + } | ||
| 140 | +} | ||
| 141 | + | ||
| 76 | type Message struct { | 142 | type Message struct { |
| 77 | ID int `json:"id" db:"id"` | 143 | ID int `json:"id" db:"id"` |
| 78 | Type int `json:"type" db:"type"` | 144 | Type int `json:"type" db:"type"` |
| ... | @@ -114,6 +180,38 @@ func (app *App) GetMessages(c echo.Context) error { | ... | @@ -114,6 +180,38 @@ func (app *App) GetMessages(c echo.Context) error { |
| 114 | return c.JSON(http.StatusOK, messages) | 180 | return c.JSON(http.StatusOK, messages) |
| 115 | } | 181 | } |
| 116 | 182 | ||
| 183 | +func (app *App) PostMessage(c echo.Context) error { | ||
| 184 | + message := Message{} | ||
| 185 | + if err := c.Bind(&message); err != nil { | ||
| 186 | + return err | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + query := "INSERT INTO messages VALUES (?, ?, ?, ?, ?, ?)" | ||
| 190 | + _, err := app.db.Exec(query, c.Param("no"), message.ID, message.Type, message.Address, message.Body, message.Date) | ||
| 191 | + | ||
| 192 | + if err != nil { | ||
| 193 | + return err | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + return c.NoContent(http.StatusNoContent) | ||
| 197 | +} | ||
| 198 | + | ||
| 199 | +func (app *App) DeleteMessage(c echo.Context) error { | ||
| 200 | + query := "DELETE FROM messages WHERE `extraction_no`=? AND `id`=?" | ||
| 201 | + res, err := app.db.Exec(query, c.Param("no"), c.Param("id")) | ||
| 202 | + if err != nil { | ||
| 203 | + return err | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + if rows, err := res.RowsAffected(); err != nil { | ||
| 207 | + return err | ||
| 208 | + } else if rows == 0 { | ||
| 209 | + return echo.NewHTTPError(http.StatusNotFound, "Can not find the message") | ||
| 210 | + } else { | ||
| 211 | + return c.NoContent(http.StatusNoContent) | ||
| 212 | + } | ||
| 213 | +} | ||
| 214 | + | ||
| 117 | type MessageStats struct { | 215 | type MessageStats struct { |
| 118 | Address string `json:"address" db:"address"` | 216 | Address string `json:"address" db:"address"` |
| 119 | Receive int `json:"receive" db:"receive"` | 217 | Receive int `json:"receive" db:"receive"` | ... | ... |
-
Please register or login to post a comment