Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a26e203
aplicatia spring boot init
HampuCristian Mar 3, 2023
d83637a
test ceva
ciprianwang-dev Mar 3, 2023
437f64c
Merge branch 'feature/app' of https://github.com/radu103/curs-java in…
HampuCristian Mar 3, 2023
6204610
Merge pull request #3 from radu103/feature/cristi-app
HampuCristian Mar 3, 2023
6400133
sterg ca sunt ale lui ciprian
HampuCristian Mar 7, 2023
f6f68fa
remove login (hopefully)
HampuCristian Mar 9, 2023
0d7ce7e
didn't work
HampuCristian Mar 9, 2023
79b7d82
all actuators + security config
HampuCristian Mar 10, 2023
809b7c3
Merge pull request #11 from radu103/feature-cristi/all-actuators
HampuCristian Mar 10, 2023
7020860
mvc tests
HampuCristian Mar 17, 2023
2ac7f84
ce incercasem sa pun pentru ora trecuta
HampuCristian Mar 22, 2023
f69225c
vs code vrea sa dau commit(sper ca va fi bine :) )
HampuCristian Mar 22, 2023
3b76df7
new & improved(controller&tests)gets no work bcs""
HampuCristian Mar 23, 2023
20ced2b
ora trecuta + tema merge cu dev
HampuCristian Mar 30, 2023
5fe348a
au ramas si astea cumva
HampuCristian Mar 30, 2023
2b59252
a mai ramas si asta
HampuCristian Mar 30, 2023
cee8411
schimbare la controllerul vechi care am uitat sa o pun
HampuCristian Mar 30, 2023
bedb6ee
dependency scris de 2 ori
HampuCristian May 4, 2023
b3043a9
cristi profile now works
HampuCristian May 11, 2023
80247e2
teste service and validator
HampuCristian May 12, 2023
a9b4164
added model and year to validator + tests
HampuCristian May 12, 2023
3788837
split validation method for maker and model, separately
HampuCristian May 18, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ target/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
14 changes: 10 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<version>2.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ro.radu</groupId>
<groupId>ro.cristi</groupId>
<artifactId>curs</artifactId>
<version>1.0.0</version>
<name>java-app</name>
<description>Java App</description>
<name>java</name>
<description>JavaApp</description>
<properties>
<java.version>11</java.version>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -57,6 +57,12 @@
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ro/cristi/curs/Repository/CarRepository.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ro.cristi.curs.Repository;
package ro.cristi.curs.repository;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ro.cristi.curs.Repository;
package ro.cristi.curs.repository;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import ro.cristi.curs.Repository.MemoryRepository;
import ro.cristi.curs.model.Car;
import ro.cristi.curs.repository.MemoryRepository;

