-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/com/yourssu/soongpt/domain/rating/application/RatingController.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,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) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/yourssu/soongpt/domain/rating/application/dto/RatingCreatedRequest.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,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, | ||
) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/com/yourssu/soongpt/domain/rating/application/dto/RatingFoundRequest.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,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, | ||
) | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/yourssu/soongpt/domain/rating/business/RatingCreatedCommand.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,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, | ||
) | ||
} | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/com/yourssu/soongpt/domain/rating/business/RatingFoundCommand.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,6 @@ | ||
package com.yourssu.soongpt.domain.rating.business | ||
|
||
class RatingFoundCommand( | ||
val course: String, | ||
val professor: String, | ||
) |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/yourssu/soongpt/domain/rating/business/RatingService.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,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) | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/com/yourssu/soongpt/domain/rating/implement/RatingWriter.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,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) | ||
} | ||
} |