Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design2
/
2016104120
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Ma Suhyeon
2021-05-03 10:30:46 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f0ca74764fb0ae55b263a1ade7413f3bd4440039
f0ca7476
1 parent
51c3d7c9
Implement post call, post message, post app analysis
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
0 deletions
src/server/app.go
src/server/data.go
src/server/app.go
View file @
f0ca747
...
...
@@ -63,10 +63,21 @@ func NewApp(config Config) *App {
app
.
echo
.
POST
(
"/extractions"
,
app
.
PostExtractions
,
auth
)
extraction
:=
app
.
echo
.
Group
(
"/extractions/:no"
)
extraction
.
GET
(
"/calls"
,
app
.
GetCalls
)
extraction
.
POST
(
"/calls"
,
app
.
PostCall
)
extraction
.
DELETE
(
"/calls/:id"
,
app
.
DeleteCall
)
extraction
.
GET
(
"/messages"
,
app
.
GetMessages
)
extraction
.
POST
(
"/messages"
,
app
.
PostMessage
)
extraction
.
DELETE
(
"/messages/:id"
,
app
.
DeleteMessage
)
extraction
.
GET
(
"/calls/analyses"
,
app
.
GetCallsAnalyses
)
extraction
.
GET
(
"/apps/analyses"
,
app
.
GetAppsAnalyses
)
extraction
.
POST
(
"/apps/analyses"
,
app
.
PostAppAnalysis
)
extraction
.
DELETE
(
"/apps/analyses/:package"
,
app
.
DeleteAppAnalysis
)
extraction
.
GET
(
"/messages/analyses"
,
app
.
GetMessagesAnalyses
)
extraction
.
GET
(
"/processes"
,
app
.
GetProcesses
)
extraction
.
GET
(
"/alarms"
,
app
.
GetAlarms
)
...
...
src/server/data.go
View file @
f0ca747
...
...
@@ -33,6 +33,37 @@ func (app *App) GetCalls(c echo.Context) error {
return
c
.
JSON
(
http
.
StatusOK
,
calls
)
}
func
(
app
*
App
)
PostCall
(
c
echo
.
Context
)
error
{
call
:=
Call
{}
if
err
:=
c
.
Bind
(
&
call
);
err
!=
nil
{
return
err
}
query
:=
"INSERT INTO calls VALUES (?, ?, ?, ?, ?, ?, ?)"
_
,
err
:=
app
.
db
.
Exec
(
query
,
c
.
Param
(
"no"
),
call
.
ID
,
call
.
Type
,
call
.
Name
,
call
.
Number
,
call
.
Duration
,
call
.
Date
)
if
err
!=
nil
{
return
nil
}
return
c
.
NoContent
(
http
.
StatusNoContent
)
}
func
(
app
*
App
)
DeleteCall
(
c
echo
.
Context
)
error
{
query
:=
"DELETE FROM calls WHERE `extraction_no`=? AND `id`=?"
res
,
err
:=
app
.
db
.
Exec
(
query
,
c
.
Param
(
"no"
),
c
.
Param
(
"id"
))
if
err
!=
nil
{
return
err
}
if
rows
,
err
:=
res
.
RowsAffected
();
err
!=
nil
{
return
err
}
else
if
rows
==
0
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
"Can not find the call"
)
}
else
{
return
c
.
NoContent
(
http
.
StatusNoContent
)
}
}
type
CallStats
struct
{
Number
string
`json:"number" db:"number"`
Name
*
string
`json:"name" db:"name"`
...
...
@@ -73,6 +104,41 @@ func (app *App) GetAppsAnalyses(c echo.Context) error {
return
c
.
JSON
(
http
.
StatusOK
,
apps
)
}
func
(
app
*
App
)
PostAppAnalysis
(
c
echo
.
Context
)
error
{
info
:=
AppInfo
{}
if
err
:=
c
.
Bind
(
&
info
);
err
!=
nil
{
return
err
}
query
:=
"INSERT INTO apps VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
_
,
err
:=
app
.
db
.
Exec
(
query
,
c
.
Param
(
"no"
),
info
.
PackageName
,
info
.
Name
,
info
.
Version
,
info
.
WifiUsage
,
info
.
CellularUsage
,
info
.
LastUsed
,
info
.
ForegroundTime
,
)
if
err
!=
nil
{
return
err
}
return
c
.
NoContent
(
http
.
StatusNoContent
)
}
func
(
app
*
App
)
DeleteAppAnalysis
(
c
echo
.
Context
)
error
{
query
:=
"DELETE FROM apps WHERE `extraction_no`=? AND `package_name`=?"
res
,
err
:=
app
.
db
.
Exec
(
query
,
c
.
Param
(
"no"
),
c
.
Param
(
"package"
))
if
err
!=
nil
{
return
err
}
if
rows
,
err
:=
res
.
RowsAffected
();
err
!=
nil
{
return
err
}
else
if
rows
==
0
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
"Can not find the app"
)
}
else
{
return
c
.
NoContent
(
http
.
StatusNoContent
)
}
}
type
Message
struct
{
ID
int
`json:"id" db:"id"`
Type
int
`json:"type" db:"type"`
...
...
@@ -114,6 +180,38 @@ func (app *App) GetMessages(c echo.Context) error {
return
c
.
JSON
(
http
.
StatusOK
,
messages
)
}
func
(
app
*
App
)
PostMessage
(
c
echo
.
Context
)
error
{
message
:=
Message
{}
if
err
:=
c
.
Bind
(
&
message
);
err
!=
nil
{
return
err
}
query
:=
"INSERT INTO messages VALUES (?, ?, ?, ?, ?, ?)"
_
,
err
:=
app
.
db
.
Exec
(
query
,
c
.
Param
(
"no"
),
message
.
ID
,
message
.
Type
,
message
.
Address
,
message
.
Body
,
message
.
Date
)
if
err
!=
nil
{
return
err
}
return
c
.
NoContent
(
http
.
StatusNoContent
)
}
func
(
app
*
App
)
DeleteMessage
(
c
echo
.
Context
)
error
{
query
:=
"DELETE FROM messages WHERE `extraction_no`=? AND `id`=?"
res
,
err
:=
app
.
db
.
Exec
(
query
,
c
.
Param
(
"no"
),
c
.
Param
(
"id"
))
if
err
!=
nil
{
return
err
}
if
rows
,
err
:=
res
.
RowsAffected
();
err
!=
nil
{
return
err
}
else
if
rows
==
0
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
"Can not find the message"
)
}
else
{
return
c
.
NoContent
(
http
.
StatusNoContent
)
}
}
type
MessageStats
struct
{
Address
string
`json:"address" db:"address"`
Receive
int
`json:"receive" db:"receive"`
...
...
Please
register
or
login
to post a comment