Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE#90: Einkaufslistenwidget implementiert #146

Merged
merged 26 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
598c34d
FE-#90: init components shopping
Lica200 May 12, 2024
e794e05
FE-#90: default page extended
Lica200 May 12, 2024
cb6d153
FE-#90: renamed default-widget-page
Lica200 May 12, 2024
e99d3ea
FE-#90: renamed default-widget-page
Lica200 May 12, 2024
c838d3e
Merge branch 'main' into dev-einkaufsliste
ebauersandoval May 13, 2024
79e9943
FE-#90: refactor display of default page or einkaufsliste widget page
ebauersandoval May 13, 2024
ca4eed0
FE-#90: changes by Service
ebauersandoval May 13, 2024
4bb51d2
FE-#90: adjusted form
Lica200 May 13, 2024
1fbe090
Merge branch 'main' into dev-einkaufsliste
Lica200 May 14, 2024
a6515bb
FE-#90: eventanlegen works
Lica200 May 14, 2024
2ee77cb
Merge branch 'main' into dev-einkaufsliste
Lica200 May 15, 2024
b3b8913
FE-#90: edit eintrag hinzugefügt
Lica200 May 15, 2024
bd1b084
FE-#128: added new Component einkaufsliste-eintrag-list-item
ebauersandoval May 15, 2024
fe92738
FE-#90: beautify code
Lica200 May 15, 2024
1da710e
Merge remote-tracking branch 'origin/dev-einkaufsliste' into dev-eink…
Lica200 May 15, 2024
dda3b08
FE-#128: refactor widgetupdate after change and added checkbox before…
ebauersandoval May 15, 2024
99cce5c
FE-#128: adjust display of entry-cards and fix reload of widget in wi…
ebauersandoval May 16, 2024
56ceb46
FE-#128: added delete functionality in frontend and added logic for e…
ebauersandoval May 17, 2024
4bd0d40
FE-#128: fix edit functionality
ebauersandoval May 17, 2024
2a9d5cb
FE-#128: added test for Shopping Entry edit
ebauersandoval May 17, 2024
5f675f0
Merge branch 'refs/heads/main' into dev-einkaufsliste
ebauersandoval May 17, 2024
54d6048
Merge branch 'refs/heads/main' into dev-einkaufsliste
ebauersandoval May 18, 2024
0a4ff6a
FE-#128: refactored Test and loading of buyer id in entry card
ebauersandoval May 18, 2024
14887b1
FE-#128: refactored mobile view
ebauersandoval May 18, 2024
b7dbf8c
FE-#0: Remove material-components-web dependency
Drumber May 19, 2024
e98e7f4
FE-#90: Code-QA
Drumber May 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import com.dhbw.get2gether.backend.event.model.Event;
import com.dhbw.get2gether.backend.widget.application.ShoppingListWidgetService;
import com.dhbw.get2gether.backend.widget.model.shoppinglist.EntryAddCommand;
import com.dhbw.get2gether.backend.widget.model.shoppinglist.EntryCheckCommand;
import com.dhbw.get2gether.backend.widget.model.shoppinglist.ShoppingListCreateCommand;
import com.dhbw.get2gether.backend.widget.model.shoppinglist.ShoppingListWidget;
import com.dhbw.get2gether.backend.widget.model.shoppinglist.*;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -60,4 +57,15 @@
return service.checkEntry(principal, eventId, widgetId, entryId, checkCommand);
}

