-
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 #85 from grida-diary/feature/diary
Feature/diary
- Loading branch information
Showing
21 changed files
with
333 additions
and
116 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...ore/core-api/src/main/kotlin/org/grida/presentation/v1/diaryimage/DiaryImageController.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,27 @@ | ||
package org.grida.presentation.v1.diaryimage | ||
|
||
import io.wwan13.wintersecurity.resolve.RequestUserId | ||
import org.grida.api.ApiResponse | ||
import org.grida.api.dto.IdResponse | ||
import org.grida.domain.diaryimage.DiaryImageService | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/diary") | ||
class DiaryImageController( | ||
private val diaryImageService: DiaryImageService | ||
) { | ||
|
||
@PostMapping("/{diaryId}/image") | ||
fun generateDiaryImage( | ||
@RequestUserId userId: Long, | ||
@PathVariable diaryId: Long | ||
): ApiResponse<IdResponse> { | ||
val generatedDiaryImageId = diaryImageService.generateDiaryImage(diaryId, userId) | ||
val response = IdResponse(generatedDiaryImageId) | ||
return ApiResponse.success(response) | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.grida.domain.image.Image | ||
|
||
data class DiaryImage( | ||
val id: Long = 0, | ||
val userId: Long, | ||
val diaryId: Long, | ||
val image: Image | ||
) |
25 changes: 25 additions & 0 deletions
25
grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageAppender.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,25 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.grida.domain.diary.DiaryReader | ||
import org.grida.domain.user.UserReader | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Component | ||
class DiaryImageAppender( | ||
private val diaryImageRepository: DiaryImageRepository, | ||
private val diaryReader: DiaryReader, | ||
private val userReader: UserReader | ||
) { | ||
|
||
@Transactional | ||
fun append( | ||
diaryImage: DiaryImage, | ||
diaryId: Long, | ||
userId: Long | ||
): Long { | ||
val diary = diaryReader.read(diaryId) | ||
val user = userReader.read(userId) | ||
return diaryImageRepository.save(diaryImage, diary, user) | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageGenerator.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,12 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class DiaryImageGenerator { | ||
|
||
fun generate(diaryContent: String): String { | ||
// TODO | ||
return "https://tmpImageUrl.com" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.grida.domain.diary.Diary | ||
import org.grida.domain.user.User | ||
|
||
interface DiaryImageRepository { | ||
fun save(diaryImage: DiaryImage, diary: Diary, user: User): Long | ||
} |
32 changes: 32 additions & 0 deletions
32
grida-core/core-domain/src/main/kotlin/org/grida/domain/diaryimage/DiaryImageService.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,32 @@ | ||
package org.grida.domain.diaryimage | ||
|
||
import org.grida.domain.diary.DiaryReader | ||
import org.grida.domain.diary.DiaryValidator | ||
import org.grida.domain.image.Image | ||
import org.grida.domain.image.ImageStatus | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class DiaryImageService( | ||
private val diaryImageAppender: DiaryImageAppender, | ||
private val diaryImageGenerator: DiaryImageGenerator, | ||
private val diaryReader: DiaryReader, | ||
private val diaryValidator: DiaryValidator | ||
) { | ||
|
||
fun generateDiaryImage( | ||
diaryId: Long, | ||
userId: Long | ||
): Long { | ||
val diary = diaryReader.read(diaryId) | ||
diaryValidator.validateIsOwner(diary, userId) | ||
val generatedImageUrl = diaryImageGenerator.generate(diary.content) | ||
|
||
val diaryImage = DiaryImage( | ||
userId = userId, | ||
diaryId = diaryId, | ||
image = Image(generatedImageUrl, ImageStatus.DEACTIVATE) | ||
) | ||
return diaryImageAppender.append(diaryImage, diaryId, userId) | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
grida-database/database-rds/src/main/kotlin/org/grida/persistence/diary/DiaryEntityMapper.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,26 @@ | ||
package org.grida.persistence.diary | ||
|
||
import org.grida.domain.diary.Diary | ||
import org.grida.domain.user.User | ||
import org.grida.persistence.user.toEntity | ||
|
||
fun Diary.toEntity(user: User): DiaryEntity { | ||
return DiaryEntity( | ||
id = this.id, | ||
targetDate = this.targetDate, | ||
content = this.content, | ||
scope = this.scope, | ||
user = user.toEntity() | ||
) | ||
} | ||
|
||
fun DiaryEntity.toDomain(): Diary { | ||
return Diary( | ||
id = this.id, | ||
timestamp = this.toTimeStamp(), | ||
targetDate = this.targetDate, | ||
content = this.content, | ||
scope = this.scope, | ||
userId = this.user.id | ||
) | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...atabase/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntity.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,42 @@ | ||
package org.grida.persistence.diaryimage | ||
|
||
import org.grida.domain.diaryimage.DiaryImage | ||
import org.grida.domain.image.ImageStatus | ||
import org.grida.persistence.base.BaseEntity | ||
import org.grida.persistence.diary.DiaryEntity | ||
import org.grida.persistence.user.UserEntity | ||
import javax.persistence.Column | ||
import javax.persistence.Entity | ||
import javax.persistence.EnumType | ||
import javax.persistence.Enumerated | ||
import javax.persistence.FetchType | ||
import javax.persistence.GeneratedValue | ||
import javax.persistence.GenerationType | ||
import javax.persistence.Id | ||
import javax.persistence.JoinColumn | ||
import javax.persistence.ManyToOne | ||
import javax.persistence.Table | ||
|
||
@Entity | ||
@Table(name = "diary_image") | ||
class DiaryImageEntity( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "diary_image_id") | ||
var id: Long = 0, | ||
|
||
@Column(length = 511) | ||
var imageUrl: String, | ||
|
||
@Enumerated(EnumType.STRING) | ||
@Column(length = 127) | ||
var status: ImageStatus, | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "user_id") | ||
var user: UserEntity, | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "diary_id") | ||
var diary: DiaryEntity, | ||
) : BaseEntity() |
34 changes: 34 additions & 0 deletions
34
...e/database-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityMapper.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,34 @@ | ||
package org.grida.persistence.diaryimage | ||
|
||
import org.grida.domain.diary.Diary | ||
import org.grida.domain.diaryimage.DiaryImage | ||
import org.grida.domain.image.Image | ||
import org.grida.domain.user.User | ||
import org.grida.persistence.diary.toEntity | ||
import org.grida.persistence.user.toEntity | ||
|
||
fun DiaryImage.toEntity( | ||
user: User, | ||
diary: Diary | ||
): DiaryImageEntity { | ||
return DiaryImageEntity( | ||
id = this.id, | ||
imageUrl = this.image.url, | ||
status = this.image.status, | ||
user = user.toEntity(), | ||
diary = diary.toEntity(user) | ||
) | ||
} | ||
|
||
fun DiaryImageEntity.toDomain(): DiaryImage { | ||
return DiaryImage( | ||
id = this.id, | ||
userId = this.user.id, | ||
diaryId = this.diary.id, | ||
image = Image( | ||
url = imageUrl, | ||
status = this.status, | ||
timestamp = this.toTimeStamp() | ||
) | ||
) | ||
} |
31 changes: 31 additions & 0 deletions
31
...tabase-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageEntityRepository.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,31 @@ | ||
package org.grida.persistence.diaryimage | ||
|
||
import org.grida.domain.diary.Diary | ||
import org.grida.domain.diaryimage.DiaryImage | ||
import org.grida.domain.diaryimage.DiaryImageRepository | ||
import org.grida.domain.user.User | ||
import org.grida.persistence.diary.DiaryEntity | ||
import org.grida.persistence.user.UserEntity | ||
import org.springframework.stereotype.Repository | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Repository | ||
@Transactional(readOnly = true) | ||
class DiaryImageEntityRepository( | ||
private val diaryImageJpaEntityRepository: DiaryImageJpaEntityRepository | ||
) : DiaryImageRepository { | ||
|
||
@Transactional | ||
override fun save( | ||
diaryImage: DiaryImage, | ||
diary: Diary, | ||
user: User | ||
): Long { | ||
val diaryEntity = diaryImage.toEntity( | ||
UserEntity.from(user), | ||
DiaryEntity.from(diary, user) | ||
) | ||
diaryImageJpaEntityRepository.save(diaryEntity) | ||
return diaryEntity.id | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...ase-rds/src/main/kotlin/org/grida/persistence/diaryimage/DiaryImageJpaEntityRepository.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.persistence.diaryimage | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface DiaryImageJpaEntityRepository : JpaRepository<DiaryImageEntity, Long> { | ||
} |
Oops, something went wrong.