-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
78 changed files
with
675 additions
and
2,270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
kodemy-backend/src/main/java/pl/sknikod/kodemybackend/infrastructure/aspect/AfterAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package pl.sknikod.kodemybackend.infrastructure.aspect; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface AfterAction { | ||
Action action(); | ||
|
||
enum Action { | ||
SAVE, | ||
UPDATE, | ||
STATUS_UPDATE | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...ckend/src/main/java/pl/sknikod/kodemybackend/infrastructure/aspect/AfterActionAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package pl.sknikod.kodemybackend.infrastructure.aspect; | ||
|
||
import io.vavr.Tuple; | ||
import io.vavr.Tuple2; | ||
import io.vavr.control.Try; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.aspectj.lang.annotation.AfterReturning; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.annotation.Pointcut; | ||
import org.springframework.stereotype.Component; | ||
import pl.sknikod.kodemybackend.infrastructure.database.Material; | ||
import pl.sknikod.kodemybackend.infrastructure.event.producer.MaterialCreatedProducer; | ||
import pl.sknikod.kodemybackend.infrastructure.event.producer.MaterialStatusUpdatedProducer; | ||
import pl.sknikod.kodemybackend.infrastructure.event.producer.MaterialUpdatedProducer; | ||
import pl.sknikod.kodemybackend.infrastructure.store.GradeStore; | ||
import pl.sknikod.kodemybackend.infrastructure.store.UserStore; | ||
|
||
@Aspect | ||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class AfterActionAspect { | ||
private final GradeStore gradeStore; | ||
private final UserStore userStore; | ||
private final MaterialCreatedProducer materialCreatedProducer; | ||
private final MaterialUpdatedProducer materialUpdatedProducer; | ||
private final MaterialStatusUpdatedProducer materialStatusUpdatedProducer; | ||
|
||
@Pointcut("@annotation(afterAction)") | ||
public void afterActionPointcut(AfterAction afterAction) { | ||
// placeholder | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@AfterReturning(value = "afterActionPointcut(afterAction)", returning = "result", argNames = "afterAction,result") | ||
public void executeAfterAction(AfterAction afterAction, Object result) { | ||
switch (afterAction.action()) { | ||
case SAVE -> afterSave((Try<Material>) result); | ||
case UPDATE -> afterUpdate((Try<Material>) result); | ||
case STATUS_UPDATE -> afterStatusUpdate((Tuple2<Long, Material.MaterialStatus>) result); | ||
} | ||
} | ||
|
||
private void afterSave(Try<Material> result) { | ||
log.info("After save action executed"); | ||
result | ||
.filter(material -> Material.MaterialStatus.APPROVED.equals(material.getStatus())) | ||
.mapTry(material -> { | ||
UserStore.User user = userStore.findById(material.getUserId()).get(); | ||
Double avgGrade = gradeStore.findAvgGradeByMaterial(material.getUserId()).get(); | ||
return Tuple.of(material, avgGrade, user); | ||
}) | ||
.mapTry(tuple -> MaterialCreatedProducer.Message.map(tuple._1, tuple._3.getUsername())) | ||
.peek(materialCreatedProducer::publish); | ||
} | ||
|
||
private void afterUpdate(Try<Material> result) { | ||
log.info("After update action executed"); | ||
result.filter(material -> Material.MaterialStatus.APPROVED.equals(material.getStatus())) | ||
.mapTry(material -> { | ||
UserStore.User user = userStore.findById(material.getUserId()).get(); | ||
Double avgGrade = gradeStore.findAvgGradeByMaterial(material.getUserId()).get(); | ||
return Tuple.of(material, avgGrade, user); | ||
}) | ||
.mapTry(tuple -> MaterialUpdatedProducer.Message.map(tuple._1, tuple._2, tuple._3.getUsername())) | ||
.peek(materialUpdatedProducer::publish); | ||
} | ||
|
||
private void afterStatusUpdate(Tuple2<Long, Material.MaterialStatus> result) { | ||
log.info("After status update action executed"); | ||
Try.of(() -> new MaterialStatusUpdatedProducer.Message(result._1, result._2)) | ||
.peek(materialStatusUpdatedProducer::publish); | ||
} | ||
} |
67 changes: 0 additions & 67 deletions
67
...d/src/main/java/pl/sknikod/kodemybackend/infrastructure/common/lan/LanNetworkHandler.java
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
kodemy-backend/src/main/java/pl/sknikod/kodemybackend/infrastructure/dao/GradeDao.java
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
kodemy-backend/src/main/java/pl/sknikod/kodemybackend/infrastructure/dao/MaterialDao.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
kodemy-backend/src/main/java/pl/sknikod/kodemybackend/infrastructure/event/Producer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package pl.sknikod.kodemybackend.infrastructure.event; | ||
|
||
public interface Producer<T> { | ||
void publish(T object); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.