Skip to content

Commit ea63495

Browse files
committed
Add backoffice backend application
1 parent 98111bf commit ea63495

File tree

16 files changed

+120
-18
lines changed

16 files changed

+120
-18
lines changed

apps/main/tv/codely/apps/Starter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.WebApplicationType;
55
import org.springframework.context.ConfigurableApplicationContext;
6+
import tv.codely.apps.backoffice.backend.BackofficeBackendApplication;
67
import tv.codely.apps.backoffice.frontend.BackofficeFrontendApplication;
78
import tv.codely.apps.mooc.backend.MoocBackendApplication;
89
import tv.codely.shared.infrastructure.cli.ConsoleCommand;
@@ -67,6 +68,7 @@ private static HashMap<String, Class<?>> applications() {
6768
HashMap<String, Class<?>> applications = new HashMap<>();
6869

6970
applications.put("mooc_backend", MoocBackendApplication.class);
71+
applications.put("backoffice_backend", BackofficeBackendApplication.class);
7072
applications.put("backoffice_frontend", BackofficeFrontendApplication.class);
7173

7274
return applications;
@@ -76,6 +78,8 @@ private static HashMap<String, HashMap<String, Class<?>>> commands() {
7678
HashMap<String, HashMap<String, Class<?>>> commands = new HashMap<>();
7779

7880
commands.put("mooc_backend", MoocBackendApplication.commands());
81+
commands.put("backoffice_backend", BackofficeBackendApplication.commands());
82+
commands.put("backoffice_frontend", BackofficeFrontendApplication.commands());
7983

8084
return commands;
8185
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package tv.codely.apps.backoffice.backend;
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication;
4+
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
5+
import org.springframework.context.annotation.ComponentScan;
6+
import org.springframework.context.annotation.FilterType;
7+
import tv.codely.shared.domain.Service;
8+
9+
import java.util.HashMap;
10+
11+
@SpringBootApplication(exclude = HibernateJpaAutoConfiguration.class)
12+
@ComponentScan(
13+
includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Service.class),
14+
value = {"tv.codely.shared", "tv.codely.backoffice", "tv.codely.apps.backoffice.backend"}
15+
)
16+
public class BackofficeBackendApplication {
17+
public static HashMap<String, Class<?>> commands() {
18+
return new HashMap<String, Class<?>>() {{
19+
}};
20+
}
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package tv.codely.apps.backoffice.backend.config;
2+
3+
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
4+
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
5+
import org.springframework.stereotype.Component;
6+
import tv.codely.shared.infrastructure.config.Parameter;
7+
import tv.codely.shared.infrastructure.config.ParameterNotExist;
8+
9+
@Component
10+
public final class BackofficeBackendServerPortCustomizer implements WebServerFactoryCustomizer<ConfigurableWebServerFactory> {
11+
private final Parameter param;
12+
13+
public BackofficeBackendServerPortCustomizer(Parameter param) {
14+
this.param = param;
15+
}
16+
17+
@Override
18+
public void customize(ConfigurableWebServerFactory factory) {
19+
try {
20+
factory.setPort(param.getInt("BACKOFFICE_BACKEND_SERVER_PORT"));
21+
} catch (ParameterNotExist parameterNotExist) {
22+
parameterNotExist.printStackTrace();
23+
}
24+
}
25+
}

apps/main/tv/codely/apps/backoffice/backend/controller/.gitkeep

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package tv.codely.apps.backoffice.backend.controller.health_check;
2+
3+
import org.springframework.web.bind.annotation.GetMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
6+
import java.util.HashMap;
7+
8+
@RestController
9+
public final class HealthCheckGetController {
10+
@GetMapping("/health-check")
11+
public HashMap<String, String> index() {
12+
HashMap<String, String> status = new HashMap<>();
13+
status.put("application", "backoffice_backend");
14+
status.put("status", "ok");
15+
16+
return status;
17+
}
18+
}

apps/main/tv/codely/apps/backoffice/frontend/controller/health_check/HealthCheckGetController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public final class HealthCheckGetController {
1010
@GetMapping("/health-check")
1111
public HashMap<String, String> index() {
1212
HashMap<String, String> status = new HashMap<>();
13+
status.put("application", "backoffice_frontend");
1314
status.put("status", "ok");
1415

1516
return status;

apps/main/tv/codely/apps/mooc/backend/controller/health_check/HealthCheckGetController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
@RestController
99
public final class HealthCheckGetController {
10-
1110
@GetMapping("/health-check")
1211
public HashMap<String, String> index() {
1312
HashMap<String, String> status = new HashMap<>();
13+
status.put("application", "mooc_backend");
1414
status.put("status", "ok");
1515

1616
return status;
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
package tv.codely.apps.mooc.backend.controller;
1+
package tv.codely.apps;
22

3-
import org.hibernate.SessionFactory;
4-
import org.junit.jupiter.api.BeforeEach;
53
import org.junit.runner.RunWith;
64
import org.springframework.beans.factory.annotation.Autowired;
75
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
@@ -13,9 +11,7 @@
1311
import tv.codely.shared.domain.bus.event.DomainEvent;
1412
import tv.codely.shared.domain.bus.event.EventBus;
1513

16-
import javax.transaction.Transactional;
1714
import java.util.Arrays;
18-
import java.util.Collections;
1915

2016
import static org.springframework.http.MediaType.APPLICATION_JSON;
2117
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -26,7 +22,6 @@
2622
@RunWith(SpringRunner.class)
2723
@SpringBootTest
2824
@AutoConfigureMockMvc
29-
@Transactional
3025
public abstract class ApplicationTestCase {
3126
@Autowired
3227
private MockMvc mockMvc;
@@ -39,8 +34,8 @@ protected void assertResponse(
3934
String expectedResponse
4035
) throws Exception {
4136
ResultMatcher response = expectedResponse.isEmpty()
42-
? content().string("")
43-
: content().json(expectedResponse);
37+
? content().string("")
38+
: content().json(expectedResponse);
4439

4540
mockMvc
4641
.perform(get(endpoint))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package tv.codely.apps.backoffice;
2+
3+
import org.springframework.transaction.annotation.Transactional;
4+
import tv.codely.apps.ApplicationTestCase;
5+
6+
@Transactional("backoffice-transaction_manager")
7+
public abstract class BackofficeApplicationTestCase extends ApplicationTestCase {
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package tv.codely.apps.backoffice.backend.controller.health_check;
2+
3+
import org.junit.jupiter.api.Test;
4+
import tv.codely.apps.ApplicationTestCase;
5+
6+
final class HealthCheckGetControllerShould extends ApplicationTestCase {
7+
@Test
8+
void check_the_app_is_working_ok() throws Exception {
9+
assertResponse("/health-check", 200, "{'application':'backoffice_backend','status':'ok'}");
10+
}
11+
}

0 commit comments

Comments
 (0)