Compare commits

9 Commits

Author SHA1 Message Date
emirbarucija
9ac172bcb0 Changes related mainly to status codes 2018-05-23 18:56:12 +02:00
emirbarucija
20ab74f392 Made some changes in file names and added zip files for deploying 2018-05-21 17:54:52 +02:00
emirbarucija
4007c55be2 Added Project structure and more data to files 2018-05-18 18:55:40 +02:00
emirbarucija
dcb2339404 Added amazon folder and changed body of JSON return 2018-05-17 15:42:40 +02:00
emirbarucija
f13c7701dc Modified some files 2018-05-16 14:59:10 +02:00
emirbarucija
ad0b6cd53e Added serverless folder and files in it 2018-05-15 17:14:54 +02:00
emirbarucija
6a54807efc Added User structure and more attributes to Task structure, changed file so that it returns JSON now 2018-05-11 16:07:47 +02:00
emirbarucija
722caccf3b Changed API, added folders and server file 2018-05-10 16:15:15 +02:00
emirbarucija
205c70de23 Made GO API 2018-05-09 15:56:57 +02:00
11 changed files with 331 additions and 0 deletions

View File

View File

@@ -0,0 +1,6 @@
build:
go get github.com/aws/aws-lambda-go/lambda
go get github.com/aws/aws-lambda-go/events
set GOOS=linux
go build -o bin/Task_API Tasks.go
C:\Users\Emir\go\bin\build-lambda-zip.exe -o bin/Task_API.zip bin/Task_API

View File

