Skip to content

Commit

Permalink
feat: 평점 저장, 조회 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
DWL21 committed Feb 4, 2025
1 parent f8112cc commit 71812e1
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.yourssu.soongpt.domain.rating.application

import com.yourssu.soongpt.common.business.dto.Response
import com.yourssu.soongpt.domain.rating.application.dto.RatingCreatedRequest
import com.yourssu.soongpt.domain.rating.application.dto.RatingFoundRequest
import com.yourssu.soongpt.domain.rating.business.RatingService
import com.yourssu.soongpt.domain.rating.business.dto.RatingResponse
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/api/ratings")
class RatingController(
private val ratingService: RatingService,
) {
@PostMapping
fun save(request: RatingCreatedRequest): Response<RatingResponse> {
val response = ratingService.save(request.toCommand())
return Response(result = response)
}

@GetMapping
fun findBy(request: RatingFoundRequest): Response<RatingResponse> {
val response = ratingService.findBy(request.toCommand())
return Response(result = response)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.yourssu.soongpt.domain.rating.application.dto

import com.yourssu.soongpt.domain.rating.business.RatingCreatedCommand

data class RatingCreatedRequest(
val course: String,
val professor: String,
val courseCode: String,
val star: Int,
) {
fun toCommand(): RatingCreatedCommand {
return RatingCreatedCommand(
course = course,
professor = professor,
courseCode = courseCode,
star = star,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.yourssu.soongpt.domain.rating.application.dto

import com.yourssu.soongpt.domain.rating.business.RatingFoundCommand

class RatingFoundRequest(
val course: String,
val professor: String,
) {
fun toCommand(): RatingFoundCommand {
return RatingFoundCommand(
course = course,
professor = professor,
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.yourssu.soongpt.domain.rating.business

import com.yourssu.soongpt.domain.rating.implement.Rating

class RatingCreatedCommand(
val course: String,
val professor: String,
val courseCode: String,
val star: Int,
) {
fun toRating(): Rating {
return Rating(
courseName = course,
professorName = professor,
courseCode = courseCode,
star = star,
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.yourssu.soongpt.domain.rating.business

class RatingFoundCommand(
val course: String,
val professor: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.yourssu.soongpt.domain.rating.business

import com.yourssu.soongpt.domain.rating.business.dto.RatingResponse
import com.yourssu.soongpt.domain.rating.implement.RatingReader
import com.yourssu.soongpt.domain.rating.implement.RatingWriter
import org.springframework.stereotype.Service

@Service
class RatingService(
private val ratingWriter: RatingWriter,
private val ratingReader: RatingReader,
) {
fun save(command: RatingCreatedCommand): RatingResponse {
val rating = ratingWriter.save(command.toRating())
return RatingResponse.from(rating)
}

fun findBy(command: RatingFoundCommand): RatingResponse {
val rating = ratingReader.findBy(courseName = command.course, professorName = command.professor)
return RatingResponse.from(rating)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.yourssu.soongpt.domain.rating.implement

import org.springframework.stereotype.Component

@Component
class RatingWriter(
private val ratingRepository: RatingRepository,
) {
fun save(rating: Rating): Rating {
return ratingRepository.save(rating)
}
}

0 comments on commit 71812e1

Please sign in to comment.