@PutMapping("/{widgetId}/entries/update/{entryId}")
public ShoppingListWidget updateEntry(
@AuthenticationPrincipal OAuth2User principal,
@PathVariable String eventId,
@PathVariable String widgetId,
@PathVariable String entryId,
@RequestBody EntryUpdateCommand updateCommand
) {
return service.updateEntry(principal, eventId, widgetId, entryId, updateCommand);

Check warning on line 68 in backend/src/main/java/com/dhbw/get2gether/backend/widget/adapter/in/ShoppingListWidgetController.java

View check run for this annotation

Codecov / codecov/patch

backend/src/main/java/com/dhbw/get2gether/backend/widget/adapter/in/ShoppingListWidgetController.java#L68

Added line #L68 was not covered by tests
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,25 @@ public ShoppingListWidget removeEntry(AuthenticatedPrincipal principal, String e
public ShoppingListWidget checkEntry(AuthenticatedPrincipal principal, String eventId, String widgetId, String entryId, EntryCheckCommand checkCommand) {
Event event = getEventById(principal, eventId);
ShoppingListWidget widget = getWidgetFromEvent(event, widgetId);
Entry entry = widget.getEntries().stream()
.filter(l -> Objects.equals(l.getId(), entryId)).findFirst()
.orElseThrow(() -> new EntityNotFoundException("Entry not found"));
Entry entry = getEntry(widget, entryId);
entry.check(userService.getUserByPrincipal(principal).getId(), mapper.mapEntryCheckCommandToEntryCheck(checkCommand));
return updateAndGetWidget(principal, event, widget);
}

@PreAuthorize("hasRole('USER')")
public ShoppingListWidget updateEntry(AuthenticatedPrincipal principal, String eventId, String widgetId, String entryId, EntryUpdateCommand updateCommand) {
Event event = getEventById(principal, eventId);
ShoppingListWidget widget = getWidgetFromEvent(event, widgetId);
Entry entry = getEntry(widget, entryId);
entry.update(updateCommand);
return updateAndGetWidget(principal, event, widget);
}

private Entry getEntry(ShoppingListWidget widget, String entryId) {
return widget.getEntries().stream()
.filter(l -> Objects.equals(l.getId(), entryId)).findFirst()
.orElseThrow(() -> new EntityNotFoundException("Entry not found"));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,9 @@ public void check(String buyerId, EntryCheck entryCheck) {
// BuyerID soll nicht gelöscht werden, wenn der Eintrag nicht mehr gecheckt ist, aber überschrieben werden können
}
}

public void update(EntryUpdateCommand updateEntry) {
this.description = updateEntry.getDescription();
this.amount = updateEntry.getAmount();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.dhbw.get2gether.backend.widget.model.shoppinglist;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Builder(toBuilder = true)
@Getter
@AllArgsConstructor
public class EntryUpdateCommand {
private String description;
private String amount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,61 @@ void shouldUnCheckEntry() {
.isEqualTo(entryAfterCheck);
assertThat(returnedWidget.getEntries().get(0).getId()).isNotBlank();
}

@Test
@WithMockOAuth2User
void shouldUpdateEntry() {
// given
AuthenticatedPrincipal principal = (AuthenticatedPrincipal)
SecurityContextHolder.getContext().getAuthentication().getPrincipal();
Entry entry = Entry.builder()
.description("Test")
.amount("1")
.checked(false)
.creatorId("creator-id")
.id("123")
.build();
ShoppingListWidget widget = ShoppingListWidget.builder()
.id("wi-123")
.entries(new ArrayList<>(List.of(entry)))
.build();
Event event = Event.builder()
.id("ev-123")
.widgets(new ArrayList<>(List.of(widget)))
.build();
EntryUpdateCommand updateCommand = EntryUpdateCommand.builder()
.description("Edited")
.amount("2")
.build();
Entry entryAfterUpdate = Entry.builder()
.description("Edited")
.amount("2")
.checked(false)
.creatorId("creator-id")
.id("123")
.build();

when(eventService.getSingleEvent(any(), eq(event.getId()))).thenReturn(event);
when(eventService.updateEventWidgets(any(), eq(event.getId()), any()))
.thenAnswer(i -> event.toBuilder()
.widgets(
i.getArgument(2, EventWidgetUpdateCommand.class).getWidgets()
)
.build()
);
when(userService.getUserByPrincipal(principal)).thenReturn(User.builder()
.id("test")
.email("[email protected]").build());

// when
ShoppingListWidget returnedWidget = shoppingListWidgetService.updateEntry(principal, event.getId(), widget.getId(), entry.getId(), updateCommand);

// then
assertThat(returnedWidget).isNotNull();
assertThat(returnedWidget.getEntries()).hasSize(1);
assertThat(returnedWidget.getEntries().get(0)).usingRecursiveComparison()
.ignoringFields("id")
.isEqualTo(entryAfterUpdate);
assertThat(returnedWidget.getEntries().get(0).getId()).isNotBlank();
}
}
Loading
Loading