Skip to content

Commit

Permalink
feat: #51 user type(일반 유저, 사진작가) 추가 및 사진 작가 entity 설계/구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Wo-ogie committed Nov 11, 2024
1 parent 925252f commit 8113a58
Show file tree
Hide file tree
Showing 21 changed files with 339 additions and 7 deletions.
5 changes: 4 additions & 1 deletion damaba/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ tasks.jacocoTestCoverageVerification {
"*.adapter.outbound.*.*Repository*",
"*.adapter.outbound.*.*Adapter*",
"*.application.listener.*.*EventListener*",
"*.application.service.*.*",
"*.application.service.*",
"*.application.port.*",
"*.domain.*.*",
)

// TODO: 회원가입 기능 구현 후 제거
excludes = listOf("*.domain.photographer.*")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.damaba.damaba.adapter.outbound.photographer

import jakarta.persistence.AttributeConverter
import jakarta.persistence.Converter
import java.time.DayOfWeek

@Converter
class BusinessDaysConverter : AttributeConverter<Set<DayOfWeek>, String> {
override fun convertToDatabaseColumn(attributes: Set<DayOfWeek>?): String? =
attributes
?.sortedBy { it.value }
?.joinToString(DELIMITER) { it.name }

override fun convertToEntityAttribute(dbData: String?): Set<DayOfWeek>? =
dbData?.split(DELIMITER)
?.map { DayOfWeek.valueOf(it) }
?.sortedBy { it.value }
?.toSet()

companion object {
private const val DELIMITER = ","
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.damaba.damaba.adapter.outbound.photographer

import jakarta.persistence.Column
import jakarta.persistence.Convert
import jakarta.persistence.Embeddable
import java.time.DayOfWeek
import java.time.LocalTime

@Embeddable
data class BusinessScheduleEmbeddable(
@Convert(converter = BusinessDaysConverter::class)
@Column(name = "business_days", nullable = true)
val days: Set<DayOfWeek>,

@Column(name = "business_start_time", nullable = true)
val startTime: LocalTime,

@Column(name = "business_end_time", nullable = true)
val endTime: LocalTime,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.damaba.damaba.adapter.outbound.photographer

import com.damaba.damaba.domain.common.PhotographyType
import jakarta.persistence.AttributeConverter
import jakarta.persistence.Converter
import java.util.stream.Collectors

@Converter
class MainPhotohraphyTypesConverter : AttributeConverter<Set<PhotographyType>, String> {
override fun convertToDatabaseColumn(attribute: Set<PhotographyType>): String =
attribute.stream()
.map { roleType -> roleType.name }
.sorted()
.collect(Collectors.joining(DELIMITER))

override fun convertToEntityAttribute(dbData: String): Set<PhotographyType> =
dbData.split(DELIMITER)
.map { roleType -> PhotographyType.valueOf(roleType) }
.toSet()

companion object {
private const val DELIMITER = ","
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.damaba.damaba.adapter.outbound.photographer

import com.damaba.damaba.adapter.outbound.common.BaseJpaTimeEntity
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table

@Table(name = "photographer_active_region")
@Entity
class PhotographerActiveRegionJpaEntity(
photographer: PhotographerJpaEntity,
category: String,
name: String,
) : BaseJpaTimeEntity() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
val id: Long = 0

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "photographer_id", nullable = false)
var photographer: PhotographerJpaEntity = photographer
private set

@Column(name = "category", nullable = false)
var category: String = category
private set

@Column(name = "name", nullable = false)
var name: String = name
private set
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.damaba.damaba.adapter.outbound.photographer

import com.damaba.damaba.adapter.outbound.common.AddressJpaEmbeddable
import com.damaba.damaba.adapter.outbound.common.BaseJpaTimeEntity
import com.damaba.damaba.domain.common.PhotographyType
import jakarta.persistence.CascadeType
import jakarta.persistence.Column
import jakarta.persistence.Convert
import jakarta.persistence.Embedded
import jakarta.persistence.Entity
import jakarta.persistence.Id
import jakarta.persistence.OneToMany
import jakarta.persistence.Table

@Table(name = "photographer")
@Entity
class PhotographerJpaEntity(
@Id @Column(name = "user_id", nullable = false)
val userId: Long,
mainPhotographyTypes: Set<PhotographyType>,
contactLink: String?,
description: String?,
address: AddressJpaEmbeddable?,
businessSchedule: BusinessScheduleEmbeddable?,
) : BaseJpaTimeEntity() {
@Convert(converter = MainPhotohraphyTypesConverter::class)
@Column(name = "main_photography_type", nullable = false)
var mainPhotographyTypes: Set<PhotographyType> = mainPhotographyTypes
private set

@Column(name = "contact_link", nullable = false)
var contactLink: String? = contactLink
private set

@Column(name = "description", length = 500, nullable = true)
var description: String? = description
private set

@Embedded
var address: AddressJpaEmbeddable? = address
private set

@Embedded
var businessSchedule: BusinessScheduleEmbeddable? = businessSchedule
private set

@OneToMany(mappedBy = "photographer", cascade = [CascadeType.PERSIST])
var portfolio: MutableList<PhotographerPortfolioImageJpaEntity> = mutableListOf()
private set

@OneToMany(mappedBy = "photographer", cascade = [CascadeType.ALL], orphanRemoval = true)
var activeRegions: MutableSet<PhotographerActiveRegionJpaEntity> = mutableSetOf()
private set
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.damaba.damaba.adapter.outbound.photographer

import com.damaba.damaba.adapter.outbound.common.BaseJpaEntity
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.FetchType
import jakarta.persistence.GeneratedValue
import jakarta.persistence.GenerationType
import jakarta.persistence.Id
import jakarta.persistence.JoinColumn
import jakarta.persistence.ManyToOne
import jakarta.persistence.Table
import java.time.LocalDateTime

@Table(name = "photographer_portfolio_image")
@Entity
class PhotographerPortfolioImageJpaEntity(
photographer: PhotographerJpaEntity,
name: String,
url: String,
) : BaseJpaEntity() {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
val id: Long = 0

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "photographer_id", nullable = false)
var photographer: PhotographerJpaEntity = photographer
private set

@Column(name = "name", unique = true, nullable = false)
var name: String = name
private set

@Column(name = "url", unique = true, nullable = false)
var url: String = url
private set

@Column(name = "deleted_at", nullable = true)
var deletedAt: LocalDateTime? = null
private set
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.damaba.damaba.domain.common

enum class PhotographyType {
SNAP,
PROFILE,
CONCEPT,
ID_PHOTO,
SELF,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.damaba.damaba.domain.photographer

import java.time.DayOfWeek
import java.time.LocalTime

data class BusinessSchedule(
val days: Set<DayOfWeek>,
val startTime: LocalTime,
val endTime: LocalTime,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.damaba.damaba.domain.photographer

import com.damaba.damaba.domain.common.Address
import com.damaba.damaba.domain.common.PhotographyType

data class Photographer(
val userId: Long,
val mainPhotographyTypes: Set<PhotographyType>,
val contactLink: String?,
val description: String?,
val address: Address?,
val businessSchedule: BusinessSchedule?,
val portfolio: List<PhotographerPortfolioImage>,
val activeRegions: List<PhotographerActiveRegion>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.damaba.damaba.domain.photographer

data class PhotographerActiveRegion(
val category: String,
val name: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.damaba.damaba.domain.photographer

data class PhotographerPortfolioImage(
val name: String,
val url: String,
)
50 changes: 50 additions & 0 deletions damaba/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
DROP TABLE IF EXISTS `user`;
DROP TABLE IF EXISTS photographer;
DROP TABLE IF EXISTS photographer_active_region;
DROP TABLE IF EXISTS photographer_portfolio_image;
DROP TABLE IF EXISTS user_profile_image;
DROP TABLE IF EXISTS promotion;
DROP TABLE IF EXISTS promotion_image;
Expand All @@ -8,6 +11,7 @@ DROP TABLE IF EXISTS promotion_hashtag;
CREATE TABLE `user`
(
id BIGINT NOT NULL AUTO_INCREMENT,
type VARCHAR(255) NOT NULL,
roles VARCHAR(255) NOT NULL,
login_type VARCHAR(255) NOT NULL,
o_auth_login_uid VARCHAR(255) NOT NULL UNIQUE,
Expand All @@ -22,6 +26,52 @@ CREATE TABLE `user`
);
CREATE INDEX idx__user__o_auth_login_uid ON `user` (o_auth_login_uid);

CREATE TABLE photographer
(
user_id BIGINT NOT NULL COMMENT '(FK) id of user',
main_photography_type VARCHAR(255) NOT NULL,
contact_link VARCHAR(255),
description VARCHAR(500),
sido VARCHAR(255),
sigungu VARCHAR(255),
road_address VARCHAR(255),
jibun_address VARCHAR(255),
business_days VARCHAR(255),
business_start_time TIME,
business_end_time TIME,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (user_id)
);
CREATE INDEX fk_idx__photographer__user_id ON photographer (user_id);

CREATE TABLE photographer_active_region
(
id BIGINT NOT NULL AUTO_INCREMENT,
photographer_user_id BIGINT COMMENT '(FK) id of photographer',
category VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
PRIMARY KEY (id)
);
CREATE INDEX fk_idx__photographer_active_region__photographer_id ON photographer_active_region (photographer_user_id);

CREATE TABLE photographer_portfolio_image
(
id BIGINT NOT NULL AUTO_INCREMENT,
photographer_user_id BIGINT COMMENT '(FK) id of photographer',
name VARCHAR(255) NOT NULL,
url VARCHAR(255) NOT NULL UNIQUE,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL,
deleted_at DATETIME,
created_by BIGINT NOT NULL,
updated_by BIGINT NOT NULL,
PRIMARY KEY (id)
);
CREATE INDEX fk_idx__photographer_portfolio__photographer_id ON photographer_active_region (photographer_user_id);

CREATE TABLE user_profile_image
(
id BIGINT NOT NULL AUTO_INCREMENT,
Expand Down
3 changes: 3 additions & 0 deletions damaba/src/test/kotlin/com/damaba/damaba/util/TestFixture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.damaba.user.domain.user.UserProfileImage
import com.damaba.user.domain.user.constant.Gender
import com.damaba.user.domain.user.constant.LoginType
import com.damaba.user.domain.user.constant.UserRoleType
import com.damaba.user.domain.user.constant.UserType
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import org.springframework.security.core.Authentication
import org.springframework.security.core.authority.SimpleGrantedAuthority
Expand All @@ -28,6 +29,7 @@ import java.time.LocalDate
object TestFixture {
fun createUser(
id: Long = randomLong(),
type: UserType = UserType.USER,
roles: Set<UserRoleType> = setOf(UserRoleType.USER),
oAuthLoginUid: String = randomString(),
loginType: LoginType = LoginType.KAKAO,
Expand All @@ -37,6 +39,7 @@ object TestFixture {
instagramId: String = randomString(len = 30),
): User = User(
id = id,
type = type,
roles = roles,
oAuthLoginUid = oAuthLoginUid,
loginType = loginType,
Expand Down
Loading

0 comments on commit 8113a58

Please sign in to comment.