Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client code to separate module #164

Merged
merged 10 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/sepuling/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ COPY sepuling*.jar app.jar
ENTRYPOINT [ \
"java", "-cp", "app.jar:libs/*", \
"-Dconfig.file=application.conf", \
"smecalculus.bezmen.interior.construction.App" \
"smecalculus.bezmen.construction.App" \
]
1 change: 0 additions & 1 deletion apps/sepuling/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<groupId>${project.groupId}</groupId>
<artifactId>storage</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>testing</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package smecalculus.bezmen.construction;

import static smecalculus.bezmen.configuration.MessageMappingMode.SPRING_MVC;
import static smecalculus.bezmen.configuration.StateMappingMode.MY_BATIS;
import static smecalculus.bezmen.configuration.StateMappingMode.SPRING_DATA;

import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;
import smecalculus.bezmen.core.SepulkaService;
import smecalculus.bezmen.core.SepulkaServiceImpl;
import smecalculus.bezmen.core.SepulkaSliceMapper;
import smecalculus.bezmen.core.SepulkaSliceMapperImpl;
import smecalculus.bezmen.messaging.SepulkaClient;
import smecalculus.bezmen.messaging.SepulkaClientImpl;
import smecalculus.bezmen.messaging.SepulkaMsgMapper;
import smecalculus.bezmen.messaging.SepulkaMsgMapperImpl;
import smecalculus.bezmen.messaging.springmvc.SepulkaController;
import smecalculus.bezmen.storage.SepulkaDao;
import smecalculus.bezmen.storage.SepulkaDaoMyBatis;
import smecalculus.bezmen.storage.SepulkaDaoSpringData;
import smecalculus.bezmen.storage.SepulkaRecMapper;
import smecalculus.bezmen.storage.SepulkaRecMapperImpl;
import smecalculus.bezmen.storage.mybatis.SepulkaSqlMapper;
import smecalculus.bezmen.storage.springdata.SepulkaRepository;
import smecalculus.bezmen.validation.EdgeValidator;

@Import({ValidationBeans.class, ConfigBeans.class, MessagingBeans.class, StorageBeans.class})
@PropertySource("classpath:application.properties")
@Configuration(proxyBeanMethods = false)
public class App {

public static void main(String[] args) {
SpringApplication.run(App.class, args);
}

@Bean
@ConditionalOnMessageMappingModes(SPRING_MVC)
SepulkaController sepulkaControllerSpringMvc(SepulkaClient client) {
return new SepulkaController(client);
}

@Bean
SepulkaMsgMapper sepulkaMsgMapper() {
return new SepulkaMsgMapperImpl();
}

@Bean
SepulkaClient sepulkaClient(EdgeValidator validator, SepulkaMsgMapper mapper, SepulkaService service) {
return new SepulkaClientImpl(validator, mapper, service);
}

@Bean
SepulkaSliceMapper sepulkaSliceMapper() {
return new SepulkaSliceMapperImpl();
}

@Bean
SepulkaService sepulkaService(SepulkaSliceMapper mapper, SepulkaDao dao) {
return new SepulkaServiceImpl(mapper, dao);
}

@Bean
SepulkaRecMapper sepulkaRecMapper() {
return new SepulkaRecMapperImpl();
}

@Bean
@ConditionalOnStateMappingMode(SPRING_DATA)
SepulkaDaoSpringData sepulkaDaoSpringData(SepulkaRecMapper mapper, SepulkaRepository repository) {
return new SepulkaDaoSpringData(mapper, repository);
}

@Bean
@ConditionalOnStateMappingMode(MY_BATIS)
SepulkaDaoMyBatis sepulkaDaoMyBatis(SepulkaRecMapper recMapper, SepulkaSqlMapper sqlMapper) {
return new SepulkaDaoMyBatis(recMapper, sqlMapper);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package smecalculus.bezmen.core;

import static java.util.UUID.randomUUID;

import java.util.List;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import smecalculus.bezmen.storage.SepulkaDao;

@RequiredArgsConstructor
public class SepulkaServiceImpl implements SepulkaService {

@NonNull
private SepulkaSliceMapper mapper;

@NonNull
private SepulkaDao dao;

@Override
public SepulkaNewResponse register(SepulkaNewRequest request) {
var sepulkaCreated = mapper.toDomain(request).id(randomUUID()).build();
var sepulkaSaved = dao.save(sepulkaCreated);
return mapper.toSlice(sepulkaSaved);
}

@Override
public List<Sepulka> getSepulkas() {
return dao.getSepulkas();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package smecalculus.bezmen.messaging;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import smecalculus.bezmen.core.SepulkaService;
import smecalculus.bezmen.validation.EdgeValidator;

@RequiredArgsConstructor
public class SepulkaClientImpl implements SepulkaClient {

@NonNull
private EdgeValidator validator;

@NonNull
private SepulkaMsgMapper mapper;

@NonNull
private SepulkaService service;

@Override
public SepulkaNewResponseMsg register(SepulkaNewRequestMsg requestMsg) {
validator.validate(requestMsg);
var request = mapper.toDomain(requestMsg);
var response = service.register(request);
return mapper.toMsg(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package smecalculus.bezmen.messaging.springmvc;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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.RestController;
import smecalculus.bezmen.messaging.SepulkaClient;
import smecalculus.bezmen.messaging.SepulkaNewRequestMsg;
import smecalculus.bezmen.messaging.SepulkaNewResponseMsg;

@RestController
@RequestMapping("sepulkas")
@RequiredArgsConstructor
public class SepulkaController {

@NonNull
private SepulkaClient client;

@PostMapping
ResponseEntity<SepulkaNewResponseMsg> register(@RequestBody SepulkaNewRequestMsg requestMsg) {
var responseMsg = client.register(requestMsg);
return ResponseEntity.status(HttpStatus.CREATED).body(responseMsg);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package smecalculus.bezmen.interior.storage;
package smecalculus.bezmen.storage;

import java.util.List;
import java.util.UUID;
import smecalculus.bezmen.interior.core.Sepulka;
import smecalculus.bezmen.core.Sepulka;

public interface SepulkaDao {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package smecalculus.bezmen.interior.storage;
package smecalculus.bezmen.storage;

import static java.util.stream.Collectors.toList;

import java.util.List;
import java.util.UUID;
import lombok.NonNull;
import smecalculus.bezmen.interior.core.Sepulka;
import smecalculus.bezmen.interior.storage.mybatis.SepulkaSqlMapper;
import lombok.RequiredArgsConstructor;
import smecalculus.bezmen.core.Sepulka;
import smecalculus.bezmen.storage.mybatis.SepulkaSqlMapper;

public record SepulkaDaoMyBatis(@NonNull SepulkaRecMapper recMapper, @NonNull SepulkaSqlMapper sqlMapper)
implements SepulkaDao {
@RequiredArgsConstructor
public class SepulkaDaoMyBatis implements SepulkaDao {

@NonNull
private SepulkaRecMapper recMapper;

@NonNull
private SepulkaSqlMapper sqlMapper;

@Override
public Sepulka getById(@NonNull UUID id) {
Expand Down
Loading