Ma Suhyeon

Fix API

...@@ -35,4 +35,5 @@ ...@@ -35,4 +35,5 @@
35 35
36 __debug_bin 36 __debug_bin
37 config.json 37 config.json
38 -data
...\ No newline at end of file ...\ No newline at end of file
38 +data
39 +mf-server
...\ No newline at end of file ...\ No newline at end of file
......
1 +{
2 + "go.inferGopath": false
3 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "net/http" 5 "net/http"
6 6
7 + "github.com/gorilla/handlers"
7 "github.com/gorilla/mux" 8 "github.com/gorilla/mux"
8 9
9 _ "github.com/go-sql-driver/mysql" 10 _ "github.com/go-sql-driver/mysql"
...@@ -43,5 +44,8 @@ func NewApp(config Config) *App { ...@@ -43,5 +44,8 @@ func NewApp(config Config) *App {
43 } 44 }
44 45
45 func (app *App) Serve() { 46 func (app *App) Serve() {
46 - http.ListenAndServe(fmt.Sprintf(":%d", app.Config.Port), app.router) 47 + http.ListenAndServe(fmt.Sprintf(":%d", app.Config.Port), handlers.CORS(
48 + handlers.AllowedMethods([]string{"GET", "POST", "UPDATE", "DELETE"}),
49 + handlers.AllowedOrigins([]string{"*"}),
50 + )(app.router))
47 } 51 }
......
...@@ -75,7 +75,7 @@ type AppInfo struct { ...@@ -75,7 +75,7 @@ type AppInfo struct {
75 WifiUsage int `json:"wifi_usage" db:"wifiusage"` 75 WifiUsage int `json:"wifi_usage" db:"wifiusage"`
76 CellularUsage int `json:"cellular_usage" db:"cellularusage"` 76 CellularUsage int `json:"cellular_usage" db:"cellularusage"`
77 LastUsed time.Time `json:"last_used" db:"lasttimeused"` 77 LastUsed time.Time `json:"last_used" db:"lasttimeused"`
78 - ForegroundTime int `json:"foreground_time" db:"totaltimeforeground"` 78 + ForegroundTime int64 `json:"foreground_time" db:"totaltimeforeground"`
79 } 79 }
80 80
81 func (app *App) GetAppsAnalyses(w http.ResponseWriter, r *http.Request) { 81 func (app *App) GetAppsAnalyses(w http.ResponseWriter, r *http.Request) {
...@@ -92,8 +92,8 @@ func (app *App) GetAppsAnalyses(w http.ResponseWriter, r *http.Request) { ...@@ -92,8 +92,8 @@ func (app *App) GetAppsAnalyses(w http.ResponseWriter, r *http.Request) {
92 query := `SELECT 92 query := `SELECT
93 a.packagename, a.name, a.version, a.wifiusage, a.cellularusage, 93 a.packagename, a.name, a.version, a.wifiusage, a.cellularusage,
94 u.lasttimeused, u.totaltimeforeground 94 u.lasttimeused, u.totaltimeforeground
95 - FROM AppInfo a JOIN AppUsageYear u 95 + FROM AppInfo a JOIN AppUsageYear u ON a.packagename=u.packagename
96 - ORDER BY totaltimeforeground DESC` 96 + ORDER BY u.totaltimeforeground DESC LIMIT 0, 100`
97 db.Select(&apps, query) 97 db.Select(&apps, query)
98 98
99 WriteJson(w, apps) 99 WriteJson(w, apps)
...@@ -125,9 +125,9 @@ func (app *App) GetMessages(w http.ResponseWriter, r *http.Request) { ...@@ -125,9 +125,9 @@ func (app *App) GetMessages(w http.ResponseWriter, r *http.Request) {
125 } 125 }
126 126
127 type MessageStats struct { 127 type MessageStats struct {
128 - Address string `json:"number" db:"number"` 128 + Address string `json:"address" db:"address"`
129 - Receive int `json:"incoming" db:"incoming"` 129 + Receive int `json:"receive" db:"receive"`
130 - Send int `json:"outgoing" db:"outgoing"` 130 + Send int `json:"send" db:"send"`
131 } 131 }
132 132
133 func (app *App) GetMessagesAnalyses(w http.ResponseWriter, r *http.Request) { 133 func (app *App) GetMessagesAnalyses(w http.ResponseWriter, r *http.Request) {
...@@ -145,7 +145,7 @@ func (app *App) GetMessagesAnalyses(w http.ResponseWriter, r *http.Request) { ...@@ -145,7 +145,7 @@ func (app *App) GetMessagesAnalyses(w http.ResponseWriter, r *http.Request) {
145 (SELECT COUNT(1) FROM sms m WHERE m.address=s.address AND m.type=1) receive, 145 (SELECT COUNT(1) FROM sms m WHERE m.address=s.address AND m.type=1) receive,
146 (SELECT COUNT(1) FROM sms m WHERE m.address=s.address AND m.type=2) send 146 (SELECT COUNT(1) FROM sms m WHERE m.address=s.address AND m.type=2) send
147 FROM sms s GROUP BY address ORDER BY receive + send DESC` 147 FROM sms s GROUP BY address ORDER BY receive + send DESC`
148 - db.Select(&messages, query) 148 + fmt.Println(db.Select(&messages, query))
149 149
150 WriteJson(w, messages) 150 WriteJson(w, messages)
151 } 151 }
......
...@@ -6,6 +6,7 @@ require ( ...@@ -6,6 +6,7 @@ require (
6 github.com/dgrijalva/jwt-go v3.2.0+incompatible 6 github.com/dgrijalva/jwt-go v3.2.0+incompatible
7 github.com/go-sql-driver/mysql v1.5.0 7 github.com/go-sql-driver/mysql v1.5.0
8 github.com/google/uuid v1.1.2 8 github.com/google/uuid v1.1.2
9 + github.com/gorilla/handlers v1.5.1
9 github.com/gorilla/mux v1.8.0 10 github.com/gorilla/mux v1.8.0
10 github.com/jmoiron/sqlx v1.2.0 11 github.com/jmoiron/sqlx v1.2.0
11 github.com/mattn/go-sqlite3 v1.9.0 12 github.com/mattn/go-sqlite3 v1.9.0
......
1 github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM= 1 github.com/dgrijalva/jwt-go v1.0.2 h1:KPldsxuKGsS2FPWsNeg9ZO18aCrGKujPoWXn2yo+KQM=
2 github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= 2 github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
3 github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 3 github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
4 +github.com/felixge/httpsnoop v1.0.1 h1:lvB5Jl89CsZtGIWuTcDM1E/vkVs49/Ml7JJe07l8SPQ=
5 +github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
4 github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= 6 github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
5 github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= 7 github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
6 github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 8 github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
7 github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= 9 github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
8 github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 10 github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
11 +github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
12 +github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
9 github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= 13 github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
10 github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= 14 github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
11 github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA= 15 github.com/jmoiron/sqlx v1.2.0 h1:41Ip0zITnmWNR/vHV+S4m+VoUivnWY5E4OJfLZjCJMA=
......