Skip to content

Commit

Permalink
conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
leonliu288 committed Dec 6, 2023
2 parents 85e4de8 + 54cf2af commit 0592c39
Show file tree
Hide file tree
Showing 64 changed files with 998 additions and 709 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# 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)

## 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

Expand All @@ -29,7 +25,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/))

Expand Down Expand Up @@ -142,7 +138,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:

- <https://github.com/CAS735-F23/macrun-archless-team/actions/workflows/test.yml>

Expand Down
7 changes: 7 additions & 0 deletions challenge-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
<version>2.12.3</version>
</dependency>

<!-- Api docs -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>

<!-- SpringCloud Nacos -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenericMessage<List<BadgeDto>>> getBadgeList(
@RequestParam String challenge, @RequestParam String username) {
BadgeGetRequest request = new BadgeGetRequest(challenge, username);
GenericMessage<List<BadgeDto>> 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<GenericMessage<BadgeDto>> addBadge(@RequestBody BadgeAddRequest request) {
GenericMessage<BadgeDto> response = badgeService.addBadge(request);
return ResponseEntity.status(response.getStatus()).body(response);
}
@GetMapping("/list")
public ResponseEntity<GenericMessage<List<BadgeDto>>> getBadgeList(
@RequestParam String challenge, @RequestParam String username) {
BadgeGetRequest request = new BadgeGetRequest(challenge, username);
GenericMessage<List<BadgeDto>> response = badgeService.getBadgeList(request);
return ResponseEntity.status(response.getStatus()).body(response);
}

@RequestMapping(method = RequestMethod.DELETE)
public ResponseEntity<GenericMessage<BadgeDto>> deleteBadge(
@RequestBody BadgeDeleteRequest request) {
GenericMessage<BadgeDto> response = badgeService.deleteBadge(request);
return ResponseEntity.status(response.getStatus()).body(response);
}
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<GenericMessage<BadgeDto>> addBadge(@RequestBody BadgeAddRequest request) {
GenericMessage<BadgeDto> response = badgeService.addBadge(request);
return ResponseEntity.status(response.getStatus()).body(response);
}

@RequestMapping(method = RequestMethod.DELETE)
public ResponseEntity<GenericMessage<BadgeDto>> deleteBadge(
@RequestBody BadgeDeleteRequest request) {
GenericMessage<BadgeDto> response = badgeService.deleteBadge(request);
return ResponseEntity.status(response.getStatus()).body(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<GenericMessage<ChallengeTypeDto>> getChallenge(
@RequestParam Long userHeartRate, @RequestParam String type) {
ChallengeGetRequest request = new ChallengeGetRequest(userHeartRate, type);
GenericMessage<ChallengeTypeDto> 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<GenericMessage<ChallengeTypeDto>> addChallenge(
@RequestBody ChallengeAddRequest request) {
GenericMessage<ChallengeTypeDto> response = challengeService.addChallenge(request);
return ResponseEntity.status(response.getStatus()).body(response);
}
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<GenericMessage<ChallengeTypeDto>> getChallenge(
@RequestParam Long userHeartRate, @RequestParam String type) {
ChallengeGetRequest request = new ChallengeGetRequest(userHeartRate, type);
GenericMessage<ChallengeTypeDto> response = challengeService.getChallenge(request);
return ResponseEntity.status(response.getStatus()).body(response);
}

@RequestMapping(method = RequestMethod.DELETE)
public ResponseEntity<GenericMessage<ChallengeTypeDto>> deleteChallenge(
@RequestBody ChallengeDeleteRequest request) {
GenericMessage<ChallengeTypeDto> response = challengeService.deleteChallenge(request);
return ResponseEntity.status(response.getStatus()).body(response);
}
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<GenericMessage<ChallengeTypeDto>> addChallenge(
@RequestBody ChallengeAddRequest request) {
GenericMessage<ChallengeTypeDto> response = challengeService.addChallenge(request);
return ResponseEntity.status(response.getStatus()).body(response);
}

@RequestMapping(method = RequestMethod.DELETE)
public ResponseEntity<GenericMessage<ChallengeTypeDto>> deleteChallenge(
@RequestBody ChallengeDeleteRequest request) {
GenericMessage<ChallengeTypeDto> response = challengeService.deleteChallenge(request);
return ResponseEntity.status(response.getStatus()).body(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@NoArgsConstructor
@EqualsAndHashCode
public class BadgeGetRequest {
private String challenge;
private String username;

private String challenge;
private String username;
}
Loading

0 comments on commit 0592c39

Please sign in to comment.