-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from grida-diary/main
Docs
- Loading branch information
Showing
19 changed files
with
203 additions
and
32 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
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
grida-core/core-domain/src/main/kotlin/org/grida/domain/base/AccessManager.kt
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 org.grida.domain.base | ||
|
||
import org.grida.error.AccessFailed | ||
import org.grida.error.GridaException | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class AccessManager { | ||
|
||
fun ownerOnly( | ||
target: Ownable, | ||
accessorId: Long | ||
) { | ||
if (!target.isOwner(accessorId)) { | ||
throw GridaException(AccessFailed) | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
grida-core/core-domain/src/main/kotlin/org/grida/domain/base/Ownable.kt
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,6 @@ | ||
package org.grida.domain.base | ||
|
||
interface Ownable { | ||
|
||
fun isOwner(accessorId: Long): Boolean | ||
} |
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
8 changes: 7 additions & 1 deletion
8
grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImage.kt
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 |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.grida.domain.base.Ownable | ||
import org.grida.domain.image.Image | ||
|
||
data class DiaryImage( | ||
val id: Long = 0, | ||
val userId: Long, | ||
val diaryId: Long, | ||
val image: Image | ||
) | ||
) : Ownable { | ||
|
||
override fun isOwner(accessorId: Long): Boolean { | ||
return userId == accessorId | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageModifier.kt
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,22 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.grida.domain.base.AccessManager | ||
import org.grida.domain.image.ImageStatus | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class DiaryImageModifier( | ||
private val diaryImageRepository: DiaryImageRepository, | ||
private val diaryImageReader: DiaryImageReader, | ||
private val accessManager: AccessManager | ||
) { | ||
|
||
@Transactional | ||
fun modifyAsActivate(diaryImageId: Long, userId: Long) { | ||
val diaryImage = diaryImageReader.read(diaryImageId) | ||
accessManager.ownerOnly(diaryImage, userId) | ||
|
||
diaryImageRepository.updateStatus(diaryImageId, ImageStatus.ACTIVATE) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageReader.kt
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,15 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class DiaryImageReader( | ||
private val diaryImageRepository: DiaryImageRepository | ||
) { | ||
|
||
@Transactional(readOnly = true) | ||
fun read(diaryId: Long): DiaryImage { | ||
return diaryImageRepository.findById(diaryId) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageRepository.kt
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 |
---|---|---|
@@ -1,8 +1,15 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.grida.domain.diary.Diary | ||
import org.grida.domain.image.ImageStatus | ||
import org.grida.domain.user.User | ||
|
||
interface DiaryImageRepository { | ||
fun save(diaryImage: DiaryImage, diary: Diary, user: User): Long | ||
|
||
fun findById(id: Long): DiaryImage | ||
|
||
fun existsByDiaryIdAndStatus(diaryId: Long, status: ImageStatus): Boolean | ||
|
||
fun updateStatus(diaryImageId: Long, status: ImageStatus): Long | ||
} |
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
20 changes: 20 additions & 0 deletions
20
grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageValidator.kt
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,20 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.grida.domain.image.ImageStatus | ||
import org.grida.error.ActivateImageAlreadyExists | ||
import org.grida.error.GridaException | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class DiaryImageValidator( | ||
private val diaryImageRepository: DiaryImageRepository | ||
) { | ||
|
||
@Transactional(readOnly = true) | ||
fun validateAlreadyHasActivateDiaryImage(diaryId: Long) { | ||
if (diaryImageRepository.existsByDiaryIdAndStatus(diaryId, ImageStatus.ACTIVATE)) { | ||
throw GridaException(ActivateImageAlreadyExists) | ||
} | ||
} | ||
} |
6 changes: 4 additions & 2 deletions
6
grida-core/core-domain/src/main/kotlin/org/grida/domain/profileimage/ProfileImage.kt
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 |
---|---|---|
@@ -1,14 +1,16 @@ | ||
package org.grida.domain.profileimage | ||
|
||
import org.grida.domain.base.Ownable | ||
import org.grida.domain.image.Image | ||
|
||
data class ProfileImage( | ||
val id: Long = 0, | ||
val userId: Long, | ||
val image: Image, | ||
val appearance: Appearance | ||
) { | ||
fun isOwner(accessorId: Long): Boolean { | ||
) : Ownable { | ||
|
||
override fun isOwner(accessorId: Long): Boolean { | ||
return userId == accessorId | ||
} | ||
} |
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
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
Oops, something went wrong.