Skip to content

Commit

Permalink
Feat/back office
Browse files Browse the repository at this point in the history
Feat/back office
  • Loading branch information
MoonMinHyuk1 authored Jun 8, 2023
2 parents 7daa933 + c0cbae1 commit 26a716f
Show file tree
Hide file tree
Showing 26 changed files with 133 additions and 103 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sonarqube {
property("sonar.sources", "src")
property("sonar.sourceEncoding", "UTF-8")
property("sonar.test.inclusions", "**/*Test.kt")
property("sonar.exclusions", "**/test/**, **/resources/**, **/docs/**, **/*Application*.kt, **/global/**, **/dto/**, **/*Exception*.kt, **/*ErrorCode*.kt, **/*Category*.kt, **/admin/**, **/*RepositoryImpl.kt" )
property("sonar.exclusions", "**/test/**, **/resources/**, **/docs/**, **/*Application*.kt, **/global/**, **/dto/**, **/entity/**, **/*Exception*.kt, **/*ErrorCode*.kt, **/*Category*.kt, **/admin/**, **/*RepositoryImpl.kt" )
property("sonar.java.coveragePlugin", "jacoco")
property("sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/customJacocoReportDir/test/jacocoTestReport.xml")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.jhouse_server.domain.record.dto

import com.example.jhouse_server.domain.record.entity.Part
import com.example.jhouse_server.domain.record_comment.dto.RecordCommentResDto
import com.example.jhouse_server.domain.record_review.dto.RecordReviewResDto
import com.example.jhouse_server.domain.record_review_apply.dto.RecordReviewApplyResDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import com.example.jhouse_server.global.exception.ApplicationException
import com.example.jhouse_server.global.exception.ErrorCode

enum class Part(val value: String) {
ALL("all"),
WEB("web"),
SERVER("server"),
INFRA("infra");

companion object {
fun getPart(value: String): Part? {
fun getPart(value: String): Part {
for(part in Part.values()) {
if(part.value == value) {
if(part.value == value.lowercase()) {
return part
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.jhouse_server.domain.record.entity

import com.example.jhouse_server.global.exception.ApplicationException
import com.example.jhouse_server.global.exception.ErrorCode

enum class RecordType(val value: String) {
ALL("all"),
ODORI("odori"),
RETRO("retro"),
TECH("tech");

companion object {
fun getType(value: String): RecordType {
for(type in RecordType.values()) {
if(type.value == value.lowercase()) {
return type
}
}
throw ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.jhouse_server.domain.record.entity.odori

import com.example.jhouse_server.domain.record.entity.Part
import com.example.jhouse_server.domain.record.entity.Record
import com.example.jhouse_server.domain.record.entity.RecordStatus
import com.example.jhouse_server.domain.user.entity.User
import javax.persistence.DiscriminatorValue
import javax.persistence.Entity
import javax.persistence.EnumType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.jhouse_server.domain.record.entity.retrospection

import com.example.jhouse_server.domain.record.entity.Part
import com.example.jhouse_server.domain.record.entity.Record
import com.example.jhouse_server.domain.record.entity.RecordStatus
import com.example.jhouse_server.domain.user.entity.User
import javax.persistence.DiscriminatorValue
import javax.persistence.Entity
import javax.persistence.EnumType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.jhouse_server.domain.record.entity.technology

import com.example.jhouse_server.domain.record.entity.Part
import com.example.jhouse_server.domain.record.entity.Record
import com.example.jhouse_server.domain.record.entity.RecordStatus
import com.example.jhouse_server.domain.user.entity.User
import javax.persistence.DiscriminatorValue
import javax.persistence.Entity
import javax.persistence.EnumType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.example.jhouse_server.domain.record.repository

import com.example.jhouse_server.domain.record.entity.Record
import com.example.jhouse_server.domain.record.repository.odori.OdoriRepositoryCustom
import com.example.jhouse_server.domain.record.repository.retrospection.RetrospectionRepositoryCustom
import com.example.jhouse_server.domain.record.repository.technology.TechnologyRepositoryCustom
import org.springframework.data.jpa.repository.EntityGraph
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package com.example.jhouse_server.domain.record.repository.common

import com.example.jhouse_server.domain.record.entity.Part
import com.example.jhouse_server.domain.record.entity.QRecord
import com.example.jhouse_server.domain.record.entity.QRecord.record
import com.example.jhouse_server.domain.record.entity.RecordType
import com.example.jhouse_server.domain.record.entity.odori.OdoriCategory
import com.example.jhouse_server.domain.record.entity.odori.QOdori
import com.example.jhouse_server.domain.record.entity.odori.QOdori.odori
import com.example.jhouse_server.domain.record.entity.retrospection.QRetrospection
import com.example.jhouse_server.domain.record.entity.retrospection.QRetrospection.retrospection
import com.example.jhouse_server.domain.record.entity.retrospection.RetrospectionCategory
import com.example.jhouse_server.domain.record.entity.technology.QTechnology
import com.example.jhouse_server.domain.record.entity.technology.QTechnology.technology
import com.example.jhouse_server.domain.record.entity.technology.TechnologyCategory
import com.example.jhouse_server.global.exception.ApplicationException
import com.example.jhouse_server.global.exception.ErrorCode
import com.querydsl.core.types.dsl.BooleanExpression
import com.querydsl.jpa.impl.JPAQuery
import org.springframework.data.domain.Page
Expand All @@ -29,52 +24,47 @@ class RecordCommonMethod {
}

fun recordPartEq(part: String): BooleanExpression? {
return when (part) {
"all" -> null
"web" -> record.part.eq(Part.WEB)
"server" -> record.part.eq(Part.SERVER)
"infra" -> record.part.eq(Part.INFRA)
else -> throw ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)
return when (Part.getPart(part)) {
Part.ALL -> null
Part.WEB -> record.part.eq(Part.WEB)
Part.SERVER -> record.part.eq(Part.SERVER)
Part.INFRA -> record.part.eq(Part.INFRA)
}
}

fun odoriPartEq(part: String): BooleanExpression? {
return when (part) {
"all" -> null
"web" -> odori.part.eq(Part.WEB)
"server" -> odori.part.eq(Part.SERVER)
"infra" -> odori.part.eq(Part.INFRA)
else -> throw ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)
return when (Part.getPart(part)) {
Part.ALL -> null
Part.WEB -> odori.part.eq(Part.WEB)
Part.SERVER -> odori.part.eq(Part.SERVER)
Part.INFRA -> odori.part.eq(Part.INFRA)
}
}

fun retroPartEq(part: String): BooleanExpression? {
return when (part) {
"all" -> null
"web" -> retrospection.part.eq(Part.WEB)
"server" -> retrospection.part.eq(Part.SERVER)
"infra" -> retrospection.part.eq(Part.INFRA)
else -> throw ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)
return when (Part.getPart(part)) {
Part.ALL -> null
Part.WEB -> retrospection.part.eq(Part.WEB)
Part.SERVER -> retrospection.part.eq(Part.SERVER)
Part.INFRA -> retrospection.part.eq(Part.INFRA)
}
}

fun techPartEq(part: String): BooleanExpression? {
return when (part) {
"all" -> null
"web" -> technology.part.eq(Part.WEB)
"server" -> technology.part.eq(Part.SERVER)
"infra" -> technology.part.eq(Part.INFRA)
else -> throw ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)
return when (Part.getPart(part)) {
Part.ALL -> null
Part.WEB -> technology.part.eq(Part.WEB)
Part.SERVER -> technology.part.eq(Part.SERVER)
Part.INFRA -> technology.part.eq(Part.INFRA)
}
}

fun categoryEq(type: String, category: String): BooleanExpression? {
return when (type) {
"all" -> null
"odori" -> odori.category.eq(OdoriCategory.getCategoryByEnum(category))
"retro" -> retrospection.category.eq(RetrospectionCategory.getCategoryByEnum(category))
"tech" -> technology.category.eq(TechnologyCategory.getCategoryByEnum(category))
else -> throw ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)
return when (RecordType.getType(type)) {
RecordType.ALL -> null
RecordType.ODORI -> odori.category.eq(OdoriCategory.getCategoryByEnum(category))
RecordType.RETRO -> retrospection.category.eq(RetrospectionCategory.getCategoryByEnum(category))
RecordType.TECH -> technology.category.eq(TechnologyCategory.getCategoryByEnum(category))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.example.jhouse_server.domain.record.dto.*
import com.example.jhouse_server.domain.record.entity.Record
import com.example.jhouse_server.domain.user.entity.User
import org.springframework.data.domain.Pageable
import javax.servlet.http.HttpServletRequest

interface RecordService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.example.jhouse_server.domain.record.dto.*
import com.example.jhouse_server.domain.record.entity.Part
import com.example.jhouse_server.domain.record.entity.Record
import com.example.jhouse_server.domain.record.entity.RecordStatus
import com.example.jhouse_server.domain.record.entity.RecordType
import com.example.jhouse_server.domain.record.entity.odori.Odori
import com.example.jhouse_server.domain.record.entity.odori.OdoriCategory
import com.example.jhouse_server.domain.record.entity.retrospection.Retrospection
Expand Down Expand Up @@ -81,24 +82,23 @@ class RecordServiceImpl(
}

override fun getRecords(condition: RecordPageCondition, pageable: Pageable): RecordPageResDto {
return when (condition.type) {
"all" -> {
return when (RecordType.getType(condition.type)) {
RecordType.ALL -> {
val records = recordRepository.findRecords(condition, pageable)
RecordPageResDto(records)
}
"odori" -> {
RecordType.ODORI -> {
val records = odoriRepository.findOdoris(condition, pageable)
RecordPageResDto(records)
}
"retro" -> {
RecordType.RETRO -> {
val records = retrospectionRepository.findRetrospections(condition, pageable)
RecordPageResDto(records)
}
"tech" -> {
RecordType.TECH -> {
val records = technologyRepository.findTechnologies(condition, pageable)
RecordPageResDto(records)
}
else -> throw ApplicationException(NOT_FOUND_EXCEPTION)
}
}

Expand All @@ -112,17 +112,17 @@ class RecordServiceImpl(
"O" -> {
val odori = record as Odori
RecordResDto(odori.id, odori.title!!, odori.content!!, odori.hits, odori.part!!.value,
"odori", odori.category.toString().lowercase(), odori.user!!.nickName, odori.createdAt, comments)
RecordType.ODORI.value, odori.category.toString().lowercase(), odori.user!!.nickName, odori.createdAt, comments)
}
"R" -> {
val retro = record as Retrospection
RecordResDto(retro.id, retro.title!!, retro.content!!, retro.hits, retro.part!!.value,
"retro", retro.category.toString().lowercase(), retro.user!!.nickName, retro.createdAt, comments)
RecordType.RETRO.value, retro.category.toString().lowercase(), retro.user!!.nickName, retro.createdAt, comments)
}
"T" -> {
val tech = record as Technology
RecordResDto(tech.id, tech.title!!, tech.content!!, tech.hits, tech.part!!.value,
"tech", tech.category.toString().lowercase(), tech.user!!.nickName, tech.createdAt, comments)
RecordType.TECH.value, tech.category.toString().lowercase(), tech.user!!.nickName, tech.createdAt, comments)
}
else -> throw ApplicationException(NOT_FOUND_EXCEPTION)
}
Expand Down Expand Up @@ -173,10 +173,10 @@ class RecordServiceImpl(
}

private fun matchType(record: Record, category: String, type: String): Record {
return when (type) {
"odori" -> Odori(OdoriCategory.getCategoryByEnum(category)!!, record)
"retro" -> Retrospection(RetrospectionCategory.getCategoryByEnum(category)!!, record)
"tech" -> Technology(TechnologyCategory.getCategoryByEnum(category)!!, record)
return when (RecordType.getType(type)) {
RecordType.ODORI -> Odori(OdoriCategory.getCategoryByEnum(category)!!, record)
RecordType.RETRO -> Retrospection(RetrospectionCategory.getCategoryByEnum(category)!!, record)
RecordType.TECH -> Technology(TechnologyCategory.getCategoryByEnum(category)!!, record)
else -> throw ApplicationException(NOT_FOUND_EXCEPTION)
}
}
Expand All @@ -189,7 +189,7 @@ class RecordServiceImpl(

private fun applyForReview(record: Record, user: User) {
recordReviewApplyRepository.save(RecordReviewApply(RecordReviewApplyStatus.MINE, record, user))
val reviewers = userRepository.findAllByAdminType(user.id, user.adminType!!)
val reviewers = userRepository.findAllByUserType(user.id, user.userType!!)
reviewers.forEach {
val recordReviewApply = RecordReviewApply(RecordReviewApplyStatus.WAIT, record, it)
recordReviewApplyRepository.save(recordReviewApply)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.fasterxml.jackson.annotation.JsonProperty
import com.querydsl.core.annotations.QueryProjection
import java.time.LocalDateTime
import javax.validation.constraints.NotBlank
import javax.validation.constraints.NotNull

data class RecordCommentReqDto(
@JsonProperty("record_id")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.example.jhouse_server.domain.record_comment.repository
import com.example.jhouse_server.domain.record.entity.Record
import com.example.jhouse_server.domain.record_comment.entity.RecordComment
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class RecordCommentServiceImpl(
val record = recordRepository.findByIdOrThrow(recordCommentReqDto.recordId)
var parent: RecordComment? = null
val refCount = recordCommentRepository.findNextRef(record)
var ref: Long = if(refCount == null) 1 else (refCount + 1).toLong()
var ref: Long = (refCount + 1).toLong()
var step: Long = 1
var level: Long = 1
var allChildrenSize: Long = 0
val allChildrenSize: Long = 0
if(recordCommentReqDto.parentId != null) {
parent = recordCommentRepository.findByIdOrThrow(recordCommentReqDto.parentId)

Expand All @@ -43,7 +43,9 @@ class RecordCommentServiceImpl(
updateAllChildrenSize(parent)
updateStep(comments, step)
}
return recordCommentRepository.save(RecordComment(recordCommentReqDto.content, record, user, ref, step, level, allChildrenSize, parent)).id
return recordCommentRepository.save(
RecordComment(recordCommentReqDto.content, record, user, ref, step, level, allChildrenSize, parent)
).id
}

@Transactional
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class User(
val id : Long = 0L,
): BaseEntity() {
@Enumerated(EnumType.STRING)
var adminType: AdminType? = null
var userType: UserType? = null

fun update(phoneNum: String) {
this.phoneNum = phoneNum
Expand All @@ -76,8 +76,8 @@ class User(
this.authority = authority
}

fun updateAdminType(adminType: AdminType) {
this.adminType = adminType
fun updateUserType(userType: UserType) {
this.userType = userType
}

fun withdrawalUser() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.jhouse_server.domain.user.entity

enum class UserType(val authority: Authority) {
WEB(Authority.ADMIN),
SERVER(Authority.ADMIN);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.jhouse_server.domain.user.repository

import com.example.jhouse_server.domain.user.entity.AdminType
import com.example.jhouse_server.domain.user.entity.UserType
import com.example.jhouse_server.domain.user.entity.Authority
import com.example.jhouse_server.domain.user.entity.User
import org.springframework.data.jpa.repository.JpaRepository
Expand All @@ -20,6 +20,6 @@ interface UserRepository: JpaRepository<User, Long> , UserRepositoryCustom{

fun findByEmailAndAuthority(email: String, authority: Authority) : Optional<User>

@Query("select u from User u where u.adminType = :adminType and u.id <> :userId")
fun findAllByAdminType(@Param("userId") userId: Long, @Param("adminType") adminType: AdminType): List<User>
@Query("select u from User u where u.userType = :userType and u.id <> :userId")
fun findAllByUserType(@Param("userId") userId: Long, @Param("userType") userType: UserType): List<User>
}
Loading

0 comments on commit 26a716f

Please sign in to comment.