Skip to content

Commit

Permalink
Removed goods endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
HirbodBehnam committed Dec 31, 2023
1 parent 9e46102 commit bf5dc06
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 412 deletions.
306 changes: 0 additions & 306 deletions payment/WSS Payment.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,50 +167,6 @@
"cookie": [],
"body": "\"empty buying_goods\""
},
{
"name": "N/A Good",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"user_id\": 1234,\n \"to_pay_amount\": 1000,\n \"discount_amount\": 1000,\n \"description\": \"Sample description\",\n \"buying_goods\": [\"not-available-good\"],\n \"name\": \"Crow\",\n \"phone\": \"09123456789\",\n \"mail\": \"[email protected]\",\n \"callback_url\": \"https://google.com/\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{BASE_URL}}/create",
"host": [
"{{BASE_URL}}"
],
"path": [
"create"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 28 Dec 2023 20:47:33 GMT"
},
{
"key": "Content-Length",
"value": "38"
}
],
"cookie": [],
"body": "\"cannot find good: not-available-good\""
},
{
"name": "IDPay Failed",
"originalRequest": {
Expand Down Expand Up @@ -453,268 +409,6 @@
}
]
},
{
"name": "Goods",
"item": [
{
"name": "List Goods",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{BASE_URL}}/goods",
"host": [
"{{BASE_URL}}"
],
"path": [
"goods"
]
}
},
"response": [
{
"name": "New Request",
"originalRequest": {
"method": "GET",
"header": [],
"url": {
"raw": "{{BASE_URL}}/goods",
"host": [
"{{BASE_URL}}"
],
"path": [
"goods"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 28 Dec 2023 19:56:56 GMT"
},
{
"key": "Content-Length",
"value": "123"
}
],
"cookie": [],
"body": "[\n {\n \"ID\": 1,\n \"Name\": \"kir\",\n \"Price\": 420,\n \"Description\": \"random description\"\n },\n {\n \"ID\": 5,\n \"Name\": \"kir2\",\n \"Price\": 1000,\n \"Description\": \"\"\n }\n]"
}
]
},
{
"name": "Add Good",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"kir\",\n \"price\": 420,\n \"description\": \"random description\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{BASE_URL}}/goods",
"host": [
"{{BASE_URL}}"
],
"path": [
"goods"
]
},
"description": "Adds a \"good\" to database. A \"good\" is basically an item which can be bought once for each user. This endpoint can create one of them in order to allow the admins to add items on fly.\n\nThe body of this endpoint consists of 3 key and values:\n\n- `name`: The name of the good. This must be unique.\n- `price`: The price of the good. Must be more than zero.\n- `description`(Optional): An description which is only stored in database.\n \n\nThis endpoint returns the ID of the newly created object."
},
"response": [
{
"name": "Add Good",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"kir\",\n \"price\": 420,\n \"description\": \"this is a description\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{BASE_URL}}/goods",
"host": [
"{{BASE_URL}}"
],
"path": [
"goods"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 28 Dec 2023 19:42:26 GMT"
},
{
"key": "Content-Length",
"value": "8"
}
],
"cookie": [],
"body": "{\n \"id\": 1\n}"
},
{
"name": "Add Good Without Description",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"kir2\",\n \"price\": 1000\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{BASE_URL}}/goods",
"host": [
"{{BASE_URL}}"
],
"path": [
"goods"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 28 Dec 2023 19:42:56 GMT"
},
{
"key": "Content-Length",
"value": "8"
}
],
"cookie": [],
"body": "{\n \"id\": 2\n}"
},
{
"name": "Existing Good",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"kir\",\n \"price\": 420,\n \"description\": \"random description\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{BASE_URL}}/goods",
"host": [
"{{BASE_URL}}"
],
"path": [
"goods"
]
}
},
"status": "Conflict",
"code": 409,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"key": "Date",
"value": "Thu, 28 Dec 2023 19:55:39 GMT"
},
{
"key": "Content-Length",
"value": "21"
}
],
"cookie": [],
"body": "\"good already exists\""
},
{
"name": "Invalid Price",
"originalRequest": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"name\": \"kir\",\n \"price\": 0,\n \"description\": \"random description\"\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{BASE_URL}}/goods",
"host": [
"{{BASE_URL}}"
],
"path": [
"goods"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "plain",
"header": [
{
"key": "Date",
"value": "Thu, 28 Dec 2023 20:32:00 GMT"
},
{
"key": "Content-Length",
"value": "96"
},
{
"key": "Content-Type",
"value": "text/plain; charset=utf-8"
}
],
"cookie": [],
"body": "\"Key: 'createGoodRequest.Price' Error:Field validation for 'Price' failed on the 'required' tag\""
}
]
}
]
},
{
"name": "Health Check",
"request": {
Expand Down
53 changes: 0 additions & 53 deletions payment/api/goods.go

This file was deleted.

18 changes: 4 additions & 14 deletions payment/api/idpay.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,11 @@ func (api *API) CreateTransaction(c *gin.Context) {
c.JSON(http.StatusBadRequest, "empty buying_goods")
return
}
// Try to get the list of goods from database. This will fail if user has bought something
// from its BuyingGoods before
goods, err := api.Database.GetGoodsFromName(body.BuyingGoods)
if err != nil {
var goodError database.GoodNotFoundError
if errors.As(err, &goodError) {
logger.WithError(err).Warn("unknown good")
c.JSON(http.StatusBadRequest, err.Error())
} else {
logger.WithError(err).Error("cannot query goods")
c.JSON(http.StatusInternalServerError, "cannot query goods: "+err.Error())
}
return
}
// Now we try to insert it in database. This should probably succeed
goods := make([]database.Good, len(body.BuyingGoods))
for i := range body.BuyingGoods {
goods[i] = database.Good{Name: body.BuyingGoods[i]}
}
payment := database.Payment{
UserID: body.UserID,
ToPayAmount: body.ToPayAmount,
Expand Down
Loading

0 comments on commit bf5dc06

Please sign in to comment.