-
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 #114 from soma-baekgu/feature/BG-257-ongoing-event…
…-retrieve [BG-257]: 워크스페이스 이벤트 조회(3H/3H)
- Loading branch information
Showing
12 changed files
with
271 additions
and
5 deletions.
There are no files selected for viewing
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
api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventQueryController.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 com.backgu.amaker.api.event.controller | ||
|
||
import com.backgu.amaker.api.event.dto.response.EventBriefResponse | ||
import com.backgu.amaker.api.event.service.EventFacadeService | ||
import com.backgu.amaker.common.http.ApiHandler | ||
import com.backgu.amaker.common.http.response.ApiResult | ||
import com.backgu.amaker.common.security.jwt.authentication.JwtAuthentication | ||
import com.backgu.amaker.domain.event.EventStatus | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal | ||
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.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
import java.util.Locale | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/workspaces/{workspace-id}/events") | ||
class EventQueryController( | ||
private val eventFacadeService: EventFacadeService, | ||
private val apiHandler: ApiHandler, | ||
) : EventQuerySwagger { | ||
@GetMapping | ||
override fun getOngoingEvent( | ||
@AuthenticationPrincipal token: JwtAuthentication, | ||
@PathVariable("workspace-id") workspaceId: Long, | ||
@RequestParam status: String, | ||
): ResponseEntity<ApiResult<List<EventBriefResponse>>> { | ||
val eventStatus = EventStatus.valueOf(status.uppercase(Locale.getDefault())) | ||
return ResponseEntity.ok().body( | ||
apiHandler.onSuccess( | ||
eventFacadeService | ||
.getEvents( | ||
token.id, | ||
workspaceId, | ||
eventStatus, | ||
).map { EventBriefResponse.of(it, token.id) }, | ||
), | ||
) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
api/src/main/kotlin/com/backgu/amaker/api/event/controller/EventQuerySwagger.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,30 @@ | ||
package com.backgu.amaker.api.event.controller | ||
|
||
import com.backgu.amaker.api.event.dto.response.EventBriefResponse | ||
import com.backgu.amaker.common.http.response.ApiResult | ||
import com.backgu.amaker.common.security.jwt.authentication.JwtAuthentication | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal | ||
import org.springframework.web.bind.annotation.PathVariable | ||
|
||
@Tag(name = "event-query", description = "이벤트 조회 API") | ||
interface EventQuerySwagger { | ||
@Operation(summary = "진행중인 이벤트 조회", description = "진행중인 이벤트 리스트 조회입니다.") | ||
@ApiResponses( | ||
value = [ | ||
ApiResponse( | ||
responseCode = "200", | ||
description = "진행중인 이벤트 리스트 조회 성공", | ||
), | ||
], | ||
) | ||
fun getOngoingEvent( | ||
@AuthenticationPrincipal token: JwtAuthentication, | ||
@PathVariable("workspace-id") workspaceId: Long, | ||
status: String, | ||
): ResponseEntity<ApiResult<List<EventBriefResponse>>> | ||
} |
39 changes: 39 additions & 0 deletions
39
api/src/main/kotlin/com/backgu/amaker/api/event/dto/EventWithUserAndChatRoomDto.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,39 @@ | ||
package com.backgu.amaker.api.event.dto | ||
|
||
import com.backgu.amaker.api.user.dto.UserDto | ||
import com.backgu.amaker.domain.chat.Chat | ||
import com.backgu.amaker.domain.event.Event | ||
import com.backgu.amaker.domain.user.User | ||
import java.time.LocalDateTime | ||
|
||
data class EventWithUserAndChatRoomDto( | ||
val id: Long, | ||
val chatRoomId: Long, | ||
val eventTitle: String, | ||
val deadLine: LocalDateTime, | ||
val notificationStartTime: LocalDateTime, | ||
val notificationInterval: Int, | ||
val users: List<UserDto>, | ||
val finishedCount: Int, | ||
val totalAssignedCount: Int, | ||
) { | ||
companion object { | ||
fun of( | ||
event: Event, | ||
chat: Chat, | ||
users: List<User>, | ||
finishedCount: Int = 0, | ||
): EventWithUserAndChatRoomDto = | ||
EventWithUserAndChatRoomDto( | ||
id = event.id, | ||
chatRoomId = chat.chatRoomId, | ||
eventTitle = event.eventTitle, | ||
deadLine = event.deadLine, | ||
notificationStartTime = event.notificationStartTime, | ||
notificationInterval = event.notificationInterval, | ||
users = users.map { UserDto.of(it) }, | ||
finishedCount = finishedCount, | ||
totalAssignedCount = users.size, | ||
) | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
api/src/main/kotlin/com/backgu/amaker/api/event/dto/response/EventBriefResponse.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,76 @@ | ||
package com.backgu.amaker.api.event.dto.response | ||
|
||
import com.backgu.amaker.api.event.dto.EventWithUserAndChatRoomDto | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import java.time.LocalDateTime | ||
|
||
data class EventBriefResponse( | ||
@Schema( | ||
description = "이벤트 아이디", | ||
example = "2", | ||
) | ||
val eventId: Long, | ||
@Schema( | ||
description = "채팅방 아이디", | ||
example = "21", | ||
) | ||
val chatRoomId: Long, | ||
@Schema( | ||
description = "이벤트 제목", | ||
example = "우리 어디서 만날지", | ||
) | ||
val eventTitle: String, | ||
@Schema( | ||
description = "데드라인", | ||
example = "2024-07-24T07:39:37.598", | ||
) | ||
val deadLine: LocalDateTime, | ||
@Schema( | ||
description = "알림 보낼 시작 시간", | ||
example = "2024-07-24T06:09:37.598", | ||
) | ||
val notificationStartTime: LocalDateTime, | ||
@Schema( | ||
description = "알림 주기", | ||
example = "15", | ||
) | ||
val notificationInterval: Int, | ||
@Schema( | ||
description = "유저 사진 리스트", | ||
example = "[\"http://a-maker.com/hi1.png\", \"http://a-maker.com/hi2.png\"]", | ||
) | ||
val users: List<String>, | ||
@Schema( | ||
description = "완료된 이벤트 수", | ||
example = "2", | ||
) | ||
val finishedCount: Int, | ||
@Schema( | ||
description = "총 배정된 이벤트 수", | ||
example = "5", | ||
) | ||
val totalAssignedCount: Int, | ||
@Schema( | ||
description = "이벤트가 자신의 것인지", | ||
example = "true", | ||
) | ||
val isMine: Boolean, | ||
) { | ||
companion object { | ||
fun of( | ||
event: EventWithUserAndChatRoomDto, | ||
userId: String, | ||
) = EventBriefResponse( | ||
eventId = event.id, | ||
chatRoomId = event.chatRoomId, | ||
eventTitle = event.eventTitle, | ||
deadLine = event.deadLine, | ||
notificationStartTime = event.notificationStartTime, | ||
notificationInterval = event.notificationInterval, | ||
users = event.users.map { it.picture }, | ||
finishedCount = event.finishedCount, | ||
totalAssignedCount = event.totalAssignedCount, | ||
isMine = event.users.any { it.id == 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
27 changes: 27 additions & 0 deletions
27
domain/src/main/kotlin/com/backgu/amaker/domain/event/EventStatus.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 com.backgu.amaker.domain.event | ||
|
||
enum class EventStatus { | ||
ONGOING { | ||
override fun filter( | ||
event: Event, | ||
assignedUsers: List<EventAssignedUser>, | ||
): Boolean = !event.isAchieved(assignedUsers) && !event.isClosed() | ||
}, | ||
EXPIRED { | ||
override fun filter( | ||
event: Event, | ||
assignedUsers: List<EventAssignedUser>, | ||
): Boolean = event.isClosed() && !event.isAchieved(assignedUsers) | ||
}, | ||
COMPLETED { | ||
override fun filter( | ||
event: Event, | ||
assignedUsers: List<EventAssignedUser>, | ||
): Boolean = event.isAchieved(assignedUsers) | ||
}, ; | ||
|
||
abstract fun filter( | ||
event: Event, | ||
assignedUsers: List<EventAssignedUser>, | ||
): Boolean | ||
} |
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
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