@@ -38,8 +38,7 @@ public UUID createSpreadsheetConfig(SpreadsheetConfigInfos dto) {
38
38
39
39
@ Transactional
40
40
public UUID duplicateSpreadsheetConfig (UUID id ) {
41
- SpreadsheetConfigEntity entity = spreadsheetConfigRepository .findById (id )
42
- .orElseThrow (() -> new EntityNotFoundException ("SpreadsheetConfig not found with id: " + id ));
41
+ SpreadsheetConfigEntity entity = findEntityById (id );
43
42
44
43
SpreadsheetConfigEntity duplicate = SpreadsheetConfigEntity .builder ()
45
44
.sheetType (entity .getSheetType ())
@@ -59,9 +58,7 @@ public UUID duplicateSpreadsheetConfig(UUID id) {
59
58
60
59
@ Transactional (readOnly = true )
61
60
public SpreadsheetConfigInfos getSpreadsheetConfig (UUID id ) {
62
- return spreadsheetConfigRepository .findById (id )
63
- .map (SpreadsheetConfigMapper ::toDto )
64
- .orElseThrow (() -> new EntityNotFoundException ("SpreadsheetConfig not found with id: " + id ));
61
+ return SpreadsheetConfigMapper .toDto (findEntityById (id ));
65
62
}
66
63
67
64
@ Transactional (readOnly = true )
@@ -83,8 +80,7 @@ public List<MetadataInfos> getSpreadsheetConfigsMetadata(List<UUID> ids) {
83
80
84
81
@ Transactional
85
82
public void updateSpreadsheetConfig (UUID id , SpreadsheetConfigInfos dto ) {
86
- SpreadsheetConfigEntity entity = spreadsheetConfigRepository .findById (id )
87
- .orElseThrow (() -> new EntityNotFoundException ("SpreadsheetConfig not found with id: " + id ));
83
+ SpreadsheetConfigEntity entity = findEntityById (id );
88
84
89
85
entity .setSheetType (dto .sheetType ());
90
86
entity .getCustomColumns ().clear ();
@@ -98,9 +94,18 @@ public void updateSpreadsheetConfig(UUID id, SpreadsheetConfigInfos dto) {
98
94
@ Transactional
99
95
public void deleteSpreadsheetConfig (UUID id ) {
100
96
if (!spreadsheetConfigRepository .existsById (id )) {
101
- throw new EntityNotFoundException ( "SpreadsheetConfig not found with id: " + id );
97
+ throw entityNotFoundException ( id );
102
98
}
103
99
spreadsheetConfigRepository .deleteById (id );
104
100
}
105
101
102
+ private SpreadsheetConfigEntity findEntityById (UUID id ) {
103
+ return spreadsheetConfigRepository .findById (id )
104
+ .orElseThrow (() -> entityNotFoundException (id ));
105
+ }
106
+
107
+ private EntityNotFoundException entityNotFoundException (UUID id ) {
108
+ return new EntityNotFoundException ("SpreadsheetConfig not found with id: " + id );
109
+ }
110
+
106
111
}
0 commit comments