Skip to content

Commit 50d5dab

Browse files
committed
✨ p13n: back to lhmExtId as identifier because why not
1 parent adc2854 commit 50d5dab

File tree

14 files changed

+65
-65
lines changed

14 files changed

+65
-65
lines changed

personalization-service/src/main/java/de/muenchen/dbs/personalization/checklist/ChecklistRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
@Repository
1010
public interface ChecklistRepository extends JpaRepository<Checklist, UUID> {
1111

12-
List<Checklist> findChecklistByEmail(String email);
12+
List<Checklist> findChecklistByLhmExtId(String lhmExtId);
1313

1414
}

personalization-service/src/main/java/de/muenchen/dbs/personalization/checklist/ChecklistService.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,34 @@ public class ChecklistService {
2525
private final ChecklistRepository checklistRepository;
2626

2727
public Checklist createChecklist(final Checklist checklist) {
28-
final String userMail = getUserMailFromAuthenticationOrThrow();
29-
log.debug("Create Checklist {} for {}", checklist, userMail);
30-
checklist.setEmail(userMail);
28+
final String lhmExtId = getLhmExtIdFromAuthenticationOrThrow();
29+
log.debug("Create Checklist {} for {}", checklist, lhmExtId);
30+
checklist.setLhmExtId(lhmExtId);
3131
return checklistRepository.save(checklist);
3232
}
3333

3434
public List<Checklist> getChecklists() {
35-
final String userMail = getUserMailFromAuthenticationOrThrow();
36-
log.debug("Get all checklists of {}", userMail);
37-
return checklistRepository.findChecklistByEmail(userMail);
35+
final String lhmExtId = getLhmExtIdFromAuthenticationOrThrow();
36+
log.debug("Get all checklists of {}", lhmExtId);
37+
return checklistRepository.findChecklistByLhmExtId(lhmExtId);
3838
}
3939

4040
public Checklist getChecklist(final UUID checklistId) {
41-
final String userMail = getUserMailFromAuthenticationOrThrow();
42-
log.debug("Get checklist with ID {} for {}", checklistId, userMail);
41+
final String lhmExtId = getLhmExtIdFromAuthenticationOrThrow();
42+
log.debug("Get checklist with ID {} for {}", checklistId, lhmExtId);
4343
final Checklist checklistOrThrowException = getChecklistOrThrowException(checklistId);
4444

45-
isChecklistOwnerOrThrow(checklistOrThrowException, userMail);
45+
isChecklistOwnerOrThrow(checklistOrThrowException, lhmExtId);
4646

4747
return checklistOrThrowException;
4848
}
4949

5050
public Checklist updateChecklist(final Checklist checklist, final UUID checklistId) {
51-
final String userMail = getUserMailFromAuthenticationOrThrow();
52-
log.debug("Update checklist with ID {} for {}", checklistId, userMail);
51+
final String lhmExtId = getLhmExtIdFromAuthenticationOrThrow();
52+
log.debug("Update checklist with ID {} for {}", checklistId, lhmExtId);
5353
final Checklist foundChecklist = getChecklistOrThrowException(checklistId);
5454

55-
isChecklistOwnerOrThrow(foundChecklist, userMail);
55+
isChecklistOwnerOrThrow(foundChecklist, lhmExtId);
5656

5757
foundChecklist.setChecklistItems(checklist.getChecklistItems());
5858
foundChecklist.setLastUpdate(ZonedDateTime.now());
@@ -61,11 +61,11 @@ public Checklist updateChecklist(final Checklist checklist, final UUID checklist
6161
}
6262

6363
public void deleteChecklist(final UUID checklistId) {
64-
final String userMail = getUserMailFromAuthenticationOrThrow();
65-
log.debug("Delete Checklist with ID {} for {}", checklistId, userMail);
64+
final String lhmExtId = getLhmExtIdFromAuthenticationOrThrow();
65+
log.debug("Delete Checklist with ID {} for {}", checklistId, lhmExtId);
6666

6767
final Checklist foundChecklist = getChecklistOrThrowException(checklistId);
68-
isChecklistOwnerOrThrow(foundChecklist, userMail);
68+
isChecklistOwnerOrThrow(foundChecklist, lhmExtId);
6969

7070
checklistRepository.deleteById(checklistId);
7171
}
@@ -76,19 +76,19 @@ private Checklist getChecklistOrThrowException(final UUID checklistId) {
7676
.orElseThrow(() -> new NotFoundException(String.format(MSG_NOT_FOUND, checklistId)));
7777
}
7878

79-
private String getUserMailFromAuthenticationOrThrow() {
79+
private String getLhmExtIdFromAuthenticationOrThrow() {
8080
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
8181
if (authentication.getPrincipal() instanceof Jwt jwt) {
82-
final Object emailClaim = jwt.getClaims().get("email");
83-
if (emailClaim != null && !StringUtils.isBlank(emailClaim.toString())) {
84-
return emailClaim.toString();
82+
final Object lhmExtIdClaim = jwt.getClaims().get("lhmExtId");
83+
if (lhmExtIdClaim != null && !StringUtils.isBlank(lhmExtIdClaim.toString())) {
84+
return lhmExtIdClaim.toString();
8585
}
8686
}
8787
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED);
8888
}
8989

90-
private void isChecklistOwnerOrThrow(final Checklist checklist, final String userMail) {
91-
if (!checklist.getEmail().equals(userMail)) {
90+
private void isChecklistOwnerOrThrow(final Checklist checklist, final String lhmExtId) {
91+
if (!checklist.getLhmExtId().equals(lhmExtId)) {
9292
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "User does not own the checklist");
9393
}
9494
}

personalization-service/src/main/java/de/muenchen/dbs/personalization/checklist/domain/Checklist.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public class Checklist extends BaseEntity {
2525
@Serial
2626
private static final long serialVersionUID = 1L;
2727

28-
@Column(name = "email", nullable = false)
28+
@Column(name = "lhm_ext_id", nullable = false)
2929
@NotNull
30-
private String email;
30+
private String lhmExtId;
3131

3232
@Column(name = "title")
3333
@NotNull

personalization-service/src/main/java/de/muenchen/dbs/personalization/checklist/domain/ChecklistMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public interface ChecklistMapper {
1010
ChecklistReadDTO toReadDTO(Checklist checklist);
1111

1212
@Mapping(target = "id", ignore = true)
13-
@Mapping(target = "email", ignore = true)
13+
@Mapping(target = "lhmExtId", ignore = true)
1414
Checklist toCreateChecklist(ChecklistCreateDTO checklistUpdateDTO);
1515

1616
@Mapping(target = "id", ignore = true)

personalization-service/src/main/java/de/muenchen/dbs/personalization/checklist/domain/ChecklistReadDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.List;
66
import java.util.UUID;
77

8-
public record ChecklistReadDTO(@NotNull UUID id, @NotNull String email, @NotNull String title, @NotNull ZonedDateTime lastUpdate,
8+
public record ChecklistReadDTO(@NotNull UUID id, @NotNull String lhmExtId, @NotNull String title, @NotNull ZonedDateTime lastUpdate,
99
@NotNull List<ChecklistItemDTO> checklistItems) {
1010

1111
}

personalization-service/src/main/java/de/muenchen/dbs/personalization/checklist/domain/ChecklistUpdateDTO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
import java.util.List;
55
import java.util.UUID;
66

7-
public record ChecklistUpdateDTO(@NotNull UUID id, @NotNull String email, @NotNull String title, @NotNull List<ChecklistItemDTO> checklistItems) {
7+
public record ChecklistUpdateDTO(@NotNull UUID id, @NotNull String lhmExtId, @NotNull String title, @NotNull List<ChecklistItemDTO> checklistItems) {
88

99
}

personalization-service/src/main/resources/db/migration/schema/V001__Checklist_schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
create table checklist (
2-
email varchar(255) not null,
2+
lhm_ext_id varchar(255) not null,
33
title varchar(255) not null,
44
last_update timestamp with time zone,
55
id uuid not null,
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
truncate checklist CASCADE;
22
truncate checklist_item CASCADE;
33

4-
INSERT INTO checklist (email, title, last_update, id) VALUES
5-
('user1@example.com', 'title1', NOW(), '123e4567-e89b-12d3-a456-426614174000'),
6-
('user2@example.com', 'title2', NOW(), '123e4567-e89b-12d3-a456-426614174001'),
7-
('user3@example.com', 'title3', NOW(), '123e4567-e89b-12d3-a456-426614174002');
4+
INSERT INTO checklist (lhm_ext_id, title, last_update, id) VALUES
5+
('user1-lhm-ext-id', 'title1', NOW(), '123e4567-e89b-12d3-a456-426614174000'),
6+
('user2-lhm-ext-id', 'title2', NOW(), '123e4567-e89b-12d3-a456-426614174001'),
7+
('user3-lhm-ext-id', 'title3', NOW(), '123e4567-e89b-12d3-a456-426614174002');
88

99
INSERT INTO checklist_item (service_id, checked, title, note, required, checklist_id) VALUES
10-
('service1', NOW(), 'Item 1', 'Note for Item 1', TRUE, (select id from checklist where email='user1@example.com')),
11-
('service2', NOW(), 'Item 2', 'Note for Item 2', FALSE, (select id from checklist where email='user1@example.com')),
12-
('service3', NOW(), 'Item 3', 'Note for Item 3', FALSE, (select id from checklist where email='user2@example.com')),
13-
('service4', NOW(), 'Item 4', 'Note for Item 4', TRUE, (select id from checklist where email='user3@example.com')),
14-
('service5', NOW(), 'Item 5', 'Note for Item 5', TRUE, (select id from checklist where email='user3@example.com')),
15-
('service6', NOW(), 'Item 6', 'Note for Item 6', FALSE, (select id from checklist where email='user3@example.com'));
10+
('service1', NOW(), 'Item 1', 'Note for Item 1', TRUE, (select id from checklist where lhm_ext_id='user1-lhm-ext-id')),
11+
('service2', NOW(), 'Item 2', 'Note for Item 2', FALSE, (select id from checklist where lhm_ext_id='user1-lhm-ext-id')),
12+
('service3', NOW(), 'Item 3', 'Note for Item 3', FALSE, (select id from checklist where lhm_ext_id='user2-lhm-ext-id')),
13+
('service4', NOW(), 'Item 4', 'Note for Item 4', TRUE, (select id from checklist where lhm_ext_id='user3-lhm-ext-id')),
14+
('service5', NOW(), 'Item 5', 'Note for Item 5', TRUE, (select id from checklist where lhm_ext_id='user3-lhm-ext-id')),
15+
('service6', NOW(), 'Item 6', 'Note for Item 6', FALSE, (select id from checklist where lhm_ext_id='user3-lhm-ext-id'));

personalization-service/src/test/java/de/muenchen/dbs/personalization/IntegrationTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ public class IntegrationTestBase {
3232
@Autowired
3333
protected ObjectMapper objectMapper;
3434

35-
protected static final String TOKEN_USER_MAIL = "testuser@example.com";
35+
protected static final String TOKEN_USER_LHM_EXT_ID = "testuser-lhm-ext-id";
3636
protected static final Jwt DEFAULT_JWT = new Jwt(
3737
"tokenvalue",
3838
Instant.now(),
3939
Instant.now().plusSeconds(3600),
4040
Map.of("alg", "HS256",
4141
"typ", "JWT"),
42-
Map.of("email", TOKEN_USER_MAIL));
42+
Map.of("lhmExtId", TOKEN_USER_LHM_EXT_ID));
4343
}

personalization-service/src/test/java/de/muenchen/dbs/personalization/checklist/ChecklistIntegrationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class ChecklistIntegrationTest extends IntegrationTestBase {
5151
@BeforeEach
5252
public void setUp() {
5353
checklistRepository.deleteAll();
54-
final Checklist exampleChecklist = createTestChecklist(null, TOKEN_USER_MAIL, null);
54+
final Checklist exampleChecklist = createTestChecklist(null, TOKEN_USER_LHM_EXT_ID, null);
5555
testChecklistId = checklistRepository.save(exampleChecklist).getId();
5656
}
5757

@@ -70,14 +70,14 @@ void givenChecklistId_thenReturnChecklist() throws Exception {
7070
.andExpect(status().isOk())
7171
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
7272
.andExpect(jsonPath("$.id", is(testChecklistId.toString())))
73-
.andExpect(jsonPath("$.email", is(TOKEN_USER_MAIL)));
73+
.andExpect(jsonPath("$.lhmExtId", is(TOKEN_USER_LHM_EXT_ID)));
7474
}
7575
}
7676

7777
@Nested
7878
class GetChecklists {
7979
@Test
80-
void givenEmail_thenReturnChecklists() throws Exception {
80+
void givenLhmExtId_thenReturnChecklists() throws Exception {
8181
mockMvc.perform(get("/checklist")
8282
.contentType(MediaType.APPLICATION_JSON)
8383
.with(SecurityMockMvcRequestPostProcessors.jwt().jwt(DEFAULT_JWT)))
@@ -107,7 +107,7 @@ void givenChecklist_thenChecklistIsSaved() throws Exception {
107107
.with(SecurityMockMvcRequestPostProcessors.jwt().jwt(DEFAULT_JWT)))
108108
.andExpect(status().isCreated())
109109
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
110-
.andExpect(jsonPath("$.email", is(TOKEN_USER_MAIL)));
110+
.andExpect(jsonPath("$.lhmExtId", is(TOKEN_USER_LHM_EXT_ID)));
111111
}
112112
}
113113

0 commit comments

Comments
 (0)