From 6532213d7fd8bae753d0c37e3c09c8f5163e9a08 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Wed, 6 Dec 2023 00:01:41 -0500 Subject: [PATCH 01/10] chore: minor update/adjust --- game-service/game/core.go | 2 +- simulator-script/simulator.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/game-service/game/core.go b/game-service/game/core.go index 8d5b313..9c1d858 100644 --- a/game-service/game/core.go +++ b/game-service/game/core.go @@ -45,7 +45,7 @@ func (app *App) StartGame(player *dto.PlayerDTO, location dto.PointDTO) error { } } }{} - if err := app.GetService("geo-service", fmt.Sprintf("/geo/trail?username=%s", strings.ToLower(player.Username)), &data); err != nil { + if err := app.GetService("geo-service", fmt.Sprintf("/geo/trail?username=%s", player.Username), &data); err != nil { return fmt.Errorf("get init trail failed: %v", err) } diff --git a/simulator-script/simulator.py b/simulator-script/simulator.py index 68bd1e0..259be2b 100644 --- a/simulator-script/simulator.py +++ b/simulator-script/simulator.py @@ -28,7 +28,7 @@ def simulate(base: str): pprint(r.json()) time.sleep(1) - with session.post(url=urljoin(base, '/player/set-location'), json={ + with session.post(url=urljoin(base, '/player/set-zone'), json={ "username": "leon", "zone": "mac" }) as r: @@ -44,11 +44,10 @@ def simulate(base: str): pprint(r.text) time.sleep(1) - x, y = (12, 13) + x, y = (13, 14) with session.post(url=urljoin(base, '/game/start'), json={ "username": "leon", - "zone": "mac", "location": { "x": x, "y": y, @@ -64,8 +63,9 @@ def simulate(base: str): for i in range(10): time.sleep(2) - x, y = x + random.randint(1, 10), y + random.randint(1, 10) + x, y = x + random.randint(2, 20), y + random.randint(2, 20) action = random.choice(('Escaping', 'Fighting', 'Sheltering')) + with session.post(url=urljoin(base, '/game/action'), json={ "username": "leon", "action": action, From 17d50b3748904c1c8eda6c2f6b9c1926a6ff950e Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Wed, 6 Dec 2023 01:06:29 -0500 Subject: [PATCH 02/10] chore: minor doc change --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9379ef3..4dd5070 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# MacRun Services +# MacRun! Services - [Project Assignment Description](.project-docs/Project_Assignment_Description.pdf) - [Case Study (Fall 23): ACME Run](.project-docs/Case_Study_Fall2023.pdf) From 2baf72b65ed94c86c24e730685150e7351ab4e0f Mon Sep 17 00:00:00 2001 From: Jason Lyu Date: Wed, 6 Dec 2023 01:31:46 -0500 Subject: [PATCH 03/10] chore: only ci is used --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4dd5070..1b21c34 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ - API Gateway ([Caddy](https://caddyserver.com/)) - Health Check ([Docker](https://www.docker.com/)) - Session Cache ([Redis](https://redis.io/)) -- Build Test CI/CD ([Actions](https://github.com/features/actions)) +- Build Test CI ([Actions](https://github.com/features/actions)) - Service Discovery ([Nacos](https://nacos.io/en-us/)) - Message Queue ([RabbitMQ](https://www.rabbitmq.com/)) @@ -142,7 +142,7 @@ python3 ./simulator.py 127.0.0.1:8080 ### Auto Test -We automate the testing of our services using GitHub Actions (CI/CD). You can view the test results at: +We automate the testing of our services using GitHub Actions CI. You can view the test results at: - From 7817f907b2e53dce2cc9daa2d5130967adaf6328 Mon Sep 17 00:00:00 2001 From: J1aM1ng Date: Wed, 6 Dec 2023 02:00:05 -0500 Subject: [PATCH 04/10] test: tests for badge service --- challenge-service/pom.xml | 7 + .../BadgeControllerTests.java | 84 +++++++++++ .../challengeservice/BadgeServiceTests.java | 100 +++++++++++++ .../ChallengeControllerTests.java | 136 +++++++++--------- geo-service/pom.xml | 7 + 5 files changed, 267 insertions(+), 67 deletions(-) create mode 100644 challenge-service/src/test/java/com/cas/challengeservice/BadgeControllerTests.java create mode 100644 challenge-service/src/test/java/com/cas/challengeservice/BadgeServiceTests.java diff --git a/challenge-service/pom.xml b/challenge-service/pom.xml index 37715dc..c4dcc61 100644 --- a/challenge-service/pom.xml +++ b/challenge-service/pom.xml @@ -81,6 +81,13 @@ 2.12.3 + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.2.0 + + com.alibaba.cloud diff --git a/challenge-service/src/test/java/com/cas/challengeservice/BadgeControllerTests.java b/challenge-service/src/test/java/com/cas/challengeservice/BadgeControllerTests.java new file mode 100644 index 0000000..8e9dc42 --- /dev/null +++ b/challenge-service/src/test/java/com/cas/challengeservice/BadgeControllerTests.java @@ -0,0 +1,84 @@ +package com.cas.challengeservice; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +import com.cas.challengeservice.controller.BadgeController; +import com.cas.challengeservice.dto.*; +import com.cas.challengeservice.service.BadgeService; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +@SpringBootTest +public class BadgeControllerTests { + @Mock + private BadgeService badgeService; + @InjectMocks + private BadgeController badgeController; + + private String challenge; + private String username; + private String badgeName; + + private GenericMessage message; + private BadgeGetRequest badgeGetRequest; + private BadgeAddRequest badgeAddRequest; + private BadgeDeleteRequest badgeDeleteRequest; + + @BeforeEach + public void setUp() { + challenge = "Balance"; + username = "JohnDoe"; + badgeName = "BalanceMaster"; + + badgeGetRequest = BadgeGetRequest.builder().challenge(challenge).username(username).build(); + badgeAddRequest = BadgeAddRequest.builder().challenge(challenge).username(username).badgeName(badgeName).build(); + badgeDeleteRequest = BadgeDeleteRequest.builder().challenge(challenge).username(username).build(); + + message = GenericMessage.builder() + .status(HttpStatus.OK) + .message("Badge Response") + .build(); + } + + @Test + public void testGetBadgeList() { + when(badgeService.getBadgeList(any())).thenReturn(new GenericMessage>(HttpStatus.OK, "Badge List Response", new ArrayList<>())); + + ResponseEntity>> responseEntity = + badgeController.getBadgeList(challenge, username); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + verify(badgeService, times(1)).getBadgeList(any()); + } + + @Test + public void testAddBadge() { + when(badgeService.addBadge(any())).thenReturn(message); + + ResponseEntity> responseEntity = + badgeController.addBadge(badgeAddRequest); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + verify(badgeService, times(1)).addBadge(any()); + } + + @Test + public void testDeleteBadge() { + when(badgeService.deleteBadge(any())).thenReturn(message); + + ResponseEntity> responseEntity = + badgeController.deleteBadge(badgeDeleteRequest); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + verify(badgeService, times(1)).deleteBadge(any()); + } +} diff --git a/challenge-service/src/test/java/com/cas/challengeservice/BadgeServiceTests.java b/challenge-service/src/test/java/com/cas/challengeservice/BadgeServiceTests.java new file mode 100644 index 0000000..9143e7d --- /dev/null +++ b/challenge-service/src/test/java/com/cas/challengeservice/BadgeServiceTests.java @@ -0,0 +1,100 @@ +package com.cas.challengeservice; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; + +import com.cas.challengeservice.dto.*; +import com.cas.challengeservice.entity.Badge; +import com.cas.challengeservice.repository.BadgeRepository; +import com.cas.challengeservice.service.Impl.BadgeServiceImpl; +import java.util.Optional; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class BadgeServiceTests { + @Mock + private BadgeRepository badgeRepository; + @InjectMocks + private BadgeServiceImpl badgeServiceImpl; + + private BadgeGetRequest badgeGetRequest; + private BadgeAddRequest badgeAddRequest; + private BadgeDeleteRequest badgeDeleteRequest; + @BeforeEach + public void setUp() { + badgeGetRequest = new BadgeGetRequest("challengeType","username"); + badgeAddRequest = new BadgeAddRequest("challengeType","username","badgeName"); + badgeDeleteRequest = new BadgeDeleteRequest("challengeType","username","badgeName"); + } + @Test + public void testGetBadgeListWhenBadgeNotFound() { + when(badgeRepository.findAllByChallengeAndUsername(any(),any())).thenReturn(new ArrayList<>()); + + GenericMessage> result = badgeServiceImpl.getBadgeList(badgeGetRequest); + + assertEquals(HttpStatus.NOT_FOUND, result.getStatus()); + assertEquals("No badges associated with this challenge and user", result.getMessage()); + } + + @Test + public void testGetBadgeListSuccess() { + List badges = new ArrayList<>(); + badges.add(new Badge(1L, "challenge", "username", "badgeName")); + when(badgeRepository.findAllByChallengeAndUsername(any(),any())).thenReturn(badges); + + GenericMessage> result = badgeServiceImpl.getBadgeList(badgeGetRequest); + + assertEquals(HttpStatus.OK, result.getStatus()); + assertEquals("Badges found successfully, and returned", result.getMessage()); + } + + @Test + public void testAddBadgeWhenBadgeExist() { + Badge badge = new Badge(1L, "challenge", "username", "badgeName"); + when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(),any(),any())).thenReturn(Optional.of(badge)); + + GenericMessage result = badgeServiceImpl.addBadge(badgeAddRequest); + + assertEquals(HttpStatus.CONFLICT, result.getStatus()); + assertEquals("Badge already exists.", result.getMessage()); + } + + @Test + public void testAddBadgeSuccess() { + when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(),any(),any())).thenReturn(Optional.empty()); + + GenericMessage result = badgeServiceImpl.addBadge(badgeAddRequest); + + assertEquals(HttpStatus.CREATED, result.getStatus()); + assertEquals("Badge added successfully", result.getMessage()); + } + + @Test + public void testDeleteBadgeWhenBadgeNotFound() { + when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(),any(),any())).thenReturn(Optional.empty()); + + GenericMessage result = badgeServiceImpl.deleteBadge(badgeDeleteRequest); + + assertEquals(HttpStatus.NOT_FOUND, result.getStatus()); + assertEquals("Badge not found", result.getMessage()); + } + + @Test + public void testDeleteBadgeSuccess() { + Badge badge = new Badge(1L, "challenge", "username", "badgeName"); + when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(),any(),any())).thenReturn(Optional.of(badge)); + + GenericMessage result = badgeServiceImpl.deleteBadge(badgeDeleteRequest); + + assertEquals(HttpStatus.OK, result.getStatus()); + assertEquals("Badge deleted successfully", result.getMessage()); + } +} diff --git a/challenge-service/src/test/java/com/cas/challengeservice/ChallengeControllerTests.java b/challenge-service/src/test/java/com/cas/challengeservice/ChallengeControllerTests.java index 84ae9cb..0967811 100644 --- a/challenge-service/src/test/java/com/cas/challengeservice/ChallengeControllerTests.java +++ b/challenge-service/src/test/java/com/cas/challengeservice/ChallengeControllerTests.java @@ -1,4 +1,3 @@ -/* (C)2023 */ package com.cas.challengeservice; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -18,70 +17,73 @@ @SpringBootTest public class ChallengeControllerTests { - @Mock private ChallengeService challengeService; - @InjectMocks private ChallengeController challengeController; - private Long userHeartRate; - private Long exerciseCount; - private String type; - - private GenericMessage message; - private ChallengeGetRequest challengeGetRequest; - private ChallengeAddRequest challengeAddRequest; - private ChallengeDeleteRequest challengeDeleteRequest; - - @BeforeEach - public void setUp() { - userHeartRate = 70L; - type = "Balance"; - exerciseCount = 30L; - - challengeGetRequest = - ChallengeGetRequest.builder().userHeartRate(userHeartRate).type(type).build(); - challengeAddRequest = - ChallengeAddRequest.builder() - .userHeartRate(userHeartRate) - .exerciseCount(exerciseCount) - .type(type) - .build(); - challengeDeleteRequest = ChallengeDeleteRequest.builder().type(type).build(); - - message = - GenericMessage.builder() - .status(HttpStatus.OK) - .message("Challenge Response") - .build(); - } - - @Test - public void testGetChallenge() { - when(challengeService.getChallenge(any())).thenReturn(message); - - ResponseEntity> responseEntity = - challengeController.getChallenge(userHeartRate, type); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - verify(challengeService, times(1)).getChallenge(any()); - } - - @Test - public void testAddChallenge() { - when(challengeService.addChallenge(any())).thenReturn(message); - - ResponseEntity> responseEntity = - challengeController.addChallenge(challengeAddRequest); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - verify(challengeService, times(1)).addChallenge(any()); - } - - @Test - public void testDeleteChallenge() { - when(challengeService.deleteChallenge(any())).thenReturn(message); - - ResponseEntity> responseEntity = - challengeController.deleteChallenge(challengeDeleteRequest); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - verify(challengeService, times(1)).deleteChallenge(any()); - } + + @Mock + private ChallengeService challengeService; + @InjectMocks + private ChallengeController challengeController; + private Long userHeartRate; + private Long exerciseCount; + private String type; + + private GenericMessage message; + private ChallengeGetRequest challengeGetRequest; + private ChallengeAddRequest challengeAddRequest; + private ChallengeDeleteRequest challengeDeleteRequest; + + @BeforeEach + public void setUp() { + userHeartRate = 70L; + type = "Balance"; + exerciseCount = 30L; + + challengeGetRequest = + ChallengeGetRequest.builder().userHeartRate(userHeartRate).type(type).build(); + challengeAddRequest = + ChallengeAddRequest.builder() + .userHeartRate(userHeartRate) + .exerciseCount(exerciseCount) + .type(type) + .build(); + challengeDeleteRequest = ChallengeDeleteRequest.builder().type(type).build(); + + message = + GenericMessage.builder() + .status(HttpStatus.OK) + .message("Challenge Response") + .build(); + } + + @Test + public void testGetChallenge() { + when(challengeService.getChallenge(any())).thenReturn(message); + + ResponseEntity> responseEntity = + challengeController.getChallenge(userHeartRate, type); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + verify(challengeService, times(1)).getChallenge(any()); + } + + @Test + public void testAddChallenge() { + when(challengeService.addChallenge(any())).thenReturn(message); + + ResponseEntity> responseEntity = + challengeController.addChallenge(challengeAddRequest); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + verify(challengeService, times(1)).addChallenge(any()); + } + + @Test + public void testDeleteChallenge() { + when(challengeService.deleteChallenge(any())).thenReturn(message); + + ResponseEntity> responseEntity = + challengeController.deleteChallenge(challengeDeleteRequest); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + verify(challengeService, times(1)).deleteChallenge(any()); + } } diff --git a/geo-service/pom.xml b/geo-service/pom.xml index 8b07137..9aa58fa 100644 --- a/geo-service/pom.xml +++ b/geo-service/pom.xml @@ -86,6 +86,13 @@ 2.12.3 + + + org.springdoc + springdoc-openapi-starter-webmvc-ui + 2.2.0 + + com.alibaba.cloud From ea5f7a5210f61ed735b1dc8446735072ea04bfa0 Mon Sep 17 00:00:00 2001 From: J1aM1ng Date: Wed, 6 Dec 2023 02:11:29 -0500 Subject: [PATCH 05/10] style: lint --- .../config/BadgeListener.java | 49 ++--- .../config/RabbitMQConfig.java | 120 ++++++------ .../challengeservice/constant/Constants.java | 3 +- .../controller/BadgeController.java | 47 ++--- .../controller/ChallengeController.java | 49 ++--- .../challengeservice/dto/BadgeAddRequest.java | 7 +- .../dto/BadgeDeleteRequest.java | 7 +- .../cas/challengeservice/dto/BadgeDto.java | 9 +- .../challengeservice/dto/BadgeGetRequest.java | 5 +- .../dto/ChallengeAddRequest.java | 7 +- .../dto/ChallengeDeleteRequest.java | 3 +- .../dto/ChallengeGetRequest.java | 5 +- .../dto/ChallengeTypeDto.java | 9 +- .../challengeservice/dto/GenericMessage.java | 8 +- .../cas/challengeservice/dto/MessageDto.java | 10 +- .../cas/challengeservice/entity/Badge.java | 29 +-- .../entity/ChallengeType.java | 27 +-- .../repository/BadgeRepository.java | 7 +- .../repository/ChallengeTypeRepository.java | 11 +- .../service/BadgeService.java | 7 +- .../service/ChallengeService.java | 7 +- .../service/Impl/BadgeServiceImpl.java | 135 ++++++------- .../service/Impl/ChallengeServiceImpl.java | 183 +++++++++--------- .../service/Impl/MessageServiceImpl.java | 23 +-- .../service/MessageService.java | 3 +- .../BadgeControllerTests.java | 11 +- .../challengeservice/BadgeServiceTests.java | 26 ++- .../ChallengeServiceTests.java | 9 +- .../cas/geoservice/config/RabbitMQConfig.java | 120 ++++++------ .../cas/geoservice/config/ZoneListener.java | 83 ++++---- .../cas/geoservice/constant/Constants.java | 3 +- .../controller/TrailController.java | 23 +-- .../cas/geoservice/dto/GenericMessage.java | 8 +- .../com/cas/geoservice/dto/MessageDto.java | 10 +- .../java/com/cas/geoservice/dto/PlaceDto.java | 13 +- .../geoservice/dto/PlayerSetZoneRequest.java | 5 +- .../java/com/cas/geoservice/dto/TrailDto.java | 7 +- .../cas/geoservice/dto/TrailGetRequest.java | 3 +- .../java/com/cas/geoservice/entity/Place.java | 41 ++-- .../com/cas/geoservice/entity/PlayerZone.java | 13 +- .../java/com/cas/geoservice/entity/Trail.java | 21 +- .../repository/PlaceRepository.java | 4 +- .../repository/PlayerZoneRepository.java | 3 +- .../repository/TrailRepository.java | 3 +- .../service/Impl/MessageServiceImpl.java | 23 +-- .../service/Impl/TrailServiceImpl.java | 71 +++---- .../geoservice/service/MessageService.java | 3 +- .../cas/geoservice/service/TrailService.java | 3 +- .../cas/geoservice/TrailControllerTests.java | 54 +++--- .../com/cas/geoservice/TrailServiceTests.java | 6 +- 50 files changed, 707 insertions(+), 629 deletions(-) diff --git a/challenge-service/src/main/java/com/cas/challengeservice/config/BadgeListener.java b/challenge-service/src/main/java/com/cas/challengeservice/config/BadgeListener.java index d27e8ca..7195dbf 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/config/BadgeListener.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/config/BadgeListener.java @@ -16,32 +16,33 @@ @Component @Log4j2 public class BadgeListener implements MessageListener { - private BadgeService badgeService; - private ObjectMapper objectMapper; + private BadgeService badgeService; - @Autowired - public BadgeListener(BadgeService badgeService) { - this.badgeService = badgeService; - objectMapper = new ObjectMapper(); - } + private ObjectMapper objectMapper; + + @Autowired + public BadgeListener(BadgeService badgeService) { + this.badgeService = badgeService; + objectMapper = new ObjectMapper(); + } + + @Override + public void onMessage(Message message) { + try { + String messageBody = new String(message.getBody()); + log.info("Received message: " + messageBody); + + MessageDto messageDto = objectMapper.readValue(messageBody, MessageDto.class); - @Override - public void onMessage(Message message) { - try { - String messageBody = new String(message.getBody()); - log.info("Received message: " + messageBody); - - MessageDto messageDto = objectMapper.readValue(messageBody, MessageDto.class); - - switch (messageDto.getAction()) { - case MQ_REQUEST_ADD_BADGE: - log.info("MQ - Adding badge: {}", messageDto.getBadgeAddRequest()); - BadgeAddRequest badgeAddRequest = messageDto.getBadgeAddRequest(); - badgeService.addBadge(badgeAddRequest); - } - } catch (Exception e) { - e.printStackTrace(); - } + switch (messageDto.getAction()) { + case MQ_REQUEST_ADD_BADGE: + log.info("MQ - Adding badge: {}", messageDto.getBadgeAddRequest()); + BadgeAddRequest badgeAddRequest = messageDto.getBadgeAddRequest(); + badgeService.addBadge(badgeAddRequest); + } + } catch (Exception e) { + e.printStackTrace(); } + } } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/config/RabbitMQConfig.java b/challenge-service/src/main/java/com/cas/challengeservice/config/RabbitMQConfig.java index f238aba..41c9ae7 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/config/RabbitMQConfig.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/config/RabbitMQConfig.java @@ -17,63 +17,65 @@ @Configuration public class RabbitMQConfig { - @Value("${spring.rabbitmq.host}") - private String host; - - @Value("${spring.rabbitmq.port}") - private int port; - - @Value("${spring.rabbitmq.username}") - private String username; - - @Value("${spring.rabbitmq.password}") - private String password; - - @Value("${spring.rabbitmq.exchange}") - private String exchangeName; - - @Value("${spring.rabbitmq.queue}") - private String queueName; - - @Autowired private BadgeListener badgeListener; - - @Bean - public ConnectionFactory connectionFactory() { - CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); - connectionFactory.setHost(host); - connectionFactory.setPort(port); - connectionFactory.setUsername(username); - connectionFactory.setPassword(password); - return connectionFactory; - } - - @Bean - public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) { - return new RabbitTemplate(connectionFactory); - } - - @Bean - public TopicExchange topicExchange() { - return new TopicExchange(exchangeName); - } - - @Bean - public Queue challengeQueue() { - return new Queue(queueName, true); - } - - @Bean - public SimpleMessageListenerContainer badgeListenerContainer( - ConnectionFactory connectionFactory, - @Qualifier("challengeQueue") Queue queue, - @Qualifier("topicExchange") TopicExchange exchange) { - - SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); - container.setConnectionFactory(connectionFactory); - container.setQueues(queue); - container.setMessageListener(badgeListener); - - Binding binding = BindingBuilder.bind(queue).to(exchange).with("#"); - return container; - } + + @Value("${spring.rabbitmq.host}") + private String host; + + @Value("${spring.rabbitmq.port}") + private int port; + + @Value("${spring.rabbitmq.username}") + private String username; + + @Value("${spring.rabbitmq.password}") + private String password; + + @Value("${spring.rabbitmq.exchange}") + private String exchangeName; + + @Value("${spring.rabbitmq.queue}") + private String queueName; + + @Autowired + private BadgeListener badgeListener; + + @Bean + public ConnectionFactory connectionFactory() { + CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); + connectionFactory.setHost(host); + connectionFactory.setPort(port); + connectionFactory.setUsername(username); + connectionFactory.setPassword(password); + return connectionFactory; + } + + @Bean + public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) { + return new RabbitTemplate(connectionFactory); + } + + @Bean + public TopicExchange topicExchange() { + return new TopicExchange(exchangeName); + } + + @Bean + public Queue challengeQueue() { + return new Queue(queueName, true); + } + + @Bean + public SimpleMessageListenerContainer badgeListenerContainer( + ConnectionFactory connectionFactory, + @Qualifier("challengeQueue") Queue queue, + @Qualifier("topicExchange") TopicExchange exchange) { + + SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); + container.setConnectionFactory(connectionFactory); + container.setQueues(queue); + container.setMessageListener(badgeListener); + + Binding binding = BindingBuilder.bind(queue).to(exchange).with("#"); + return container; + } } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/constant/Constants.java b/challenge-service/src/main/java/com/cas/challengeservice/constant/Constants.java index 3cf78c6..ff66eb4 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/constant/Constants.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/constant/Constants.java @@ -2,5 +2,6 @@ package com.cas.challengeservice.constant; public class Constants { - public static final String MQ_REQUEST_ADD_BADGE = "ADD_BADGE"; + + public static final String MQ_REQUEST_ADD_BADGE = "ADD_BADGE"; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/controller/BadgeController.java b/challenge-service/src/main/java/com/cas/challengeservice/controller/BadgeController.java index c19d1f1..a223bc8 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/controller/BadgeController.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/controller/BadgeController.java @@ -11,31 +11,32 @@ @RestController @RequestMapping(value = "/badge") public class BadgeController { - private final BadgeService badgeService; - @Autowired - public BadgeController(BadgeService badgeService) { - this.badgeService = badgeService; - } + private final BadgeService badgeService; - @GetMapping("/list") - public ResponseEntity>> getBadgeList( - @RequestParam String challenge, @RequestParam String username) { - BadgeGetRequest request = new BadgeGetRequest(challenge, username); - GenericMessage> response = badgeService.getBadgeList(request); - return ResponseEntity.status(response.getStatus()).body(response); - } + @Autowired + public BadgeController(BadgeService badgeService) { + this.badgeService = badgeService; + } - @RequestMapping(method = RequestMethod.POST) - public ResponseEntity> addBadge(@RequestBody BadgeAddRequest request) { - GenericMessage response = badgeService.addBadge(request); - return ResponseEntity.status(response.getStatus()).body(response); - } + @GetMapping("/list") + public ResponseEntity>> getBadgeList( + @RequestParam String challenge, @RequestParam String username) { + BadgeGetRequest request = new BadgeGetRequest(challenge, username); + GenericMessage> response = badgeService.getBadgeList(request); + return ResponseEntity.status(response.getStatus()).body(response); + } - @RequestMapping(method = RequestMethod.DELETE) - public ResponseEntity> deleteBadge( - @RequestBody BadgeDeleteRequest request) { - GenericMessage response = badgeService.deleteBadge(request); - return ResponseEntity.status(response.getStatus()).body(response); - } + @RequestMapping(method = RequestMethod.POST) + public ResponseEntity> addBadge(@RequestBody BadgeAddRequest request) { + GenericMessage response = badgeService.addBadge(request); + return ResponseEntity.status(response.getStatus()).body(response); + } + + @RequestMapping(method = RequestMethod.DELETE) + public ResponseEntity> deleteBadge( + @RequestBody BadgeDeleteRequest request) { + GenericMessage response = badgeService.deleteBadge(request); + return ResponseEntity.status(response.getStatus()).body(response); + } } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/controller/ChallengeController.java b/challenge-service/src/main/java/com/cas/challengeservice/controller/ChallengeController.java index e47922c..8f1bf2d 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/controller/ChallengeController.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/controller/ChallengeController.java @@ -10,32 +10,33 @@ @RestController @RequestMapping(value = "/challenge") public class ChallengeController { - private final ChallengeService challengeService; - @Autowired - public ChallengeController(ChallengeService challengeService) { - this.challengeService = challengeService; - } + private final ChallengeService challengeService; - @RequestMapping(method = RequestMethod.GET) - public ResponseEntity> getChallenge( - @RequestParam Long userHeartRate, @RequestParam String type) { - ChallengeGetRequest request = new ChallengeGetRequest(userHeartRate, type); - GenericMessage response = challengeService.getChallenge(request); - return ResponseEntity.status(response.getStatus()).body(response); - } + @Autowired + public ChallengeController(ChallengeService challengeService) { + this.challengeService = challengeService; + } - @RequestMapping(method = RequestMethod.POST) - public ResponseEntity> addChallenge( - @RequestBody ChallengeAddRequest request) { - GenericMessage response = challengeService.addChallenge(request); - return ResponseEntity.status(response.getStatus()).body(response); - } + @RequestMapping(method = RequestMethod.GET) + public ResponseEntity> getChallenge( + @RequestParam Long userHeartRate, @RequestParam String type) { + ChallengeGetRequest request = new ChallengeGetRequest(userHeartRate, type); + GenericMessage response = challengeService.getChallenge(request); + return ResponseEntity.status(response.getStatus()).body(response); + } - @RequestMapping(method = RequestMethod.DELETE) - public ResponseEntity> deleteChallenge( - @RequestBody ChallengeDeleteRequest request) { - GenericMessage response = challengeService.deleteChallenge(request); - return ResponseEntity.status(response.getStatus()).body(response); - } + @RequestMapping(method = RequestMethod.POST) + public ResponseEntity> addChallenge( + @RequestBody ChallengeAddRequest request) { + GenericMessage response = challengeService.addChallenge(request); + return ResponseEntity.status(response.getStatus()).body(response); + } + + @RequestMapping(method = RequestMethod.DELETE) + public ResponseEntity> deleteChallenge( + @RequestBody ChallengeDeleteRequest request) { + GenericMessage response = challengeService.deleteChallenge(request); + return ResponseEntity.status(response.getStatus()).body(response); + } } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeAddRequest.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeAddRequest.java index 3336e3d..b33be96 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeAddRequest.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeAddRequest.java @@ -10,7 +10,8 @@ @NoArgsConstructor @EqualsAndHashCode public class BadgeAddRequest { - private String challenge; - private String username; - private String badgeName; + + private String challenge; + private String username; + private String badgeName; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeDeleteRequest.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeDeleteRequest.java index 9dc4916..b1d20be 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeDeleteRequest.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeDeleteRequest.java @@ -8,7 +8,8 @@ @NoArgsConstructor @Builder(toBuilder = true) public class BadgeDeleteRequest { - private String challenge; - private String username; - private String badgeName; + + private String challenge; + private String username; + private String badgeName; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeDto.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeDto.java index d351991..646701b 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeDto.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeDto.java @@ -10,8 +10,9 @@ @NoArgsConstructor @EqualsAndHashCode public class BadgeDto { - private Long id; - private String challenge; - private String username; - private String badgeName; + + private Long id; + private String challenge; + private String username; + private String badgeName; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeGetRequest.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeGetRequest.java index 7a632ad..f0ca03d 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeGetRequest.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/BadgeGetRequest.java @@ -10,6 +10,7 @@ @NoArgsConstructor @EqualsAndHashCode public class BadgeGetRequest { - private String challenge; - private String username; + + private String challenge; + private String username; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeAddRequest.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeAddRequest.java index 74c75b3..f5a6e93 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeAddRequest.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeAddRequest.java @@ -8,7 +8,8 @@ @NoArgsConstructor @Builder(toBuilder = true) public class ChallengeAddRequest { - private Long userHeartRate; - private Long exerciseCount; - private String type; + + private Long userHeartRate; + private Long exerciseCount; + private String type; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeDeleteRequest.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeDeleteRequest.java index 0e43c39..763c7a2 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeDeleteRequest.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeDeleteRequest.java @@ -8,5 +8,6 @@ @NoArgsConstructor @Builder(toBuilder = true) public class ChallengeDeleteRequest { - private String type; + + private String type; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeGetRequest.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeGetRequest.java index a40372f..1ece5be 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeGetRequest.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeGetRequest.java @@ -10,6 +10,7 @@ @NoArgsConstructor @EqualsAndHashCode public class ChallengeGetRequest { - private Long userHeartRate; - private String type; + + private Long userHeartRate; + private String type; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeTypeDto.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeTypeDto.java index ae9f07e..b20d5ed 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeTypeDto.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/ChallengeTypeDto.java @@ -10,8 +10,9 @@ @NoArgsConstructor @EqualsAndHashCode public class ChallengeTypeDto { - private Long id; - private String description; - private Long userHeartRate; - private Long exerciseCount; + + private Long id; + private String description; + private Long userHeartRate; + private Long exerciseCount; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/GenericMessage.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/GenericMessage.java index 7795a93..a69ebfa 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/GenericMessage.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/GenericMessage.java @@ -11,7 +11,9 @@ @EqualsAndHashCode @Builder(toBuilder = true) public class GenericMessage { - private HttpStatusCode status; - private String message; - @Nullable private T data; + + private HttpStatusCode status; + private String message; + @Nullable + private T data; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/dto/MessageDto.java b/challenge-service/src/main/java/com/cas/challengeservice/dto/MessageDto.java index b98ce2d..6853e78 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/dto/MessageDto.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/dto/MessageDto.java @@ -10,7 +10,11 @@ @EqualsAndHashCode @Builder(toBuilder = true) public class MessageDto { - @NonNull private BadgeAddRequest badgeAddRequest; - @NonNull private String action; - @Nullable private String message; + + @NonNull + private BadgeAddRequest badgeAddRequest; + @NonNull + private String action; + @Nullable + private String message; } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/entity/Badge.java b/challenge-service/src/main/java/com/cas/challengeservice/entity/Badge.java index aa3d0da..80e4fb2 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/entity/Badge.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/entity/Badge.java @@ -10,20 +10,21 @@ @NoArgsConstructor @AllArgsConstructor public class Badge { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String challenge; - private String username; - private String badgeName; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - public BadgeDto toDto() { - return BadgeDto.builder() - .id(this.id) - .challenge(this.challenge) - .username(this.username) - .badgeName(this.badgeName) - .build(); - } + private String challenge; + private String username; + private String badgeName; + + public BadgeDto toDto() { + return BadgeDto.builder() + .id(this.id) + .challenge(this.challenge) + .username(this.username) + .badgeName(this.badgeName) + .build(); + } } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/entity/ChallengeType.java b/challenge-service/src/main/java/com/cas/challengeservice/entity/ChallengeType.java index 3a367ef..cadea7c 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/entity/ChallengeType.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/entity/ChallengeType.java @@ -13,19 +13,20 @@ @Table @Entity public class ChallengeType { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String description; - private Long userHeartRate; - private Long exerciseCount; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - public ChallengeTypeDto toDto() { - return ChallengeTypeDto.builder() - .description(description) - .userHeartRate(userHeartRate) - .exerciseCount(exerciseCount) - .build(); - } + private String description; + private Long userHeartRate; + private Long exerciseCount; + + public ChallengeTypeDto toDto() { + return ChallengeTypeDto.builder() + .description(description) + .userHeartRate(userHeartRate) + .exerciseCount(exerciseCount) + .build(); + } } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/repository/BadgeRepository.java b/challenge-service/src/main/java/com/cas/challengeservice/repository/BadgeRepository.java index ceab5fe..a6641dc 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/repository/BadgeRepository.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/repository/BadgeRepository.java @@ -7,8 +7,9 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface BadgeRepository extends JpaRepository { - List findAllByChallengeAndUsername(String challenge, String username); - Optional findByChallengeAndUsernameAndBadgeName( - String challenge, String username, String badgeName); + List findAllByChallengeAndUsername(String challenge, String username); + + Optional findByChallengeAndUsernameAndBadgeName( + String challenge, String username, String badgeName); } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/repository/ChallengeTypeRepository.java b/challenge-service/src/main/java/com/cas/challengeservice/repository/ChallengeTypeRepository.java index cd49744..0e600f3 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/repository/ChallengeTypeRepository.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/repository/ChallengeTypeRepository.java @@ -6,11 +6,12 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface ChallengeTypeRepository extends JpaRepository { - Optional findByDescriptionAndUserHeartRateAndExerciseCount( - String description, Long userHeartRate, Long exerciseCount); - Optional findByDescriptionAndUserHeartRate( - String description, Long userHeartRate); + Optional findByDescriptionAndUserHeartRateAndExerciseCount( + String description, Long userHeartRate, Long exerciseCount); - Optional findByDescription(String description); + Optional findByDescriptionAndUserHeartRate( + String description, Long userHeartRate); + + Optional findByDescription(String description); } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/service/BadgeService.java b/challenge-service/src/main/java/com/cas/challengeservice/service/BadgeService.java index b1d5902..c7d9e2b 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/service/BadgeService.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/service/BadgeService.java @@ -5,9 +5,10 @@ import java.util.List; public interface BadgeService { - public GenericMessage> getBadgeList(BadgeGetRequest request); - public GenericMessage addBadge(BadgeAddRequest request); + public GenericMessage> getBadgeList(BadgeGetRequest request); - public GenericMessage deleteBadge(BadgeDeleteRequest request); + public GenericMessage addBadge(BadgeAddRequest request); + + public GenericMessage deleteBadge(BadgeDeleteRequest request); } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/service/ChallengeService.java b/challenge-service/src/main/java/com/cas/challengeservice/service/ChallengeService.java index 13ee9b9..b633d3a 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/service/ChallengeService.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/service/ChallengeService.java @@ -4,9 +4,10 @@ import com.cas.challengeservice.dto.*; public interface ChallengeService { - GenericMessage getChallenge(ChallengeGetRequest request); - GenericMessage addChallenge(ChallengeAddRequest request); + GenericMessage getChallenge(ChallengeGetRequest request); - GenericMessage deleteChallenge(ChallengeDeleteRequest request); + GenericMessage addChallenge(ChallengeAddRequest request); + + GenericMessage deleteChallenge(ChallengeDeleteRequest request); } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/BadgeServiceImpl.java b/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/BadgeServiceImpl.java index 3a35bd0..6c86a4e 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/BadgeServiceImpl.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/BadgeServiceImpl.java @@ -15,84 +15,85 @@ @Component public class BadgeServiceImpl implements BadgeService { - private final BadgeRepository badgeRepository; - @Autowired - public BadgeServiceImpl(BadgeRepository badgeRepository) { - this.badgeRepository = badgeRepository; - } - - @Override - public GenericMessage> getBadgeList(BadgeGetRequest request) { - List matchingBadges = - badgeRepository.findAllByChallengeAndUsername( - request.getChallenge(), request.getUsername()); + private final BadgeRepository badgeRepository; - if (matchingBadges.isEmpty()) { - return GenericMessage.>builder() - .status(HttpStatus.NOT_FOUND) - .message("No badges associated with this challenge and user") - .build(); - } else { - // Convert list of Badge to list of BadgeDto - List badgeDtoList = - matchingBadges.stream().map(Badge::toDto).collect(Collectors.toList()); + @Autowired + public BadgeServiceImpl(BadgeRepository badgeRepository) { + this.badgeRepository = badgeRepository; + } - return GenericMessage.>builder() - .status(HttpStatus.OK) - .message("Badges found successfully, and returned") - .data(badgeDtoList) - .build(); - } - } + @Override + public GenericMessage> getBadgeList(BadgeGetRequest request) { + List matchingBadges = + badgeRepository.findAllByChallengeAndUsername( + request.getChallenge(), request.getUsername()); - @Override - public GenericMessage addBadge(BadgeAddRequest request) { - Optional existingBadge = - badgeRepository.findByChallengeAndUsernameAndBadgeName( - request.getChallenge(), request.getUsername(), request.getBadgeName()); + if (matchingBadges.isEmpty()) { + return GenericMessage.>builder() + .status(HttpStatus.NOT_FOUND) + .message("No badges associated with this challenge and user") + .build(); + } else { + // Convert list of Badge to list of BadgeDto + List badgeDtoList = + matchingBadges.stream().map(Badge::toDto).collect(Collectors.toList()); - if (existingBadge.isPresent()) { - return GenericMessage.builder() - .status(HttpStatus.CONFLICT) - .message("Badge already exists.") - .build(); - } + return GenericMessage.>builder() + .status(HttpStatus.OK) + .message("Badges found successfully, and returned") + .data(badgeDtoList) + .build(); + } + } - Badge newBadge = - new Badge( - new Random().nextLong(), - request.getChallenge(), - request.getUsername(), - request.getBadgeName()); - badgeRepository.save(newBadge); + @Override + public GenericMessage addBadge(BadgeAddRequest request) { + Optional existingBadge = + badgeRepository.findByChallengeAndUsernameAndBadgeName( + request.getChallenge(), request.getUsername(), request.getBadgeName()); - return GenericMessage.builder() - .status(HttpStatus.CREATED) - .message("Badge added successfully") - .data(newBadge.toDto()) - .build(); + if (existingBadge.isPresent()) { + return GenericMessage.builder() + .status(HttpStatus.CONFLICT) + .message("Badge already exists.") + .build(); } - @Override - public GenericMessage deleteBadge(BadgeDeleteRequest request) { - Optional existingBadge = - badgeRepository.findByChallengeAndUsernameAndBadgeName( - request.getChallenge(), request.getUsername(), request.getBadgeName()); + Badge newBadge = + new Badge( + new Random().nextLong(), + request.getChallenge(), + request.getUsername(), + request.getBadgeName()); + badgeRepository.save(newBadge); - if (!existingBadge.isPresent()) { - return GenericMessage.builder() - .status(HttpStatus.NOT_FOUND) - .message("Badge not found") - .build(); - } + return GenericMessage.builder() + .status(HttpStatus.CREATED) + .message("Badge added successfully") + .data(newBadge.toDto()) + .build(); + } - badgeRepository.delete(existingBadge.get()); + @Override + public GenericMessage deleteBadge(BadgeDeleteRequest request) { + Optional existingBadge = + badgeRepository.findByChallengeAndUsernameAndBadgeName( + request.getChallenge(), request.getUsername(), request.getBadgeName()); - return GenericMessage.builder() - .status(HttpStatus.OK) - .message("Badge deleted successfully") - .data(existingBadge.get().toDto()) - .build(); + if (!existingBadge.isPresent()) { + return GenericMessage.builder() + .status(HttpStatus.NOT_FOUND) + .message("Badge not found") + .build(); } + + badgeRepository.delete(existingBadge.get()); + + return GenericMessage.builder() + .status(HttpStatus.OK) + .message("Badge deleted successfully") + .data(existingBadge.get().toDto()) + .build(); + } } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/ChallengeServiceImpl.java b/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/ChallengeServiceImpl.java index 323c6f5..eb6cede 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/ChallengeServiceImpl.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/ChallengeServiceImpl.java @@ -14,107 +14,108 @@ @Component @Log4j2 public class ChallengeServiceImpl implements ChallengeService { - private final ChallengeTypeRepository challengeTypeRepository; - @Autowired - public ChallengeServiceImpl(ChallengeTypeRepository challengeTypeRepository) { - this.challengeTypeRepository = challengeTypeRepository; - } - - /** - * get challenge - * - * @param request getChallenge request payload - * @return 200 if getChallenge successful, 401 if Heart rate is not in the range of this - * challenge typed, 404 if No challenge type associated with this type - */ - @Override - public GenericMessage getChallenge(ChallengeGetRequest request) { - Optional matchingChallengeType = - challengeTypeRepository.findByDescription(request.getType()); + private final ChallengeTypeRepository challengeTypeRepository; - if (matchingChallengeType.isPresent()) { - ChallengeType challengeType = matchingChallengeType.get(); - if (request.getUserHeartRate() >= challengeType.getUserHeartRate() - 30 - && request.getUserHeartRate() <= challengeType.getUserHeartRate() + 30) { - return GenericMessage.builder() - .status(HttpStatus.OK) - .message("Challenge type found successfully, and returned") - .data(challengeType.toDto()) - .build(); - } else { - return GenericMessage.builder() - .status(HttpStatus.UNAUTHORIZED) - .message( - "GetChallenge failed, user heart rate not in range for this" - + " challenge type") - .build(); - } - } else { - return GenericMessage.builder() - .status(HttpStatus.NOT_FOUND) - .message("GetChallenge failed, no challenge type found with this type") - .build(); - } - } + @Autowired + public ChallengeServiceImpl(ChallengeTypeRepository challengeTypeRepository) { + this.challengeTypeRepository = challengeTypeRepository; + } - /** - * add challenge - * - * @param request createChallenge request payload - * @return 200 if createChallenge successful, 409 if challenge already exists - */ - @Override - public GenericMessage addChallenge(ChallengeAddRequest request) { - Optional existingChallengeType = - challengeTypeRepository.findByDescription(request.getType()); + /** + * get challenge + * + * @param request getChallenge request payload + * @return 200 if getChallenge successful, 401 if Heart rate is not in the range of this challenge + * typed, 404 if No challenge type associated with this type + */ + @Override + public GenericMessage getChallenge(ChallengeGetRequest request) { + Optional matchingChallengeType = + challengeTypeRepository.findByDescription(request.getType()); - if (existingChallengeType.isPresent()) { - return GenericMessage.builder() - .status(HttpStatus.CONFLICT) - .message("Challenge type already exists.") - .build(); - } + if (matchingChallengeType.isPresent()) { + ChallengeType challengeType = matchingChallengeType.get(); + if (request.getUserHeartRate() >= challengeType.getUserHeartRate() - 30 + && request.getUserHeartRate() <= challengeType.getUserHeartRate() + 30) { + return GenericMessage.builder() + .status(HttpStatus.OK) + .message("Challenge type found successfully, and returned") + .data(challengeType.toDto()) + .build(); + } else { + return GenericMessage.builder() + .status(HttpStatus.UNAUTHORIZED) + .message( + "GetChallenge failed, user heart rate not in range for this" + + " challenge type") + .build(); + } + } else { + return GenericMessage.builder() + .status(HttpStatus.NOT_FOUND) + .message("GetChallenge failed, no challenge type found with this type") + .build(); + } + } - ChallengeType newChallengeType = - new ChallengeType( - new Random().nextLong(), - request.getType(), - request.getUserHeartRate(), - request.getExerciseCount()); - challengeTypeRepository.save(newChallengeType); + /** + * add challenge + * + * @param request createChallenge request payload + * @return 200 if createChallenge successful, 409 if challenge already exists + */ + @Override + public GenericMessage addChallenge(ChallengeAddRequest request) { + Optional existingChallengeType = + challengeTypeRepository.findByDescription(request.getType()); - return GenericMessage.builder() - .status(HttpStatus.CREATED) - .message("Challenge type added successfully") - .data(newChallengeType.toDto()) - .build(); + if (existingChallengeType.isPresent()) { + return GenericMessage.builder() + .status(HttpStatus.CONFLICT) + .message("Challenge type already exists.") + .build(); } - /** - * delete challenge - * - * @param request deleteChallenge request payload - * @return 200 if deleteChallenge successful, 404 if challenge not found - */ - @Override - public GenericMessage deleteChallenge(ChallengeDeleteRequest request) { - Optional existingChallengeType = - challengeTypeRepository.findByDescription(request.getType()); + ChallengeType newChallengeType = + new ChallengeType( + new Random().nextLong(), + request.getType(), + request.getUserHeartRate(), + request.getExerciseCount()); + challengeTypeRepository.save(newChallengeType); - if (!existingChallengeType.isPresent()) { - return GenericMessage.builder() - .status(HttpStatus.NOT_FOUND) - .message("DeleteChallenge failed, no challenge type found with this type") - .build(); - } + return GenericMessage.builder() + .status(HttpStatus.CREATED) + .message("Challenge type added successfully") + .data(newChallengeType.toDto()) + .build(); + } - challengeTypeRepository.delete(existingChallengeType.get()); + /** + * delete challenge + * + * @param request deleteChallenge request payload + * @return 200 if deleteChallenge successful, 404 if challenge not found + */ + @Override + public GenericMessage deleteChallenge(ChallengeDeleteRequest request) { + Optional existingChallengeType = + challengeTypeRepository.findByDescription(request.getType()); - return GenericMessage.builder() - .status(HttpStatus.OK) - .message("Challenge type deleted successfully") - .data(existingChallengeType.get().toDto()) - .build(); + if (!existingChallengeType.isPresent()) { + return GenericMessage.builder() + .status(HttpStatus.NOT_FOUND) + .message("DeleteChallenge failed, no challenge type found with this type") + .build(); } + + challengeTypeRepository.delete(existingChallengeType.get()); + + return GenericMessage.builder() + .status(HttpStatus.OK) + .message("Challenge type deleted successfully") + .data(existingChallengeType.get().toDto()) + .build(); + } } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/MessageServiceImpl.java b/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/MessageServiceImpl.java index 1f2a798..2762a8a 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/MessageServiceImpl.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/service/Impl/MessageServiceImpl.java @@ -9,18 +9,19 @@ @Service public class MessageServiceImpl implements MessageService { - @Value("${spring.rabbitmq.queue}") - private String queueName; - private final RabbitTemplate rabbitTemplate; + @Value("${spring.rabbitmq.queue}") + private String queueName; - @Autowired - public MessageServiceImpl(RabbitTemplate rabbitTemplate) { - this.rabbitTemplate = rabbitTemplate; - } + private final RabbitTemplate rabbitTemplate; - @Override - public void sendMessage(String exchangeName, String route, String message) { - rabbitTemplate.convertAndSend(exchangeName, route, message); - } + @Autowired + public MessageServiceImpl(RabbitTemplate rabbitTemplate) { + this.rabbitTemplate = rabbitTemplate; + } + + @Override + public void sendMessage(String exchangeName, String route, String message) { + rabbitTemplate.convertAndSend(exchangeName, route, message); + } } diff --git a/challenge-service/src/main/java/com/cas/challengeservice/service/MessageService.java b/challenge-service/src/main/java/com/cas/challengeservice/service/MessageService.java index b20136a..1b2baa6 100644 --- a/challenge-service/src/main/java/com/cas/challengeservice/service/MessageService.java +++ b/challenge-service/src/main/java/com/cas/challengeservice/service/MessageService.java @@ -2,5 +2,6 @@ package com.cas.challengeservice.service; public interface MessageService { - void sendMessage(String exchangeName, String route, String message); + + void sendMessage(String exchangeName, String route, String message); } diff --git a/challenge-service/src/test/java/com/cas/challengeservice/BadgeControllerTests.java b/challenge-service/src/test/java/com/cas/challengeservice/BadgeControllerTests.java index 8e9dc42..a606a34 100644 --- a/challenge-service/src/test/java/com/cas/challengeservice/BadgeControllerTests.java +++ b/challenge-service/src/test/java/com/cas/challengeservice/BadgeControllerTests.java @@ -19,6 +19,7 @@ @SpringBootTest public class BadgeControllerTests { + @Mock private BadgeService badgeService; @InjectMocks @@ -40,8 +41,10 @@ public void setUp() { badgeName = "BalanceMaster"; badgeGetRequest = BadgeGetRequest.builder().challenge(challenge).username(username).build(); - badgeAddRequest = BadgeAddRequest.builder().challenge(challenge).username(username).badgeName(badgeName).build(); - badgeDeleteRequest = BadgeDeleteRequest.builder().challenge(challenge).username(username).build(); + badgeAddRequest = BadgeAddRequest.builder().challenge(challenge).username(username) + .badgeName(badgeName).build(); + badgeDeleteRequest = BadgeDeleteRequest.builder().challenge(challenge).username(username) + .build(); message = GenericMessage.builder() .status(HttpStatus.OK) @@ -51,7 +54,9 @@ public void setUp() { @Test public void testGetBadgeList() { - when(badgeService.getBadgeList(any())).thenReturn(new GenericMessage>(HttpStatus.OK, "Badge List Response", new ArrayList<>())); + when(badgeService.getBadgeList(any())).thenReturn( + new GenericMessage>(HttpStatus.OK, "Badge List Response", + new ArrayList<>())); ResponseEntity>> responseEntity = badgeController.getBadgeList(challenge, username); diff --git a/challenge-service/src/test/java/com/cas/challengeservice/BadgeServiceTests.java b/challenge-service/src/test/java/com/cas/challengeservice/BadgeServiceTests.java index 9143e7d..1a74df2 100644 --- a/challenge-service/src/test/java/com/cas/challengeservice/BadgeServiceTests.java +++ b/challenge-service/src/test/java/com/cas/challengeservice/BadgeServiceTests.java @@ -1,4 +1,5 @@ package com.cas.challengeservice; + import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; @@ -20,6 +21,7 @@ @SpringBootTest public class BadgeServiceTests { + @Mock private BadgeRepository badgeRepository; @InjectMocks @@ -28,15 +30,17 @@ public class BadgeServiceTests { private BadgeGetRequest badgeGetRequest; private BadgeAddRequest badgeAddRequest; private BadgeDeleteRequest badgeDeleteRequest; + @BeforeEach public void setUp() { - badgeGetRequest = new BadgeGetRequest("challengeType","username"); - badgeAddRequest = new BadgeAddRequest("challengeType","username","badgeName"); - badgeDeleteRequest = new BadgeDeleteRequest("challengeType","username","badgeName"); + badgeGetRequest = new BadgeGetRequest("challengeType", "username"); + badgeAddRequest = new BadgeAddRequest("challengeType", "username", "badgeName"); + badgeDeleteRequest = new BadgeDeleteRequest("challengeType", "username", "badgeName"); } + @Test public void testGetBadgeListWhenBadgeNotFound() { - when(badgeRepository.findAllByChallengeAndUsername(any(),any())).thenReturn(new ArrayList<>()); + when(badgeRepository.findAllByChallengeAndUsername(any(), any())).thenReturn(new ArrayList<>()); GenericMessage> result = badgeServiceImpl.getBadgeList(badgeGetRequest); @@ -48,7 +52,7 @@ public void testGetBadgeListWhenBadgeNotFound() { public void testGetBadgeListSuccess() { List badges = new ArrayList<>(); badges.add(new Badge(1L, "challenge", "username", "badgeName")); - when(badgeRepository.findAllByChallengeAndUsername(any(),any())).thenReturn(badges); + when(badgeRepository.findAllByChallengeAndUsername(any(), any())).thenReturn(badges); GenericMessage> result = badgeServiceImpl.getBadgeList(badgeGetRequest); @@ -59,7 +63,8 @@ public void testGetBadgeListSuccess() { @Test public void testAddBadgeWhenBadgeExist() { Badge badge = new Badge(1L, "challenge", "username", "badgeName"); - when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(),any(),any())).thenReturn(Optional.of(badge)); + when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(), any(), any())).thenReturn( + Optional.of(badge)); GenericMessage result = badgeServiceImpl.addBadge(badgeAddRequest); @@ -69,7 +74,8 @@ public void testAddBadgeWhenBadgeExist() { @Test public void testAddBadgeSuccess() { - when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(),any(),any())).thenReturn(Optional.empty()); + when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(), any(), any())).thenReturn( + Optional.empty()); GenericMessage result = badgeServiceImpl.addBadge(badgeAddRequest); @@ -79,7 +85,8 @@ public void testAddBadgeSuccess() { @Test public void testDeleteBadgeWhenBadgeNotFound() { - when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(),any(),any())).thenReturn(Optional.empty()); + when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(), any(), any())).thenReturn( + Optional.empty()); GenericMessage result = badgeServiceImpl.deleteBadge(badgeDeleteRequest); @@ -90,7 +97,8 @@ public void testDeleteBadgeWhenBadgeNotFound() { @Test public void testDeleteBadgeSuccess() { Badge badge = new Badge(1L, "challenge", "username", "badgeName"); - when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(),any(),any())).thenReturn(Optional.of(badge)); + when(badgeRepository.findByChallengeAndUsernameAndBadgeName(any(), any(), any())).thenReturn( + Optional.of(badge)); GenericMessage result = badgeServiceImpl.deleteBadge(badgeDeleteRequest); diff --git a/challenge-service/src/test/java/com/cas/challengeservice/ChallengeServiceTests.java b/challenge-service/src/test/java/com/cas/challengeservice/ChallengeServiceTests.java index 9d79137..e424ad6 100644 --- a/challenge-service/src/test/java/com/cas/challengeservice/ChallengeServiceTests.java +++ b/challenge-service/src/test/java/com/cas/challengeservice/ChallengeServiceTests.java @@ -37,7 +37,8 @@ public void setUp() { public void testGetChallengeWhenChallengeTypeNotExist() { when(challengeTypeRepository.findByDescription(any())).thenReturn(Optional.empty()); - GenericMessage result = challengeServiceImpl.getChallenge(challengeGetRequest); + GenericMessage result = challengeServiceImpl.getChallenge( + challengeGetRequest); assertEquals(HttpStatus.NOT_FOUND, result.getStatus()); assertEquals( @@ -96,7 +97,8 @@ public void testAddChallengeTypeWhenChallengeTypeExist() { public void testAddChallengeTypeSuccess() { when(challengeTypeRepository.findByDescription(any())).thenReturn(Optional.empty()); - GenericMessage result = challengeServiceImpl.addChallenge(challengeAddRequest); + GenericMessage result = challengeServiceImpl.addChallenge( + challengeAddRequest); assertEquals(HttpStatus.CREATED, result.getStatus()); assertEquals("Challenge type added successfully", result.getMessage()); @@ -107,7 +109,8 @@ public void testDeleteChallengeTypeWhenChallengeTypeNotFound() { when(challengeTypeRepository.findByDescription(any())).thenReturn(Optional.empty()); - GenericMessage result = challengeServiceImpl.deleteChallenge(challengeDeleteRequest); + GenericMessage result = challengeServiceImpl.deleteChallenge( + challengeDeleteRequest); assertEquals(HttpStatus.NOT_FOUND, result.getStatus()); assertEquals( diff --git a/geo-service/src/main/java/com/cas/geoservice/config/RabbitMQConfig.java b/geo-service/src/main/java/com/cas/geoservice/config/RabbitMQConfig.java index 0a2cf3d..442baad 100644 --- a/geo-service/src/main/java/com/cas/geoservice/config/RabbitMQConfig.java +++ b/geo-service/src/main/java/com/cas/geoservice/config/RabbitMQConfig.java @@ -17,63 +17,65 @@ @Configuration public class RabbitMQConfig { - @Value("${spring.rabbitmq.host}") - private String host; - - @Value("${spring.rabbitmq.port}") - private int port; - - @Value("${spring.rabbitmq.username}") - private String username; - - @Value("${spring.rabbitmq.password}") - private String password; - - @Value("${spring.rabbitmq.exchange}") - private String exchangeName; - - @Value("${spring.rabbitmq.queue}") - private String queueName; - - @Autowired private ZoneListener zoneListener; - - @Bean - public ConnectionFactory connectionFactory() { - CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); - connectionFactory.setHost(host); - connectionFactory.setPort(port); - connectionFactory.setUsername(username); - connectionFactory.setPassword(password); - return connectionFactory; - } - - @Bean - public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) { - return new RabbitTemplate(connectionFactory); - } - - @Bean - public TopicExchange topicExchange() { - return new TopicExchange(exchangeName); - } - - @Bean - public Queue geoQueue() { - return new Queue(queueName, true); - } - - @Bean - public SimpleMessageListenerContainer badgeListenerContainer( - ConnectionFactory connectionFactory, - @Qualifier("geoQueue") Queue queue, - @Qualifier("topicExchange") TopicExchange exchange) { - - SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); - container.setConnectionFactory(connectionFactory); - container.setQueues(queue); - container.setMessageListener(zoneListener); - - Binding binding = BindingBuilder.bind(queue).to(exchange).with("#"); - return container; - } + + @Value("${spring.rabbitmq.host}") + private String host; + + @Value("${spring.rabbitmq.port}") + private int port; + + @Value("${spring.rabbitmq.username}") + private String username; + + @Value("${spring.rabbitmq.password}") + private String password; + + @Value("${spring.rabbitmq.exchange}") + private String exchangeName; + + @Value("${spring.rabbitmq.queue}") + private String queueName; + + @Autowired + private ZoneListener zoneListener; + + @Bean + public ConnectionFactory connectionFactory() { + CachingConnectionFactory connectionFactory = new CachingConnectionFactory(); + connectionFactory.setHost(host); + connectionFactory.setPort(port); + connectionFactory.setUsername(username); + connectionFactory.setPassword(password); + return connectionFactory; + } + + @Bean + public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) { + return new RabbitTemplate(connectionFactory); + } + + @Bean + public TopicExchange topicExchange() { + return new TopicExchange(exchangeName); + } + + @Bean + public Queue geoQueue() { + return new Queue(queueName, true); + } + + @Bean + public SimpleMessageListenerContainer badgeListenerContainer( + ConnectionFactory connectionFactory, + @Qualifier("geoQueue") Queue queue, + @Qualifier("topicExchange") TopicExchange exchange) { + + SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(); + container.setConnectionFactory(connectionFactory); + container.setQueues(queue); + container.setMessageListener(zoneListener); + + Binding binding = BindingBuilder.bind(queue).to(exchange).with("#"); + return container; + } } diff --git a/geo-service/src/main/java/com/cas/geoservice/config/ZoneListener.java b/geo-service/src/main/java/com/cas/geoservice/config/ZoneListener.java index 57d30ff..8d9cad1 100644 --- a/geo-service/src/main/java/com/cas/geoservice/config/ZoneListener.java +++ b/geo-service/src/main/java/com/cas/geoservice/config/ZoneListener.java @@ -18,52 +18,53 @@ @Component @Log4j2 public class ZoneListener implements MessageListener { - private PlayerZoneRepository playerZoneRepository; - private ObjectMapper objectMapper; + private PlayerZoneRepository playerZoneRepository; - @Autowired - public ZoneListener(PlayerZoneRepository playerZoneRepository) { - this.playerZoneRepository = playerZoneRepository; - objectMapper = new ObjectMapper(); - } + private ObjectMapper objectMapper; + + @Autowired + public ZoneListener(PlayerZoneRepository playerZoneRepository) { + this.playerZoneRepository = playerZoneRepository; + objectMapper = new ObjectMapper(); + } - @Override - public void onMessage(Message message) { - try { - String messageBody = new String(message.getBody()); - log.info("Received message: " + messageBody); + @Override + public void onMessage(Message message) { + try { + String messageBody = new String(message.getBody()); + log.info("Received message: " + messageBody); - MessageDto messageDto = objectMapper.readValue(messageBody, MessageDto.class); + MessageDto messageDto = objectMapper.readValue(messageBody, MessageDto.class); - switch (messageDto.getAction()) { - case MQ_REQUEST_SET_ZONE: - log.info("MQ - Set zone: {}", messageDto.getPlayerSetZoneRequest()); - PlayerSetZoneRequest request = messageDto.getPlayerSetZoneRequest(); - PlayerZone playerZone = - PlayerZone.builder() - .username(request.getUsername()) - .name(request.getZone()) - .build(); + switch (messageDto.getAction()) { + case MQ_REQUEST_SET_ZONE: + log.info("MQ - Set zone: {}", messageDto.getPlayerSetZoneRequest()); + PlayerSetZoneRequest request = messageDto.getPlayerSetZoneRequest(); + PlayerZone playerZone = + PlayerZone.builder() + .username(request.getUsername()) + .name(request.getZone()) + .build(); - PlayerZone zone = playerZoneRepository.findByUsername(request.getUsername()); - if (Objects.isNull(zone)) { - log.info( - "Save player {} zone to : {}", - playerZone.getUsername(), - playerZone.getName()); - playerZoneRepository.save(playerZone); - } else { - log.info( - "Update player {} zone to : {}", - zone.getUsername(), - zone.getName()); - zone.setName(request.getZone()); - playerZoneRepository.save(zone); - } - } - } catch (Exception e) { - e.printStackTrace(); - } + PlayerZone zone = playerZoneRepository.findByUsername(request.getUsername()); + if (Objects.isNull(zone)) { + log.info( + "Save player {} zone to : {}", + playerZone.getUsername(), + playerZone.getName()); + playerZoneRepository.save(playerZone); + } else { + log.info( + "Update player {} zone to : {}", + zone.getUsername(), + zone.getName()); + zone.setName(request.getZone()); + playerZoneRepository.save(zone); + } + } + } catch (Exception e) { + e.printStackTrace(); } + } } diff --git a/geo-service/src/main/java/com/cas/geoservice/constant/Constants.java b/geo-service/src/main/java/com/cas/geoservice/constant/Constants.java index ad47070..925d2ef 100644 --- a/geo-service/src/main/java/com/cas/geoservice/constant/Constants.java +++ b/geo-service/src/main/java/com/cas/geoservice/constant/Constants.java @@ -2,5 +2,6 @@ package com.cas.geoservice.constant; public class Constants { - public static final String MQ_REQUEST_SET_ZONE = "SET_ZONE"; + + public static final String MQ_REQUEST_SET_ZONE = "SET_ZONE"; } diff --git a/geo-service/src/main/java/com/cas/geoservice/controller/TrailController.java b/geo-service/src/main/java/com/cas/geoservice/controller/TrailController.java index 1b24a52..e220314 100644 --- a/geo-service/src/main/java/com/cas/geoservice/controller/TrailController.java +++ b/geo-service/src/main/java/com/cas/geoservice/controller/TrailController.java @@ -15,17 +15,18 @@ @RestController @RequestMapping(value = "/geo") public class TrailController { - private final TrailService trailService; - @Autowired - public TrailController(TrailService trailService) { - this.trailService = trailService; - } + private final TrailService trailService; - @GetMapping("/trail") - public ResponseEntity> getTrail(@RequestParam String username) { - TrailGetRequest request = new TrailGetRequest(username); - GenericMessage response = trailService.getTrail(request); - return ResponseEntity.status(response.getStatus()).body(response); - } + @Autowired + public TrailController(TrailService trailService) { + this.trailService = trailService; + } + + @GetMapping("/trail") + public ResponseEntity> getTrail(@RequestParam String username) { + TrailGetRequest request = new TrailGetRequest(username); + GenericMessage response = trailService.getTrail(request); + return ResponseEntity.status(response.getStatus()).body(response); + } } diff --git a/geo-service/src/main/java/com/cas/geoservice/dto/GenericMessage.java b/geo-service/src/main/java/com/cas/geoservice/dto/GenericMessage.java index 826351a..03a30fd 100644 --- a/geo-service/src/main/java/com/cas/geoservice/dto/GenericMessage.java +++ b/geo-service/src/main/java/com/cas/geoservice/dto/GenericMessage.java @@ -11,7 +11,9 @@ @EqualsAndHashCode @Builder(toBuilder = true) public class GenericMessage { - private HttpStatusCode status; - private String message; - @Nullable private T data; + + private HttpStatusCode status; + private String message; + @Nullable + private T data; } diff --git a/geo-service/src/main/java/com/cas/geoservice/dto/MessageDto.java b/geo-service/src/main/java/com/cas/geoservice/dto/MessageDto.java index b18eb48..5251c65 100644 --- a/geo-service/src/main/java/com/cas/geoservice/dto/MessageDto.java +++ b/geo-service/src/main/java/com/cas/geoservice/dto/MessageDto.java @@ -10,7 +10,11 @@ @EqualsAndHashCode @Builder(toBuilder = true) public class MessageDto { - @NonNull private PlayerSetZoneRequest playerSetZoneRequest; - @NonNull private String action; - @Nullable private String message; + + @NonNull + private PlayerSetZoneRequest playerSetZoneRequest; + @NonNull + private String action; + @Nullable + private String message; } diff --git a/geo-service/src/main/java/com/cas/geoservice/dto/PlaceDto.java b/geo-service/src/main/java/com/cas/geoservice/dto/PlaceDto.java index 532e8f3..d1c0aa5 100644 --- a/geo-service/src/main/java/com/cas/geoservice/dto/PlaceDto.java +++ b/geo-service/src/main/java/com/cas/geoservice/dto/PlaceDto.java @@ -10,10 +10,11 @@ @NoArgsConstructor @EqualsAndHashCode public class PlaceDto { - private Long id; - private String name; - private String type; - private Double CoordinateX; - private Double CoordinateY; - private Long trailId; + + private Long id; + private String name; + private String type; + private Double CoordinateX; + private Double CoordinateY; + private Long trailId; } diff --git a/geo-service/src/main/java/com/cas/geoservice/dto/PlayerSetZoneRequest.java b/geo-service/src/main/java/com/cas/geoservice/dto/PlayerSetZoneRequest.java index fa97307..606e8df 100644 --- a/geo-service/src/main/java/com/cas/geoservice/dto/PlayerSetZoneRequest.java +++ b/geo-service/src/main/java/com/cas/geoservice/dto/PlayerSetZoneRequest.java @@ -9,6 +9,7 @@ @NoArgsConstructor @EqualsAndHashCode public class PlayerSetZoneRequest { - private String username; - private String zone; + + private String username; + private String zone; } diff --git a/geo-service/src/main/java/com/cas/geoservice/dto/TrailDto.java b/geo-service/src/main/java/com/cas/geoservice/dto/TrailDto.java index 5acce2d..49d4111 100644 --- a/geo-service/src/main/java/com/cas/geoservice/dto/TrailDto.java +++ b/geo-service/src/main/java/com/cas/geoservice/dto/TrailDto.java @@ -11,7 +11,8 @@ @NoArgsConstructor @EqualsAndHashCode public class TrailDto { - private Long id; - private String zone; - private List path; + + private Long id; + private String zone; + private List path; } diff --git a/geo-service/src/main/java/com/cas/geoservice/dto/TrailGetRequest.java b/geo-service/src/main/java/com/cas/geoservice/dto/TrailGetRequest.java index 9fda2ce..c0da928 100644 --- a/geo-service/src/main/java/com/cas/geoservice/dto/TrailGetRequest.java +++ b/geo-service/src/main/java/com/cas/geoservice/dto/TrailGetRequest.java @@ -9,5 +9,6 @@ @NoArgsConstructor @EqualsAndHashCode public class TrailGetRequest { - private String username; + + private String username; } diff --git a/geo-service/src/main/java/com/cas/geoservice/entity/Place.java b/geo-service/src/main/java/com/cas/geoservice/entity/Place.java index fab84af..f6cc070 100644 --- a/geo-service/src/main/java/com/cas/geoservice/entity/Place.java +++ b/geo-service/src/main/java/com/cas/geoservice/entity/Place.java @@ -13,27 +13,28 @@ @Table @Entity public class Place { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String name; - private String type; - private Double CoordinateX; - private Double CoordinateY; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - @ManyToOne - @JoinColumn(name = "trail_id") - private Trail trail; + private String name; + private String type; + private Double CoordinateX; + private Double CoordinateY; - public PlaceDto toDto() { - return PlaceDto.builder() - .id(id) - .name(name) - .type(type) - .CoordinateX(CoordinateX) - .CoordinateY(CoordinateY) - .trailId(trail.getId()) - .build(); - } + @ManyToOne + @JoinColumn(name = "trail_id") + private Trail trail; + + public PlaceDto toDto() { + return PlaceDto.builder() + .id(id) + .name(name) + .type(type) + .CoordinateX(CoordinateX) + .CoordinateY(CoordinateY) + .trailId(trail.getId()) + .build(); + } } diff --git a/geo-service/src/main/java/com/cas/geoservice/entity/PlayerZone.java b/geo-service/src/main/java/com/cas/geoservice/entity/PlayerZone.java index eb33e16..1fec63c 100644 --- a/geo-service/src/main/java/com/cas/geoservice/entity/PlayerZone.java +++ b/geo-service/src/main/java/com/cas/geoservice/entity/PlayerZone.java @@ -12,12 +12,13 @@ @Table @Entity public class PlayerZone { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String name; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - @Column(unique = true) - private String username; + private String name; + + @Column(unique = true) + private String username; } diff --git a/geo-service/src/main/java/com/cas/geoservice/entity/Trail.java b/geo-service/src/main/java/com/cas/geoservice/entity/Trail.java index f3aeca0..51b0263 100644 --- a/geo-service/src/main/java/com/cas/geoservice/entity/Trail.java +++ b/geo-service/src/main/java/com/cas/geoservice/entity/Trail.java @@ -16,18 +16,19 @@ @Table @Entity public class Trail { - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - private String zone; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; - @OneToMany(mappedBy = "trail", cascade = CascadeType.ALL) - private List path; + private String zone; - public TrailDto toDto() { - List placeDtos = path.stream().map(Place::toDto).collect(Collectors.toList()); + @OneToMany(mappedBy = "trail", cascade = CascadeType.ALL) + private List path; - return TrailDto.builder().id(id).zone(zone).path(placeDtos).build(); - } + public TrailDto toDto() { + List placeDtos = path.stream().map(Place::toDto).collect(Collectors.toList()); + + return TrailDto.builder().id(id).zone(zone).path(placeDtos).build(); + } } diff --git a/geo-service/src/main/java/com/cas/geoservice/repository/PlaceRepository.java b/geo-service/src/main/java/com/cas/geoservice/repository/PlaceRepository.java index 761462e..c2579f5 100644 --- a/geo-service/src/main/java/com/cas/geoservice/repository/PlaceRepository.java +++ b/geo-service/src/main/java/com/cas/geoservice/repository/PlaceRepository.java @@ -4,4 +4,6 @@ import com.cas.geoservice.entity.Place; import org.springframework.data.jpa.repository.JpaRepository; -public interface PlaceRepository extends JpaRepository {} +public interface PlaceRepository extends JpaRepository { + +} diff --git a/geo-service/src/main/java/com/cas/geoservice/repository/PlayerZoneRepository.java b/geo-service/src/main/java/com/cas/geoservice/repository/PlayerZoneRepository.java index 31f1468..0c3a55e 100644 --- a/geo-service/src/main/java/com/cas/geoservice/repository/PlayerZoneRepository.java +++ b/geo-service/src/main/java/com/cas/geoservice/repository/PlayerZoneRepository.java @@ -7,5 +7,6 @@ @Repository public interface PlayerZoneRepository extends JpaRepository { - PlayerZone findByUsername(String username); + + PlayerZone findByUsername(String username); } diff --git a/geo-service/src/main/java/com/cas/geoservice/repository/TrailRepository.java b/geo-service/src/main/java/com/cas/geoservice/repository/TrailRepository.java index 9892741..5be1f17 100644 --- a/geo-service/src/main/java/com/cas/geoservice/repository/TrailRepository.java +++ b/geo-service/src/main/java/com/cas/geoservice/repository/TrailRepository.java @@ -8,5 +8,6 @@ @Repository public interface TrailRepository extends JpaRepository { - Optional findByZone(String zone); + + Optional findByZone(String zone); } diff --git a/geo-service/src/main/java/com/cas/geoservice/service/Impl/MessageServiceImpl.java b/geo-service/src/main/java/com/cas/geoservice/service/Impl/MessageServiceImpl.java index 81bac1d..b50f661 100644 --- a/geo-service/src/main/java/com/cas/geoservice/service/Impl/MessageServiceImpl.java +++ b/geo-service/src/main/java/com/cas/geoservice/service/Impl/MessageServiceImpl.java @@ -9,18 +9,19 @@ @Service public class MessageServiceImpl implements MessageService { - @Value("${spring.rabbitmq.queue}") - private String queueName; - private final RabbitTemplate rabbitTemplate; + @Value("${spring.rabbitmq.queue}") + private String queueName; - @Autowired - public MessageServiceImpl(RabbitTemplate rabbitTemplate) { - this.rabbitTemplate = rabbitTemplate; - } + private final RabbitTemplate rabbitTemplate; - @Override - public void sendMessage(String exchangeName, String route, String message) { - rabbitTemplate.convertAndSend(exchangeName, route, message); - } + @Autowired + public MessageServiceImpl(RabbitTemplate rabbitTemplate) { + this.rabbitTemplate = rabbitTemplate; + } + + @Override + public void sendMessage(String exchangeName, String route, String message) { + rabbitTemplate.convertAndSend(exchangeName, route, message); + } } diff --git a/geo-service/src/main/java/com/cas/geoservice/service/Impl/TrailServiceImpl.java b/geo-service/src/main/java/com/cas/geoservice/service/Impl/TrailServiceImpl.java index 832652d..e56d41a 100644 --- a/geo-service/src/main/java/com/cas/geoservice/service/Impl/TrailServiceImpl.java +++ b/geo-service/src/main/java/com/cas/geoservice/service/Impl/TrailServiceImpl.java @@ -17,44 +17,45 @@ @Service @Log4j2 public class TrailServiceImpl implements TrailService { - private final TrailRepository trailRepository; - private final PlayerZoneRepository playerZoneRepository; + private final TrailRepository trailRepository; - @Autowired - public TrailServiceImpl( - TrailRepository trailRepository, PlayerZoneRepository playerZoneRepository) { - this.trailRepository = trailRepository; - this.playerZoneRepository = playerZoneRepository; + private final PlayerZoneRepository playerZoneRepository; + + @Autowired + public TrailServiceImpl( + TrailRepository trailRepository, PlayerZoneRepository playerZoneRepository) { + this.trailRepository = trailRepository; + this.playerZoneRepository = playerZoneRepository; + } + + @Override + public GenericMessage getTrail(TrailGetRequest request) { + PlayerZone playerZone = playerZoneRepository.findByUsername(request.getUsername()); + log.info("fetching playzone for {}", request.getUsername()); + + if (Objects.isNull(playerZone)) { + return GenericMessage.builder() + .status(HttpStatus.BAD_REQUEST) + .message("The player hasn't set zone, please set zone first...") + .data(null) + .build(); } - @Override - public GenericMessage getTrail(TrailGetRequest request) { - PlayerZone playerZone = playerZoneRepository.findByUsername(request.getUsername()); - log.info("fetching playzone for {}", request.getUsername()); - - if (Objects.isNull(playerZone)) { - return GenericMessage.builder() - .status(HttpStatus.BAD_REQUEST) - .message("The player hasn't set zone, please set zone first...") - .data(null) - .build(); - } - - Optional matchingTrail = trailRepository.findByZone(playerZone.getName()); - - if (matchingTrail.isPresent()) { - Trail trail = matchingTrail.get(); - return GenericMessage.builder() - .status(HttpStatus.OK) - .message("Trail found successfully, and returned") - .data(trail.toDto()) - .build(); - } else { - return GenericMessage.builder() - .status(HttpStatus.NOT_FOUND) - .message("No trail associated with this zone") - .build(); - } + Optional matchingTrail = trailRepository.findByZone(playerZone.getName()); + + if (matchingTrail.isPresent()) { + Trail trail = matchingTrail.get(); + return GenericMessage.builder() + .status(HttpStatus.OK) + .message("Trail found successfully, and returned") + .data(trail.toDto()) + .build(); + } else { + return GenericMessage.builder() + .status(HttpStatus.NOT_FOUND) + .message("No trail associated with this zone") + .build(); } + } } diff --git a/geo-service/src/main/java/com/cas/geoservice/service/MessageService.java b/geo-service/src/main/java/com/cas/geoservice/service/MessageService.java index 60d0e05..8defc62 100644 --- a/geo-service/src/main/java/com/cas/geoservice/service/MessageService.java +++ b/geo-service/src/main/java/com/cas/geoservice/service/MessageService.java @@ -2,5 +2,6 @@ package com.cas.geoservice.service; public interface MessageService { - void sendMessage(String exchangeName, String route, String message); + + void sendMessage(String exchangeName, String route, String message); } diff --git a/geo-service/src/main/java/com/cas/geoservice/service/TrailService.java b/geo-service/src/main/java/com/cas/geoservice/service/TrailService.java index 44d4c5e..f89cd79 100644 --- a/geo-service/src/main/java/com/cas/geoservice/service/TrailService.java +++ b/geo-service/src/main/java/com/cas/geoservice/service/TrailService.java @@ -4,5 +4,6 @@ import com.cas.geoservice.dto.*; public interface TrailService { - GenericMessage getTrail(TrailGetRequest request); + + GenericMessage getTrail(TrailGetRequest request); } diff --git a/geo-service/src/test/java/com/cas/geoservice/TrailControllerTests.java b/geo-service/src/test/java/com/cas/geoservice/TrailControllerTests.java index 499d0bf..6994cf5 100644 --- a/geo-service/src/test/java/com/cas/geoservice/TrailControllerTests.java +++ b/geo-service/src/test/java/com/cas/geoservice/TrailControllerTests.java @@ -17,29 +17,33 @@ @SpringBootTest public class TrailControllerTests { - @Mock private TrailService trailService; - @InjectMocks private TrailController trailController; - - private GenericMessage message; - private String username; - @BeforeEach - public void setUp() { - username = "username"; - message = - GenericMessage.builder() - .status(HttpStatus.OK) - .message("Trail Response") - .build(); - } - - @Test - public void testGetTrail() { - when(trailService.getTrail(any())).thenReturn(message); - - ResponseEntity> responseEntity = - trailController.getTrail(username); - - assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - verify(trailService, times(1)).getTrail(any()); - } + + @Mock + private TrailService trailService; + @InjectMocks + private TrailController trailController; + + private GenericMessage message; + private String username; + + @BeforeEach + public void setUp() { + username = "username"; + message = + GenericMessage.builder() + .status(HttpStatus.OK) + .message("Trail Response") + .build(); + } + + @Test + public void testGetTrail() { + when(trailService.getTrail(any())).thenReturn(message); + + ResponseEntity> responseEntity = + trailController.getTrail(username); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + verify(trailService, times(1)).getTrail(any()); + } } diff --git a/geo-service/src/test/java/com/cas/geoservice/TrailServiceTests.java b/geo-service/src/test/java/com/cas/geoservice/TrailServiceTests.java index 06e2f38..7a3e38e 100644 --- a/geo-service/src/test/java/com/cas/geoservice/TrailServiceTests.java +++ b/geo-service/src/test/java/com/cas/geoservice/TrailServiceTests.java @@ -72,8 +72,10 @@ public void testGetTrailSuccess() { playerZone.setName("Zone1"); List places = new ArrayList<>(); - Place place1 = Place.builder().name("Place1").type("Type1").CoordinateX(1.0).CoordinateY(1.0).build(); - Place place2 = Place.builder().name("Place2").type("Type2").CoordinateX(2.0).CoordinateY(2.0).build(); + Place place1 = Place.builder().name("Place1").type("Type1").CoordinateX(1.0).CoordinateY(1.0) + .build(); + Place place2 = Place.builder().name("Place2").type("Type2").CoordinateX(2.0).CoordinateY(2.0) + .build(); places.add(place1); places.add(place2); From ad9a9e858884ba31502f5ec722b61697d8dc2672 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Wed, 6 Dec 2023 12:11:19 -0500 Subject: [PATCH 06/10] chore(game): cleanup code --- game-service/consts/consts.go | 2 -- game-service/game/app.go | 1 + game-service/game/context/context.go | 4 +--- game-service/game/core.go | 12 +++++++++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/game-service/consts/consts.go b/game-service/consts/consts.go index 1df707d..d79abe9 100644 --- a/game-service/consts/consts.go +++ b/game-service/consts/consts.go @@ -41,8 +41,6 @@ const ( AttackModeBeaver = "Coot Beaver" ) -var AttackModes = []string{AttackModeProf, AttackModeBeaver} - const ( BadgeFighter = "badge_fighter" BadgeHider = "badge_hider" diff --git a/game-service/game/app.go b/game-service/game/app.go index 8e8e146..d51afdc 100644 --- a/game-service/game/app.go +++ b/game-service/game/app.go @@ -64,6 +64,7 @@ func (app *App) Start() { if err != nil { log.Fatalln(err) } + defer app.hrmMQ.Close() go func() { log.Printf("listen to %s queue.", consts.HRMToGameQueue) diff --git a/game-service/game/context/context.go b/game-service/game/context/context.go index 34b7540..38d3845 100644 --- a/game-service/game/context/context.go +++ b/game-service/game/context/context.go @@ -63,6 +63,4 @@ func (c *Context) GetHeartRate() int { return int(c.heartRate.Load()) } -func (c *Context) Close() { - // add stop logic here if needed. -} +func (c *Context) Close() {} diff --git a/game-service/game/core.go b/game-service/game/core.go index 9c1d858..27754c6 100644 --- a/game-service/game/core.go +++ b/game-service/game/core.go @@ -81,7 +81,7 @@ func (app *App) ProcessGameAction(player *dto.PlayerDTO, action, cType string, l resp := &dto.ActionResponseDTO{} var currentSpeed float64 - { // Location checks + { // Location updates prevLoc := ctx.GetLocation() currLoc := location @@ -103,6 +103,8 @@ func (app *App) ProcessGameAction(player *dto.PlayerDTO, action, cType string, l }{} if err := app.GetService("challenge-service", fmt.Sprintf("/challenge?userHeartRate=%d&type=%s", ctx.GetHeartRate(), cType), &data); err != nil { + + // DO NOT FAIL: add fallback logic if challenge is down. //return nil, fmt.Errorf("get init challenge failed: %v", err) data.Data.UserHeartRate = ((100-player.Age)/2 + player.Weight) + rand.Intn(40) - 20 @@ -116,11 +118,13 @@ func (app *App) ProcessGameAction(player *dto.PlayerDTO, action, cType string, l ctx.Working.ExerciseCount = data.Data.ExerciseCount } + var AttackModes = []string{consts.AttackModeProf, consts.AttackModeBeaver} + // Generate Attack if h := ctx.GetHeartRate(); h < ctx.Working.RequiredHeartRate-30 || h > ctx.Working.RequiredHeartRate+30 { if ctx.GetAttackMode() == "" { resp.Attack.On = true - resp.Attack.Name = consts.AttackModes[rand.Intn(len(consts.AttackModes))] + resp.Attack.Name = AttackModes[rand.Intn(len(AttackModes))] ctx.UpdateAttackMode(resp.Attack.Name) resp.SetMessage(fmt.Sprintf("You are under attack by %s, be careful! 😱", resp.Attack.Name)) @@ -138,6 +142,7 @@ func (app *App) ProcessGameAction(player *dto.PlayerDTO, action, cType string, l resp.ResetMessage() } + // Set Action Response. if ctx.GetAttackMode() == "" && action != "" { resp.Attack.On = false resp.Attack.Name = "" @@ -149,6 +154,7 @@ func (app *App) ProcessGameAction(player *dto.PlayerDTO, action, cType string, l if action == "" { resp.SetMessage(resp.GetMessage() + "(your reaction is required now!)") } else { + // Reaction Check. switch strings.ToUpper(action) { case consts.ReactSheltering: for _, shelter := range ctx.GetShelters() { // close to shelter... @@ -188,7 +194,7 @@ func (app *App) ProcessGameAction(player *dto.PlayerDTO, action, cType string, l } } - { // Set basic attributes + { // Set Basic Attributes. resp.Score = ctx.Score resp.Speed = currentSpeed resp.Location = ctx.GetLocation() From 70f20864f4e2dfe08ab9cc74fe686cbc5dc41543 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Wed, 6 Dec 2023 12:40:31 -0500 Subject: [PATCH 07/10] docs: refine report links --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 1b21c34..4df1162 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,7 @@ - [Project Assignment Description](.project-docs/Project_Assignment_Description.pdf) - [Case Study (Fall 23): ACME Run](.project-docs/Case_Study_Fall2023.pdf) - -## Architecture Report - -- [MVP Report](https://docs.google.com/document/d/1autqAB21GcHH2TUhu9ez9Kf1AKQdTmIThb3qxiyk7p8/edit?usp=sharing) -- [Final Report](https://docs.google.com/document/d/10VK-EgGRhk5Q-xbG0QR4D0luVF6JTTd3wDxl1OF0oBA/edit?usp=sharing) +- [MVP Report](https://docs.google.com/document/d/1autqAB21GcHH2TUhu9ez9Kf1AKQdTmIThb3qxiyk7p8/edit?usp=sharing) | [Final Report](https://docs.google.com/document/d/10VK-EgGRhk5Q-xbG0QR4D0luVF6JTTd3wDxl1OF0oBA/edit?usp=sharing) ## Contents From d6dabb23a05e62dfc98622bcb13bf11ebd13c63e Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Wed, 6 Dec 2023 13:37:39 -0500 Subject: [PATCH 08/10] chore: add example comments --- docker-compose.local.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 52f0cbf..a80a29d 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -7,6 +7,9 @@ services: healthcheck: test: [ "CMD", "curl", "-sf", "http://localhost:8848/nacos/v1/ns/service/list?pageNo=1&pageSize=2" ] + # Register & Deregister Example: + # curl -sf -X POST 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.health.test&ip=1.1.1.1&port=8888' + # curl -sf -X DELETE 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.health.test&ip=1.1.1.1&port=8888' networks: - srvnet environment: From 5850c72950c3354d340a3f3b986d02581e25ce5e Mon Sep 17 00:00:00 2001 From: J1aM1ng Date: Wed, 6 Dec 2023 14:21:19 -0500 Subject: [PATCH 09/10] chore: swagger api --- challenge-service/src/main/resources/application-local.yml | 5 +++++ challenge-service/src/main/resources/application.yml | 5 +++++ geo-service/src/main/resources/application-local.yml | 5 +++++ geo-service/src/main/resources/application.yml | 5 +++++ 4 files changed, 20 insertions(+) diff --git a/challenge-service/src/main/resources/application-local.yml b/challenge-service/src/main/resources/application-local.yml index 750352f..116569c 100644 --- a/challenge-service/src/main/resources/application-local.yml +++ b/challenge-service/src/main/resources/application-local.yml @@ -37,3 +37,8 @@ spring: server: port: 9001 +springdoc: + api-docs: + path: /api-docs + swagger-ui: + path: /api.html diff --git a/challenge-service/src/main/resources/application.yml b/challenge-service/src/main/resources/application.yml index 0058f9d..c950e2d 100644 --- a/challenge-service/src/main/resources/application.yml +++ b/challenge-service/src/main/resources/application.yml @@ -37,3 +37,8 @@ spring: server: port: 9001 +springdoc: + api-docs: + path: /api-docs + swagger-ui: + path: /api.html diff --git a/geo-service/src/main/resources/application-local.yml b/geo-service/src/main/resources/application-local.yml index c4c5276..16fd0a3 100644 --- a/geo-service/src/main/resources/application-local.yml +++ b/geo-service/src/main/resources/application-local.yml @@ -37,3 +37,8 @@ spring: server: port: 9002 +springdoc: + api-docs: + path: /api-docs + swagger-ui: + path: /api.html diff --git a/geo-service/src/main/resources/application.yml b/geo-service/src/main/resources/application.yml index ab8db9c..ab2a3a4 100644 --- a/geo-service/src/main/resources/application.yml +++ b/geo-service/src/main/resources/application.yml @@ -37,3 +37,8 @@ spring: server: port: 9002 +springdoc: + api-docs: + path: /api-docs + swagger-ui: + path: /api.html From 54cf2af3e8f00b8e7ab416cef8b1f0779f485e5c Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Wed, 6 Dec 2023 15:36:03 -0500 Subject: [PATCH 10/10] chore(game): add init log --- game-service/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game-service/main.go b/game-service/main.go index 65f32b1..472db31 100644 --- a/game-service/main.go +++ b/game-service/main.go @@ -12,7 +12,7 @@ import ( ) func init() { - // nop + log.Println("Initializing Game Service...") } func main() {