Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliL committed May 3, 2024
1 parent c210316 commit d3554e5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@
package org.laladev.moneyjinn.server.controller.impl.crud;

import java.util.List;
import java.util.Optional;

import org.laladev.moneyjinn.model.access.Group;
import org.laladev.moneyjinn.model.access.User;
import org.laladev.moneyjinn.model.access.UserID;
import org.laladev.moneyjinn.model.etf.Etf;
import org.laladev.moneyjinn.model.etf.EtfID;
import org.laladev.moneyjinn.model.setting.ClientListEtfDepotDefaultEtfId;
import org.laladev.moneyjinn.model.validation.ValidationResult;
import org.laladev.moneyjinn.server.controller.api.CrudEtfControllerApi;
import org.laladev.moneyjinn.server.controller.impl.AbstractController;
import org.laladev.moneyjinn.server.controller.mapper.EtfTransportMapper;
import org.laladev.moneyjinn.server.model.EtfTransport;
import org.laladev.moneyjinn.service.api.IAccessRelationService;
import org.laladev.moneyjinn.service.api.IEtfService;
import org.laladev.moneyjinn.service.api.ISettingService;
import org.laladev.moneyjinn.service.api.IUserService;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Propagation;
Expand All @@ -58,6 +61,7 @@ public class CrudEtfController extends AbstractController implements CrudEtfCont
private final IAccessRelationService accessRelationService;
private final IEtfService etfService;
private final IUserService userService;
private final ISettingService settingService;
private final EtfTransportMapper etfTransportMapper;

@Override
Expand All @@ -71,7 +75,17 @@ public ResponseEntity<List<EtfTransport>> readAll() {
final UserID userId = super.getUserId();
final List<Etf> etfs = this.etfService.getAllEtf(userId);

return ResponseEntity.ok(super.mapList(etfs, EtfTransport.class));
final List<EtfTransport> transports = super.mapList(etfs, EtfTransport.class);

final Optional<ClientListEtfDepotDefaultEtfId> setting = this.settingService
.getClientListEtfDepotDefaultEtfId(this.getUserId());
if (setting.isPresent()) {
final var favoriteEtfId = Long.valueOf(setting.get().getSetting());
transports.stream().filter(t -> t.getEtfId().equals(favoriteEtfId)).findFirst()
.ifPresent((e) -> e.setIsFavorite(1));

}
return ResponseEntity.ok(transports);
}

@Override
Expand All @@ -84,7 +98,18 @@ public ResponseEntity<EtfTransport> readOne(@PathVariable("id") final Long id) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(super.map(etf, EtfTransport.class));
final EtfTransport transport = super.map(etf, EtfTransport.class);

final Optional<ClientListEtfDepotDefaultEtfId> setting = this.settingService
.getClientListEtfDepotDefaultEtfId(this.getUserId());
if (setting.isPresent()) {
final var favoriteEtfId = Long.valueOf(setting.get().getSetting());
if (favoriteEtfId.equals(id)) {
transport.setIsFavorite(1);
}
}

return ResponseEntity.ok(transport);
}

@Override
Expand All @@ -104,6 +129,9 @@ public ResponseEntity<EtfTransport> create(@RequestBody final EtfTransport etfTr
final EtfID etfId = this.etfService.createEtf(etf);

etf.setId(etfId);
if (Integer.valueOf(1).equals(etfTransport.getIsFavorite()))
this.settingService.setClientListEtfDepotDefaultEtfId(userId,
new ClientListEtfDepotDefaultEtfId(etfId.getId().toString()));

return this.preferedReturn(prefer, etf, EtfTransport.class);

Expand All @@ -123,6 +151,9 @@ public ResponseEntity<EtfTransport> update(@RequestBody final EtfTransport etfTr
this.throwValidationExceptionIfInvalid(validationResult);

this.etfService.updateEtf(etf);
if (Integer.valueOf(1).equals(etfTransport.getIsFavorite()))
this.settingService.setClientListEtfDepotDefaultEtfId(userId,
new ClientListEtfDepotDefaultEtfId(etf.getId().getId().toString()));

return this.preferedReturn(prefer, etf, EtfTransport.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ public interface EtfTransportMapper extends IMapstructMapper<Etf, EtfTransport>
@Override
@Mapping(target = "etfId", source = "id")
@Mapping(target = "userid", source = "user.id")
@Mapping(target = "isFavorite", ignore = true)
EtfTransport mapAToB(Etf a);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
},
"chartUrl": {
"type": "string"
},
"isFavorite": {
"type": "integer",
"format": "int32"
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<mybatis.version>3.5.16</mybatis.version>
<mybatis-spring.version>3.0.3</mybatis-spring.version>
<commons.io.version>2.16.1</commons.io.version>
<commons.codec.version>1.16.1</commons.codec.version>
<commons.codec.version>1.17.0</commons.codec.version>
<apache.tika.version>3.0.0-BETA</apache.tika.version>
<jjwt.version>0.12.5</jjwt.version>
<lombok.version>1.18.32</lombok.version>
Expand Down

0 comments on commit d3554e5

Please sign in to comment.