Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert 한 코드를 다시 되돌림 #47

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ dependencies {

/* websocket */
implementation("org.springframework.boot:spring-boot-starter-websocket")

/* actuator */
implementation("org.springframework.boot:spring-boot-starter-actuator")
}

tasks.withType<KotlinCompile> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package team.themoment.gsmNetworking.domain.mentor.controller

import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.DeleteMapping
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.RestController
import team.themoment.gsmNetworking.domain.mentor.dto.SearchTempMentorInfoDto
import team.themoment.gsmNetworking.domain.mentor.dto.TempMentorInfoDto
import team.themoment.gsmNetworking.domain.mentor.service.DeleteTempMentorService
import team.themoment.gsmNetworking.domain.mentor.service.QueryTempMentorListService
import team.themoment.gsmNetworking.domain.mentor.service.SearchTempMentorListService

@RestController
@RequestMapping("/api/v1/temp-mentor")
class TempMentorController (
class TempMentorController(
private val queryTempMentorListService: QueryTempMentorListService,
private val searchTempMentorListService: SearchTempMentorListService
private val searchTempMentorListService: SearchTempMentorListService,
private val deleteTempMentorService: DeleteTempMentorService
) {

@GetMapping
Expand All @@ -24,9 +28,15 @@ class TempMentorController (
}

@GetMapping("/{name}")
fun searchTempMentorListByName(@PathVariable name: String): ResponseEntity<List<SearchTempMentorInfoDto>>{
fun searchTempMentorListByName(@PathVariable name: String): ResponseEntity<List<SearchTempMentorInfoDto>> {
val searchTempMentorList = searchTempMentorListService.execute(name)
return ResponseEntity.ok(searchTempMentorList)
}

@DeleteMapping("/{firebaseId}")
fun deleteTempMentor(@PathVariable firebaseId: String): ResponseEntity<Void> {
deleteTempMentorService.execute(firebaseId)
return ResponseEntity.status(HttpStatus.RESET_CONTENT).build()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Career(
@Column(nullable = false)
val companyName: String,

@Column(nullable = false)
@Column(nullable = true)
val companyUrl: String,

@Column(nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package team.themoment.gsmNetworking.domain.mentor.domain

import org.hibernate.annotations.SQLDelete
import org.hibernate.annotations.Where
import javax.persistence.*

@Entity
@Table(name = "temp_mentor")
@Where(clause = "deleted = false")
class TempMentor(
@Id
@Column(name = "real_id")
Expand Down Expand Up @@ -31,5 +34,8 @@ class TempMentor(
val companyName: String,

@Column(nullable = false, name = "position")
val position: String
val position: String,

@Column(nullable = false, name = "deleted")
var deleted: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty

data class TempMentorInfoDto(
var id: Long,
val firebaseId: String,
val name: String,
val email: String,
val generation: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package team.themoment.gsmNetworking.domain.mentor.repository
import org.springframework.data.repository.CrudRepository
import team.themoment.gsmNetworking.domain.mentor.domain.TempMentor

interface TempMentorRepository : CrudRepository<TempMentor, Int> {
interface TempMentorRepository : CrudRepository<TempMentor, Long> {

fun findByNameContaining(name: String): List<TempMentor>

fun findByFirebaseId(firebaseId: String): TempMentor?

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package team.themoment.gsmNetworking.domain.mentor.service

import org.springframework.http.HttpStatus
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import team.themoment.gsmNetworking.common.exception.ExpectedException
import team.themoment.gsmNetworking.domain.mentor.repository.TempMentorRepository

@Service
@Transactional(rollbackFor = [Exception::class])
class DeleteTempMentorService(
private val tempMentorRepository: TempMentorRepository
) {

fun execute(firebaseId: String) {
val tempMentor = tempMentorRepository.findByFirebaseId(firebaseId)
?: throw ExpectedException("존재하지 않은 firebaseId : $firebaseId 입니다.", HttpStatus.NOT_FOUND)
tempMentor.deleted = true
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ class QueryAllMentorsListService(
*
* @return 모든 멘토 정보가 담긴 dto 리스트
*/
fun execute(): List<MentorInfoDto> = listOf(
mentorRepository.findAllMentorInfoDto(),
queryTempMentorListService.execute().map(TempMentorInfoDto::toMentorInfoDto)
).flatten().let(this::increaseMentorInfoCount)
fun execute(): List<MentorInfoDto> {
val allMentors = (
mentorRepository.findAllMentorInfoDto() +
queryTempMentorListService.execute().map(TempMentorInfoDto::toMentorInfoDto)
).distinctBy { Pair(it.generation, it.name) }

private fun increaseMentorInfoCount(allMentors: List<MentorInfoDto>): List<MentorInfoDto> {
var newId = 1L
increaseMentorIdCount(allMentors)

return allMentors
}

private fun increaseMentorIdCount(allMentors: List<MentorInfoDto>): List<MentorInfoDto> {
val newId = 1L
allMentors.forEach { mentorInfo ->
mentorInfo.id = newId++
mentorInfo.id = newId.inc()
}

return allMentors
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class QueryTempMentorListService(
val tempMentors = tempMentorRepository.findAll().map { tempMentor ->
TempMentorInfoDto(
tempMentor.id,
tempMentor.firebaseId,
tempMentor.name,
tempMentor.email ?: "",
tempMentor.generation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SecurityConfig(
http.authorizeHttpRequests()
// /mentor
.mvcMatchers("/api/v1/mentor/*").hasAnyRole(
Authority.USER.name,
Authority.USER.name
)
.mvcMatchers(HttpMethod.GET, "/api/v1/mentor").hasAnyRole(
Authority.TEMP_USER.name,
Expand All @@ -64,6 +64,13 @@ class SecurityConfig(
.mvcMatchers(HttpMethod.POST, "/api/v1/mentor").hasAnyRole(
Authority.TEMP_USER.name
)
// /tempMentor
.mvcMatchers(HttpMethod.GET, "/api/v1/temp-mentor/**").hasAnyRole(
Authority.TEMP_USER.name
)
.mvcMatchers(HttpMethod.DELETE, "/api/v1/temp-mentor/*").hasAnyRole(
Authority.USER.name
)
// /mentee
.mvcMatchers("/api/v1/mentee/*").hasAnyRole(
Authority.USER.name,
Expand Down
19 changes: 19 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,22 @@ oauth2:
success:
sign-up-redirect-url: http://localhost:8080/signup
default-redirect-url: http://localhost:8080/

management:
endpoints:
enabled-by-default: false
web:
base-path: ${ACTUATOR_BASE_PATH}
exposure:
include: health
endpoint:
health:
enabled: true
show-details: always
health:
diskspace:
enabled: false
ping:
enabled: false
server:
port: ${ACTUATOR_SERVER_PORT}
19 changes: 19 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,22 @@ oauth2:
success:
sign-up-redirect-url: ${OAUTH2_SIGN_UP_REDIRECT_URI}
default-redirect-url: ${OAUTH2_DEFAULT_SUCCESS_REDIRECT_URI}

management:
endpoints:
enabled-by-default: false
web:
base-path: ${ACTUATOR_BASE_PATH}
exposure:
include: health
endpoint:
health:
enabled: true
show-details: always
health:
diskspace:
enabled: false
ping:
enabled: false
server:
port: ${ACTUATOR_SERVER_PORT}