Skip to content

Commit f5de3e2

Browse files
finish dapp
1 parent aefbe50 commit f5de3e2

12 files changed

+321
-96
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*.dll
55
*.so
66
*.dylib
7-
7+
.DS_Store
88
# Test binary, built with `go test -c`
99
*.test
1010

Makefile

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
include .env
21
run:
32
swag init --parseDependency --parseInternal --parseDepth 1 --md docs/md_endpoints
43
go mod tidy
5-
go build -o ${DAPPPATH}
6-
api.dapp
4+
go mod vendor
5+
go build -o ./api.dapp
6+
./api.dapp
7+
8+
echo-export:
9+
echo export HLF_DAPP_CONFIG=${PWD}/conf.linux_and_wsl.yaml

api/endpoints/end_files_txs.go

+21-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package endpoints
22

33
import (
4+
"fmt"
5+
46
"github.com/ic-matcom/api.dapp/repo/hlf"
57
"github.com/ic-matcom/api.dapp/schema"
68
"github.com/ic-matcom/api.dapp/schema/dto"
@@ -57,12 +59,12 @@ func NewFilesTxsHandler(app *iris.Application, mdwAuthChecker *context.Handler,
5759
// we use the hero handler to inject the depObtainUserDid dependency. If we don't need to inject any dependencies we jus call guardTxsRouter.Get("/identity/identity/{id:string}", h.Identity_DevPopulate)
5860

5961
guardTxsRouter.Post("/file", h.CreateFile)
60-
guardTxsRouter.Patch("/file/{id:string}", h.UpdateFile)
6162
guardTxsRouter.Delete("/file/{id:string}", h.DeleteFile)
63+
guardTxsRouter.Patch("/file/{id:string}", h.UpdateFile)
6264
guardTxsRouter.Patch("/transfer/file/{id:string}", h.TransferFile)
63-
guardTxsRouter.Get("/file/{id:string}", h.GetFileById)
6465
guardTxsRouter.Get("/file", h.GetAllFiles)
65-
guardTxsRouter.Get("/history/file", h.FilesHistory)
66+
guardTxsRouter.Get("/file/{id:string}", h.GetFileById)
67+
guardTxsRouter.Get("/history/file/{id:string}", h.FilesHistory)
6668
}
6769

6870
return h
@@ -71,14 +73,13 @@ func NewFilesTxsHandler(app *iris.Application, mdwAuthChecker *context.Handler,
7173
// region ======== ENDPOINT HANDLERS DEV =================================================
7274

7375
// CreateFile
74-
// @description.markdown SetElection_Request
7576
// @Tags Txs.eVote
7677
// @Security ApiKeyAuth
7778
// @Accept json
7879
// @Produce json
7980
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
8081
// @Param tx body dto.FilesCreateDto true "Test data"
81-
// @Success 200 {object} []dto.TestRequest "OK"
82+
// @Success 200 {object} interface{} "OK"
8283
// @Failure 401 {object} dto.Problem "err.unauthorized"
8384
// @Failure 400 {object} dto.Problem "err.processing_param"
8485
// @Failure 502 {object} dto.Problem "err.bad_gateway"
@@ -108,15 +109,16 @@ func (h HFilesTxs) CreateFile(ctx iris.Context) {
108109
// @Accept json
109110
// @Produce json
110111
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
111-
// @Param tx path string true "file id"
112+
// @Param id path string true "ID" Format(string) default(mockAssect1)
112113
// @Param tx body dto.FilesUpdateDto true "Test data"
113-
// @Success 200 {object} []dto.TestRequest "OK"
114+
// @Success 200 {object} interface{} "OK"
114115
// @Failure 401 {object} dto.Problem "err.unauthorized"
115116
// @Failure 400 {object} dto.Problem "err.processing_param"
116117
// @Failure 502 {object} dto.Problem "err.bad_gateway"
117118
// @Failure 504 {object} dto.Problem "err.network"
118119
// @Router /txs/file/{id} [patch]
119120
func (h HFilesTxs) UpdateFile(ctx iris.Context) {
121+
fmt.Printf("Aqui estoy")
120122

121123
id := ctx.Params().GetString("id")
122124
if id == "" {
@@ -146,8 +148,8 @@ func (h HFilesTxs) UpdateFile(ctx iris.Context) {
146148
// @Accept json
147149
// @Produce json
148150
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
149-
// @Param tx path string true "file id"
150-
// @Success 200 {object} []dto.TestRequest "OK"
151+
// @Param id path string true "ID" Format(string) default(mockAssect1)
152+
// @Success 200 {object} interface{} "OK"
151153
// @Failure 401 {object} dto.Problem "err.unauthorized"
152154
// @Failure 400 {object} dto.Problem "err.processing_param"
153155
// @Failure 502 {object} dto.Problem "err.bad_gateway"
@@ -176,9 +178,9 @@ func (h HFilesTxs) DeleteFile(ctx iris.Context) {
176178
// @Accept json
177179
// @Produce json
178180
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
179-
// @Param tx path string true "file id"
181+
// @Param id path string true "ID" Format(string) default(mockAssect1)
180182
// @Param tx body dto.FileTransferDto true "Test data"
181-
// @Success 200 {object} []dto.TestRequest "OK"
183+
// @Success 200 {object} interface{} "OK"
182184
// @Failure 401 {object} dto.Problem "err.unauthorized"
183185
// @Failure 400 {object} dto.Problem "err.processing_param"
184186
// @Failure 502 {object} dto.Problem "err.bad_gateway"
@@ -214,8 +216,7 @@ func (h HFilesTxs) TransferFile(ctx iris.Context) {
214216
// @Accept json
215217
// @Produce json
216218
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
217-
// @Param tx path dto.FilesCreateDto true "Test data"
218-
// @Success 200 {object} []dto.Files "OK"
219+
// @Param id path string true "ID" Format(string) default(mockAssect1)
219220
// @Failure 401 {object} dto.Problem "err.unauthorized"
220221
// @Failure 400 {object} dto.Problem "err.processing_param"
221222
// @Failure 502 {object} dto.Problem "err.bad_gateway"
@@ -244,24 +245,18 @@ func (h HFilesTxs) GetFileById(ctx iris.Context) {
244245
// @Accept json
245246
// @Produce json
246247
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
247-
// @Param tx query dto.FileGetAllQuery true "filter query"
248+
// @Param owner query string false "ownerID" Format(string) default([email protected])
248249
// @Success 200 {object} []dto.Files "OK"
249250
// @Failure 401 {object} dto.Problem "err.unauthorized"
250251
// @Failure 400 {object} dto.Problem "err.processing_param"
251252
// @Failure 502 {object} dto.Problem "err.bad_gateway"
252253
// @Failure 504 {object} dto.Problem "err.network"
253-
// @Router /txs/file/ [get]
254+
// @Router /txs/file [get]
254255
func (h HFilesTxs) GetAllFiles(ctx iris.Context) {
255-
var request dto.FileGetAllQuery
256+
owner := ctx.URLParam("owner")
256257

257-
e := ctx.ReadQuery(request)
258-
if e != nil {
259-
(*h.response).ResErr(&dto.Problem{Status: iris.StatusBadRequest, Title: schema.ErrProcParam, Detail: e.Error()}, &ctx)
260-
return
261-
}
262-
263-
if request.Owner != "" {
264-
res, problem := (*h.service).GetAllFilesByOwner(request.Owner)
258+
if owner != "" {
259+
res, problem := (*h.service).GetAllFilesByOwner(owner)
265260
if problem != nil {
266261
(*h.response).ResErr(problem, &ctx)
267262
return
@@ -285,8 +280,8 @@ func (h HFilesTxs) GetAllFiles(ctx iris.Context) {
285280
// @Accept json
286281
// @Produce json
287282
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
288-
// @Param tx path string true "file id"
289-
// @Success 200 {object} []dto.Files "OK"
283+
// @Param id path string true "ID" Format(string) default(mockAssect1)
284+
// @Success 200 {object} []dto.FileHistoryDto "OK"
290285
// @Failure 401 {object} dto.Problem "err.unauthorized"
291286
// @Failure 400 {object} dto.Problem "err.processing_param"
292287
// @Failure 502 {object} dto.Problem "err.bad_gateway"

api/endpoints/end_users_txs.go

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package endpoints
2+
3+
import (
4+
"github.com/ic-matcom/api.dapp/repo/hlf"
5+
"github.com/ic-matcom/api.dapp/schema"
6+
"github.com/ic-matcom/api.dapp/schema/dto"
7+
"github.com/ic-matcom/api.dapp/service"
8+
"github.com/ic-matcom/api.dapp/service/utils"
9+
"github.com/kataras/iris/v12"
10+
"github.com/kataras/iris/v12/context"
11+
"github.com/kataras/iris/v12/hero"
12+
)
13+
14+
// HBlockchainTxs endpoint handler struct for HLF blockchain transactions
15+
type HUserTxs struct {
16+
response *utils.SvcResponse
17+
service *service.ISvcUserTxs
18+
}
19+
20+
// NewBlockchainTxsHandler create and register the handler for HLF blockchain transactions (txs)
21+
//
22+
// - app [*iris.Application] ~ Iris App instance
23+
//
24+
// - MdwAuthChecker [*context.Handler] ~ Authentication checker middleware
25+
//
26+
// - svcR [*utils.SvcResponse] ~ GrantIntentResponse service instance
27+
//
28+
// - svcC [utils.SvcConfig] ~ Configuration service instance
29+
func NewUserTxsHandler(app *iris.Application, mdwAuthChecker *context.Handler, svcR *utils.SvcResponse, svcC *utils.SvcConfig) HUserTxs {
30+
31+
// --- VARS SETUP ---
32+
repo := hlf.NewRepoUserBlockchain(svcC)
33+
svc := service.NewSvcUserTxs(&repo)
34+
// registering protected / guarded router
35+
h := HUserTxs{svcR, &svc}
36+
//repoUsers := db.NewRepoUsers(svcC)
37+
38+
// registering unprotected router
39+
//authRouter := app.Party("/txs") // unauthorized
40+
//{
41+
//
42+
//}
43+
44+
// registering protected / guarded router
45+
guardTxsRouter := app.Party("/txs")
46+
{
47+
// --- GROUP / PARTY MIDDLEWARES ---
48+
guardTxsRouter.Use(*mdwAuthChecker)
49+
50+
// --- DEPENDENCIES ---
51+
hero.Register(DepObtainUserDid)
52+
//hero.Register(repoUsers)
53+
54+
// --- REGISTERING ENDPOINTS ---
55+
56+
// identity contract
57+
// we use the hero handler to inject the depObtainUserDid dependency. If we don't need to inject any dependencies we jus call guardTxsRouter.Get("/identity/identity/{id:string}", h.Identity_DevPopulate)
58+
59+
guardTxsRouter.Post("/user", h.CreateUser)
60+
guardTxsRouter.Delete("/user/{id:string}", h.DeleteUser)
61+
guardTxsRouter.Get("/user/{id:string}", h.GetUserById)
62+
guardTxsRouter.Get("/user", h.GetAllUsers)
63+
}
64+
65+
return h
66+
}
67+
68+
// region ======== ENDPOINT HANDLERS DEV =================================================
69+
70+
// CreateUser
71+
// @Tags Txs.eVote
72+
// @Security ApiKeyAuth
73+
// @Accept json
74+
// @Produce json
75+
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
76+
// @Param tx body dto.UserBlockchainCreate true "Test data"
77+
// @Success 200 {object} interface{} "OK"
78+
// @Failure 401 {object} dto.Problem "err.unauthorized"
79+
// @Failure 400 {object} dto.Problem "err.processing_param"
80+
// @Failure 502 {object} dto.Problem "err.bad_gateway"
81+
// @Failure 504 {object} dto.Problem "err.network"
82+
// @Router /txs/user [post]
83+
func (h HUserTxs) CreateUser(ctx iris.Context) {
84+
var request dto.UserBlockchainCreate
85+
86+
// unmarshalling the json and check
87+
if err := ctx.ReadJSON(&request); err != nil {
88+
(*h.response).ResErr(&dto.Problem{Status: iris.StatusBadRequest, Title: schema.ErrProcParam, Detail: err.Error()}, &ctx)
89+
return
90+
}
91+
92+
problem := (*h.service).CreateUser(request)
93+
if problem != nil {
94+
(*h.response).ResErr(problem, &ctx)
95+
return
96+
}
97+
98+
(*h.response).ResOKWithData("res", &ctx)
99+
}
100+
101+
// DeleteUser
102+
// @Tags Txs.eVote
103+
// @Security ApiKeyAuth
104+
// @Accept json
105+
// @Produce json
106+
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
107+
// @Param id path string true "ID" Format(string) default([email protected])
108+
// @Success 200 {object} interface{} "OK"
109+
// @Failure 401 {object} dto.Problem "err.unauthorized"
110+
// @Failure 400 {object} dto.Problem "err.processing_param"
111+
// @Failure 502 {object} dto.Problem "err.bad_gateway"
112+
// @Failure 504 {object} dto.Problem "err.network"
113+
// @Router /txs/user/{id} [delete]
114+
func (h HUserTxs) DeleteUser(ctx iris.Context) {
115+
116+
id := ctx.Params().GetString("id")
117+
if id == "" {
118+
(*h.response).ResErr(&dto.Problem{Status: iris.StatusBadRequest, Title: schema.ErrProcParam, Detail: schema.ErrDetInvalidField}, &ctx)
119+
return
120+
}
121+
122+
problem := (*h.service).DeleteUser(id)
123+
if problem != nil {
124+
(*h.response).ResErr(problem, &ctx)
125+
return
126+
}
127+
128+
(*h.response).ResOKWithData("res", &ctx)
129+
}
130+
131+
// GetUserById
132+
// @Tags Txs.eVote
133+
// @Security ApiKeyAuth
134+
// @Accept json
135+
// @Produce json
136+
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
137+
// @Param id path string true "ID" Format(string) default([email protected])
138+
// @Success 200 {object} dto.UserBlockchain "OK"
139+
// @Failure 401 {object} dto.Problem "err.unauthorized"
140+
// @Failure 400 {object} dto.Problem "err.processing_param"
141+
// @Failure 502 {object} dto.Problem "err.bad_gateway"
142+
// @Failure 504 {object} dto.Problem "err.network"
143+
// @Router /txs/user/{id} [get]
144+
func (h HUserTxs) GetUserById(ctx iris.Context) {
145+
146+
id := ctx.Params().GetString("id")
147+
if id == "" {
148+
(*h.response).ResErr(&dto.Problem{Status: iris.StatusBadRequest, Title: schema.ErrProcParam, Detail: schema.ErrDetInvalidField}, &ctx)
149+
return
150+
}
151+
152+
res, problem := (*h.service).GetUserById(id)
153+
if problem != nil {
154+
(*h.response).ResErr(problem, &ctx)
155+
return
156+
}
157+
158+
(*h.response).ResOKWithData(res, &ctx)
159+
}
160+
161+
// GetAllUsers
162+
// @Tags Txs.eVote
163+
// @Security ApiKeyAuth
164+
// @Accept json
165+
// @Produce json
166+
// @Param Authorization header string true "Insert access token" default(Bearer <Add access token here>)
167+
// @Success 200 {object} []dto.UserBlockchain "OK"
168+
// @Failure 401 {object} dto.Problem "err.unauthorized"
169+
// @Failure 400 {object} dto.Problem "err.processing_param"
170+
// @Failure 502 {object} dto.Problem "err.bad_gateway"
171+
// @Failure 504 {object} dto.Problem "err.network"
172+
// @Router /txs/user [get]
173+
func (h HUserTxs) GetAllUsers(ctx iris.Context) {
174+
res, problem := (*h.service).GetAllUsers()
175+
if problem != nil {
176+
(*h.response).ResErr(problem, &ctx)
177+
return
178+
}
179+
180+
(*h.response).ResOKWithData(res, &ctx)
181+
}

crypmaterials/wallet_/readme.md

Whitespace-only changes.

go.mod

-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ require (
1212
github.com/json-iterator/go v1.1.12
1313
github.com/kataras/iris/v12 v12.2.0-alpha2.0.20210304161013-7272c76847eb
1414
github.com/lib/pq v1.10.0
15-
<<<<<<< HEAD
1615
github.com/smartystreets/goconvey v1.6.4 // indirect
1716
github.com/stretchr/testify v1.7.0 // indirect
1817
github.com/swaggo/swag v1.7.0
@@ -22,9 +21,5 @@ require (
2221
golang.org/x/tools v0.1.5 // indirect
2322
google.golang.org/grpc v1.33.2 // indirect
2423
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
25-
=======
26-
github.com/swaggo/swag v1.7.0
27-
github.com/tkanos/gonfig v0.0.0-20210106201359-53e13348de2f
28-
>>>>>>> 2cdd586e6517bc9edafdc49395ce5f7b8feac33d
2924
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
3025
)

main.go

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func main() {
7979
endpoints.NewAuthHandler(app, &MdwAuthChecker, svcResponse, svcConfig)
8080
endpoints.NewBlockchainTxsHandler(app, &MdwAuthChecker, svcResponse, svcConfig) // Blockchain transactions handlers
8181
endpoints.NewFilesTxsHandler(app, &MdwAuthChecker, svcResponse, svcConfig)
82+
endpoints.NewUserTxsHandler(app, &MdwAuthChecker, svcResponse, svcConfig)
8283
// endregion =============================================================================
8384

8485
// region ======== SWAGGER REGISTRATION ==================================================

0 commit comments

Comments
 (0)