Skip to content

Commit

Permalink
Merge pull request #31 from YooJHyun/main
Browse files Browse the repository at this point in the history
[Feat] Calendar 기능 구현
  • Loading branch information
YooJHyun authored Nov 5, 2024
2 parents 75bd6ea + a57d534 commit 2639fa1
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package org.tenten.bittakotlin

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.data.web.config.EnableSpringDataWebSupport
import org.springframework.scheduling.annotation.EnableScheduling

@SpringBootApplication
@EnableScheduling
@EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO)
class BittaKotlinApplication

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,12 @@ class ApplyController(
applyService.applyStatusUpdate(applyId, applyStatusUpdateDTO.applyStatus!!, profileId)
return ResponseEntity.ok("상태가 변경되었습니다")
}

@PostMapping("/calendar")
fun applyToCalendar(@RequestParam jobPostId: Long, @RequestParam profileId: Long): ResponseEntity<String> {
applyService.applyToCalendar(jobPostId, profileId)
return ResponseEntity.ok("캘린더가 등록되었습니다")
}

}

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.tenten.bittakotlin.apply.service

import org.tenten.bittakotlin.apply.dto.ApplyDTO
import org.tenten.bittakotlin.apply.entity.Apply
import org.tenten.bittakotlin.apply.entity.ApplyStatus
import org.tenten.bittakotlin.calendar.entity.EventCalendar
import org.tenten.bittakotlin.profile.entity.Profile

