generated from Avanade/avanade-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ismael Ibuan <[email protected]>
Showing
26 changed files
with
337 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package item | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"main/config" | ||
"main/model" | ||
"main/pkg/session" | ||
"main/service" | ||
"net/http" | ||
) | ||
|
||
type itemPageController struct { | ||
*service.Service | ||
CommunityPortalAppId string | ||
} | ||
|
||
func NewItemPageController(s *service.Service, conf config.ConfigManager) ItemPageController { | ||
return &itemPageController{ | ||
Service: s, | ||
CommunityPortalAppId: conf.GetCommunityPortalAppId(), | ||
} | ||
} | ||
|
||
func (c *itemPageController) MyRequests(w http.ResponseWriter, r *http.Request) { | ||
session, err := session.Store.Get(r, "auth-session") | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
var profile map[string]interface{} | ||
u := session.Values["profile"] | ||
profile, ok := u.(map[string]interface{}) | ||
if !ok { | ||
http.Error(w, "Error getting user data", http.StatusInternalServerError) | ||
return | ||
} | ||
user := model.AzureUser{ | ||
Name: profile["name"].(string), | ||
Email: profile["preferred_username"].(string), | ||
} | ||
|
||
application, err := c.Service.Application.GetApplicationById(c.CommunityPortalAppId) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
b, err := json.Marshal(application) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
t, d := c.Service.Template.UseTemplate("myrequests", r.URL.Path, user, string(b)) | ||
|
||
err = t.Execute(w, d) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package model | ||
|
||
type Application struct { | ||
Id string `json:"id"` | ||
Name string `json:"name"` | ||
ExportUrl string `json:"exportUrl"` | ||
OrganizationTypeUrl string `json:"organizationTypeUrl"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/goapp/repository/application/application-repository-interface.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package application | ||
|
||
import ( | ||
"main/model" | ||
) | ||
|
||
type ApplicationRepository interface { | ||
GetApplicationById(id string) (*model.Application, error) | ||
} |
44 changes: 44 additions & 0 deletions
44
src/goapp/repository/application/application-repository.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package application | ||
|
||
import ( | ||
"database/sql" | ||
db "main/infrastructure/database" | ||
"main/model" | ||
) | ||
|
||
type applicationRepository struct { | ||
*db.Database | ||
} | ||
|
||
func NewApplicationRepository(db *db.Database) ApplicationRepository { | ||
return &applicationRepository{ | ||
Database: db, | ||
} | ||
} | ||
|
||
func (r *applicationRepository) GetApplicationById(id string) (*model.Application, error) { | ||
var application model.Application | ||
rowApplication, err := r.Query("PR_Applications_Select_ById", sql.Named("Id", id)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
applications, err := r.RowsToMap(rowApplication) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(applications) == 0 { | ||
return nil, nil | ||
} else { | ||
application.Id = applications[0]["Id"].(string) | ||
application.Name = applications[0]["Name"].(string) | ||
if applications[0]["ExportUrl"] != nil { | ||
application.ExportUrl = applications[0]["ExportUrl"].(string) | ||
} | ||
if applications[0]["OrganizationTypeUrl"] != nil { | ||
application.OrganizationTypeUrl = applications[0]["OrganizationTypeUrl"].(string) | ||
} | ||
} | ||
return &application, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/goapp/service/application/application-service-interface.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package application | ||
|
||
import ( | ||
"main/model" | ||
) | ||
|
||
type ApplicationService interface { | ||
GetApplicationById(id string) (*model.Application, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package application | ||
|
||
import ( | ||
"main/model" | ||
"main/repository" | ||
) | ||
|
||
type applicationService struct { | ||
Repository *repository.Repository | ||
} | ||
|
||
func NewApplicationService(r *repository.Repository) ApplicationService { | ||
return &applicationService{ | ||
Repository: r, | ||
} | ||
} | ||
|
||
func (s *applicationService) GetApplicationById(id string) (*model.Application, error) { | ||
application, err := s.Repository.Application.GetApplicationById(id) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return application, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package template | ||
|
||
import ( | ||
"main/model" | ||
"text/template" | ||
) | ||
|
||
type TemplateService interface { | ||
UseTemplate(page, path string, user model.AzureUser, pageData interface{}) (*template.Template, *model.MasterPageData) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package template | ||
|
||
import ( | ||
"fmt" | ||
"main/config" | ||
"main/model" | ||
"strings" | ||
"text/template" | ||
) | ||
|
||
type templateService struct { | ||
LinkFooters string | ||
OrganizationName string | ||
} | ||
|
||
func NewTemplateService(config config.ConfigManager) TemplateService { | ||
return &templateService{ | ||
LinkFooters: config.GetLinkFooters(), | ||
OrganizationName: config.GetOrganizationName(), | ||
} | ||
} | ||
|
||
func (t *templateService) UseTemplate(page, path string, user model.AzureUser, pageData interface{}) (*template.Template, *model.MasterPageData) { | ||
// Data on master page | ||
var menu []model.Menu | ||
menu = append(menu, model.Menu{Name: "My Requests", Url: "/", IconPath: "/public/icons/projects.svg"}) | ||
menu = append(menu, model.Menu{Name: "My Approvals", Url: "/myapprovals", IconPath: "/public/icons/approvals.svg"}) | ||
masterPageData := model.Headers{Menu: menu, Page: getUrlPath(path)} | ||
|
||
//Footers | ||
var footers []model.Footer | ||
footerString := t.LinkFooters | ||
res := strings.Split(footerString, ";") | ||
for _, footer := range res { | ||
f := strings.Split(footer, ">") | ||
footers = append(footers, model.Footer{Text: f[0], Url: f[1]}) | ||
} | ||
|
||
data := model.MasterPageData{ | ||
Header: masterPageData, | ||
Profile: user, | ||
Content: pageData, | ||
Footers: footers, | ||
OrganizationName: t.OrganizationName, | ||
} | ||
|
||
tmpl := template.Must( | ||
template.ParseFiles("templates/master.html", "templates/buttons.html", | ||
fmt.Sprintf("templates/%v.html", page))) | ||
|
||
return tmpl, &data | ||
} | ||
|
||
func getUrlPath(path string) string { | ||
p := strings.Split(path, "/") | ||
if p[1] == "" { | ||
return "/" | ||
} else { | ||
return fmt.Sprintf("/%s", p[1]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters