-
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 3 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 |
|---|---|---|
|
|
@@ -3,19 +3,29 @@ | |
| import com.arcadedb.remote.RemoteDatabase; | ||
| import io.javalin.Javalin; | ||
| import it.robfrank.linklift.adapter.in.web.AuthenticationController; | ||
| import it.robfrank.linklift.adapter.in.web.CollectionController; | ||
| import it.robfrank.linklift.adapter.in.web.CollectionController; | ||
| import it.robfrank.linklift.adapter.in.web.GetContentController; | ||
| import it.robfrank.linklift.adapter.in.web.GetRelatedLinksController; | ||
| import it.robfrank.linklift.adapter.in.web.GetRelatedLinksController; | ||
| import it.robfrank.linklift.adapter.in.web.ListLinksController; | ||
| import it.robfrank.linklift.adapter.in.web.NewLinkController; | ||
| import it.robfrank.linklift.adapter.out.content.SimpleTextSummarizer; | ||
| import it.robfrank.linklift.adapter.out.event.SimpleEventPublisher; | ||
| import it.robfrank.linklift.adapter.out.http.HttpContentDownloader; | ||
| import it.robfrank.linklift.adapter.out.http.JsoupContentExtractor; | ||
| import it.robfrank.linklift.adapter.out.persitence.*; | ||
| import it.robfrank.linklift.adapter.out.persitence.ArcadeCollectionRepository; | ||
| import it.robfrank.linklift.adapter.out.persitence.CollectionPersistenceAdapter; | ||
| import it.robfrank.linklift.adapter.out.security.BCryptPasswordSecurityAdapter; | ||
| import it.robfrank.linklift.adapter.out.security.JwtTokenAdapter; | ||
| import it.robfrank.linklift.application.domain.event.*; | ||
| import it.robfrank.linklift.application.domain.service.*; | ||
| import it.robfrank.linklift.application.domain.service.CreateCollectionService; | ||
| import it.robfrank.linklift.application.domain.service.GetRelatedLinksService; | ||
| import it.robfrank.linklift.application.port.in.*; | ||
| import it.robfrank.linklift.application.port.in.CreateCollectionUseCase; | ||
| import it.robfrank.linklift.application.port.in.GetRelatedLinksUseCase; | ||
| import it.robfrank.linklift.application.port.out.ContentDownloaderPort; | ||
| import it.robfrank.linklift.config.DatabaseInitializer; | ||
| import it.robfrank.linklift.config.SecureConfiguration; | ||
|
|
@@ -26,6 +36,7 @@ | |
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.Executors; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class Application { | ||
|
|
@@ -109,6 +120,15 @@ public static void main(String[] args) { | |
| NewLinkUseCase newLinkUseCase = new NewLinkService(linkPersistenceAdapter, eventPublisher); | ||
| ListLinksUseCase listLinksUseCase = new ListLinksService(linkPersistenceAdapter, eventPublisher); | ||
|
|
||
| // Initialize Collection and Related Links components | ||
| ArcadeCollectionRepository collectionRepository = new ArcadeCollectionRepository(database); | ||
| CollectionPersistenceAdapter collectionPersistenceAdapter = new CollectionPersistenceAdapter(collectionRepository); | ||
| CreateCollectionUseCase createCollectionUseCase = new CreateCollectionService(collectionPersistenceAdapter); | ||
| GetRelatedLinksUseCase getRelatedLinksUseCase = new GetRelatedLinksService(linkPersistenceAdapter); | ||
|
|
||
| CollectionController collectionController = new CollectionController(createCollectionUseCase); | ||
| GetRelatedLinksController getRelatedLinksController = new GetRelatedLinksController(getRelatedLinksUseCase); | ||
|
|
||
|
Comment on lines
+120
to
+128
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 block of initialization logic is duplicated in the |
||
| // Initialize controllers | ||
| NewLinkController newLinkController = new NewLinkController(newLinkUseCase); | ||
| ListLinksController listLinksController = new ListLinksController(listLinksUseCase); | ||
|
|
@@ -122,33 +142,63 @@ public static void main(String[] args) { | |
| .withLinkController(newLinkController) | ||
| .withListLinksController(listLinksController) | ||
| .withGetContentController(getContentController) | ||
| .withCollectionController(collectionController) | ||
| .withGetRelatedLinksController(getRelatedLinksController) | ||
| .build(); | ||
|
|
||
| app.start(7070); | ||
| } | ||
|
|
||
| private static void configureEventSubscribers(SimpleEventPublisher eventPublisher, DownloadContentUseCase linkContentExtractorService) { | ||
| // Configure event subscribers - this is where different components can subscribe to events | ||
| // Configure event subscribers - this is where different components can | ||
| // subscribe to events | ||
| eventPublisher.subscribe(LinkCreatedEvent.class, event -> { | ||
| logger.atInfo().addArgument(() -> event.getLink().url()).addArgument(event.getUserId()).addArgument(event.getTimestamp()).log("Link created: {} for user: {} at {}"); | ||
| logger | ||
| .atInfo() | ||
| .addArgument(() -> event.getLink().url()) | ||
| .addArgument(event.getUserId()) | ||
| .addArgument(event.getTimestamp()) | ||
| .log("Link created: {} for user: {} at {}"); | ||
| linkContentExtractorService.downloadContentAsync(new DownloadContentCommand(event.getLink().id(), event.getLink().url())); | ||
| }); | ||
|
|
||
| eventPublisher.subscribe(LinksQueryEvent.class, event -> { | ||
| logger.atInfo().addArgument(() -> event.getQuery().page()).addArgument(() -> event.getQuery().size()).addArgument(event.getResultCount()).addArgument(() -> event.getQuery().userId()).addArgument(event.getTimestamp()).log("Links queried: page={}, size={}, results={} for user: {} at {}"); | ||
| logger | ||
| .atInfo() | ||
| .addArgument(() -> event.getQuery().page()) | ||
| .addArgument(() -> event.getQuery().size()) | ||
| .addArgument(event.getResultCount()) | ||
| .addArgument(() -> event.getQuery().userId()) | ||
| .addArgument(event.getTimestamp()) | ||
| .log("Links queried: page={}, size={}, results={} for user: {} at {}"); | ||
| }); | ||
|
|
||
| // User management events | ||
| eventPublisher.subscribe(CreateUserService.UserCreatedEvent.class, event -> { | ||
| logger.atInfo().addArgument(() -> event.username()).addArgument(() -> event.email()).addArgument(() -> LocalDateTime.now()).log("User created: {} ({}) at {}"); | ||
| logger | ||
| .atInfo() | ||
| .addArgument(() -> event.username()) | ||
| .addArgument(() -> event.email()) | ||
| .addArgument(() -> LocalDateTime.now()) | ||
| .log("User created: {} ({}) at {}"); | ||
| }); | ||
|
|
||
| eventPublisher.subscribe(AuthenticationService.UserAuthenticatedEvent.class, event -> { | ||
| logger.atInfo().addArgument(() -> event.username()).addArgument(() -> event.ipAddress()).addArgument(() -> event.timestamp()).log("User authenticated: {} from {} at {}"); | ||
| logger | ||
| .atInfo() | ||
| .addArgument(() -> event.username()) | ||
| .addArgument(() -> event.ipAddress()) | ||
| .addArgument(() -> event.timestamp()) | ||
| .log("User authenticated: {} from {} at {}"); | ||
| }); | ||
|
|
||
| eventPublisher.subscribe(AuthenticationService.TokenRefreshedEvent.class, event -> { | ||
| logger.atInfo().addArgument(() -> event.username()).addArgument(() -> event.ipAddress()).addArgument(() -> event.timestamp()).log("Token refreshed for user: {} from {} at {}"); | ||
| logger | ||
| .atInfo() | ||
| .addArgument(() -> event.username()) | ||
| .addArgument(() -> event.ipAddress()) | ||
| .addArgument(() -> event.timestamp()) | ||
| .log("Token refreshed for user: {} from {} at {}"); | ||
| }); | ||
|
|
||
| // Content download events | ||
|
|
@@ -239,6 +289,15 @@ public Javalin start(int port) { | |
| NewLinkUseCase newLinkUseCase = new NewLinkService(linkPersistenceAdapter, eventPublisher); | ||
| ListLinksUseCase listLinksUseCase = new ListLinksService(linkPersistenceAdapter, eventPublisher); | ||
|
|
||
| // Initialize Collection and Related Links components | ||
| ArcadeCollectionRepository collectionRepository = new ArcadeCollectionRepository(database); | ||
| CollectionPersistenceAdapter collectionPersistenceAdapter = new CollectionPersistenceAdapter(collectionRepository); | ||
| CreateCollectionUseCase createCollectionUseCase = new CreateCollectionService(collectionPersistenceAdapter); | ||
| GetRelatedLinksUseCase getRelatedLinksUseCase = new GetRelatedLinksService(linkPersistenceAdapter); | ||
|
|
||
| CollectionController collectionController = new CollectionController(createCollectionUseCase); | ||
| GetRelatedLinksController getRelatedLinksController = new GetRelatedLinksController(getRelatedLinksUseCase); | ||
|
|
||
| // Initialize controllers | ||
| NewLinkController newLinkController = new NewLinkController(newLinkUseCase); | ||
| ListLinksController listLinksController = new ListLinksController(listLinksUseCase); | ||
|
|
@@ -252,6 +311,8 @@ public Javalin start(int port) { | |
| .withLinkController(newLinkController) | ||
| .withListLinksController(listLinksController) | ||
| .withGetContentController(getContentController) | ||
| .withCollectionController(collectionController) | ||
| .withGetRelatedLinksController(getRelatedLinksController) | ||
| .build(); | ||
|
|
||
| app.start(port); | ||
|
|
||
| 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) {} | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.