-
Notifications
You must be signed in to change notification settings - Fork 0
feature: add collection management and related links functionality #443
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
Changes from all commits
f6c0ed4
5b5c19a
4de9e70
d4ce047
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,7 +198,7 @@ web_modules/ | |
|
|
||
| # Next.js build output | ||
| .next | ||
| out | ||
| /out | ||
|
|
||
| # Nuxt.js build / generate output | ||
| .nuxt | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package it.robfrank.linklift.adapter.in.web; | ||
|
|
||
| import io.javalin.http.Context; | ||
| import it.robfrank.linklift.adapter.in.web.error.ErrorResponse; | ||
| import it.robfrank.linklift.application.domain.model.Collection; | ||
| import it.robfrank.linklift.application.port.in.CreateCollectionCommand; | ||
| import it.robfrank.linklift.application.port.in.CreateCollectionUseCase; | ||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| public class CollectionController { | ||
|
|
||
| private final CreateCollectionUseCase createCollectionUseCase; | ||
|
|
||
| public CollectionController(CreateCollectionUseCase createCollectionUseCase) { | ||
| this.createCollectionUseCase = createCollectionUseCase; | ||
| } | ||
|
|
||
| public void createCollection(@NonNull Context ctx) { | ||
| var request = ctx.bodyAsClass(CreateCollectionRequest.class); | ||
| var userId = ctx.attribute("userId"); | ||
|
|
||
| if (userId == null) { | ||
| ctx.status(401).json(ErrorResponse.builder().status(401).message("Unauthorized").build()); | ||
| return; | ||
| } | ||
robfrank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| var command = new CreateCollectionCommand(request.name(), request.description(), userId.toString(), request.query()); | ||
|
|
||
| var collection = createCollectionUseCase.createCollection(command); | ||
| ctx.status(201).json(new CollectionResponse(collection)); | ||
| } | ||
|
|
||
| public record CreateCollectionRequest(String name, String description, String query) {} | ||
|
|
||
| public record CollectionResponse(Collection data) {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package it.robfrank.linklift.adapter.in.web; | ||
|
|
||
| import io.javalin.http.Context; | ||
| import it.robfrank.linklift.adapter.in.web.error.ErrorResponse; | ||
| import it.robfrank.linklift.application.domain.model.Link; | ||
| import it.robfrank.linklift.application.port.in.GetRelatedLinksUseCase; | ||
| import java.util.List; | ||
| import org.jspecify.annotations.NonNull; | ||
|
|
||
| public class GetRelatedLinksController { | ||
|
|
||
| private final GetRelatedLinksUseCase getRelatedLinksUseCase; | ||
|
|
||
| public GetRelatedLinksController(GetRelatedLinksUseCase getRelatedLinksUseCase) { | ||
| this.getRelatedLinksUseCase = getRelatedLinksUseCase; | ||
| } | ||
|
|
||
| public void getRelatedLinks(@NonNull Context ctx) { | ||
| var linkId = ctx.pathParam("linkId"); | ||
| var userId = ctx.attribute("userId"); | ||
|
|
||
| if (userId == null) { | ||
| ctx.status(401).json(ErrorResponse.builder().status(401).message("Unauthorized").build()); | ||
| return; | ||
| } | ||
|
Comment on lines
+22
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
|
|
||
| var links = getRelatedLinksUseCase.getRelatedLinks(linkId, userId.toString()); | ||
| ctx.json(new RelatedLinksResponse(links)); | ||
| } | ||
|
|
||
| public record RelatedLinksResponse(List<Link> data) {} | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of initialization logic is duplicated in the
start(int port)method (lines 292-300). This extends an existing code duplication issue in theApplicationclass. To improve maintainability and reduce redundancy, consider refactoring the entire dependency injection setup into a private helper method that can be called from bothmainandstart.