Skip to content

Commit

Permalink
feat: Entity를 생성한다. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
inpink authored Jan 20, 2025
1 parent 246bb5a commit 086839b
Show file tree
Hide file tree
Showing 21 changed files with 268 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test {
}

application {
mainClassName = 'com.misik.api.Application'
mainClassName = 'me.misik.api.Application'
}

apply from: "gradle/db.gradle"
Expand Down
33 changes: 33 additions & 0 deletions docs/api/리뷰_생성_API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 리뷰 생성

리뷰를 생성합니다.

## Request

### HTTP METHOD : `POST`

### url : `https://api.misik.me/reviews`
### Http Headers
- device-id: 식별할 수 있는 값
`미래에도 변하지 않아야함 앱을 삭제했다 다시 깔아도 안변하는 값으로 줄 수 있는지`

### RequestBody

```json
{
"ocrText": "",
"hashTag": ["특별한 메뉴가 있어요", "뷰가 좋아요", ..., "종류가 다양해요"],
"reviewStyle": "딱딱한 미식가"
}
```

### Response

#### `Response Status 200 OK`

```json
{
"id": "123456789",
"review": "카야토스는 숨겨져 있는 카야잼과 버터가 확실히 가득합니다. 또한, 가게의 분위기는 아늑하고 편안하고 바깥쪽에 있고 사랑하는 시간을 보낼 수 있는 공간입니다. 무엇보다 가격에 비해 음식의 품질이 정말 훌륭해서, 마음에 들었습니다."
}
```
23 changes: 23 additions & 0 deletions docs/api/리뷰_재생성_API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 리뷰 재생성

리뷰를 재생성합니다.

## Request

### HTTP METHOD : `POST`

### url : `https://api.misik.me/reviews/{id}/re-create`
### Http Headers
- device-id: 식별할 수 있는 값
`미래에도 변하지 않아야함 앱을 삭제했다 다시 깔아도 안변하는 값으로 줄 수 있는지`

### Response

#### `Response Status 200 OK`

```json
{
"id": "123456789",
"review": "가득합니다....."
}
```
25 changes: 25 additions & 0 deletions docs/api/선택가능한_가능한_어조_조회_API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 가능한 어조 조회

선택 가능한 어조를 조회합니다.

## Request

### HTTP METHOD : `GET`

### url : `https://api.misik.me/reviews/styles`

### Response

#### `Response Status 200 OK`

```json
{
"reviewStyles": [
{
"icon": "https://static.misik.me/",
"style": "딱딱한 미식가"
},
...
]
}
```
5 changes: 4 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kotlin.code.style=official

### Project ###
group=com.misik.api
group=me.misik.api
version=1.0

### Spring ###
Expand All @@ -28,3 +28,6 @@ netxVersion=0.4.8

### H2version ###
h2Version=1.4.200

