Skip to content

Commit

Permalink
Merge pull request #896 from cassandre-tech/issue_880_global_code_review
Browse files Browse the repository at this point in the history
Issue 880 global code review
  • Loading branch information
straumat committed Feb 8, 2022
2 parents ca10df3 + 788a80f commit 89ced62
Show file tree
Hide file tree
Showing 180 changed files with 4,514 additions and 6,071 deletions.
12 changes: 9 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ updates:
interval: "daily"
time: "18:00"
timezone: "Europe/Paris"
open-pull-requests-limit: 9
target-branch: development

- package-ecosystem: npm
Expand All @@ -15,5 +14,12 @@ updates:
interval: "daily"
time: "18:00"
timezone: "Europe/Paris"
open-pull-requests-limit: 9
target-branch: development
target-branch: development

- package-ecosystem: github-actions
directory: "/"
schedule:
interval: "daily"
time: "18:00"
timezone: "Europe/Paris"
target-branch: development
8 changes: 4 additions & 4 deletions .github/workflows/branch-push-or-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:

steps:
# ================================================================================================================
- name: JDK 11 Setup
uses: actions/setup-java@v2
- name: JDK 17 Setup
uses: actions/setup-java@v2.5.0
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '17'

# ================================================================================================================
- name: Retrieve the sources
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:

steps:
# ================================================================================================================
- name: JDK 11 Setup
uses: actions/setup-java@v2
- name: JDK 17 Setup
uses: actions/setup-java@v2.5.0
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '17'

# ================================================================================================================
- name: Retrieve the sources
Expand Down
51 changes: 0 additions & 51 deletions .github/workflows/integration-tests.yml

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/publish-snapshot-and-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jobs:

steps:
# ================================================================================================================
- name: JDK 11 Setup
uses: actions/setup-java@v2
- name: JDK 17 Setup
uses: actions/setup-java@v2.5.0
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '17'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-creation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:

