Skip to content

Commit

Permalink
updated dependencies
Browse files Browse the repository at this point in the history
added index function
improved error catching in callbacks
added make tasks for tests
  • Loading branch information
Southclaws committed Jul 8, 2018
1 parent 25b8452 commit f33cb9d
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 28 deletions.
27 changes: 20 additions & 7 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,43 @@ release: build push
# build release binaries with current version tag
GITHUB_TOKEN=$(GITHUB_TOKEN) goreleaser --rm-dist

local:
WAREHOUSE_TEMPORARY=false \
WAREHOUSE_BIND=localhost:7788 \
WAREHOUSE_AUTH=cunning_fox \
WAREHOUSE_MONGO_HOST=localhost \
WAREHOUSE_MONGO_PORT=27017 \
WAREHOUSE_MONGO_NAME=warehouse \
WAREHOUSE_MONGO_USER=warehouse \
WAREHOUSE_MONGO_PASS=warehouse \
DEBUG=1 \
./warehouse

# -
# Testing
# -

test:
TESTING=1 go test -v -race ./server

test-pawn:
sampctl p build
sampctl p run

test-all: test test-pawn

databases:
-docker stop mongodb
-docker rm mongodb
-docker stop postgres
-docker rm postgres
-docker stop express
-docker rm express
docker run \
--name mongodb \
--publish 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=warehouse \
-e MONGO_INITDB_ROOT_PASSWORD=warehouse \
--detach \
mongo
docker run \
--name postgres \
--publish 5432:5432 \
--detach \
postgres
sleep 5
docker run \
--name express \
Expand Down
4 changes: 2 additions & 2 deletions pawn.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"output": "test.amx",
"dependencies": [
"sampctl/samp-stdlib",
"Southclaws/pawn-errors",
"Southclaws/pawn-requests",
"Southclaws/pawn-errors:1.2.2",
"Southclaws/pawn-requests:0.8.2",
"BigETI/pawn-map"
],
"dev_dependencies": [
Expand Down
1 change: 1 addition & 0 deletions server/handler_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ func (app *App) indexRoutes() []Route {
}

func (app *App) index(r io.Reader, query url.Values) (status types.Status, err error) {
logger.Debug("received request index")
return types.NewStatus(app.handlers, true, fmt.Sprintf("warehouse version: %s, good luck out there survivors!", version)), nil
}
17 changes: 13 additions & 4 deletions test.pwn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <YSI\y_testing>


new buf[4096];

Test:ParseStatus() {
new Node:n = JsonObject(
"result", JsonObject(
Expand Down Expand Up @@ -40,6 +42,14 @@ public OnScriptInit() {
print("failed to create requests client");
}

new Error:e = WarehouseIndex(testClient);
if(IsError(e)) {
PrintErrors();
Handled();
}
}

public OnWarehouseIndex(bool:success, message[], Error:error, Node:result) {
new Error:e = WarehousePlayerCreate(testClient, 0, JsonObject(
"account", JsonObject(
"name", JsonString("Southclaws"),
Expand All @@ -52,6 +62,7 @@ public OnScriptInit() {
PrintErrors();
Handled();
}
return;
}

new PlayerObjectID[25];
Expand Down Expand Up @@ -90,9 +101,8 @@ public OnWarehousePlayerGet(playerid, bool:success, message[], Error:error, Node
return;
}

new buf[512];
JsonStringify(result, buf);
print(buf);
printf("success: %s", buf);

// Update the record

Expand Down Expand Up @@ -131,9 +141,8 @@ public OnWarehousePlayerUpdate(playerid, bool:success, message[], Error:error, N
return;
}

new buf[512];
JsonStringify(result, buf);
print(buf);
printf("success: %s", buf);
}

public OnRequestFailure(Request:id, errorCode, errorMessage[], len) {
Expand Down
82 changes: 67 additions & 15 deletions warehouse.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <map>


// OnWarehouseIndex is called after WarehouseIndex finishes
forward OnWarehouseIndex(bool:success, message[], Error:error, Node:result);

// OnWarehousePlayerCreate is called after WarehousePlayerCreate finishes
forward OnWarehousePlayerCreate(playerid, bool:success, message[], Error:error, Node:result);

Expand Down Expand Up @@ -47,6 +50,49 @@ stock Error:ParseStatus(Node:node, &bool:success, &Node:result, message[], len =
}


// -
// Interface: /
// -

forward _warehouse_onIndex(Request:id, E_HTTP_STATUS:status, Node:node);

stock Error:WarehouseIndex(RequestsClient:client) {
new Request:id = RequestJSON(
client,
"/",
HTTP_METHOD_GET,
"_warehouse_onIndex"
);
if(!IsValidRequest(id)) {
return Error(1, "failed to send playerCreate request");
}
return NoError();
}
public _warehouse_onIndex(Request:id, E_HTTP_STATUS:status, Node:node) {
new bool:success;
new Node:result;
new message[128];
new Error:e;
if(status == HTTP_STATUS_OK) {
e = ParseStatus(node, success, result, message);
if(IsError(e)) {
e = Error(1, "failed to parse status");
}
} else {
e = Error(1, "status was not OK");
}

if(message[0] == 0) {
message[0] = '\1';
}

JsonToggleGC(result, false);
CallLocalFunction("OnWarehouseIndex", "dsdd", success, message, _:e, _:result);
JsonToggleGC(result, true);

return;
}

// -
// Interface: /store/playerCreate
// -
Expand Down Expand Up @@ -77,11 +123,13 @@ public _warehouse_onPlayerCreate(Request:id, E_HTTP_STATUS:status, Node:node) {
new bool:success;
new Node:result;
new message[128];
new Error:e = ParseStatus(node, success, result, message);
if(IsError(e)) {
e = Error(1, "failed to parse status");
}
if(status != HTTP_STATUS_OK) {
new Error:e;
if(status == HTTP_STATUS_OK) {
e = ParseStatus(node, success, result, message);
if(IsError(e)) {
e = Error(1, "failed to parse status");
}
} else {
e = Error(1, "status was not OK");
}

Expand Down Expand Up @@ -130,11 +178,13 @@ public _warehouse_onPlayerGet(Request:id, E_HTTP_STATUS:status, Node:node) {
new bool:success;
new Node:result;
new message[128];
new Error:e = ParseStatus(node, success, result, message);
if(IsError(e)) {
e = Error(1, "failed to parse status");
}
if(status != HTTP_STATUS_OK) {
new Error:e;
if(status == HTTP_STATUS_OK) {
e = ParseStatus(node, success, result, message);
if(IsError(e)) {
e = Error(1, "failed to parse status");
}
} else {
e = Error(1, "status was not OK");
}

Expand Down Expand Up @@ -182,11 +232,13 @@ public _warehouse_onPlayerUpdate(Request:id, E_HTTP_STATUS:status, Node:node) {
new bool:success;
new Node:result;
new message[128];
new Error:e = ParseStatus(node, success, result, message);
if(IsError(e)) {
e = Error(1, "failed to parse status");
}
if(status != HTTP_STATUS_OK) {
new Error:e;
if(status == HTTP_STATUS_OK) {
e = ParseStatus(node, success, result, message);
if(IsError(e)) {
e = Error(1, "failed to parse status");
}
} else {
e = Error(1, "status was not OK");
}

Expand Down

0 comments on commit f33cb9d

Please sign in to comment.