Skip to content

Commit f0128fb

Browse files
Merge pull request #192 from Avanade/sprint-42
Sprint 42
2 parents f491b05 + b670ea5 commit f0128fb

21 files changed

+383
-31
lines changed

src/goapp/controller/ip-disclosure/ip-disclosure-controller-interface.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "net/http"
44

55
type IpDisclosureController interface {
66
InsertIPDisclosureRequest(w http.ResponseWriter, r *http.Request)
7+
UpdateResponse(w http.ResponseWriter, r *http.Request)
78
}
89

910
type IpDisclosurePageController interface {

src/goapp/controller/ip-disclosure/ip-disclosure-controller.go

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (c *ipDisclosureController) InsertIPDisclosureRequest(w http.ResponseWriter
207207
ApplicationId: c.Config.GetIPDRAppId(),
208208
ApplicationModuleId: c.Config.GetIPDRModuleId(),
209209
Emails: []string{c.Config.GetCTO()},
210-
Subject: "IP Disclosure Request",
210+
Subject: "IP Disclosure Request - " + request.IPTitle,
211211
Body: body,
212212
RequesterEmail: user.Email,
213213
}
@@ -262,3 +262,43 @@ func (c *ipDisclosureController) InsertIPDisclosureRequest(w http.ResponseWriter
262262

263263
w.WriteHeader(http.StatusOK)
264264
}
265+
266+
func (c *ipDisclosureController) UpdateResponse(w http.ResponseWriter, r *http.Request) {
267+
// Decode payload
268+
var data model.ResponseCallback
269+
err := json.NewDecoder(r.Body).Decode(&data)
270+
if err != nil {
271+
http.Error(w, err.Error(), http.StatusBadRequest)
272+
return
273+
}
274+
275+
// Update response
276+
err = c.Service.IPDisclosureRequest.UpdateResponse(&data)
277+
if err != nil {
278+
http.Error(w, err.Error(), http.StatusInternalServerError)
279+
return
280+
}
281+
282+
// Get IPD Request
283+
request, err := c.Service.IPDisclosureRequest.GetIPDRequestByApprovalRequestId(data.ItemId)
284+
if err != nil {
285+
http.Error(w, err.Error(), http.StatusInternalServerError)
286+
return
287+
}
288+
289+
// Get request item
290+
item, err := c.Service.Item.GetItemById(request.ApprovalRequestId)
291+
if err != nil {
292+
http.Error(w, err.Error(), http.StatusInternalServerError)
293+
return
294+
}
295+
296+
// Send email to requestor
297+
err = c.Service.Email.SendIPDRResponseEmail(request, item, c.Config.GetHomeURL())
298+
if err != nil {
299+
http.Error(w, err.Error(), http.StatusInternalServerError)
300+
return
301+
}
302+
303+
w.WriteHeader(http.StatusOK)
304+
}

src/goapp/controller/item/item-page-controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ func (c *itemPageController) RespondToItem(w http.ResponseWriter, r *http.Reques
238238
Data: *item,
239239
RequireRemarks: itemIsAuthorized.RequireRemarks,
240240
IsApprover: isApprover, // show remarks and approve/reject buttons
241-
AlreadyProcessed: itemIsAuthorized.IsApproved.Value,
241+
AlreadyProcessed: item.DateResponded != "",
242242
ApproverResponse: approverResponse,
243243
ConsultLegalButton: consultLegalButton,
244244
Action: action,

src/goapp/model/ipdrequest.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package model
22

33
type IPDRequest struct {
4-
RequestId int64 `json:"requestId"`
5-
RequestorName string `json:"requestorName"`
6-
RequestorEmail string `json:"requestorEmail"`
7-
IPTitle string `json:"title"`
8-
IPType string `json:"type"`
9-
IPDescription string `json:"description"`
10-
Reason string `json:"reason"`
11-
InvolvementId []string `json:"involvementId"`
12-
Involvement []string `json:"involvement"`
4+
RequestId int64 `json:"requestId"`
5+
RequestorName string `json:"requestorName"`
6+
RequestorEmail string `json:"requestorEmail"`
7+
IPTitle string `json:"title"`
8+
IPType string `json:"type"`
9+
IPDescription string `json:"description"`
10+
Reason string `json:"reason"`
11+
InvolvementId []string `json:"involvementId"`
12+
Involvement []string `json:"involvement"`
13+
IsApproved bool `json:"isApproved"`
14+
ApprovalRequestId string `json:"approvalRequestId"`
15+
ApproverRemarks string `json:"approverRemarks"`
16+
ResponseDate string `json:"responseDate"`
17+
RespondedBy string `json:"respondedBy"`
18+
Created string `json:"created"`
1319
}

src/goapp/repository/ipdr-involvement/ipdr-involvement-repository.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,29 @@ func NewIpdrInvolvementRepository(db *db.Database) IpdrInvolvementRepository {
1717
}
1818
}
1919

20+
func (r *ipdrInvolvementRepository) GetIpdrInvolvementByRequestId(requestId int64) (involvementIds []string, involvements []string, err error) {
21+
row, err := r.Query("PR_IPDRInvolvement_Select_ByIPDRId",
22+
sql.Named("RequestId", requestId),
23+
)
24+
25+
if err != nil {
26+
return nil, nil, err
27+
}
28+
defer row.Close()
29+
30+
result, err := r.RowsToMap(row)
31+
if err != nil {
32+
return nil, nil, err
33+
}
34+
35+
for _, row := range result {
36+
involvementIds = append(involvementIds, strconv.FormatInt(row["InvolvementId"].(int64), 10))
37+
involvements = append(involvements, row["InvolvementName"].(string))
38+
}
39+
40+
return involvementIds, involvements, nil
41+
}
42+
2043
func (r *ipdrInvolvementRepository) InsertIpdrInvolvement(ipdrInvolvement model.IpdrInvolvement) error {
2144
involvementId, err := strconv.Atoi(ipdrInvolvement.InvolvementId)
2245
if err != nil {

src/goapp/repository/ipdr-involvement/ipdr-invovlement-repository-interface.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ import (
55
)
66

77
type IpdrInvolvementRepository interface {
8+
GetIpdrInvolvementByRequestId(requestId int64) ([]string, []string, error)
89
InsertIpdrInvolvement(ipdrInvolvement model.IpdrInvolvement) error
9-
}
10+
}

src/goapp/repository/ipdrequest/ipdrequest-repository-interface.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
)
66

77
type IpdRequestRepository interface {
8+
GetIpdRequestByApprovalRequestId(approvalRequestId string) (*model.IPDRequest, error)
89
InsertIpdRequest(ipdRequest *model.IPDRequest) (int64, error)
910
UpdateApprovalRequestId(approvalRequestId string, IPDRequestId int64) error
11+
UpdateResponse(data *model.ResponseCallback) error
1012
}

src/goapp/repository/ipdrequest/ipdrequest-repository.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"database/sql"
55
db "main/infrastructure/database"
66
"main/model"
7+
"time"
78
)
89

