Skip to content

Commit 0194de4

Browse files
authored
Support guides (#4)
* Contoso CAMS app configuration * Support guide CAMS * terraform
1 parent 3a6df09 commit 0194de4

File tree

17 files changed

+230
-59
lines changed

17 files changed

+230
-59
lines changed

.vscode/launch.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@
1717
"mainClass": "com.contoso.cams.CamsApplication",
1818
"projectName": "cams",
1919
"env": {
20-
"SPRING_PROFILES_ACTIVE": "local"
20+
"DATABASE_URL": "",
21+
"DATABASE_USERNAME": "",
22+
"DATABASE_PASSWORD": "",
23+
"REDIS_HOST": "",
24+
"REDIS_PORT": "",
25+
"REDIS_PASSWORD": "",
26+
"AZURE_ACTIVE_DIRECTORY_CREDENTIAL_CLIENT_ID": "",
27+
"AZURE_ACTIVE_DIRECTORY_CREDENTIAL_CLIENT_SECRET": "",
28+
"AZURE_ACTIVE_DIRECTORY_CREDENTIAL_TENANT_ID": "",
29+
"AZURE_SERVICEBUS_NAMESPACE": "",
30+
"AZURE_SERVICEBUS_EMAIL_REQUEST_QUEUE_NAME": "",
31+
"AZURE_SERVICEBUS_EMAIL_RESPONSE_QUEUE_NAME": ""
2132
}
2233
},
2334
{
@@ -33,4 +44,4 @@
3344
}
3445
}
3546
]
36-
}
47+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.contoso.cams.model;
2+
3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.GeneratedValue;
6+
import jakarta.persistence.GenerationType;
7+
import jakarta.persistence.Id;
8+
import jakarta.persistence.Table;
9+
import lombok.Data;
10+
11+
@Entity
12+
@Table(name = "support_guides")
13+
@Data
14+
public class SupportGuide {
15+
16+
@Id
17+
@Column(name = "activity_type_id", nullable = false, updatable = false)
18+
@GeneratedValue(strategy = GenerationType.IDENTITY)
19+
private Long id;
20+
21+
@Column(name = "name", nullable = false)
22+
private String name;
23+
24+
@Column(name = "description", nullable = false)
25+
private String description;
26+
27+
@Column(name = "url", nullable = false)
28+
private String url;
29+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.contoso.cams.model;
2+
3+
import org.springframework.data.jpa.repository.JpaRepository;
4+
5+
public interface SupportGuideRepository extends JpaRepository<SupportGuide, Long> {
6+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.contoso.cams.supportguide;
2+
3+
import java.util.List;
4+
5+
import org.springframework.security.access.prepost.PreAuthorize;
6+
import org.springframework.stereotype.Controller;
7+
import org.springframework.ui.Model;
8+
import org.springframework.web.bind.annotation.GetMapping;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
11+
import lombok.AllArgsConstructor;
12+
13+
@Controller
14+
@AllArgsConstructor
15+
@RequestMapping(value = "/guides")
16+
public class SupportGuideController {
17+
private final SupportGuideService guideService;
18+
19+
@GetMapping("/list")
20+
@PreAuthorize("hasAnyAuthority('APPROLE_AccountManager')")
21+
public String listServiceGuides(Model model) {
22+
List<SupportGuideDto> serviceGuides = guideService.getSupportGuides();
23+
model.addAttribute("guides", serviceGuides);
24+
return "pages/guides/list";
25+
}
26+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.contoso.cams.supportguide;
2+
3+
public record SupportGuideDto(Long id, String name, String description, String url) {
4+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.contoso.cams.supportguide;
2+
3+
import java.util.List;
4+
import java.util.stream.Collectors;
5+
6+
import org.springframework.stereotype.Service;
7+
8+
import com.contoso.cams.model.SupportGuideRepository;
9+
10+
import lombok.AllArgsConstructor;
11+
12+
@Service
13+
@AllArgsConstructor
14+
public class SupportGuideService {
15+
16+
private final SupportGuideRepository guideRepository;
17+
18+
public List<SupportGuideDto> getSupportGuides() {
19+
return guideRepository.findAll().stream()
20+
.map(guide -> new SupportGuideDto(
21+
guide.getId(),
22+
guide.getName(),
23+
guide.getDescription(),
24+
guide.getUrl()))
25+
.collect(Collectors.toList());
26+
}
27+
}

apps/contoso-fiber/src/main/resources/application-local.properties

Lines changed: 0 additions & 30 deletions
This file was deleted.

apps/contoso-fiber/src/main/resources/application.properties

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
1+
# Contoso Configuration
2+
contoso.retry.demo=0
3+
## email, queue, demo
4+
contoso.guide.request.service=email
5+
16
# Spring Data JPA
7+
spring.datasource.url=${DATABASE_URL}
8+
spring.datasource.username=${DATABASE_USERNAME}
9+
spring.datasource.password=${DATABASE_PASSWORD}
210
spring.jpa.hibernate.ddl-auto=validate
311

412
# Azure AD
513
spring.cloud.azure.active-directory.enabled=true
14+
spring.cloud.azure.active-directory.credential.client-id=${AZURE_ACTIVE_DIRECTORY_CREDENTIAL_CLIENT_ID}
15+
spring.cloud.azure.active-directory.credential.client-secret=${AZURE_ACTIVE_DIRECTORY_CREDENTIAL_CLIENT_SECRET}
16+
spring.cloud.azure.active-directory.profile.tenant-id=${AZURE_ACTIVE_DIRECTORY_TENANT_ID}
617

718
# Redis
19+
spring.data.redis.host=${REDIS_HOST}
20+
spring.data.redis.port=${REDIS_PORT}
21+
spring.data.redis.password=${REDIS_PASSWORD}
822
spring.data.redis.ssl.enabled=true
923

1024
# Spring Session to leverage Redis to back a web application’s HttpSession
1125
spring.session.redis.namespace=spring:session
1226

27+
# Spring Cloud Stream - Azure Service Bus
28+
spring.cloud.azure.servicebus.namespace=${AZURE_SERVICEBUS_NAMESPACE}
29+
spring.cloud.stream.bindings.consume-in-0.destination=${AZURE_SERVICEBUS_EMAIL_RESPONSE_QUEUE_NAME}
30+
spring.cloud.stream.servicebus.bindings.supply-out-0.producer.entity-type=queue
31+
spring.cloud.stream.bindings.consume-out-0.destination=${AZURE_SERVICEBUS_EMAIL_REQUEST_QUEUE_NAME}
32+
spring.cloud.stream.servicebus.bindings.consume-out-0.producer.entity-type=queue
33+
spring.cloud.function.definition=consume;
34+
1335
# Actuator
1436
management.endpoints.web.exposure.include=metrics,health,info,retry,retryevents
1537

@@ -43,4 +65,4 @@ resilience4j.retry.configs.default.retryExceptions[1]=java.lang.RuntimeException
4365
resilience4j.circuitbreaker.instances.servicePlan.baseConfig=default
4466

4567
#ServicePlan retry policy should use default config
46-
resilience4j.retry.instances.servicePlan.baseConfig=default
68+
resilience4j.retry.instances.servicePlan.baseConfig=default
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
create table support_guides(
2+
activity_type_id bigserial not null,
3+
description varchar(255) not null,
4+
name varchar(255) not null,
5+
url varchar(255) not null,
6+
primary key (activity_type_id)
7+
);
8+
9+
-- Sample Data
10+
insert into support_guides(activity_type_id, description, name, url) values (1, 'Instructions on how to reset your password', 'How to reset your password', 'https://www.contoso.com/password-reset.pdf');
11+
insert into support_guides(activity_type_id, description, name, url) values (2, 'Instructions on how to create a support ticket', 'How to open a support case', 'https://www.contoso.com/support-case.pdf');

apps/contoso-fiber/src/main/resources/templates/fragments/menu.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@
5353
<span>Service Plans</span>
5454
</a>
5555
</li>
56+
<li th:class="${#execInfo.templateNames[0] == 'pages/plans/list'} ? @{nav-item active} : @{nav-item}">
57+
<a class="nav-link" th:href=@{~/guides/list}>
58+
<i class="fas fa-fw fa-shapes"></i>
59+
<span>Support Guides</span>
60+
</a>
61+
</li>
5662
</div>

0 commit comments

Comments
 (0)