-
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.
Thumbnail, new schema offers, enable changing visibility
- Loading branch information
1 parent
92af67d
commit f6447a9
Showing
11 changed files
with
204 additions
and
18 deletions.
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 |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
public enum CarStatus { | ||
|
||
FIRST_INITIALIZATION, NEW, DISPLAYED; | ||
NEW, SEEN, FIRST_INITIALIZATION; | ||
|
||
} |
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/example/backend/scheme/dto/SchemeDisplayDto.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,32 @@ | ||
package com.example.backend.scheme.dto; | ||
|
||
import com.example.backend.scheme.CarStatus; | ||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import java.util.Set; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class SchemeDisplayDto { | ||
|
||
private Set<Long> ids; | ||
|
||
private CarStatus status; | ||
|
||
public Set<Long> getIds() { | ||
return ids; | ||
} | ||
|
||
public void setIds(Set<Long> ids) { | ||
this.ids = ids; | ||
} | ||
|
||
public CarStatus getStatus() { | ||
return status; | ||
} | ||
|
||
public void setStatus(CarStatus status) { | ||
this.status = status; | ||
} | ||
} |
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
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
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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/example/backend/scheme/service/SchemeToCarService.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,40 @@ | ||
package com.example.backend.scheme.service; | ||
|
||
import com.example.backend.common.ErrorCode; | ||
import com.example.backend.exception.exceptions.IllegalInputException; | ||
import com.example.backend.scheme.CarStatus; | ||
import com.example.backend.scheme.dto.SchemeDisplayDto; | ||
import com.example.backend.scheme.model.SchemeToCar; | ||
import com.example.backend.scheme.repository.SchemeToCarRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Set; | ||
|
||
@Service | ||
public class SchemeToCarService { | ||
|
||
private final SchemeToCarRepository schemeToCarRepository; | ||
|
||
public SchemeToCarService(SchemeToCarRepository schemeToCarRepository) { | ||
this.schemeToCarRepository = schemeToCarRepository; | ||
} | ||
|
||
public Set<SchemeToCar> changeVisibility(SchemeDisplayDto schemeDisplayDto) throws IllegalInputException { | ||
CarStatus status = schemeDisplayDto.getStatus(); | ||
Set<Long> schemeToCarIds = schemeDisplayDto.getIds(); | ||
|
||
if (status == null || CarStatus.FIRST_INITIALIZATION.equals(status)) | ||
throw new IllegalInputException(ErrorCode.STATUS_NOT_ALLOWED); | ||
|
||
if (schemeToCarIds == null || schemeToCarIds.isEmpty()) | ||
throw new IllegalInputException(ErrorCode.CAR_IDS_REQUIRED); | ||
|
||
Set<SchemeToCar> schemeToCars = schemeToCarRepository.findAllByIdIn(schemeToCarIds); | ||
for (SchemeToCar schemeToCar : schemeToCars) | ||
schemeToCar.setStatus(status); | ||
|
||
schemeToCarRepository.saveAll(schemeToCars); | ||
return schemeToCars; | ||
} | ||
|
||
} |