Skip to content

Commit

Permalink
commits -> problems 도메인 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
gidskql6671 committed May 27, 2024
1 parent bb05e60 commit 1932a13
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
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 knu.dong.onedayonebaek.domain.User
import knu.dong.onedayonebaek.dto.CommitInfo
import knu.dong.onedayonebaek.dto.ProblemDto
import knu.dong.onedayonebaek.exception.response.BadRequestResponse
import knu.dong.onedayonebaek.service.CommitService
import knu.dong.onedayonebaek.service.ProblemService
import org.springframework.security.core.Authentication
import org.springframework.validation.annotation.Validated
import org.springframework.web.bind.annotation.*
Expand All @@ -18,8 +19,9 @@ import java.time.YearMonth

@Validated
@RestController
@RequestMapping("/commits")
class CommitController(private val commitService: CommitService) {
@RequestMapping("/problems")
@Tag(name = "해결한 문제 APIs", description = "해결한 문제들을 조회하는 APIs")
class ProblemController(private val problemService: ProblemService) {

@Operation(
summary = "로그인된 유저가 해결한 문제 목록 조회",
Expand All @@ -33,20 +35,20 @@ class CommitController(private val commitService: CommitService) {
)
)
@GetMapping
fun getCommits(
fun getProblems(
@Schema(
description = "커밋 목록을 조회하고 싶은 년도와 월",
description = "해결한 문제 목록을 조회하고 싶은 년도와 월",
required = true,
example = "2024-05",
type = "String",
format = "YYYY-MM"
)
yearMonth: YearMonth,
authentication: Authentication
): List<CommitInfo> {
): List<ProblemDto> {
val user = authentication.principal as User

return commitService.getCommits(user, yearMonth)
return problemService.getProblems(user, yearMonth)
}

@Operation(
Expand All @@ -61,9 +63,9 @@ class CommitController(private val commitService: CommitService) {
)
)
@GetMapping("/count")
fun getCommitCountOfDay(
fun getProblemCountOfDay(
@Schema(
description = "커밋 개수를 조회하고 싶은 날짜",
description = "해결한 문제 개수를 조회하고 싶은 날짜",
required = true,
example = "2024-05-25"
)
Expand All @@ -72,6 +74,6 @@ class CommitController(private val commitService: CommitService) {
): Int {
val user = authentication.principal as User

return commitService.getCommits(user, date).size
return problemService.getProblems(user, date).size
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import java.time.LocalDate


@Entity
@Table(name = "commits")
class Commit(
@Table(name = "problems")
class Problem(
@Column(nullable = false)
var commitDate: LocalDate,
var solvedDate: LocalDate,

@Column(nullable = false, unique = true)
var commitUrl: String,

var problemRank: String,

@Column(nullable = false)
var problemTitle: String,
var title: String,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
Expand Down
25 changes: 0 additions & 25 deletions back/src/main/kotlin/knu/dong/onedayonebaek/dto/CommitInfo.kt

This file was deleted.

25 changes: 25 additions & 0 deletions back/src/main/kotlin/knu/dong/onedayonebaek/dto/ProblemDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package knu.dong.onedayonebaek.dto

import io.swagger.v3.oas.annotations.media.Schema
import knu.dong.onedayonebaek.domain.Problem
import java.time.LocalDate

data class ProblemDto(
@Schema(description = "문제를 해결한 날짜", nullable = false, example = "2024-05-09")
val solvedDate: LocalDate,

@Schema(description = "문제 코드가 담긴 커밋 url", nullable = false, example = "https://github.com/gidskql6671")
val commitUrl: String,

@Schema(description = "사용자명", nullable = false, example = "Kim DongHwan")
val username: String,

@Schema(description = "문제 제목", nullable = false, example = "아기 상어")
val title: String,

@Schema(description = "문제 난이도", nullable = false, example = "Gold V")
val rank: String
)


fun Problem.toProblemDto() = ProblemDto(solvedDate, commitUrl, user.name, title, problemRank)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package knu.dong.onedayonebaek.repository

import knu.dong.onedayonebaek.domain.Problem
import knu.dong.onedayonebaek.domain.User
import org.springframework.data.jpa.repository.JpaRepository
import java.time.LocalDate


interface ProblemRepository: JpaRepository<Problem, Long> {
fun findAllBySolvedDateBetweenAndUser(start: LocalDate, end: LocalDate, user: User): List<Problem>
fun findAllBySolvedDateAndUser(date: LocalDate, user: User): List<Problem>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package knu.dong.onedayonebaek.service

import io.github.oshai.kotlinlogging.KotlinLogging
import knu.dong.onedayonebaek.domain.User
import knu.dong.onedayonebaek.dto.CommitInfo
import knu.dong.onedayonebaek.dto.toCommitInfo
import knu.dong.onedayonebaek.repository.CommitRepository
import knu.dong.onedayonebaek.dto.ProblemDto
import knu.dong.onedayonebaek.dto.toProblemDto
import knu.dong.onedayonebaek.repository.ProblemRepository
import knu.dong.onedayonebaek.repository.UserRepository
import org.springframework.stereotype.Service
import java.time.LocalDate
Expand All @@ -14,27 +14,27 @@ import java.util.stream.Collectors
private val myLogger = KotlinLogging.logger {}

@Service
class CommitService(
private val commitRepository: CommitRepository,
class ProblemService(
private val problemRepository: ProblemRepository,
private val userRepository: UserRepository
) {

fun getCommits(user: User, yearMonth: YearMonth): List<CommitInfo> {
fun getProblems(user: User, yearMonth: YearMonth): List<ProblemDto> {
val start = yearMonth.atDay(1)
val end = yearMonth.atEndOfMonth()

return commitRepository
.findAllByCommitDateBetweenAndUser(start, end, user)
return problemRepository
.findAllBySolvedDateBetweenAndUser(start, end, user)
.stream()
.map { it.toCommitInfo() }
.map { it.toProblemDto() }
.collect(Collectors.toList())
}

fun getCommits(user: User, date: LocalDate): List<CommitInfo> {
return commitRepository
.findAllByCommitDateAndUser(date, user)
fun getProblems(user: User, date: LocalDate): List<ProblemDto> {
return problemRepository
.findAllBySolvedDateAndUser(date, user)
.stream()
.map { it.toCommitInfo() }
.map { it.toProblemDto() }
.collect(Collectors.toList())
}
}

0 comments on commit 1932a13

Please sign in to comment.