steps:
# ================================================================================================================
- name: JDK 11 Setup
uses: actions/setup-java@v2
- name: JDK 17 Setup
uses: actions/setup-java@v2.5.0
with:
distribution: 'adopt'
java-version: '11'
distribution: 'temurin'
java-version: '17'
server-id: ossrh
server-username: MAVEN_USERNAME
server-password: MAVEN_PASSWORD
Expand Down
4 changes: 4 additions & 0 deletions docs/docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ export default defineUserConfig<DefaultThemeOptions>({
link: '/ressources/how-tos/how-to-install-development-tools'
},
{text: 'Build from sources', link: '/ressources/how-tos/how-to-build-from-sources'},
{
text: 'Review code',
link: '/ressources/how-tos/how-to-review-code'
},
{text: 'Create a release', link: '/ressources/how-tos/how-to-create-a-release'},
{
text: 'Create a Kucoin account',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ sudo apt-get -y install git

## [Java](https://openjdk.java.net/install/)
```bash
sudo apt-get -y install openjdk-11-jdk
sudo apt-get -y install openjdk-17-jdk
```

## [Maven](https://maven.apache.org/)
Expand Down
18 changes: 18 additions & 0 deletions docs/docs/ressources/how-tos/how-to-review-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
lang: en-US
title: How to review code
description: How to review Cassandre code
---
# How to review code

## Core code (not tests & not archetypes)
* Check class comment and see if there is a right usage of {@link}.
* Instance variable should have the same name as its class like: `UserService userService`.
* No new line between method start ({) and method end (}).
* When a variable represents an id, say it in the name like 'carId'.
* When a variable is DTO, say it in the name like `carDTO`.
* Check logs texts.
* No point at the end of logs texts.
* Add @ExcludeFromCoverageGeneratedReport when it's required.
* Use of Optional.ofNullable() instead of "if (x != null) return x.getAnyValue()".
* In services, first line of implementations is a log.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
<!-- Project configuration -->
<properties>
<!-- Java build configuration -->
<java.version>11</java.version>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<java.version>17</java.version>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class ConfigurationDataFetcher extends BaseDataFetcher {

/** API Version. */
private static final String API_VERSION = "1.0";
private static final String API_VERSION = "1.1";

/**
* Returns server configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import tech.cassandre.trading.bot.repository.OrderRepository;

import java.util.List;
import java.util.stream.Collectors;

/**
* Order data fetcher.
Expand All @@ -31,18 +30,18 @@ public final List<OrderDTO> orders() {
return orderRepository.findAll()
.stream()
.map(ORDER_MAPPER::mapToOrderDTO)
.collect(Collectors.toList());
.toList();
}

/**
* Returns the order with the corresponding id value.
*
* @param id id
* @param uid uid
* @return order
*/
@DgsQuery
public OrderDTO order(@InputArgument final long id) {
return orderRepository.findById(id)
public OrderDTO order(@InputArgument final long uid) {
return orderRepository.findById(uid)
.map(ORDER_MAPPER::mapToOrderDTO)
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
* Position data fetcher.
Expand All @@ -33,35 +32,35 @@ public final List<PositionDTO> positions() {
return positionRepository.findAll()
.stream()
.map(POSITION_MAPPER::mapToPositionDTO)
.collect(Collectors.toList());
.toList();
}

/**
* Returns the position with the corresponding id value.
* Returns the position with the corresponding uid value.
*
* @param id id
* @param uid position uid
* @return position
*/
@DgsQuery
public final PositionDTO position(@InputArgument final long id) {
return positionRepository.findById(id)
public final PositionDTO position(@InputArgument final long uid) {
return positionRepository.findById(uid)
.map(POSITION_MAPPER::mapToPositionDTO)
.orElse(null);
}

/**
* Returns the positions of a strategy.
*
* @param id id of strategy the position
* @param uid uid of strategy the position
* @return positions
*/
@DgsQuery
public final List<PositionDTO> positionsByStrategy(@InputArgument final long id) {
public final List<PositionDTO> positionsByStrategy(@InputArgument final long uid) {
return positionRepository.findAll()
.stream()
.filter(position -> position.getStrategy().getId() == id)
.filter(position -> position.getStrategy().getUid() == uid)
.map(POSITION_MAPPER::mapToPositionDTO)
.collect(Collectors.toList());
.toList();
}

/**
Expand All @@ -76,24 +75,24 @@ public final List<PositionDTO> positionsByStrategyId(@InputArgument final String
.stream()
.filter(position -> Objects.equals(position.getStrategy().getStrategyId(), strategyId))
.map(POSITION_MAPPER::mapToPositionDTO)
.collect(Collectors.toList());
.toList();
}

/**
* Returns the positions of a strategy with a certain status.
*
* @param id id of strategy the position
* @param uid uid of strategy the position
* @param status position status
* @return positions
*/
@DgsQuery
public final List<PositionDTO> positionsByStrategyAndStatus(@InputArgument final long id,
public final List<PositionDTO> positionsByStrategyAndStatus(@InputArgument final long uid,
@InputArgument final PositionStatusDTO status) {
return positionRepository.findByStatus(status)
.stream()
.filter(position -> position.getStrategy().getId() == id)
.filter(position -> position.getStrategy().getUid() == uid)
.map(POSITION_MAPPER::mapToPositionDTO)
.collect(Collectors.toList());
.toList();
}

/**
Expand All @@ -110,7 +109,7 @@ public final List<PositionDTO> positionsByStrategyIdAndStatus(@InputArgument fin
.stream()
.filter(position -> Objects.equals(position.getStrategy().getStrategyId(), strategyId))
.map(POSITION_MAPPER::mapToPositionDTO)
.collect(Collectors.toList());
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import tech.cassandre.trading.bot.repository.StrategyRepository;

import java.util.List;
import java.util.stream.Collectors;

/**
* Strategy data fetcher.
Expand All @@ -31,18 +30,18 @@ public final List<StrategyDTO> strategies() {
return strategyRepository.findAll()
.stream()
.map(STRATEGY_MAPPER::mapToStrategyDTO)
.collect(Collectors.toList());
.toList();
}

/**
* Returns the strategy with the corresponding id value.
*
* @param id id
* @param uid uid
* @return strategy
*/
@DgsQuery
public StrategyDTO strategy(@InputArgument final long id) {
return strategyRepository.findById(id)
public StrategyDTO strategy(@InputArgument final long uid) {
return strategyRepository.findById(uid)
.map(STRATEGY_MAPPER::mapToStrategyDTO)
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import tech.cassandre.trading.bot.repository.TradeRepository;

import java.util.List;
import java.util.stream.Collectors;

/**
* Trade data fetcher.
Expand All @@ -31,18 +30,18 @@ public final List<TradeDTO> trades() {
return tradeRepository.findAll()
.stream()
.map(TRADE_MAPPER::mapToTradeDTO)
.collect(Collectors.toList());
.toList();
}

/**
* Returns the trade with the corresponding id value.
*
* @param id id
* @param uid uid
* @return trade
*/
@DgsQuery
public final TradeDTO trade(@InputArgument final long id) {
return tradeRepository.findById(id)
public final TradeDTO trade(@InputArgument final long uid) {
return tradeRepository.findById(uid)
.map(TRADE_MAPPER::mapToTradeDTO)
.orElse(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public GraphQLAPIKeyAuthenticationManager(final String newKey) {
public final Authentication authenticate(final Authentication authentication) throws AuthenticationException {
String principal = (String) authentication.getPrincipal();
if (key != null && !key.equals(principal)) {
throw new BadCredentialsException("The API key was not found or not the expected value.");
throw new BadCredentialsException("The API key was not found or not the expected valueUnknownExchangeTest.checkErrorMessages");
}
authentication.setAuthenticated(true);
return authentication;
Expand Down

0 comments on commit 89ced62

Please sign in to comment.