Team-Members is a back-end application that helps organizations manage their teams. It consists of a Go RESTful API app and uses MongoDb for the database. The Gin Web Framework package is used for HTTP routing and the MongoDB Go Driver package is used to connect and work with MongoDB.
-
A member has a name and a type. The member type can be an employee or a contractor - if it's a contractor, the duration of the contract needs to be saved and if it's an employee we need to store their role, for instance: Software Engineer, Project Manager and so on.
-
A member can be tagged, for instance: C#, Angular, General Frontend, Seasoned Leader and so on. (Tags will likely be used as filters later, so keep that in mind)
A RESTful CRUD is offered for the information above.
Follow the instructions here: https://golang.org/doc/install
Follow the instructions here: https://docs.mongodb.com/manual/installation/
go get -u github.com/gin-gonic/gin
go get github.com/mongodb/mongo-go-driver
NOTE: The output of this may look like a warning stating something like package github.com/mongodb/mongo-go-driver
: no Go files in (...). This is expected output.
5. Install gotoenv package
go get github.com/subosito/gotenv
Copy team-members directory to /go/src
NOTE: Examples shown here below use the default configuration settings avaiable in the .env file under team-members directory. Feel free to change the settings to your preferred configuration settings:
MONGODB=mongodb://localhost:27017
DB_NAME=members
#PORT=8080
PORT environment variable is for the Gin engine and if not set team-members/main.go will default it to "8080"
- Start MongoDB
sudo mongod
- Build team-members. From /go/src/team-members run
go build
- Run team-membrers. From /go/src/team-members run
go run team-members
NOTE: I highly recommend using Postman to work with and test Team-Members RESTful API Golang/MongoDB app.
-
The payload data to create new employee and contractor members through a POST request will be the following JSON data structures respectively:
Employee:
{ "oid": null, "name": "Joel McDaniel", "type": { "key": 1, "value": "Employee", "properties": { "role": "Senior Golang Engineer" } }, "tags": [ "Go", "Golang", "MongoDB" ] }
Contractor:
{ "oid": null, "name": "Someone Else", "type": { "key": 0, "value": "Contractor", "properties": { "duration": "6 months" } }, "tags": [ "JavaScript", "HTML5/CSS3", "Vue.js" ] }
NOTE: For your convenience the above JSON data can be also be found under the team-members directory in the create_member_payload_data.json file.
Using Postman (or some similar tool) use the member json data structures above for the body of the POST request to be posted as raw JSON.
To create a new member in the database POST the new member JSON to /api/member like so:
POST: http://localhost:8080/api/member
For the first member, this will create the mongodb "members" database and insert the document record.
-
To read the collection of members inserted into the "members" database use Postman to make a GET request to the same URI as above like so:
GET: http://localhost:8080/api/members
The existing members collection response will be returned as JSON and each members' oid property value will be set to the document record ObjectID string value. This is the unique primary key value MongoDB generated during the inserts represented as the _id field in the "members" database. This value will be used in the request URI to fetch individual members as shown later below in section 4.
[ { "oid": "5ce9f998527c85b1d5a930f1", "name": "Joel McDaniel", "type": { "key": 1, "value": "Employee", "properties": { "role": "Senior Golang Engineer" } }, "tags": [ "Go", "Golang", "MongoDB" ] }, { "oid": "5ce9f9c4527c85b1d5a930f2", "name": "Someone Else", "type": { "key": 0, "value": "Contractor", "properties": { "duration": "6 months" } }, "tags": [ "JavaScript", "HTML5/CSS3", "Vue.js" ] } ]
-
To read members filtered by tags make a get request to /api/members/?tags=
<tag>
&tags=<tag>
ect. appending /? and tags querystring parameter for each tag you wish to filter on like so:GET: http://localhost:8080/api/members/?tags=Meowin&tags=Hunting&tags=Go
This will return members corresponding to the tags filtered on from the request URI querystring:
{ "oid": "5ce9f998527c85b1d5a930f1", "name": "Joel McDaniel", "type": { "key": 1, "value": "Employee", "properties": { "role": "Senior Golang Engineer" } }, "tags": [ "Go", "Golang", "MongoDB" ] }, { "oid": "5cec7a92fc1f14ada5542358", "name": "Franz Wooleybear", "type": { "key": 1, "value": "Employee", "properties": { "role": "Señor Kitty Cat" } }, "tags": [ "Meowin", "Loungin", "Hunting" ] }
-
By ObjectID:
To read individual existing members by ObjectID use Postman to make a GET request to /api/member/oid/:oid appending the oid string value to the URI endpoint path like so:
GET: http://localhost:8080/api/member/oid/5ce9f998527c85b1d5a930f1
This will return the member corresponding to the string ObjectID (:oid):
{ "oid": "5ce9f998527c85b1d5a930f1", "name": "Joel McDaniel", "type": { "key": 1, "value": "Employee", "properties": { "role": "Senior Golang Engineer" } }, "tags": [ "Go", "Golang", "MongoDB" ] }
By Name:
To read individual existing members by Name use Postman to make a GET request to /api/member/name/:name appending the name string value to the URI endpoint path like so:
GET: http://localhost:8080/api/member/name/Franz Wooleybear
This will return the member corresponding to the string name (:name):
{ "oid": "5cec7a92fc1f14ada5542358", "name": "Franz Wooleybear", "type": { "key": 1, "value": "Employee", "properties": { "role": "Señor Kitty Cat" } }, "tags": [ "Meowin", "Loungin", "Hunting" ] }
-
To update a member use Postman with the JSON member data from a GET request (including oid value) for the body of the PUT request as raw JSON making any changes to the data before sending the request.
{ "oid": "5ce9f9c4527c85b1d5a930f2", "name": "Someone Else", "type": { "key": 1, "value": "Employee", "properties": { "role": "Front-end Developer" } }, "tags": [ "JavaScript", "HTML5/CSS3", "Vue.js" ] }
Make the PUT request to /api/member/:oid with the oid string value appended to the URI endpoint path like so:
PUT: http://localhost:8080/api/member/5ce9f9c4527c85b1d5a930f2
Make another GET request at the same URI to verify/return the updated document record.
-
To delete a member use Postman to make a DELETE request to /api/member/:oid with the oid string value appended to the URI endpoint path like so:
DELETE: http://localhost:8080/api/member/5ce9f9c4527c85b1d5a930f2
Make another GET all members request to verify the member was removed from the collection.