@@ -0,0 +1,149 @@
package main
import (
"fmt"
"encoding/json"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type User struct {
Username string
FirstName string
LastName string
ListOfTasks []Task
}
type Project struct {
Name string
Description string
Leader User
ListOfTasks []Task
}
type Task struct {
Title string
Description string
UsersOnTask []User
Date string
TaskProject Project
}
func main() {
lambda.Start(Handler)
}
func Handler() (events.APIGatewayProxyResponse, error) {
// Getting JSON as []byte
b, err := convertTasksToJSON()
status := 200
if err != nil {
status = 500
}
return events.APIGatewayProxyResponse {
Body: string(b[:]),
StatusCode: status,
}, err
}
func convertTasksToJSON() ([]byte, error) {
user1 := User {
Username: "emirbarucija",
FirstName: "Emir",
LastName: "Baručija",
}
user2 := User {
Username: "noviUser",
FirstName: "Novi",
LastName: "User",
}
project1 := Project {
Name: "GO language project",
Description: "Making Web API in GO language",
Leader: user1,
}
project2 := Project {
Name: "Movie collection",
Description: "Collection of movies, listed by categories. Make Web API in Java, and connect it with frontend application",
Leader: user2,
}
task1 := Task {
Title: "First task",
Description: "This is my first task in GO language",
UsersOnTask: []User{user1},
Date: "10.04.2018.",
TaskProject: project1,
}
task2 := Task {
Title: "Second task",
Description: "This is my second task in GO language",
UsersOnTask: []User{user1},
Date: "14.04.2018.",
TaskProject: project1,
}
task3 := Task {
Title: "Models in Java",
Description: "The goal of task is to make some models for Java application",
UsersOnTask: []User{user2},
Date: "05.02.2018.",
TaskProject: project2,
}
task4 := Task {
Title: "Controllers in Java",
Description: "The goal is to make controllers for CRUD operations on models",
UsersOnTask: []User{user1, user2},
Date: "15.02.2018.",
TaskProject: project2,
}
task5 := Task {
Title: "Correct menu items positions",
Description: "Items in menu need to be corrected via CSS, all items should be of the same size and aligned in the same way",
UsersOnTask: []User{user1},
Date: "12.03.2018.",
TaskProject: project2,
}
task6 := Task {
Title: "Diplay entries from database in list",
Description: "Categories from the database need to be displayed in the list of the Categories menu",
UsersOnTask: []User{user1, user2},
Date: "24.03.2018.",
TaskProject: project2,
}
project1.ListOfTasks = []Task{task1, task2}
project2.ListOfTasks = []Task{task3, task4, task5, task6}
user1.ListOfTasks = []Task{task1, task2, task4, task5, task6}
user2.ListOfTasks = []Task{task3, task4, task6}
tasks := []Task{task1, task2, task3, task4, task5, task6}
b, err := json.Marshal(tasks)
return b, err
}
func (u User) String() string {
return fmt.Sprintf("Username: %v\nFirst name: %v\nLast name: %v\nTAsks: %v", u.Username, u.FirstName, u.LastName, u.ListOfTasks)
}
func (t Task) String() string {
return fmt.Sprintf("Title: %v\nDescription: %v\nUsers: %v\nDate: %v\nProject: %v", t.Title, t.Description, t.UsersOnTask, t.Date, t.TaskProject)
}
func (p Project) String() string {
return fmt.Sprintf("Name: %v\nDescription: %v\nLeader: %v", p.Name, p.Description, p.Leader)
}

Binary file not shown.

View File

@@ -0,0 +1,2 @@
# Serverless directories
.serverless

View File

@@ -0,0 +1,6 @@
build:
go get github.com/aws/aws-lambda-go/lambda
go get github.com/aws/aws-lambda-go/events
set GOOS=linux
go build -o bin/Task_API Tasks.go
C:\Users\Emir\go\bin\build-lambda-zip.exe -o bin/Task_API.zip bin/Task_API

View File

@@ -0,0 +1,149 @@
package main
import (
"fmt"
"encoding/json"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
type User struct {
Username string
FirstName string
LastName string
ListOfTasks []Task
}
type Project struct {
Name string
Description string
Leader User
ListOfTasks []Task
}
type Task struct {
Title string
Description string
UsersOnTask []User
Date string
TaskProject Project
}
func main() {
lambda.Start(Handler)
}
func Handler() (events.APIGatewayProxyResponse, error) {
// Getting JSON as []byte
b, err := convertTasksToJSON()
status := 200
if err != nil {
status = 500
}
return events.APIGatewayProxyResponse {
Body: string(b[:]),
StatusCode: status,
}, err
}
func convertTasksToJSON() ([]byte, error) {
user1 := User {
Username: "emirbarucija",
FirstName: "Emir",
LastName: "Baručija",
}
user2 := User {
Username: "noviUser",
FirstName: "Novi",
LastName: "User",
}
project1 := Project {
Name: "GO language project",
Description: "Making Web API in GO language",
Leader: user1,
}
project2 := Project {
Name: "Movie collection",
Description: "Collection of movies, listed by categories. Make Web API in Java, and connect it with frontend application",
Leader: user2,
}
task1 := Task {
Title: "First task",
Description: "This is my first task in GO language",
UsersOnTask: []User{user1},
Date: "10.04.2018.",
TaskProject: project1,
}
task2 := Task {
Title: "Second task",
Description: "This is my second task in GO language",
UsersOnTask: []User{user1},
Date: "14.04.2018.",
TaskProject: project1,
}
task3 := Task {
Title: "Models in Java",
Description: "The goal of task is to make some models for Java application",
UsersOnTask: []User{user2},
Date: "05.02.2018.",
TaskProject: project2,
}
task4 := Task {
Title: "Controllers in Java",
Description: "The goal is to make controllers for CRUD operations on models",
UsersOnTask: []User{user1, user2},
Date: "15.02.2018.",
TaskProject: project2,
}
task5 := Task {
Title: "Correct menu items positions",
Description: "Items in menu need to be corrected via CSS, all items should be of the same size and aligned in the same way",
UsersOnTask: []User{user1},
Date: "12.03.2018.",
TaskProject: project2,
}
task6 := Task {
Title: "Diplay entries from database in list",
Description: "Categories from the database need to be displayed in the list of the Categories menu",
UsersOnTask: []User{user1, user2},
Date: "24.03.2018.",
TaskProject: project2,
}
project1.ListOfTasks = []Task{task1, task2}
project2.ListOfTasks = []Task{task3, task4, task5, task6}
user1.ListOfTasks = []Task{task1, task2, task4, task5, task6}
user2.ListOfTasks = []Task{task3, task4, task6}
tasks := []Task{task1, task2, task3, task4, task5, task6}
b, err := json.Marshal(tasks)
return b, err
}
func (u User) String() string {
return fmt.Sprintf("Username: %v\nFirst name: %v\nLast name: %v\nTAsks: %v", u.Username, u.FirstName, u.LastName, u.ListOfTasks)
}
func (t Task) String() string {
return fmt.Sprintf("Title: %v\nDescription: %v\nUsers: %v\nDate: %v\nProject: %v", t.Title, t.Description, t.UsersOnTask, t.Date, t.TaskProject)
}
func (p Project) String() string {
return fmt.Sprintf("Name: %v\nDescription: %v\nLeader: %v", p.Name, p.Description, p.Leader)
}

View File

@@ -0,0 +1,19 @@
service: Task_API_service
provider:
name: aws
runtime: go1.x
package:
exclude:
- ./**
include:
- ./bin/**
functions:
Task_API:
handler: bin/Task_API
events:
- http:
path: tasks
method: GET