Area API for creating hierarchical area/sub-area in a space. #655
Conversation
Codecov Report
@@ Coverage Diff @@
## master #655 +/- ##
=========================================
- Coverage 72.12% 72.1% -0.02%
=========================================
Files 80 83 +3
Lines 4760 4972 +212
=========================================
+ Hits 3433 3585 +152
- Misses 996 1041 +45
- Partials 331 346 +15
Continue to review full report at Codecov.
|
|
[test] |
0194224
to
aa19829
Compare
|
Scenario: Create a space and an area under it 1. Create a Space under which the areas and sub areas would be created. 2. Create an area under the space created above Scenario : Create area under an area, basically a sub-area. The json-api response looks like this. In the database column "path", The hierarchy is dot delimited, the uuids of the parent area(s) is stored by replacing the "-" with "_" because the "-" character is not supported in the ltree field. ** Scenario : List all children of a specific area ** |
5e5b403
to
e93121b
Compare
|
[test] |
|
[test] |
|
[test] |
area.go
Outdated
| spaceID := area.SpaceID.String() | ||
|
|
||
| selfURL := rest.AbsoluteURL(request, app.AreaHref(area.ID)) | ||
| spaceSelfURL := rest.AbsoluteURL(request, "/api/spaces/"+spaceID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpaceHref ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out - done here, 39a653f
migration/migration.go
Outdated
| @@ -139,6 +139,9 @@ func getMigrations() migrations { | |||
| // Version 20 | |||
| m = append(m, steps{executeSQLFile("020-work-item-description-update-search-index.sql")}) | |||
|
|
|||
| // Version 21 | |||
| m = append(m, steps{executeSQLFile("021-areas.sql")}) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to 22?
| return svc, NewSpaceAreasController(svc, rest.db) | ||
| } | ||
|
|
||
| func (rest *TestSpaceAreaREST) TestSuccessCreateArea() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some non happy case tests, e.g. 404 on create area in missing space. Missing auth on create..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure @aslakknutsen - was waiting to have my approach reviewed before I did that. Thanks for the review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added negative tests: 1104884
|
|
||
| var areaAttributes = a.Type("AreaAttributes", func() { | ||
| a.Description(`JSONAPI store for all the "attributes" of a Area. +See also see http://jsonapi.org/format/#document-resource-object-attributes`) | ||
| a.Attribute("name", d.String, "The Area name", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expose created-at
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expose path, but resolved by Name.
name: Child2
path: Area1.Child2.Child2
Maybe both 'path' as uuid and 'path' as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposed CreatedAt and Version ( e48559a )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aslakknutsen , does this mean that in the request parameter, only path would be passed as area1.child1.child2
and internally we would be persisting in the database both the name( derived ) and path ?
Maybe both 'path' as uuid and 'path' as resolved.
Didn't understand this - Could you please explain ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, the following needs to be exposed, agnostic to how we persist in the database:
- path ( of UUIDs upto topmost parent )
- path_resolved ( of area_names of the above UUIDs )
- relationship : link to all children
- relationship : link to parent.
migration/sql-files/021-areas.sql
Outdated
| @@ -0,0 +1,13 @@ | |||
| CREATE EXTENSION IF NOT EXISTS "ltree"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 2 migration scripts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silly me, removed.
c300f31
to
e8c91bb
Compare
| defer goa.MeasureSince([]string{"goa", "db", "area", "create"}, time.Now()) | ||
|
|
||
| u.ID = uuid.NewV4() | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should default value for Path be ConvertToLltreeFormat(u.ID.String()) ?
if u.Path == ""{
u.Path = ConvertToLltreeFormat(u.ID.String())
}
Ref:- default path for base WIT is itself.
postgres=# select name,path from work_item_types where name = 'planneritem';
name | path
-------------+-------------
planneritem | planneritem
(1 row)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback @pranavgore09 - yes we could, but the path is the parent path - the name has been renamed at the service level to parent_path..
| }) | ||
|
|
||
| // new version of "list" for migration | ||
| var _ = a.Resource("space-areas", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a.Resource("space-area", func() {
a.BasePath("/space-areas")
for the sake of consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback @alexeykazakov ,
Sorry if I'm missing something silly and obvious !
I don't quite understand what is the advantage of doing so. I checked `design/iterations.go' and we do not add the base path mentioned by you.
./bin/alm-cli create space-areas --key $ALM_TOKEN --id "f214c5d7-1166-4a05-9b43-9e82394d818c" --payload '{ "data":{"type":"areas","attributes":{"name":"area1"} }}' -H localhost:8080 --pp
2017/02/08 23:37:59 [INFO] started id=yND1mdkC POST=http://localhost:8080/api/spaces/f214c5d7-1166-4a05-9b43-9e82394d818c/Areas
2017/02/08 23:37:59 [INFO] completed id=yND1mdkC status=201 time=8.446925ms
{
"data": {
"attributes": {
"created-at": "2017-02-08T23:37:59.644013+05:30",
"name": "area1",
"parent_path": "/",
"version": 0
},
"id": "256db834-a620-46b8-9322-808ee983c8a7",
"links": {
"self": "http://localhost:8080/api/areas/256db834-a620-46b8-9322-808ee983c8a7"
},
"relationships": {
"children": {
"links": {
"self": "http://localhost:8080/api/areas/256db834-a620-46b8-9322-808ee983c8a7/children"
}
},
"space": {
"data": {
"id": "f214c5d7-1166-4a05-9b43-9e82394d818c",
"type": "spaces"
},
"links": {
"self": "http://localhost:8080/api/spaces/f214c5d7-1166-4a05-9b43-9e82394d818c"
}
}
},
"type": "areas"
}
}
The above is how the request looks like , how do you suggest we design the url paths in the API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
./bin/alm-cli create space-area instead of ./bin/alm-cli create space-areas
as we do for space: ./bin/alm-cli create space
As I said, just for the sake of consistency ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @alexeykazakov , I was following space-iterations for consistency - If u suggest I could update stuff of space-area here and space-iteration in another PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. so we have more inconsistency than I though ;)
8464e8d
to
ce10325
Compare
An Area is a hierarchical structure that belongs to a Space.
As part of this PR, I added REST capabilities to
Design decisions:
ltreetype in postgres supports only the "" special character and not the "-" character. Hence UUIDs are converted into the 'ltree' format by converting "-" to "" and vice versa when needed.Fixes #688 , #689 and #690