Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:go-park-mail-ru/2023_2_Hamster i…
Browse files Browse the repository at this point in the history
…nto develop
  • Loading branch information
DmitriyKomarovCoder committed Nov 8, 2023
2 parents 213bec9 + 8d3b5d4 commit 5edceca
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ SECRET="vzqqEH6o5so_VGJZoLhrfdrH7Y7kvFe-7N2i3I3w314=п"

DB_CONTAINER_NAME=HammyWallet_DB
DB_NAME=HammyWallets
DB_USER=kossmatoff
DB_USER=hamster
DB_PASSWORD=2003
DB_HOST=0.0.0.0
DB_SSLMODE=disable
DB_PORT=5436
DB_PORT=5432

SERVER_NAME=HammyWallet_API
SERVER_HOST=127.0.0.1
Expand Down
45 changes: 20 additions & 25 deletions cmd/api/init/db/postgresql/schema/initdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,6 @@ CREATE TABLE TransactionCategory (
category_id UUID REFERENCES Category(id),
PRIMARY KEY (transaction_id, category_id)
);
--=============================================================================

ALTER TABLE Users
ALTER COLUMN planned_budget SET DEFAULT 0.0;

--=============================================================================

INSERT INTO "users"(login, username, password_hash, planned_budget)
VALUES ('kossmatof','komarov', '$argon2id$v=19$m=65536,t=1,p=4$m8qhM3XLae+RCTGirBFEww$Znu5RBnxlam2xRoVtwBzbdSrN4/sRCm1IMOVX4N2uxw', 10000);

INSERT INTO "users"(login, username, password_hash, planned_budget)
VALUES ('test','test1', '$argon2id$v=19$m=65536,t=1,p=4$m8qhM3XLae+RCTGirBFEww$Znu5RBnxlam2xRoVtwBzbdSrN4/sRCm1IMOVX4N2uxw', 10000);

INSERT INTO "accounts"(user_id, balance, mean_payment)
VALUES ((SELECT id FROM Users limit 1), 1000, 'Кошелек');

INSERT INTO "accounts"(user_id, balance, mean_payment)
VALUES ((SELECT id FROM Users limit 1), 1000, 'Наличка');

INSERT INTO "category"(user_id, name)
VALUES ((SELECT id FROM Users limit 1), 'ЖКХ');

INSERT INTO "category"(user_id, name)
VALUES ((SELECT id FROM Users limit 1), 'Стипендия');

CREATE OR REPLACE FUNCTION add_default_categoies()
RETURNS TRIGGER AS $$
Expand All @@ -94,4 +70,23 @@ $$ LANGUAGE plpgsql;
CREATE OR REPLACE TRIGGER after_user_created
AFTER INSERT ON users
FOR EACH ROW
EXECUTE FUNCTION add_default_categoies();
EXECUTE FUNCTION add_default_categoies();
--=============================================================================

ALTER TABLE Users
ALTER COLUMN planned_budget SET DEFAULT 0.0;

--=============================================================================

INSERT INTO "users"(login, username, password_hash, planned_budget)
VALUES ('kossmatof','komarov', '$argon2id$v=19$m=65536,t=1,p=4$m8qhM3XLae+RCTGirBFEww$Znu5RBnxlam2xRoVtwBzbdSrN4/sRCm1IMOVX4N2uxw', 10000);

INSERT INTO "users"(login, username, password_hash, planned_budget)
VALUES ('test','test1', '$argon2id$v=19$m=65536,t=1,p=4$m8qhM3XLae+RCTGirBFEww$Znu5RBnxlam2xRoVtwBzbdSrN4/sRCm1IMOVX4N2uxw', 10000);

INSERT INTO "accounts"(user_id, balance, mean_payment)
VALUES ((SELECT id FROM Users limit 1), 1000, 'Кошелек');

INSERT INTO "accounts"(user_id, balance, mean_payment)
VALUES ((SELECT id FROM Users limit 1), 1000, 'Наличка');

2 changes: 2 additions & 0 deletions cmd/api/init/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ func InitRouter(auth *auth.Handler,
}

