-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9995262
commit d19f16c
Showing
23 changed files
with
944 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,4 +47,5 @@ yarn-error.logy | |
*/coverage | ||
/libpeerconnection.log | ||
testem.log | ||
/typings | ||
/typings | ||
*.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
val springBootVersion by extra { "3.1.5" } | ||
val redisJedisVersion by extra { "5.0.2" } | ||
val apacheLang3Version by extra { "3.13.0" } | ||
|
||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath("org.springframework.boot:spring-boot-gradle-plugin:3.1.5") | ||
} | ||
} | ||
|
||
plugins { | ||
java | ||
id("org.springframework.boot") version "3.1.5" | ||
id("io.spring.dependency-management") version "1.1.3" | ||
} | ||
|
||
group = "com.project" | ||
version = "0.0.1-SNAPSHOT" | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
tasks.named<Test>("test") { | ||
useJUnitPlatform() | ||
} | ||
|
||
abstract class Redis : DefaultTask() { | ||
@TaskAction | ||
fun greet() { | ||
project.exec { | ||
commandLine("redis-server.exe") | ||
} | ||
} | ||
} | ||
|
||
// Create a task using the task type | ||
tasks.register<Redis>("redis") | ||
|
||
dependencyManagement { | ||
imports { | ||
mavenBom("org.springframework.boot:spring-boot-starter:$springBootVersion") | ||
} | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("org.springframework.boot:spring-boot-starter:$springBootVersion") | ||
implementation("org.springframework.boot:spring-boot-starter-web:$springBootVersion") | ||
implementation("org.springframework.boot:spring-boot-starter-data-redis:$springBootVersion") | ||
implementation("redis.clients:jedis:$redisJedisVersion") | ||
testImplementation("org.springframework.boot:spring-boot-starter-test:$springBootVersion") | ||
testImplementation("org.apache.commons:commons-lang3:$apacheLang3Version") | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
13 changes: 13 additions & 0 deletions
13
app-api/src/main/java/com/project/reactdashboard/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.project.reactdashboard; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
app-api/src/main/java/com/project/reactdashboard/config/RedisConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.project.reactdashboard.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.RedisStandaloneConfiguration; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
private static final String HOST = "localhost"; | ||
|
||
private static final int PORT = 6379; | ||
|
||
@Bean | ||
RedisConnectionFactory jedisConnectionFactory() { | ||
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(HOST, PORT); | ||
return new LettuceConnectionFactory(configuration); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, Object> redisTemplate() { | ||
RedisTemplate<String, Object> template = new RedisTemplate<>(); | ||
template.setConnectionFactory(jedisConnectionFactory()); | ||
template.setKeySerializer(new StringRedisSerializer()); | ||
template.setHashKeySerializer(new StringRedisSerializer()); | ||
template.setHashKeySerializer(new JdkSerializationRedisSerializer()); | ||
template.setValueSerializer(new JdkSerializationRedisSerializer()); | ||
template.setEnableTransactionSupport(true); | ||
template.afterPropertiesSet(); | ||
return template; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
app-api/src/main/java/com/project/reactdashboard/entities/Model.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.project.reactdashboard.entities; | ||
|
||
import org.springframework.data.redis.core.RedisHash; | ||
|
||
import java.io.Serializable; | ||
|
||
@RedisHash("Model") | ||
public class Model implements Serializable { | ||
|
||
private int id; | ||
|
||
private String value; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
public Model() { | ||
} | ||
|
||
private Model(ModelBuilder builder) { | ||
this.id = builder.id; | ||
this.value = builder.value; | ||
} | ||
|
||
public static class ModelBuilder{ | ||
|
||
private int id; | ||
|
||
private String value; | ||
|
||
public ModelBuilder(){ | ||
} | ||
|
||
public ModelBuilder withId(int id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public ModelBuilder withValue(String value) { | ||
this.value = value; | ||
return this; | ||
} | ||
|
||
public Model build(){ | ||
return new Model(this); | ||
} | ||
|
||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
app-api/src/main/java/com/project/reactdashboard/entities/ModelDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.project.reactdashboard.entities; | ||
|
||
public class ModelDto { | ||
|
||
private int id; | ||
|
||
private String value; | ||
|
||
public int getId() { | ||
return id; | ||
} | ||
|
||
public void setId(int id) { | ||
this.id = id; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
public ModelDto() { | ||
} | ||
|
||
private ModelDto(ModelDtoBuilder builder) { | ||
this.id = builder.id; | ||
this.value = builder.value; | ||
} | ||
|
||
public static class ModelDtoBuilder{ | ||
|
||
private int id; | ||
|
||
private String value; | ||
|
||
public ModelDtoBuilder(){ | ||
} | ||
|
||
public ModelDtoBuilder withId(int id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public ModelDtoBuilder withValue(String value) { | ||
this.value = value; | ||
return this; | ||
} | ||
|
||
public ModelDto build(){ | ||
return new ModelDto(this); | ||
} | ||
|
||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app-api/src/main/java/com/project/reactdashboard/stockmarket/StockMarketController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.project.reactdashboard.stockmarket; | ||
|
||
import com.project.reactdashboard.entities.Model; | ||
import com.project.reactdashboard.entities.ModelDto; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/api/stock-market") | ||
public class StockMarketController { | ||
|
||
private final StockMarketMapper mapper; | ||
|
||
private final StockMarketService service; | ||
|
||
public StockMarketController(StockMarketMapper mapper, StockMarketService service) { | ||
this.mapper = mapper; | ||
this.service = service; | ||
} | ||
|
||
@GetMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
public ResponseEntity<List<ModelDto>> findAll() { | ||
List<Model> models = service.findAll(); | ||
List<ModelDto> dtos = mapper.toListDto(models); | ||
return ResponseEntity.ok(dtos); | ||
} | ||
|
||
@PostMapping | ||
@ResponseStatus(HttpStatus.CREATED) | ||
public ResponseEntity<Integer> create(@RequestBody ModelDto modeldto) { | ||
Model model = mapper.toEntity(modeldto); | ||
service.create(model); | ||
return ResponseEntity.ok(1); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
app-api/src/main/java/com/project/reactdashboard/stockmarket/StockMarketMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.project.reactdashboard.stockmarket; | ||
|
||
import com.project.reactdashboard.entities.Model; | ||
import com.project.reactdashboard.entities.ModelDto; | ||
|
||
import java.util.List; | ||
|
||
public class StockMarketMapper { | ||
|
||
public Model toEntity(ModelDto dto) { | ||
return new Model.ModelBuilder() | ||
.withId(dto.getId()) | ||
.withValue(dto.getValue()) | ||
.build(); | ||
} | ||
|
||
public ModelDto toDto(Model entity) { | ||
return new ModelDto.ModelDtoBuilder() | ||
.withId(entity.getId()) | ||
.withValue(entity.getValue()) | ||
.build(); | ||
} | ||
|
||
public List<ModelDto> toListDto(List<Model> models) { | ||
return models.stream() | ||
.map(this::toDto) | ||
.toList(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app-api/src/main/java/com/project/reactdashboard/stockmarket/StockMarketRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.project.reactdashboard.stockmarket; | ||
|
||
import com.project.reactdashboard.entities.Model; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface StockMarketRepository extends CrudRepository<Model, String> { | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
app-api/src/main/java/com/project/reactdashboard/stockmarket/StockMarketService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.project.reactdashboard.stockmarket; | ||
|
||
import com.project.reactdashboard.entities.Model; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class StockMarketService { | ||
|
||
private final StockMarketRepository repository; | ||
|
||
public StockMarketService(StockMarketRepository repository) { | ||
this.repository = repository; | ||
} | ||
|
||
public void create(Model model) { | ||
repository.save(model); | ||
} | ||
|
||
public List<Model> findAll() { | ||
return (List<Model>) repository.findAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
Oops, something went wrong.