Skip to content

Commit

Permalink
Api-v0.0.3-3
Browse files Browse the repository at this point in the history
  • Loading branch information
kdomo authored Jul 3, 2023
2 parents f7921aa + 46af5f5 commit d529445
Show file tree
Hide file tree
Showing 56 changed files with 708 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.depromeet.whatnow.annotation.ApiErrorCodeExample
import com.depromeet.whatnow.api.config.kakao.KakaoKauthErrorCode
import com.depromeet.whatnow.domains.image.exception.ImageErrorCode
import com.depromeet.whatnow.domains.progresshistory.exception.PromiseHistoryErrorCode
import com.depromeet.whatnow.domains.promise.exception.PromiseErrorCode
import com.depromeet.whatnow.domains.promiseuser.exception.PromiseUserErrorCode
import com.depromeet.whatnow.domains.user.exception.UserErrorCode
import com.depromeet.whatnow.exception.GlobalErrorCode
import io.swagger.v3.oas.annotations.Operation
Expand Down Expand Up @@ -45,4 +47,14 @@ class ExampleController() {
@Operation(summary = "이미지 업로드 관련 에러코드 나열")
@ApiErrorCodeExample(ImageErrorCode::class)
fun imageErrorCode() {}

@GetMapping("/promises")
@Operation(summary = "약속 관련 에러코드 나열")
@ApiErrorCodeExample(PromiseErrorCode::class)
fun promiseErrorCode() {}

@GetMapping("/promise-users")
@Operation(summary = "약속 참여 관련 에러코드 나열")
@ApiErrorCodeExample(PromiseUserErrorCode::class)
fun promiseUserErrorCode() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package com.depromeet.whatnow.api.image.controller
import com.depromeet.whatnow.api.image.dto.ImageUrlResponse
import com.depromeet.whatnow.api.image.usecase.GetPresignedUrlUseCase
import com.depromeet.whatnow.api.image.usecase.ImageUploadSuccessUseCase
import com.depromeet.whatnow.common.vo.CoordinateVo
import com.depromeet.whatnow.config.s3.ImageFileExtension
import com.depromeet.whatnow.domains.image.domain.ImageCommentType
import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import javax.validation.Valid

@RestController
@Tag(name = "6. [이미지]")
Expand All @@ -23,8 +26,8 @@ class ImageController(
val getPresignedUrlUseCase: GetPresignedUrlUseCase,
val successUseCase: ImageUploadSuccessUseCase,
) {
@Operation(summary = "약속 관련 이미지 업로드 Presigned URL 발급")
@GetMapping("/promises/{promiseId}/images")
@Operation(summary = "약속 이미지 업로드 Presigned URL 발급")
@GetMapping("/images/promises/{promiseId}")
fun getPresignedUrlOfPromise(
@PathVariable promiseId: Long,
@RequestParam fileExtension: ImageFileExtension,
Expand All @@ -33,21 +36,27 @@ class ImageController(
}

@Operation(summary = "유저 프로필 이미지 업로드 Presigned URL 발급")
@GetMapping("/users/me/images")
@GetMapping("/images/users/me")
fun getPresignedUrlOfUser(
@RequestParam fileExtension: ImageFileExtension,
): ImageUrlResponse {
return getPresignedUrlUseCase.forUser(fileExtension)
}

@Operation(summary = "약속 관련 이미지 업로드 성공 요청")
@PostMapping("/promises/{promiseId}/images/success/{imageKey}")
fun promiseUploadImageSuccess(@PathVariable promiseId: Long, @PathVariable imageKey: String, @RequestParam imageCommentType: ImageCommentType) {
successUseCase.promiseUploadImageSuccess(promiseId, imageKey, imageCommentType)
@Operation(summary = "약속 이미지 업로드 성공 요청")
@PostMapping("/images/{imageKey}/promises/{promiseId}")
fun promiseUploadImageSuccess(
@PathVariable promiseId: Long,
@PathVariable imageKey: String,
@RequestParam promiseImageCommentType: PromiseImageCommentType,
@RequestBody @Valid
userLocation: CoordinateVo,
) {
successUseCase.promiseUploadImageSuccess(promiseId, imageKey, promiseImageCommentType, userLocation)
}

@Operation(summary = "유저 프로필 이미지 업로드 성공 요청")
@PostMapping("/users/me/images/success/{imageKey}")
@PostMapping("/images/{imageKey}/users/me")
fun userUploadImageSuccess(@PathVariable imageKey: String) {
successUseCase.userUploadImageSuccess(imageKey)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package com.depromeet.whatnow.api.image.usecase

import com.depromeet.whatnow.annotation.UseCase
import com.depromeet.whatnow.common.vo.CoordinateVo
import com.depromeet.whatnow.config.security.SecurityUtils
import com.depromeet.whatnow.domains.image.domain.ImageCommentType
import com.depromeet.whatnow.domains.image.domain.PromiseImageCommentType
import com.depromeet.whatnow.domains.image.service.ImageDomainService

@UseCase
class ImageUploadSuccessUseCase(
val imageDomainService: ImageDomainService,
) {
fun promiseUploadImageSuccess(promiseId: Long, imageKey: String, imageCommentType: ImageCommentType) {
fun promiseUploadImageSuccess(
promiseId: Long,
imageKey: String,
promiseImageCommentType: PromiseImageCommentType,
userLocation: CoordinateVo,
) {
val currentUserId: Long = SecurityUtils.currentUserId
imageDomainService.promiseUploadImageSuccess(currentUserId, promiseId, imageKey, imageCommentType)
imageDomainService.promiseImageUploadSuccess(currentUserId, promiseId, imageKey, promiseImageCommentType, userLocation)
}

fun userUploadImageSuccess(imageKey: String) {
val currentUserId: Long = SecurityUtils.currentUserId
imageDomainService.userUploadImageSuccess(currentUserId, imageKey)
imageDomainService.userImageUploadSuccess(currentUserId, imageKey)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.depromeet.whatnow.api.interaction.dto

import com.depromeet.whatnow.api.promiseprogress.dto.response.UserProgressResponse

data class InteractionResponse(
val userProgressResponse: UserProgressResponse,
val interactionDtoList: List<InteractionDto>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,29 @@ package com.depromeet.whatnow.api.interaction.usecase
import com.depromeet.whatnow.annotation.UseCase
import com.depromeet.whatnow.api.interaction.dto.InteractionDto
import com.depromeet.whatnow.api.interaction.dto.InteractionResponse
import com.depromeet.whatnow.api.promiseprogress.dto.response.UserProgressResponse
import com.depromeet.whatnow.config.security.SecurityUtils
import com.depromeet.whatnow.domains.interaction.service.InteractionDomainService
import com.depromeet.whatnow.domains.progresshistory.adapter.ProgressHistoryAdapter
import com.depromeet.whatnow.domains.user.adapter.UserAdapter

@UseCase
class InteractionReadUseCase(
val interactionDomainService: InteractionDomainService,
val progressHistoryAdapter: ProgressHistoryAdapter,
val userAdapter: UserAdapter,
) {

fun findMyInteraction(promiseId: Long): InteractionResponse {
val userId: Long = SecurityUtils.currentUserId
val history = progressHistoryAdapter.findByPromiseIdAndUserId(promiseId, userId)
val userProgressResponse = UserProgressResponse(
userAdapter.queryUser(userId).toUserInfoVo(),
history.currentPromiseProgress,
history.prePromiseProgress,
)
return InteractionResponse(
userProgressResponse,
interactionDomainService.queryAllInteraction(promiseId, userId).map { InteractionDto.from(it) },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class NcpHelper(

// 검색 키워드 조회
fun getLocalSearch(keyword: String): NcpMapInfoResponse {
println("ncpPropertie.accessKey: ${ncpPropertie.accessKey}")
println("ncpPropertie.secretKey: ${ncpPropertie.secretKey}")

return ncpClient.searchByKeyword(ncpPropertie.accessKey, ncpPropertie.secretKey, keyword)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.depromeet.whatnow.api.promise.controller

import com.depromeet.whatnow.api.dto.NcpMapInfoResponse
import com.depromeet.whatnow.api.location.helper.NcpHelper
import com.depromeet.whatnow.api.promise.usecase.GetDistrictUseCase
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import io.swagger.v3.oas.annotations.tags.Tag
Expand All @@ -12,14 +13,24 @@ import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/v1")
@Tag(name = "3.1 [약속-장소]")
@SecurityRequirement(name = "access-token")
@Tag(name = "3.1 [약속-장소]")
class LocalController(
val getDistrictUseCase: GetDistrictUseCase,
val ncpHelper: NcpHelper,
) {
@Operation(summary = "약속 장소 검색", description = "약속 장소를 검색합니다.")
@GetMapping("/location")
fun searchLocal(@RequestParam(value = "location") addressKeyword: String): NcpMapInfoResponse {
return ncpHelper.getLocalSearch(addressKeyword)
}

@Operation(summary = "행정동 조회", description = "좌표를 통해 행정동을 조회합니다.")
@GetMapping("/district")
fun getDistrict(
@RequestParam coordinateX: Double,
@RequestParam coordinateY: Double,
): String {
return getDistrictUseCase.execute(coordinateX, coordinateY)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,18 @@ class PromiseController(
return promiseReadUseCase.findPromiseByUserIdYearMonth(yearMonth)
}

@Operation(summary = "약속 모음집 상세", description = "D3. 지난(AFTER) 약속 상세 조회 (날짜(월,일), 약속 사진 url, 타임오버 캡쳐, 만난 사람(프로필 tkwls Url, 이름, wait/late 여부, interaction 종륲별 카운트), 하이라이트 기록 최대 3개")
@Operation(summary = "약속 모음집 상세", description = "D3. 지난(AFTER) 약속 상세 조회 (날짜(월,일), 약속 사진 url, 타임오버 캡쳐, 만난 사람(프로필 사진 Url, 이름, wait/late 여부, interaction 종륲별 카운트), 하이라이트 기록 최대 3개")
@GetMapping("/promises/users/status/{status}")
fun findPromiseDetailByStatus(@PathVariable(value = "status") status: PromiseType): List<PromiseDetailDto> {
return promiseReadUseCase.findPromiseDetailByStatus(status)
}

@Operation(summary = "현재 약속이 활성화 상태인지 비활성화 상태인지 조회", description = "현재 약속이 활성화 상태인지 비활성화 상태인지 조회한다.")
@GetMapping("/promises/{promise-id}/active")
fun findPromiseActive(@PathVariable(value = "promise-id") promiseId: Long): Boolean {
return promiseReadUseCase.findPromiseActive(promiseId)
}

@Operation(summary = "약속(promise) 생성", description = "약속을 생성합니다.")
@PostMapping("/promises")
fun createPromise(@RequestBody promiseRequest: PromiseRequest): PromiseDto {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.depromeet.whatnow.api.promise.usecase

import com.depromeet.whatnow.annotation.UseCase
import com.depromeet.whatnow.domains.district.repository.DistrictRepository
import com.mongodb.client.model.geojson.Point
import com.mongodb.client.model.geojson.Position

@UseCase
class GetDistrictUseCase(
val districtRepository: DistrictRepository,
) {
fun execute(coordinateX: Double, coordinateY: Double): String {
val intersects =
districtRepository.findByLocationIntersects(Point(Position(coordinateX, coordinateY)))
return intersects.properties.adm_nm
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor
import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser
import com.depromeet.whatnow.domains.user.adapter.UserAdapter
import com.depromeet.whatnow.domains.user.repository.UserRepository
import java.time.LocalDateTime
import java.time.YearMonth

@UseCase
Expand Down Expand Up @@ -135,4 +136,12 @@ class PromiseReadUseCase(
}
return result
}

fun findPromiseActive(promiseId: Long): Boolean {
val promise = promiseAdaptor.queryPromise(promiseId)
// 현재 시간이 endTime 의1시간 전과 30분 이후 사이에 있으면 true
val now = LocalDateTime.now()
val endTime = promise.endTime
return now.isAfter(endTime.minusHours(1)) && now.isBefore(endTime.plusMinutes(30))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.depromeet.whatnow.api.promiseuser.dto.PromiseUserDto
import com.depromeet.whatnow.api.promiseuser.usecase.PromiseUserReadUseCase
import com.depromeet.whatnow.api.promiseuser.usecase.PromiseUserRecordUseCase
import com.depromeet.whatnow.common.vo.CoordinateVo
import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.security.SecurityRequirement
import io.swagger.v3.oas.annotations.tags.Tag
Expand All @@ -15,34 +16,34 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/v1/")
@RequestMapping("/v1")
@Tag(name = "4. [약속 유저]")
@SecurityRequirement(name = "access-token")
class PromiseUserController(
val promiseUserRecordUseCase: PromiseUserRecordUseCase,
val promiseUserReadUseCase: PromiseUserReadUseCase,
) {
@Operation(summary = "약속 유저(promise) 생성", description = "약속에 유저가 참여합니다.")
@PostMapping("promises/{promise-id}/users")
@PostMapping("/promises/{promise-id}/users")
fun joinPromise(@PathVariable("promise-id") promiseId: Long, userId: Long, userLocation: CoordinateVo): PromiseUserDto {
return promiseUserRecordUseCase.createPromiseUser(promiseId, userId, userLocation)
}

@Operation(summary = "약속 id로 약속 유저(promiseUser) 조회", description = "약속ID 로 약속 유저를 조회합니다.")
@GetMapping("promises/{promiseId}/users")
@GetMapping("/promises/{promiseId}/users")
fun getPromiseUser(@PathVariable("promise-id") promiseId: Long): List<PromiseUserDto> {
return promiseUserReadUseCase.findByPromiseId(promiseId)
}

@Operation(summary = "유저가 약속을 취소(상태로 변경)", description = "userId로 참여한 약속 유저를 취소(cancel) 합니다.")
@GetMapping("promises/{promise-id}/users/{user-id}/status/{status}")
fun getPromiseUserByPromiseUserType(@PathVariable("promise-id") promiseId: Long, @PathVariable("user-id") userId: Long, @PathVariable("status") status: String): List<PromiseUserDto> {
return promiseUserReadUseCase.findPromiseUserByPromiseUserType(promiseId, userId, status)
@Operation(summary = "약속id 와 유저 id 로 약속에 참여한 유저의 정보를 조회", description = "약속ID 와 유저ID 로 약속에 참여한 유저의 정보를 조회합니다.")
@GetMapping("/promises/{promise-id}/users/{user-id}")
fun getPromiseUserByPromiseUserType(@PathVariable("promise-id") promiseId: Long, @PathVariable("user-id") userId: Long): PromiseUserDto {
return promiseUserReadUseCase.findPromiseUserByPromiseIdAndUserId(promiseId, userId)
}

@Operation(summary = "유저가 약속을 취소(상태로 변경)", description = "userId로 참여한 약속 유저를 취소(cancel) 합니다.")
@PutMapping("promises/{promise-id}/users/{user-id}/status/{status}")
fun cancelPromise(@PathVariable("promise-id") promiseId: Long, @PathVariable("user-id") userId: Long, @PathVariable("status") status: String): PromiseUserDto {
return promiseUserRecordUseCase.updatePromiseUserType(promiseId, userId, status)
@PutMapping("/promises/{promise-id}/users/{user-id}/status/{status}")
fun cancelPromise(@PathVariable("promise-id") promiseId: Long, @PathVariable("user-id") userId: Long, @PathVariable("status") promiseUserType: PromiseUserType): PromiseUserDto {
return promiseUserRecordUseCase.updatePromiseUserType(promiseId, userId, promiseUserType)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.depromeet.whatnow.api.promiseuser.dto

import com.depromeet.whatnow.common.vo.CoordinateVo
import com.depromeet.whatnow.domains.progresshistory.domain.PromiseProgress
import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUser
import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType

Expand All @@ -9,10 +10,11 @@ data class PromiseUserDto(
val mainUserId: Long,
val userLocation: CoordinateVo?,
val promiseUserType: PromiseUserType,
val promiseProgress: PromiseProgress,
) {
companion object {
fun from(p: PromiseUser): PromiseUserDto {
return PromiseUserDto(p.promiseId, p.userId, p.userLocation, p.promiseUserType!!)
fun of(p: PromiseUser, progress: PromiseProgress): PromiseUserDto {
return PromiseUserDto(p.promiseId, p.userId, p.userLocation, p.promiseUserType!!, progress)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,30 @@ package com.depromeet.whatnow.api.promiseuser.usecase

import com.depromeet.whatnow.annotation.UseCase
import com.depromeet.whatnow.api.promiseuser.dto.PromiseUserDto
import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType.READY
import com.depromeet.whatnow.domains.promiseuser.domain.PromiseUserType.valueOf
import com.depromeet.whatnow.domains.progresshistory.adapter.ProgressHistoryAdapter
import com.depromeet.whatnow.domains.promiseuser.adaptor.PromiseUserAdaptor
import com.depromeet.whatnow.domains.promiseuser.service.PromiseUserDomainService

@UseCase
class PromiseUserReadUseCase(
val promiseUserDomainService: PromiseUserDomainService,
val progressHistoryAdapter: ProgressHistoryAdapter,
val promiseUserAdaptor: PromiseUserAdaptor,
) {
fun findByPromiseId(promiseId: Long): List<PromiseUserDto> {
return promiseUserDomainService.findByPromiseId(promiseId).map { PromiseUserDto.from(it) }
}
fun findPromiseUserByPromiseUserType(promiseId: Long, userId: Long, status: String): List<PromiseUserDto> {
return promiseUserDomainService.findByPromiseId(promiseId)
// userType 와 status 를 비교해서 같은 것만 반환
.filter {
it.userId == userId && it.promiseUserType == valueOf(status)
}
.map { PromiseUserDto.from(it) }
}

fun findByUserIdOnReady(userId: Long): List<PromiseUserDto> {
return promiseUserDomainService.findByUserId(userId)
.filter { it.promiseUserType == READY }
.map {
PromiseUserDto.from(it)
}
val progressHistories = progressHistoryAdapter.findByPromiseId(promiseId)
val promiseUserDtos = mutableListOf<PromiseUserDto>()
val findByPromiseId = promiseUserDomainService.findByPromiseId(promiseId)
findByPromiseId.forEach { promiseUser ->
val progressHistory = progressHistories.find { it.userId == promiseUser.userId }
promiseUserDtos.add(PromiseUserDto.of(promiseUser, progressHistory!!.currentPromiseProgress))
}
return promiseUserDtos
}

fun findByUserIdWithStatus(userId: Long, status: String): List<PromiseUserDto> {
return promiseUserDomainService.findByUserId(userId)
.filter { it.promiseUserType == valueOf(status) }
.map {
PromiseUserDto.from(it)
}
fun findPromiseUserByPromiseIdAndUserId(promiseId: Long, userId: Long): PromiseUserDto {
val promiseUsers = promiseUserAdaptor.findByPromiseIdAndUserId(promiseId, userId)
val progressHistory = progressHistoryAdapter.findByPromiseIdAndUserId(promiseId, userId)
return PromiseUserDto.of(promiseUsers, progressHistory.currentPromiseProgress)
}
}
Loading

0 comments on commit d529445

Please sign in to comment.