interface ApplyService {
Expand All @@ -20,6 +22,12 @@ interface ApplyService {
fun getApplyCount(jobPostId: Long): Long

fun applyStatusUpdate(applyId: Long, applyStatus: ApplyStatus, profileId: Long)

fun setCalendar(apply: Apply?)

fun getCalendar(profileId: Long?): List<EventCalendar?>?

fun applyToCalendar(jobPostId: Long?, profileId: Long?)
}


Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ import org.tenten.bittakotlin.apply.entity.Apply
import org.tenten.bittakotlin.apply.entity.ApplyStatus
import org.tenten.bittakotlin.apply.exception.ApplyException
import org.tenten.bittakotlin.apply.repository.ApplyRepository
import org.tenten.bittakotlin.calendar.entity.EventCalendar
import org.tenten.bittakotlin.calendar.repository.EventCalendarRepository
import org.tenten.bittakotlin.jobpost.exception.JobPostException
import org.tenten.bittakotlin.jobpost.repository.JobPostRepository
import org.tenten.bittakotlin.jobpost.util.JobPostProvider
import org.tenten.bittakotlin.profile.entity.Profile
import org.tenten.bittakotlin.profile.service.ProfileProvider

@Service
class ApplyServiceImpl(
private val applyRepository: ApplyRepository,
private val jobPostRepository: JobPostRepository,
// private val memberProvider: MemberProvider,
private val jobPostProvider: JobPostProvider
private val profileProvider: ProfileProvider,
private val jobPostProvider: JobPostProvider,
private val eventCalendarRepository: EventCalendarRepository
) : ApplyService {

private val log = LoggerFactory.getLogger(this::class.java)
Expand All @@ -39,6 +43,8 @@ class ApplyServiceImpl(
jobPost!!.plusApplyCount()
jobPostRepository.save(jobPost)

addCalendar(apply)

mapOf(
"message" to "${apply.profile!!.nickname}님 지원 완료",
"data" to entityToDto(apply)
Expand All @@ -49,6 +55,18 @@ class ApplyServiceImpl(
}
}

private fun addCalendar(apply: Apply) {
val jobPost = apply.jobPost
val event = EventCalendar(
profile = apply.profile,
title = jobPost!!.title,
startDate = jobPost.startDate,
endDate = jobPost.endDate,
auditionDate = jobPost.auditionDate
)
eventCalendarRepository.save(event)
}

@Transactional
override fun delete(id: Long) {
val apply = applyRepository.findById(id).orElseThrow { ApplyException.NOT_FOUND.get() }
Expand Down Expand Up @@ -104,10 +122,30 @@ class ApplyServiceImpl(
applyRepository.save(apply)
}

override fun setCalendar(apply: Apply?) {
val event = EventCalendar(
profile = apply!!.profile,
title = apply.jobPost!!.title,
startDate = apply.jobPost!!.startDate,
endDate = apply.jobPost!!.endDate,
auditionDate = apply.jobPost!!.auditionDate
)
eventCalendarRepository.save(event)
}

override fun getCalendar(profileId: Long?): List<EventCalendar?>? {
return eventCalendarRepository.findAllByProfileId(profileId!!)
}

@Transactional
override fun applyToCalendar(jobPostId: Long?, profileId: Long?) {
val apply = Apply()
}

private fun dtoToEntity(applyDTO: ApplyDTO): Apply {
return Apply(
id = applyDTO.id,
// profile = profileProvider.getById(applyDTO.profileId!!),
profile = profileProvider.getById(applyDTO.profileId!!),
jobPost = jobPostProvider.getById(applyDTO.jobPostId!!),
appliedAt = applyDTO.appliedAt
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.tenten.bittakotlin.calendar.controller

import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.tenten.bittakotlin.calendar.dto.EventCalendarDTO
import org.tenten.bittakotlin.calendar.service.EventCalendarService

@RestController
@RequestMapping("/api/v1/calendar")
class EventCalendarController(
private val eventCalendarService: EventCalendarService
) {

@GetMapping("/{profileId}")
fun getCalendar(@PathVariable profileId: Long): ResponseEntity<List<EventCalendarDTO>> {
val events = eventCalendarService.getEventCalendar(profileId)
return ResponseEntity.ok(events)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.tenten.bittakotlin.calendar.dto

import java.time.LocalDate
import java.time.LocalDateTime
import jakarta.validation.constraints.Min
import jakarta.validation.constraints.NotNull
import io.swagger.v3.oas.annotations.media.Schema

@Schema(title = "캘린더 DTO", description = "회원의 일정을 확인할 때 사용하는 DTO입니다.")
data class EventCalendarDTO(
@Schema(title = "캘린더 ID (PK)", description = "캘린더의 고유 ID 입니다.", example = "1", minimum = "1")
@field:Min(value = 1, message = "ID는 음수가 될 수 없습니다")
val id: Long? = null,

@Schema(title = "회원 ID", description = "회원의 고유 ID 입니다.", example = "1", minimum = "1")
@field:Min(value = 1, message = "ID는 음수가 될 수 없습니다")
@field:NotNull(message = "회원의 ID가 필요합니다")
val profileId: Long? = null,

val startDate: LocalDate? = null,
val endDate: LocalDate? = null,
val auditionDate: LocalDateTime? = null,
val title: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.tenten.bittakotlin.calendar.entity

import jakarta.persistence.*
import org.springframework.data.jpa.domain.support.AuditingEntityListener
import org.tenten.bittakotlin.profile.entity.Profile
import java.time.LocalDate
import java.time.LocalDateTime

@Entity
@Table(name = "event_calendar")
@EntityListeners(AuditingEntityListener::class)
data class EventCalendar(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Long? = null,

@ManyToOne
@JoinColumn(name = "profileId", nullable = false)
val profile: Profile? = null,

@Column(nullable = false)
val title: String,

val startDate: LocalDate? = null,

val endDate: LocalDate? = null,

val auditionDate: LocalDateTime? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.tenten.bittakotlin.calendar.repository

import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.tenten.bittakotlin.calendar.entity.EventCalendar

interface EventCalendarRepository : JpaRepository<EventCalendar, Long> {
@Query("SELECT c FROM EventCalendar c WHERE c.profile.id = :profileId")
fun findAllByProfileId(profileId: Long): List<EventCalendar>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.tenten.bittakotlin.calendar.service

import org.tenten.bittakotlin.calendar.dto.EventCalendarDTO

interface EventCalendarService {
fun getEventCalendar(profileId: Long): List<EventCalendarDTO>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.tenten.bittakotlin.calendar.service

import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import org.tenten.bittakotlin.calendar.dto.EventCalendarDTO
import org.tenten.bittakotlin.calendar.entity.EventCalendar
import org.tenten.bittakotlin.calendar.repository.EventCalendarRepository

@Service
class EventCalendarServiceImpl(
private val eventCalendarRepository: EventCalendarRepository
) : EventCalendarService {

private val logger = LoggerFactory.getLogger(EventCalendarServiceImpl::class.java)

override fun getEventCalendar(profileId: Long): List<EventCalendarDTO> {
val events = eventCalendarRepository.findAllByProfileId(profileId)
return events.map { entityToDto(it) }
}

private fun entityToDto(event: EventCalendar): EventCalendarDTO {
return EventCalendarDTO(
id = event.id,
profileId = event.profile!!.id,
startDate = event.startDate,
endDate = event.endDate,
title = event.title,
auditionDate = event.auditionDate
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ class JobPostViewController {
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data class JobPostDTO(
val workCategory: WorkCategory? = null,

@Schema(title = "오디션일", description = "오디션을 진행하는 날짜입니다.", example = "2023-09-24")
val auditionDate: LocalDate? = null,
val auditionDate: LocalDateTime? = null,

@Schema(title = "촬영 시작일", description = "일이 시작하는 날짜입니다.", example = "2023-09-24")
val startDate: LocalDate? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class JobPost(
@Enumerated(EnumType.STRING)
var workCategory: WorkCategory? = null, // 작품 카테고리

val auditionDate: LocalDate? = null, // 오디션 일자
val auditionDate: LocalDateTime? = null, // 오디션 일자

val startDate: LocalDate? = null, // 촬영 기간 시작일
val endDate: LocalDate? = null, // 촬영 기간 종료일
Expand All @@ -78,7 +78,7 @@ class JobPost(
val apply: List<Apply> = mutableListOf(),

@OneToMany(mappedBy = "jobPost", fetch = FetchType.EAGER, cascade = [CascadeType.REMOVE], orphanRemoval = true)
val likes: List<Like> = mutableListOf()
val like: List<Like> = mutableListOf()
) {

fun plusApplyCount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Profile(

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
val member: Member,
val member: Member? = null,

@Column(length = 20, nullable = false)
var nickname: String,
Expand Down

0 comments on commit 2639fa1

Please sign in to comment.