Skip to content

Commit fef3eed

Browse files
authored
Merge pull request #5 from bababebr/add-utils-vcf-calculation
feat: add vcf calculation util
2 parents c78508e + c530df8 commit fef3eed

File tree

7 files changed

+96
-6
lines changed

7 files changed

+96
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ru.oil.exception;
2+
3+
public class UtilsException extends RuntimeException {
4+
5+
public UtilsException(String message) {
6+
super(message);
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package ru.oil.units.vcf;
2+
3+
/**
4+
* TODO:
5+
* Implements Table 6
6+
*/
7+
8+
public class Vcf6 {
9+
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
package ru.oil.utils;
22

3-
import org.springframework.web.bind.annotation.GetMapping;
4-
import org.springframework.web.bind.annotation.PathVariable;
5-
import org.springframework.web.bind.annotation.RequestMapping;
6-
import org.springframework.web.bind.annotation.RestController;
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.web.bind.annotation.*;
75
import ru.oil.enums.Tables;
86
import ru.oil.utils.model.VcfDto;
7+
import ru.oil.utils.service.VcfService;
98

109
@RestController
1110
@RequestMapping("/utils")
1211
public class UtilsController {
1312

13+
private final VcfService vcfService;
14+
15+
@Autowired
16+
public UtilsController(VcfService vcfService) {
17+
this.vcfService = vcfService;
18+
}
19+
1420
@GetMapping("/vcf")
15-
public VcfDto getVcf(@PathVariable Tables table) {
16-
return
21+
public VcfDto getVcf(@RequestParam Double api, @RequestParam Double temp, @RequestParam Tables table,
22+
@RequestHeader("Is-Api") boolean isApi, @RequestHeader("Is-Celsius") boolean isCelsius) {
23+
return vcfService.getVcf(api, temp, table, isApi, isCelsius);
1724
}
1825
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.oil.utils.mapper;
2+
3+
import ru.oil.units.vcf.Vcf;
4+
import ru.oil.utils.model.VcfDto;
5+
6+
public class VcfMapper {
7+
8+
public static VcfDto vcfToDto(Vcf vcf) {
9+
return VcfDto.create(vcf.getVcf());
10+
}
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
package ru.oil.utils.model;
22

3+
import lombok.AccessLevel;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import lombok.experimental.FieldDefaults;
8+
9+
@AllArgsConstructor(staticName = "create")
10+
@FieldDefaults(level = AccessLevel.PRIVATE)
11+
@Getter
12+
@Setter
313
public class VcfDto {
414

15+
double vcf;
516
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ru.oil.utils.service;
2+
3+
import ru.oil.enums.Tables;
4+
import ru.oil.utils.model.VcfDto;
5+
6+
public interface IVcfService {
7+
8+
VcfDto getVcf(double api, double temperature, Tables table, boolean isApi, boolean isCelsius);
9+
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package ru.oil.utils.service;
2+
3+
import org.springframework.stereotype.Service;
4+
import ru.oil.enums.Tables;
5+
import ru.oil.exception.UtilsException;
6+
import ru.oil.units.api.Api;
7+
import ru.oil.units.temperature.Temperature;
8+
import ru.oil.units.vcf.*;
9+
import ru.oil.utils.mapper.VcfMapper;
10+
import ru.oil.utils.model.VcfDto;
11+
12+
@Service
13+
public class VcfService implements IVcfService {
14+
@Override
15+
public VcfDto getVcf(double apiOrDensity, double temperature, Tables table, boolean isApi, boolean isCelsius) {
16+
Api api = isApi ? Api.fromApi(apiOrDensity) : Api.formDens(apiOrDensity);
17+
Temperature temp = isCelsius ? Temperature.fromCelius(temperature) : Temperature.fromFahrenheit(temperature);
18+
switch (table) {
19+
case Table6A:
20+
return VcfMapper.vcfToDto(Vcf6A.create(api, temp));
21+
case Table6B:
22+
return VcfMapper.vcfToDto(Vcf6B.create(api, temp));
23+
case Table54A:
24+
return VcfMapper.vcfToDto(Vcf54A.create(api, temp));
25+
case Table54B:
26+
return VcfMapper.vcfToDto(Vcf54B.create(api, temp));
27+
case Table6:
28+
throw new UtilsException("Table 6 not implemented yet.");
29+
default:
30+
throw new UtilsException(String.format("Table=%s not exist", table));
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)