### Snowflake ###
snowflakeVersion=5.2.5
1 change: 1 addition & 0 deletions gradle/db.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
dependencies {
implementation "mysql:mysql-connector-java:${mysqlConnectorVersion}"
implementation "com.github.f4b6a3:tsid-creator:${snowflakeVersion}"

testRuntimeOnly "com.h2database:h2:${h2Version}"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.misik.api
package me.misik.api

import org.rooftop.netx.meta.EnableSaga
import org.springframework.boot.SpringApplication
Expand Down
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions src/main/kotlin/me/misik/api/core/AggregateRoot.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package me.misik.api.core

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
annotation class AggregateRoot
20 changes: 20 additions & 0 deletions src/main/kotlin/me/misik/api/core/Clock.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package me.misik.api.core

import java.time.Clock
import java.time.Instant
import java.time.ZoneId
import java.time.ZonedDateTime

object Clock {

var clock: Clock = Clock.systemUTC()

fun instant() = Instant.now(clock)

fun Instant.toZonedDateTime() = ZonedDateTime.ofInstant(this, clock.zone)

fun Instant.toZonedDateTime(zoneId: ZoneId) = ZonedDateTime.ofInstant(this, zoneId)

fun Instant.toKr() = ZonedDateTime.ofInstant(this, ZoneId.of("Asia/Seoul"))

}
10 changes: 10 additions & 0 deletions src/main/kotlin/me/misik/api/core/IdGenerator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.misik.api.core

import com.github.f4b6a3.tsid.TsidFactory

object IdGenerator {

private val tsidFactory = TsidFactory.newInstance256()

fun generate(): Long = tsidFactory.create().toLong()
}
32 changes: 32 additions & 0 deletions src/main/kotlin/me/misik/api/domain/AbstractTime.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.misik.api.domain

import jakarta.persistence.Column
import jakarta.persistence.EntityListeners
import jakarta.persistence.MappedSuperclass
import jakarta.persistence.PrePersist
import org.springframework.data.annotation.CreatedDate
import org.springframework.data.annotation.LastModifiedDate
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import java.time.Instant

@MappedSuperclass
@EntityListeners(AuditingEntityListener::class)
abstract class AbstractTime(
@CreatedDate
@Column(name = "created_at")
var createdAt: Instant = Instant.now(),

@LastModifiedDate
@Column(name = "modified_at")
var modifiedAt: Instant? = null,
) {

@PrePersist
fun prePersist() {
modifiedAt = when (modifiedAt == null) {
true -> createdAt
false -> return
}
}
}

20 changes: 20 additions & 0 deletions src/main/kotlin/me/misik/api/domain/RequestPrompt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package me.misik.api.domain

import jakarta.persistence.*
import me.misik.api.domain.converter.ListToStringConverter

@Embeddable
class RequestPrompt(
@Enumerated(EnumType.STRING)
@Column(name = "style", nullable = false, columnDefinition = "VARCHAR(20)")
val style: ReviewStyle,

@Column(name = "text", columnDefinition = "TEXT", nullable = false)
val text: String,

@Column(name = "hash_tags", columnDefinition = "TEXT", nullable = false)
@Convert(converter = ListToStringConverter::class)
val hashTags: List<String>,
) {

}
30 changes: 30 additions & 0 deletions src/main/kotlin/me/misik/api/domain/Review.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.misik.api.domain

import jakarta.persistence.Column
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.Table
import me.misik.api.core.AggregateRoot


@Entity(name = "review")
@Table(name = "review")
@AggregateRoot
class Review(
@Id
@Column(name = "id")
val id: Long,

@Column(name = "text", length = 300, columnDefinition = "VARCHAR(300)", nullable = false)
val text: String,

@Column(name = "device_id", nullable = false, columnDefinition = "VARCHAR(100)")
val deviceId: String,

@Embedded
val requestPrompt: RequestPrompt,
): AbstractTime() {


}
5 changes: 5 additions & 0 deletions src/main/kotlin/me/misik/api/domain/ReviewRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package me.misik.api.domain

import org.springframework.data.jpa.repository.JpaRepository

interface ReviewRepository : JpaRepository<Review, Long>
11 changes: 11 additions & 0 deletions src/main/kotlin/me/misik/api/domain/ReviewService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package me.misik.api.domain

import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

@Service
@Transactional(readOnly = true)
class ReviewService(
private val reviewRepository: ReviewRepository,
) {
}
5 changes: 5 additions & 0 deletions src/main/kotlin/me/misik/api/domain/ReviewStyle.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package me.misik.api.domain

enum class ReviewStyle {
DUMMY,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package me.misik.api.domain.converter

import jakarta.persistence.AttributeConverter
import jakarta.persistence.Converter

@Converter
class ListToStringConverter : AttributeConverter<List<String>, String> {

override fun convertToDatabaseColumn(attribute: List<String>): String {
val seperatorDeletedAttribute = attribute.map { it.replace(SEPERATOR, "") }

return seperatorDeletedAttribute.joinToString(SEPERATOR)
}

override fun convertToEntityAttribute(dbData: String?): List<String> {
return dbData?.split(SEPERATOR) ?: emptyList()
}

private companion object {
private const val SEPERATOR = "|"
}
}

19 changes: 19 additions & 0 deletions src/main/kotlin/me/misik/api/domain/query/Prompt.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package me.misik.api.domain.query

import jakarta.persistence.*
import me.misik.api.domain.AbstractTime
import me.misik.api.domain.ReviewStyle

@Entity
class Prompt(
@Id
@Column(name = "id")
val id: Long,

@Column(name = "style", columnDefinition = "VARCHAR(20)", nullable = false)
@Enumerated(EnumType.STRING)
val style: ReviewStyle,

@Column(name = "text", columnDefinition = "TEXT", nullable = false)
val text: String,
) : AbstractTime()
Empty file.

0 comments on commit 086839b

Please sign in to comment.