Skip to content

Commit 809c998

Browse files
authored
Muxdbs 74 data model and interface for checklist (#9)
* ✨ add checklist to personalization-service * ✨ add last_update and change checked to ZonedDateTime * ✨ add swagger ui * ✨ add delete checklist * ✨ configure openai documentation * ✨ rename refarch to dbs * ✨ delete theentity * ✨ delete theentity * ✨ fix pmd and spotbugs errors and add title to Checklist.java * ✨ adjust swagger documentation * ✨ fix tests * ✨ set log.debug * ✨ pr feedback * ✨ pr feedback * ✨ pr feedback * ✨ pr feedback
1 parent 1ab5605 commit 809c998

40 files changed

+800
-524
lines changed

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "refarch-templates-docs",
2+
"name": "dbs-templates-docs",
33
"version": "0.0.0",
44
"type": "module",
55
"private": true,

personalization-service/pom.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353

5454
<!-- Additional required dependencies -->
5555
<lombok-mapstruct-binding.version>0.2.0</lombok-mapstruct-binding.version> <!-- Needed to make MapStruct and Lombok work together -->
56+
<springdoc-openapi-starter-webmvc-ui.version>2.8.8</springdoc-openapi-starter-webmvc-ui.version>
57+
<springdoc-openapi-maven-plugin.version>1.5</springdoc-openapi-maven-plugin.version>
58+
<therapi-runtime-javadoc.version>0.15.0</therapi-runtime-javadoc.version>
5659

5760
<!-- Flyway maven plugin configuration for local stack database -->
5861
<flyway.url>jdbc:postgresql://localhost:5432/postgres</flyway.url>
@@ -163,6 +166,16 @@
163166
<artifactId>spotbugs-annotations</artifactId>
164167
<version>${spotbugs-annotations.version}</version>
165168
</dependency>
169+
<dependency>
170+
<groupId>org.springdoc</groupId>
171+
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
172+
<version>${springdoc-openapi-starter-webmvc-ui.version}</version>
173+
</dependency>
174+
<dependency>
175+
<groupId>com.github.therapi</groupId>
176+
<artifactId>therapi-runtime-javadoc</artifactId>
177+
<version>${therapi-runtime-javadoc.version}</version>
178+
</dependency>
166179

167180
<!-- Testing -->
168181
<dependency>
@@ -270,6 +283,11 @@
270283
<artifactId>lombok-mapstruct-binding</artifactId>
271284
<version>${lombok-mapstruct-binding.version}</version>
272285
</path>
286+
<path>
287+
<groupId>com.github.therapi</groupId>
288+
<artifactId>therapi-runtime-javadoc-scribe</artifactId>
289+
<version>${therapi-runtime-javadoc.version}</version>
290+
</path>
273291
</annotationProcessorPaths>
274292
<showDeprecation>true</showDeprecation>
275293
<failOnWarning>false</failOnWarning>
@@ -288,6 +306,17 @@
288306
</executions>
289307
</plugin>
290308

309+
<plugin>
310+
<groupId>org.springdoc</groupId>
311+
<artifactId>springdoc-openapi-maven-plugin</artifactId>
312+
<version>${springdoc-openapi-maven-plugin.version}</version>
313+
<configuration>
314+
<apiDocsUrl>http://localhost:39146/v3/api-docs</apiDocsUrl>
315+
<outputFileName>${project.name}.yaml</outputFileName>
316+
<failOnError>true</failOnError>
317+
</configuration>
318+
</plugin>
319+
291320
<!-- Testing -->
292321
<plugin>
293322
<groupId>org.apache.maven.plugins</groupId>

personalization-service/spotbugs-exclude-rules.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@
66
<Match>
77
<Bug pattern="EI_EXPOSE_REP2"/> <!-- Rule is ignored because spring uses dependency injection. The classes that are injected will be managed by Spring, meaning they do not need to be immutable. See https://docs.spring.io/spring-framework/reference/core/beans/dependencies/factory-collaborators.html -->
88
</Match>
9+
<Match>
10+
<Bug pattern="EI_EXPOSE_REP"/> <!-- Rule is ignored because spring uses dependency injection. The classes that are injected will be managed by Spring, meaning they do not need to be immutable. See https://docs.spring.io/spring-framework/reference/core/beans/dependencies/factory-collaborators.html -->
11+
</Match>
912
</FindBugsFilter>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package de.muenchen.dbs.personalization.checklist;
2+
3+
import de.muenchen.dbs.personalization.checklist.domain.Checklist;
4+
import de.muenchen.dbs.personalization.checklist.domain.ChecklistCreateDTO;
5+
import de.muenchen.dbs.personalization.checklist.domain.ChecklistMapper;
6+
import de.muenchen.dbs.personalization.checklist.domain.ChecklistReadDTO;
7+
import de.muenchen.dbs.personalization.checklist.domain.ChecklistUpdateDTO;
8+
import io.swagger.v3.oas.annotations.Operation;
9+
import io.swagger.v3.oas.annotations.tags.Tag;
10+
import jakarta.validation.Valid;
11+
import java.util.List;
12+
import java.util.UUID;
13+
import lombok.RequiredArgsConstructor;
14+
import lombok.extern.slf4j.Slf4j;
15+
import org.springframework.http.HttpStatus;
16+
import org.springframework.web.bind.annotation.*;
17+
18+
@RestController
19+
@RequestMapping("/checklist")
20+
@Slf4j
21+
@RequiredArgsConstructor
22+
@Tag(name = "Checklists", description = "Creating, reading and deleting Checklists.")
23+
public class ChecklistController {
24+
25+
private final ChecklistService checklistService;
26+
private final ChecklistMapper checklistMapper;
27+
28+
@GetMapping
29+
@Operation(summary = "Get all checklists by user.", description = "Returns all checklists of an user by lhmExtId")
30+
@ResponseStatus(HttpStatus.OK)
31+
public List<ChecklistReadDTO> getChecklists(@RequestHeader("lhmExtID") final String lhmExtID) {
32+
final List<Checklist> checklists = checklistService.getChecklists(lhmExtID);
33+
return checklists.stream().map(checklistMapper::toReadDTO).toList();
34+
}
35+
36+
@GetMapping(path = "/{checklistID}")
37+
@Operation(summary = "Get specific checklist by checklist-id.", description = "Returns a checklist by checklistId")
38+
@ResponseStatus(HttpStatus.OK)
39+
public ChecklistReadDTO getChecklist(@PathVariable("checklistID") final UUID checklistID) {
40+
return checklistMapper.toReadDTO(checklistService.getChecklist(checklistID));
41+
}
42+
43+
@PostMapping
44+
@Operation(summary = "Create a new checklist", description = "Creates a new checklist using the provided checklist details.")
45+
@ResponseStatus(HttpStatus.CREATED)
46+
public ChecklistReadDTO createChecklist(@Valid @RequestBody final ChecklistCreateDTO checklistCreateDTO) {
47+
return checklistMapper
48+
.toReadDTO(checklistService.createChecklist(checklistMapper.toCreateChecklist(checklistCreateDTO)));
49+
}
50+
51+
@PutMapping("/{checklistID}")
52+
@Operation(summary = "Update a checklist", description = "Updates a checklist using the provided checklist details.")
53+
@ResponseStatus(HttpStatus.OK)
54+
public ChecklistReadDTO updateChecklist(@Valid @RequestBody final ChecklistUpdateDTO checklistUpdateDTO,
55+
@PathVariable("checklistID") final UUID checklistID) {
56+
return checklistMapper.toReadDTO(checklistService.updateChecklist(checklistMapper.toUpdateChecklist(checklistUpdateDTO), checklistID));
57+
}
58+
59+
@DeleteMapping("/{checklistID}")
60+
@Operation(summary = "Delete a checklist", description = "Deletes a checklist by checklistId.")
61+
@ResponseStatus(HttpStatus.OK)
62+
public void deleteChecklist(@PathVariable("checklistID") final UUID checklistID) {
63+
checklistService.deleteChecklist(checklistID);
64+
}
65+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package de.muenchen.dbs.personalization.checklist;
2+
3+
import de.muenchen.dbs.personalization.checklist.domain.Checklist;
4+
import java.util.List;
5+
import java.util.UUID;
6+
import org.springframework.data.jpa.repository.JpaRepository;
7+
import org.springframework.stereotype.Repository;
8+
9+
@Repository
10+
public interface ChecklistRepository extends JpaRepository<Checklist, UUID> {
11+
12+
List<Checklist> findChecklistByLhmExtId(String lhmExtId);
13+
14+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package de.muenchen.dbs.personalization.checklist;
2+
3+
import static de.muenchen.dbs.personalization.common.ExceptionMessageConstants.MSG_NOT_FOUND;
4+
5+
import de.muenchen.dbs.personalization.checklist.domain.Checklist;
6+
import de.muenchen.dbs.personalization.common.NotFoundException;
7+
import de.muenchen.dbs.personalization.security.Authorities;
8+
import java.time.ZonedDateTime;
9+
import java.util.List;
10+
import java.util.UUID;
11+
import lombok.RequiredArgsConstructor;
12+
import lombok.extern.slf4j.Slf4j;
13+
import org.springframework.security.access.prepost.PreAuthorize;
14+
import org.springframework.stereotype.Service;
15+
16+
@Service
17+
@Slf4j
18+
@RequiredArgsConstructor
19+
public class ChecklistService {
20+
21+
private final ChecklistRepository checklistRepository;
22+
23+
@PreAuthorize(Authorities.CHECKLIST_CREATE)
24+
public Checklist createChecklist(final Checklist checklist) {
25+
log.debug("Create Checklist {}", checklist);
26+
return checklistRepository.save(checklist);
27+
}
28+
29+
@PreAuthorize(Authorities.CHECKLIST_GET_ALL)
30+
public List<Checklist> getChecklists(final String userId) {
31+
log.debug("Get all checklists of {}", userId);
32+
return checklistRepository.findChecklistByLhmExtId(userId);
33+
}
34+
35+
@PreAuthorize(Authorities.CHECKLIST_GET)
36+
public Checklist getChecklist(final UUID checklistId) {
37+
log.debug("Get checklist with ID {}", checklistId);
38+
return getChecklistOrThrowException(checklistId);
39+
}
40+
41+
@PreAuthorize(Authorities.CHECKLIST_UPDATE)
42+
public Checklist updateChecklist(final Checklist checklist, final UUID checklistId) {
43+
final Checklist foundChecklist = getChecklistOrThrowException(checklistId);
44+
foundChecklist.setChecklistItems(checklist.getChecklistItems());
45+
foundChecklist.setLastUpdate(ZonedDateTime.now());
46+
log.debug("Update Checklist {}", foundChecklist);
47+
return checklistRepository.save(foundChecklist);
48+
}
49+
50+
@PreAuthorize(Authorities.CHECKLIST_DELETE)
51+
public void deleteChecklist(final UUID checklistId) {
52+
log.debug("Delete Checklist with ID {}", checklistId);
53+
checklistRepository.deleteById(checklistId);
54+
}
55+
56+
private Checklist getChecklistOrThrowException(final UUID checklistId) {
57+
return checklistRepository
58+
.findById(checklistId)
59+
.orElseThrow(() -> new NotFoundException(String.format(MSG_NOT_FOUND, checklistId)));
60+
}
61+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package de.muenchen.dbs.personalization.checklist.domain;
2+
3+
import de.muenchen.dbs.personalization.common.BaseEntity;
4+
import jakarta.persistence.CollectionTable;
5+
import jakarta.persistence.Column;
6+
import jakarta.persistence.ElementCollection;
7+
import jakarta.persistence.Entity;
8+
import jakarta.persistence.JoinColumn;
9+
import jakarta.validation.constraints.NotNull;
10+
import java.io.Serial;
11+
import java.time.ZonedDateTime;
12+
import java.util.List;
13+
import lombok.AllArgsConstructor;
14+
import lombok.Data;
15+
import lombok.EqualsAndHashCode;
16+
import lombok.NoArgsConstructor;
17+
18+
@Entity
19+
@Data
20+
@EqualsAndHashCode(callSuper = true)
21+
@NoArgsConstructor
22+
@AllArgsConstructor
23+
public class Checklist extends BaseEntity {
24+
25+
@Serial
26+
private static final long serialVersionUID = 1L;
27+
28+
@Column(name = "lhm_ext_id", nullable = false)
29+
@NotNull
30+
private String lhmExtId;
31+
32+
@Column(name = "title")
33+
@NotNull
34+
private String title;
35+
36+
@Column(name = "last_update")
37+
private ZonedDateTime lastUpdate;
38+
39+
@ElementCollection
40+
@CollectionTable(name = "checklist_item", joinColumns = @JoinColumn(name = "checklist_id"))
41+
private List<ChecklistItem> checklistItems;
42+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package de.muenchen.dbs.personalization.checklist.domain;
2+
3+
import jakarta.validation.constraints.NotNull;
4+
import java.util.List;
5+
6+
public record ChecklistCreateDTO(@NotNull String lhmExtId, @NotNull String title, @NotNull List<ChecklistItemDTO> checklistItems) {
7+
8+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package de.muenchen.dbs.personalization.checklist.domain;
2+
3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Embeddable;
5+
import java.io.Serial;
6+
import java.io.Serializable;
7+
import java.time.ZonedDateTime;
8+
import lombok.AllArgsConstructor;
9+
import lombok.Builder;
10+
import lombok.Data;
11+
import lombok.NoArgsConstructor;
12+
13+
@Embeddable
14+
@Data
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
@Builder
18+
public class ChecklistItem implements Serializable {
19+
20+
@Serial
21+
private static final long serialVersionUID = 1L;
22+
23+
@Column(name = "service_id")
24+
private String serviceID;
25+
26+
@Column(name = "checked")
27+
private ZonedDateTime checked;
28+
29+
@Column(name = "title")
30+
private String title;
31+
32+
@Column(name = "note", length = 1024)
33+
private String note;
34+
35+
@Column(name = "required")
36+
private Boolean required;
37+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package de.muenchen.dbs.personalization.checklist.domain;
2+
3+
import java.time.ZonedDateTime;
4+
5+
public record ChecklistItemDTO(String serviceID, ZonedDateTime checked, String title, String note, Boolean required) {
6+
7+
}

0 commit comments

Comments
 (0)