Skip to content

Commit

Permalink
avniproject/avni-webapp#1203 - standard report card type as part of r…
Browse files Browse the repository at this point in the history
…eport card web contract. renamed web endpoints from card to reportCard.
  • Loading branch information
petmongrels committed May 8, 2024
1 parent a9a61fc commit 290e434
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public ReportCard editCard(CardContract newCard, Long cardId) {
ReportCard existingCard = cardRepository.findOne(cardId);
assertNewNameIsUnique(newCard.getName(), existingCard.getName());
buildCard(newCard, existingCard);
cardRepository.save(existingCard);
return existingCard;
return cardRepository.save(existingCard);
}

public void deleteCard(ReportCard card) {
Expand All @@ -70,6 +69,7 @@ private void buildCard(CardContract cardContract, ReportCard card) {
card.setVoided(cardContract.isVoided());
card.setIconFileS3Key(cardContract.getIconFileS3Key());
Long standardReportCardTypeId = cardContract.getStandardReportCardTypeId();

if (standardReportCardTypeId != null) {
StandardReportCardType type = standardReportCardTypeRepository.findById(standardReportCardTypeId).orElse(null);
if (type == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,35 @@
import java.util.stream.Collectors;

@RestController
public class CardController {
public class ReportCardController {
private final CardRepository cardRepository;
private final CardService cardService;
private final AccessControlService accessControlService;

@Autowired
public CardController(CardRepository cardRepository, CardService cardService, AccessControlService accessControlService) {
public ReportCardController(CardRepository cardRepository, CardService cardService, AccessControlService accessControlService) {
this.cardRepository = cardRepository;
this.cardService = cardService;
this.accessControlService = accessControlService;
}

@GetMapping(value = "/web/card")
@GetMapping(value = "/web/reportCard")
@ResponseBody
public List<CardContract> getAll() {
return cardRepository.findAllByIsVoidedFalse()
.stream().map(CardContract::fromEntity)
.collect(Collectors.toList());
}

@GetMapping(value = "/web/card/{id}")
@GetMapping(value = "/web/reportCard/{id}")
@ResponseBody
public ResponseEntity<CardContract> getById(@PathVariable Long id) {
Optional<ReportCard> card = cardRepository.findById(id);
return card.map(c -> ResponseEntity.ok(CardContract.fromEntity(c)))
.orElseGet(() -> ResponseEntity.notFound().build());
}

@PostMapping(value = "/web/card")
@PostMapping(value = "/web/reportCard")
@ResponseBody
@Transactional
public ResponseEntity<CardContract> newCard(@RequestBody CardContract cardContract) {
Expand All @@ -53,7 +53,7 @@ public ResponseEntity<CardContract> newCard(@RequestBody CardContract cardContra
return ResponseEntity.ok(CardContract.fromEntity(card));
}

@PutMapping(value = "/web/card/{id}")
@PutMapping(value = "/web/reportCard/{id}")
@ResponseBody
@Transactional
public ResponseEntity<CardContract> editCard(@PathVariable Long id, @RequestBody CardContract cardContract) {
Expand All @@ -62,11 +62,11 @@ public ResponseEntity<CardContract> editCard(@PathVariable Long id, @RequestBody
if (!card.isPresent()) {
return ResponseEntity.notFound().build();
}
ReportCard newCard = cardService.editCard(cardContract, id);
return ResponseEntity.ok(CardContract.fromEntity(newCard));
ReportCard savedCard = cardService.editCard(cardContract, id);
return ResponseEntity.ok(CardContract.fromEntity(savedCard));
}

@DeleteMapping(value = "/web/card/{id}")
@DeleteMapping(value = "/web/reportCard/{id}")
@ResponseBody
@Transactional
public void deleteCard(@PathVariable Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CardContract extends CHSRequest {
private String color;
private Double displayOrder;
private Long standardReportCardTypeId;
private StandardReportCardTypeContract standardReportCardType;
private String iconFileS3Key;
private boolean nested;
private int count;
Expand All @@ -23,7 +24,8 @@ public static CardContract fromEntity(ReportCard card) {
cardContract.setQuery(card.getQuery());
cardContract.setDescription(card.getDescription());
cardContract.setColor(card.getColour());
cardContract.setStandardReportCardTypeId(card.getStandardReportCardTypeId());
if (card.getStandardReportCardType() != null)
cardContract.standardReportCardType = StandardReportCardTypeContract.fromEntity(card.getStandardReportCardType());
cardContract.setIconFileS3Key(card.getIconFileS3Key());
cardContract.setNested(card.isNested());
cardContract.setCount(card.getCountOfCards());
Expand Down Expand Up @@ -107,4 +109,12 @@ public int getCount() {
public void setCount(int count) {
this.count = count;
}

public StandardReportCardTypeContract getStandardReportCardType() {
return standardReportCardType;
}

public void setStandardReportCardType(StandardReportCardTypeContract standardReportCardType) {
this.standardReportCardType = standardReportCardType;
}
}

0 comments on commit 290e434

Please sign in to comment.