Skip to content

Commit

Permalink
Merge pull request #60 from kohei-s/filter-collection
Browse files Browse the repository at this point in the history
Filter collection
  • Loading branch information
kohei-s authored Sep 5, 2023
2 parents 1c44460 + 3180d53 commit e8a64a3
Show file tree
Hide file tree
Showing 151 changed files with 804 additions and 237 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v2
with:
#Set Java Version
java-version: '20'
distribution: 'adopt'
cache: 'maven'
Expand All @@ -67,15 +66,13 @@ jobs:
- name: Login to DockerHub
uses: docker/login-action@v1
with:
#Set dockerhub username
username: kokoyuyu
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push
uses: docker/build-push-action@v2
with:
push: true
#Set dockerhub project (replace "bartfastiel/java-capstone-project.de-example-app")
tags: kokoyuyu/kotoko-app:latest
context: .

Expand All @@ -87,21 +84,17 @@ jobs:
uses: appleboy/ssh-action@master
with:
host: ec2-3-79-82-35.eu-central-1.compute.amazonaws.com
#Set App Name (replace "example" with your ssh user name)
username: ec2-user
key: ${{ secrets.SSH_KEY }}
#Set App Name (replace "example" with your ssh user name)
#Set dockerhub project (replace "bartfastiel/java-capstone-project.de-example-app")
script: |
docker stop ec2-user
docker rm ec2-user
docker run --pull=always --name ec2-user --publish 80:8080 --detach --env MONGO_DB_URI=${{ secrets.MONGO_DB_URI }} kokoyuyu/kotoko-app:latest
docker stop kotokocontainer
docker rm kotokocontainer
docker run --pull=always --name kotokocontainer --publish 80:8080 --detach --env MONGO_DB_URI=${{ secrets.MONGO_DB_URI }} kokoyuyu/kotoko-app:latest
sleep 15s
docker logs ec2-user
docker logs kotokocontainer
- name: Check the deployed service URL
uses: jtalk/url-health-check-action@v3
with:
#Set App Name (replace "example" with your ssh user name)
url: http://ec2-3-79-82-35.eu-central-1.compute.amazonaws.com
max-attempts: 3
retry-delay: 5s
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/show-logs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ jobs:
uses: appleboy/ssh-action@master
with:
host: ec2-3-79-82-35.eu-central-1.compute.amazonaws.com
#Set App Name (replace "example" with "alpha"-"tango")
username: ec2-user
key: ${{ secrets.SSH_KEY }}
#Set App Name (replace "example" with "alpha"-"tango")
script: |
sudo docker logs ec2-user
sudo docker logs kotokocontainer
- name: Check the deployed service URL
uses: jtalk/url-health-check-action@v3
with:
#Set App Name (replace "example" with "alpha"-"tango")
url: http://ec2-3-79-82-35.eu-central-1.compute.amazonaws.com
max-attempts: 3
retry-delay: 5s
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# KoToKo: Japanese concentration game app
This mobile application is developed 🛠️ as my personal capstone project for [Java Development Bootcamp at neue fische](https://www.neuefische.de/en/bootcamp/java-development) from May to August 2023 (👉 [])
This mobile application is developed 🛠️ as my personal capstone project for [Java Development Bootcamp at neue fische](https://www.neuefische.de/en/bootcamp/java-development) from May to August 2023 (try the latest version 👉 [Kotoko](https://kotoko.de))

[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=kohei-s_kotoko-concentration-app-frontend&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=kohei-s_kotoko-concentration-app-frontend) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=kohei-s_kotoko-concentration-app-frontend&metric=coverage)](https://sonarcloud.io/summary/new_code?id=kohei-s_kotoko-concentration-app-frontend) [![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=kohei-s_kotoko-concentration-app-frontend&metric=sqale_index)](https://sonarcloud.io/summary/new_code?id=kohei-s_kotoko-concentration-app-frontend) \
\
Expand All @@ -18,8 +18,8 @@ Children between 5-15 years old learning Japanese as (one of) their home languag
🪄 Personalize game contents with your favorite Japanese characters \
📖 Add new characters you're about to learn \
🗻 Show game records you achieved \
📚 Expand your Hiragana & Katakana knowledge with additional diacritics cards \
🛝 Child friendly design \
(** upcoming features) \
🔎 Search Japanese character in your strongest language e.g. English or German** \
❤️ Praise your kids for their achievements and keep cheering them (feature for parents)** \
📚 Expand your Hiragana & Katakana knowledge with Diacritics Cards**
(** upcoming features)
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public class GameCard {

@NotBlank
private String cardSetName;

private String authorId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.neuefische.koheis.backend.gamegcards;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class GameCardWithoutAuthorId {
private String title;
private String cardSetName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
public class GameCardWithoutId {
private String title;
private String cardSetName;

private String authorId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ List<GameCard> getAllGameCards() {
return gameCardsService.getAllGameCards();
}

@GetMapping("/myAll")
List<GameCard> getAllMyGameCards() {

return gameCardsService.getAllMyGameCards();
}

@GetMapping("/{id}")
public ResponseEntity<GameCard> getGameCardById(@PathVariable("id") String id) {
try {
Expand All @@ -42,9 +48,9 @@ GameCardsGrid getGameCardsSet(@RequestParam String size, @RequestParam String na

@PostMapping
@ResponseStatus(HttpStatus.CREATED)
GameCard addGameCard(@Valid @RequestBody GameCardWithoutId gameCardWithoutId) {
GameCard addGameCard(@Valid @RequestBody GameCardWithoutAuthorId gameCardWithoutAuthorId) {

return gameCardsService.addGameCard(gameCardWithoutId);
return gameCardsService.addGameCard(gameCardWithoutAuthorId);
}

@PutMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface GameCardsRepository extends MongoRepository<GameCard, String> {

List<GameCard> findAllByAuthorId(String authorId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.neuefische.koheis.backend.gamegcards;

import de.neuefische.koheis.backend.idservice.IdService;
import de.neuefische.koheis.backend.security.MongoUserService;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -13,16 +15,26 @@ public class GameCardsService {
private final GameCardsRepository gameCardsRepository;
private final IdService idService;

GameCardsService(GameCardsRepository gameCardsRepository, IdService idService) {
private final MongoUserService mongoUserService;

GameCardsService(GameCardsRepository gameCardsRepository, IdService idService, MongoUserService mongoUserService) {
this.gameCardsRepository = gameCardsRepository;
this.idService = idService;
this.mongoUserService = mongoUserService;
}

public List<GameCard> getAllGameCards(){

return gameCardsRepository.findAll();
}

public List<GameCard> getAllMyGameCards() {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
String userId = mongoUserService.findUserIdByUsername(username);

return gameCardsRepository.findAllByAuthorId(userId);
}

public GameCard getGameCardById(String id){

return gameCardsRepository.findById(id)
Expand Down Expand Up @@ -77,7 +89,7 @@ public GameCard[][] generateGameBoard(String gameSize, List<GameCard> allGameCar
GameCard[][] gameCardGrid = new GameCard[rowAndColumn[0]][rowAndColumn[1]];
List<GameCard> gameCards = new ArrayList<>(allGameCards.subList(0, pairing));
gameCards.addAll(List.copyOf(gameCards));
GameCard emptyCard = new GameCard(idService.createRandomId(), "empty", "empty");
GameCard emptyCard = new GameCard(idService.createRandomId(), "empty", "empty", "all");
if (gameSize.equals("small")) {
gameCards.add(emptyCard);
}
Expand All @@ -93,15 +105,17 @@ public GameCard[][] generateGameBoard(String gameSize, List<GameCard> allGameCar
return gameCardGrid;
}

public GameCard addGameCard (GameCardWithoutId gameCardWithoutId) {
public GameCard addGameCard (GameCardWithoutAuthorId gameCardWithoutAuthorId) {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
String userId = mongoUserService.findUserIdByUsername(username);

return gameCardsRepository.insert(new GameCard(idService.createRandomId(), gameCardWithoutId.getTitle(), gameCardWithoutId.getCardSetName()));
return gameCardsRepository.insert(new GameCard(idService.createRandomId(), gameCardWithoutAuthorId.getTitle(), gameCardWithoutAuthorId.getCardSetName(), userId));
}

public GameCard updateGameCard(GameCardWithoutId gameCardWithoutId, String id){
if (!gameCardsRepository.existsById(id)) throw new NoSuchElementException();

return gameCardsRepository.save(new GameCard(id, gameCardWithoutId.getTitle(), gameCardWithoutId.getCardSetName()));
return gameCardsRepository.save(new GameCard(id, gameCardWithoutId.getTitle(), gameCardWithoutId.getCardSetName(), gameCardWithoutId.getAuthorId()));
}

public void deleteGameCard(String id){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public UserInfo findByUsername(String username) {
return new UserInfo(mongoUser.username(), mongoUser.achievement(), mongoUser.wordbook(), mongoUser.diacritics(), mongoUser.levels(), mongoUser.selectedCardSet());
}

public String findUserIdByUsername(String username) {
MongoUser user = mongoUserRepository.findByUsername(username).orElseThrow();
return user.id();
}

public void registerUser(MongoUserCreation mongoUserWithoutId) {
if (mongoUserRepository.existsByUsername(mongoUserWithoutId.username())) {
throw new IllegalArgumentException("User: " + mongoUserWithoutId.username() + " exists already!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
httpRequests
.requestMatchers(HttpMethod.GET, "/api/game_cards").permitAll()
.requestMatchers("/api/game_cards").authenticated()
.requestMatchers(HttpMethod.GET, "/api/game_cards/**").permitAll()
.requestMatchers(HttpMethod.GET, "/api/game_cards/all").permitAll()
.requestMatchers(HttpMethod.GET, "/api/game_cards/**").authenticated()
.requestMatchers("/api/game_cards/**").authenticated()
.requestMatchers("/api/users/me").authenticated()
.anyRequest().permitAll()
Expand Down
Loading

0 comments on commit e8a64a3

Please sign in to comment.