categoryRouter := apiRouter.PathPrefix("/tag").Subrouter()
categoryRouter.Use(authMid.Authentication)
categoryRouter.Use(csrfMid.CheckCSRF)
{
categoryRouter.Methods("POST").Path("/create").HandlerFunc(category.CreateTag)
categoryRouter.Methods("GET").Path("/all").HandlerFunc(category.GetTags)
Expand Down
32 changes: 20 additions & 12 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ const docTemplate = `{
"200": {
"description": "tag with id creted",
"schema": {
"$ref": "#/definitions/http.Response-uuid_UUID"
"$ref": "#/definitions/http.Response-category_CategoryCreateResponse"
}
},
"400": {
Expand Down Expand Up @@ -1060,6 +1060,14 @@ const docTemplate = `{
}
}
},
"category.CategoryCreateResponse": {
"type": "object",
"properties": {
"category_id": {
"type": "string"
}
}
},
"category.TagInput": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1168,6 +1176,17 @@ const docTemplate = `{
}
}
},
"http.Response-category_CategoryCreateResponse": {
"type": "object",
"properties": {
"body": {
"$ref": "#/definitions/category.CategoryCreateResponse"
},
"status": {
"type": "integer"
}
}
},
"http.Response-http_MasTransaction": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1311,17 +1330,6 @@ const docTemplate = `{
}
}
},
"http.Response-uuid_UUID": {
"type": "object",
"properties": {
"body": {
"type": "string"
},
"status": {
"type": "integer"
}
}
},
"http.ResponseError": {
"type": "object",
"properties": {
Expand Down
32 changes: 20 additions & 12 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@
"200": {
"description": "tag with id creted",
"schema": {
"$ref": "#/definitions/http.Response-uuid_UUID"
"$ref": "#/definitions/http.Response-category_CategoryCreateResponse"
}
},
"400": {
Expand Down Expand Up @@ -1054,6 +1054,14 @@
}
}
},
"category.CategoryCreateResponse": {
"type": "object",
"properties": {
"category_id": {
"type": "string"
}
}
},
"category.TagInput": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1162,6 +1170,17 @@
}
}
},
"http.Response-category_CategoryCreateResponse": {
"type": "object",
"properties": {
"body": {
"$ref": "#/definitions/category.CategoryCreateResponse"
},
"status": {
"type": "integer"
}
}
},
"http.Response-http_MasTransaction": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1305,17 +1324,6 @@
}
}
},
"http.Response-uuid_UUID": {
"type": "object",
"properties": {
"body": {
"type": "string"
},
"status": {
"type": "integer"
}
}
},
"http.ResponseError": {
"type": "object",
"properties": {
Expand Down
21 changes: 13 additions & 8 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ definitions:
username:
type: string
type: object
category.CategoryCreateResponse:
properties:
category_id:
type: string
type: object
category.TagInput:
properties:
name:
Expand Down Expand Up @@ -84,6 +89,13 @@ definitions:
status:
type: integer
type: object
http.Response-category_CategoryCreateResponse:
properties:
body:
$ref: '#/definitions/category.CategoryCreateResponse'
status:
type: integer
type: object
http.Response-http_MasTransaction:
properties:
body:
Expand Down Expand Up @@ -175,13 +187,6 @@ definitions:
status:
type: integer
type: object
http.Response-uuid_UUID:
properties:
body:
type: string
status:
type: integer
type: object
http.ResponseError:
properties:
message:
Expand Down Expand Up @@ -568,7 +573,7 @@ paths:
"200":
description: tag with id creted
schema:
$ref: '#/definitions/http.Response-uuid_UUID'
$ref: '#/definitions/http.Response-category_CategoryCreateResponse'
"400":
description: Incorrect Input
schema:
Expand Down
4 changes: 4 additions & 0 deletions internal/microservices/category/category_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ type (
Regular bool `json:"regular" valid:"-"`
}
)

type CategoryCreateResponse struct {
CategoryID uuid.UUID `json:"category_id"`
}
5 changes: 3 additions & 2 deletions internal/microservices/category/delivery/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewHandler(cu category.Usecase, log logger.Logger) *Handler {
// @Accept json
// @Produce json
// @Param tag body category.TagInput true "tag info"
// @Success 200 {object} Response[uuid.UUID] "tag with id creted"
// @Success 200 {object} Response[category.CategoryCreateResponse] "tag with id creted"
// @Failure 400 {object} ResponseError "Incorrect Input"
// @Failure 401 {object} ResponseError "auth error relogin"
// @Failure 429 {object} ResponseError "Server error"
Expand Down Expand Up @@ -65,7 +65,8 @@ func (h *Handler) CreateTag(w http.ResponseWriter, r *http.Request) {
return
}

response.SuccessResponse(w, http.StatusOK, id)
categoryResponse := category.CategoryCreateResponse{CategoryID: id}
response.SuccessResponse(w, http.StatusOK, categoryResponse)
}

// @Summary Get Tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (r *Repository) GetTags(ctx context.Context, userID uuid.UUID) ([]models.Ca
}

if err := rows.Err(); err != nil {
return nil, err
return nil, fmt.Errorf("[repo] Error rows error: %v", err)
}

if len(categories) == 0 {
Expand Down
Loading

0 comments on commit 5edceca

Please sign in to comment.