@Configuration
@Profile("cristi")
public class CarRepositoryConfigCristi {

@Bean
public void loadDataCristi() {
List<Car> list = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.context.annotation.Profile;

import ro.cristi.curs.model.Car;
import ro.cristi.curs.Repository.*;
import ro.cristi.curs.repository.*;

@Configuration
@Profile("dev")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.context.annotation.Profile;

import ro.cristi.curs.model.Car;
import ro.cristi.curs.Repository.*;
import ro.cristi.curs.repository.*;

@Configuration
@Profile("local")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public String getHello1() {
@PostMapping(path = "/helloworld/hello1", consumes = { MediaType.APPLICATION_JSON_VALUE }, produces = {
MediaType.APPLICATION_JSON_VALUE })
public String postHello1(@RequestBody HelloRequest helloRequest) {
return "Hello World : " + helloRequest.getInput();
return "Hello World : " + helloRequest.getA();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ro.cristi.curs.controller.v2;

import java.util.ArrayList;

import org.springframework.http.MediaType;
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.RestController;

import ro.cristi.curs.dto.HelloResponseButBetter;

@RestController
@RequestMapping("/v2")
public class HelloWorldButBetter {

@GetMapping(path = "/lista/limbaje")
public String getLimbaje(){
ArrayList<String> listaLimbaje = new ArrayList<String>(){
{
add("Java");
add("C++");
add("Python");
add("N-am avut inspiratie");
}
};
return listaLimbaje.toString();
}


@GetMapping(path = "/lista/jocuri")
public String getJocuri(){
ArrayList<String> listaJocuri = new ArrayList<String>() {
{
add("Osu!");
add("Genshin");
add("Sekai");
add("Adofai");
}
};
return listaJocuri.toString();
}

@GetMapping(path = "/vorbe_intelepte")
public HelloResponseButBetter responseVorba(){
HelloResponseButBetter respo = new HelloResponseButBetter();
respo.setMotivational("iti merge bine vere");
respo.setDemotivational("sau poate ca nu cred ca o sa iti mearga (plangi)");
return respo;
}

@PostMapping(path = "/vorbe_neintelepte", consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE})
public String postHelloV2(@RequestBody HelloResponseButBetter helloRequest){
return "Vorbele tale motivationale: " + helloRequest.getMotivational() + "\nSi alea demotivationale: " + helloRequest.getDemotivational();
}

}
8 changes: 4 additions & 4 deletions src/main/java/ro/cristi/curs/controller/v3/CarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import ro.cristi.curs.Repository.CarRepository;
import ro.cristi.curs.dto.CarDto;
import ro.cristi.curs.mapper.CarMapper;
import ro.cristi.curs.model.Car;
import ro.cristi.curs.service.CarService;
import ro.cristi.curs.repository.CarRepository;
import ro.cristi.curs.service.CarServiceBasic;

import java.util.*;

@RestController
@RequestMapping("/v1")
@RequestMapping("/v3")
public class CarController {

@Autowired
Expand All @@ -25,7 +25,7 @@ public class CarController {
CarMapper carMapper;

@Autowired
CarService carService;
CarServiceBasic carService;

@GetMapping("/car/list")
public List<CarDto> getCars() {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/ro/cristi/curs/dto/HelloRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
@Data
public class HelloRequest {

@JsonProperty("input")
String input;
}
@JsonProperty("a")
String a;
@JsonProperty("b")
String b;
}
14 changes: 14 additions & 0 deletions src/main/java/ro/cristi/curs/dto/HelloRequestButBetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ro.cristi.curs.dto;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;

@Data
public class HelloRequestButBetter {

@JsonProperty("motivational")
String motivational;
@JsonProperty("demotivational")
String demotivational;
}
14 changes: 14 additions & 0 deletions src/main/java/ro/cristi/curs/dto/HelloResponseButBetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ro.cristi.curs.dto;

import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;

@Data
public class HelloResponseButBetter {

@JsonProperty("motivational")
String motivational;
@JsonProperty("demotivational")
String demotivational;
}
1 change: 1 addition & 0 deletions src/main/java/ro/cristi/curs/dto/SedanDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ public class SedanDto extends CarDto{
private Integer doors;
private Boolean isElectric;
}

1 change: 1 addition & 0 deletions src/main/java/ro/cristi/curs/dto/VanDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@Data
public class VanDto extends CarDto{

private String capacity;
private Integer payload;
}
16 changes: 16 additions & 0 deletions src/main/java/ro/cristi/curs/exception/CarServiceException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ro.cristi.curs.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class CarServiceException extends RuntimeException{

private Integer errorCode;

public CarServiceException(Integer errorCode, String message){
super(message);
this.errorCode = errorCode;
}
}
17 changes: 17 additions & 0 deletions src/main/java/ro/cristi/curs/exception/CarValidatorException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ro.cristi.curs.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = false)
public class CarValidatorException extends RuntimeException {

private Integer errorCode;

public CarValidatorException(Integer errorCode, String message) {
super(message);
this.errorCode = errorCode;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import ro.cristi.curs.Repository.CarRepository;
import ro.cristi.curs.model.Car;
import ro.cristi.curs.repository.CarRepository;

@Service
public class CarService {
public class CarServiceBasic {

@Autowired
CarRepository carRepository;
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/ro/cristi/curs/service/CarServiceMemory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ro.cristi.curs.service;

import java.util.List;

import ro.cristi.curs.model.Car;

public interface CarServiceMemory {
List<Car> getExpensiveCars(Integer percent);

List<Car> getOlderCars(Integer years);

List<Car> getEfficientCars(Integer units);
}
60 changes: 60 additions & 0 deletions src/main/java/ro/cristi/curs/service/CarServiceMemoryImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package ro.cristi.curs.service;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;

import ro.cristi.curs.exception.CarServiceException;
import ro.cristi.curs.model.Car;
import ro.cristi.curs.repository.CarRepository;

@Service
@Profile("local")
public class CarServiceMemoryImpl implements CarServiceMemory {

@Autowired
CarRepository carRepository;

@Override
public List<Car> getExpensiveCars(Integer percent) throws CarServiceException {

List<Car> cars = carRepository.getAllCars();

if(percent > 100){
throw new CarServiceException(40001, "Percent must be less");
}
if (cars == null || cars.isEmpty()) {
throw new CarServiceException(50001, "No cars found");
} else if (cars.size()>1000) {
throw new CarServiceException(50002, "Too many cars found");
}
//after error checks
for (Car car : cars) {
car.setPrice(car.getPrice().multiply(BigDecimal.valueOf((100 + percent) / 100)));
}
return cars;
}

@Override
public List<Car> getOlderCars(Integer years){
//todo: exceptions
List<Car> cars = carRepository.getAllCars();
for(Car car : cars){
car.setYear(car.getYear() - years);
}
return cars;
}

@Override
public List<Car> getEfficientCars(Integer units){
//todo: exceptions
List<Car> cars = carRepository.getAllCars();
for(Car car : cars){
car.setConsumption(car.getConsumption() - units);
}
return cars;
}
}
Loading