910
type ipdRequestRepository struct {
@@ -16,6 +17,57 @@ func NewIpdRequestRepository(db *db.Database) IpdRequestRepository {
1617
}
1718
}
1819

20+
func (r *ipdRequestRepository) GetIpdRequestByApprovalRequestId(approvalRequestId string) (*model.IPDRequest, error) {
21+
row, err := r.Query("PR_IPDisclosureRequest_Select_ByApprovalRequestId",
22+
sql.Named("ApprovalRequestId", approvalRequestId),
23+
)
24+
25+
if err != nil {
26+
return nil, err
27+
}
28+
29+
defer row.Close()
30+
31+
result, err := r.RowsToMap(row)
32+
if err != nil {
33+
return nil, err
34+
}
35+
36+
if len(result) == 0 {
37+
return nil, nil
38+
}
39+
40+
ipdRequest := model.IPDRequest{
41+
RequestId: result[0]["Id"].(int64),
42+
RequestorName: result[0]["RequestorName"].(string),
43+
RequestorEmail: result[0]["RequestorEmail"].(string),
44+
IPTitle: result[0]["IPTitle"].(string),
45+
IPType: result[0]["IPType"].(string),
46+
IPDescription: result[0]["IPDescription"].(string),
47+
Reason: result[0]["Reason"].(string),
48+
ApprovalRequestId: approvalRequestId,
49+
Created: result[0]["Created"].(time.Time).String(),
50+
}
51+
52+
if result[0]["ResponseDate"] != nil {
53+
ipdRequest.ResponseDate = result[0]["ResponseDate"].(time.Time).String()
54+
}
55+
56+
if result[0]["IsApproved"] != nil {
57+
ipdRequest.IsApproved = result[0]["IsApproved"].(bool)
58+
}
59+
60+
if result[0]["ApproverRemarks"] != nil {
61+
ipdRequest.ApproverRemarks = result[0]["ApproverRemarks"].(string)
62+
}
63+
64+
if result[0]["RespondedBy"] != nil {
65+
ipdRequest.RespondedBy = result[0]["RespondedBy"].(string)
66+
}
67+
68+
return &ipdRequest, nil
69+
}
70+
1971
func (r *ipdRequestRepository) InsertIpdRequest(ipdRequest *model.IPDRequest) (int64, error) {
2072
row, err := r.Query("PR_IPDisclosureRequest_Insert",
2173
sql.Named("RequestorName", ipdRequest.RequestorName),
@@ -48,3 +100,14 @@ func (r *ipdRequestRepository) UpdateApprovalRequestId(approvalRequestId string,
48100

49101
return err
50102
}
103+
104+
func (r *ipdRequestRepository) UpdateResponse(data *model.ResponseCallback) error {
105+
_, err := r.Query("PR_IPDisclosureRequest_Update_Response",
106+
sql.Named("ApprovalRequestId", data.ItemId),
107+
sql.Named("IsApproved", data.IsApproved),
108+
sql.Named("ApproverRemarks", data.Remarks),
109+
sql.Named("RespondedBy", data.RespondedBy),
110+
)
111+
112+
return err
113+
}

src/goapp/repository/item/item-repository.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (r *itemRepository) GetItemById(id string) (*model.Item, error) {
7171
}
7272

7373
if result[0]["DateResponded"] != nil {
74-
item.DateResponded = result[0]["DateResponded"].(time.Time).Format("2006-01-02T15:04:05.000Z")
74+
item.DateResponded = result[0]["DateResponded"].(time.Time).String()
7575
}
7676

7777
if result[0]["DateSent"] != nil {
@@ -212,7 +212,7 @@ func (r *itemRepository) GetItemsByModuleId(moduleId string, filterOptions model
212212
}
213213

214214
if v["DateResponded"] != nil {
215-
item.DateResponded = v["DateResponded"].(time.Time).Format("2006-01-02T15:04:05.000Z")
215+
item.DateResponded = v["DateResponded"].(time.Time).String()
216216
}
217217

218218
if v["DateSent"] != nil {

src/goapp/repository/legal-consultation/legal-consultation-repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (r *legalConsultationRepository) GetLegalConsultationByEmail(email string,
5757
}
5858

5959
if v["DateResponded"] != nil {
60-
item.DateResponded = v["DateResponded"].(time.Time).Format("2006-01-02T15:04:05.000Z")
60+
item.DateResponded = v["DateResponded"].(time.Time).String()
6161
}
6262

6363
if v["DateSent"] != nil {

0 commit comments

Comments
 (0)