-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
language + information
- Loading branch information
Showing
22 changed files
with
312 additions
and
6 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
grow-api/src/main/kotlin/com/molohala/grow/api/language/LanguageController.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,25 @@ | ||
package com.molohala.grow.api.language | ||
|
||
import com.molohala.grow.api.response.Response | ||
import com.molohala.grow.api.response.ResponseData | ||
import com.molohala.grow.core.language.application.dto.req.EditLanguageReq | ||
import com.molohala.grow.core.language.application.service.LanguageService | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@RestController | ||
@RequestMapping("/language") | ||
class LanguageController( | ||
private val languageService: LanguageService | ||
) { | ||
@GetMapping | ||
fun getAll() = ResponseData.ok("언어 리스트 조회 완료", languageService.getAvailableLanguage()) | ||
|
||
@GetMapping("/me") | ||
fun languages() = ResponseData.ok("사용하는 언어 조회 완료", languageService.getUsingLanguages()) | ||
|
||
@PatchMapping("/me") | ||
fun editLanguage(@RequestBody data: EditLanguageReq): Response { | ||
languageService.updateUsingLanguages(data.langs) | ||
return Response.ok("사용하는 언어 갱신 완료") | ||
} | ||
} |
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
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
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
6 changes: 6 additions & 0 deletions
6
grow-core/src/main/kotlin/com/molohala/grow/core/info/application/dto/req/EditUserInfoReq.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.molohala.grow.core.info.application.dto.req | ||
|
||
data class EditUserInfoReq( | ||
val bio: String?, | ||
val job: String? | ||
) |
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
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
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
7 changes: 7 additions & 0 deletions
7
...re/src/main/kotlin/com/molohala/grow/core/language/application/dto/req/EditLanguageReq.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,7 @@ | ||
package com.molohala.grow.core.language.application.dto.req | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator | ||
|
||
data class EditLanguageReq @JsonCreator constructor( | ||
val langs: List<Long> | ||
) |
43 changes: 43 additions & 0 deletions
43
...core/src/main/kotlin/com/molohala/grow/core/language/application/runner/LanguageLoader.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,43 @@ | ||
package com.molohala.grow.core.language.application.runner | ||
|
||
import com.molohala.grow.core.language.domain.entity.Language | ||
import com.molohala.grow.core.language.repository.LanguageJpaRepository | ||
import org.springframework.boot.ApplicationArguments | ||
import org.springframework.boot.ApplicationRunner | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class LanguageLoader( | ||
private val languageJpaRepository: LanguageJpaRepository | ||
) : ApplicationRunner { | ||
override fun run(args: ApplicationArguments?) { | ||
val languages = languageJpaRepository.findAll() | ||
val m = listOf( | ||
"Python", | ||
"HTML", | ||
"CSS", | ||
"JavaScript", | ||
"TypeScript", | ||
"C", | ||
"C++", | ||
"C#", | ||
"Kotlin", | ||
"Java", | ||
"Swift", | ||
"Dart", | ||
"Go", | ||
"Ruby", | ||
"Rust", | ||
"SQL", | ||
"PHP", | ||
"Scala", | ||
"Lua", | ||
) | ||
val addLang = ArrayList<Language>() | ||
|
||
for (s in m) if (languages.none { it.name.lowercase() == s.lowercase() }) addLang.add(Language(s)) | ||
|
||
languageJpaRepository.saveAll(addLang) | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...re/src/main/kotlin/com/molohala/grow/core/language/application/service/LanguageService.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,9 @@ | ||
package com.molohala.grow.core.language.application.service | ||
|
||
import com.molohala.grow.core.language.domain.entity.Language | ||
|
||
interface LanguageService { | ||
fun updateUsingLanguages(langs: List<Long>) | ||
fun getUsingLanguages(): List<Language> | ||
fun getAvailableLanguage(): List<Language> | ||
} |
52 changes: 52 additions & 0 deletions
52
...rc/main/kotlin/com/molohala/grow/core/language/application/service/LanguageServiceImpl.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,52 @@ | ||
package com.molohala.grow.core.language.application.service | ||
|
||
import com.molohala.grow.common.exception.custom.CustomException | ||
import com.molohala.grow.core.language.domain.entity.Language | ||
import com.molohala.grow.core.language.domain.entity.MemberAndLanguage | ||
import com.molohala.grow.core.language.exception.LanguageExceptionCode | ||
import com.molohala.grow.core.language.repository.LanguageJpaRepository | ||
import com.molohala.grow.core.language.repository.MemberLanguageJpaRepository | ||
import com.molohala.grow.core.language.repository.MemberLanguageQueryRepository | ||
import com.molohala.grow.core.member.application.MemberSessionHolder | ||
import jakarta.transaction.Transactional | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class LanguageServiceImpl( | ||
private val memberSessionHolder: MemberSessionHolder, | ||
private val languageJpaRepository: LanguageJpaRepository, | ||
private val memberLanguageJpaRepository: MemberLanguageJpaRepository, | ||
private val memberLanguageQueryRepository: MemberLanguageQueryRepository | ||
) : LanguageService { | ||
@Transactional(rollbackOn = [Exception::class]) | ||
override fun updateUsingLanguages(langs: List<Long>) { | ||
val member = memberSessionHolder.current() | ||
val dbLang = languageJpaRepository.findAll() | ||
|
||
val owning = | ||
memberLanguageJpaRepository | ||
.findAllByMemberIdIs(member.id!!) | ||
|
||
memberLanguageJpaRepository.deleteAllInBatch(owning.filter { it.languageId !in langs }) | ||
|
||
val toAdd = ArrayList<Language>() | ||
|
||
for (lang in langs) { | ||
val ent = dbLang.find { it.id == lang } | ||
if (ent == null) | ||
throw CustomException(LanguageExceptionCode.LANGUAGE_NOT_FOUND) | ||
if (owning.none { it.languageId == lang }) toAdd.add(ent) // not owning | ||
} | ||
|
||
memberLanguageJpaRepository.saveAllAndFlush( | ||
toAdd.map { MemberAndLanguage(member.id, it.id!!) } | ||
) | ||
} | ||
|
||
override fun getUsingLanguages(): List<Language> { | ||
val member = memberSessionHolder.current() | ||
return memberLanguageQueryRepository.getLanguagesByMemberId(member.id!!) | ||
} | ||
|
||
override fun getAvailableLanguage(): List<Language> = languageJpaRepository.findAll() | ||
} |
12 changes: 12 additions & 0 deletions
12
grow-core/src/main/kotlin/com/molohala/grow/core/language/domain/entity/Language.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.molohala.grow.core.language.domain.entity | ||
|
||
import jakarta.persistence.* | ||
|
||
@Entity(name = "tbl_langs") | ||
data class Language( | ||
val name: String, | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(updatable = false, nullable = false, name = "id") | ||
val id: Long? = null | ||
) |
22 changes: 22 additions & 0 deletions
22
grow-core/src/main/kotlin/com/molohala/grow/core/language/domain/entity/MemberAndLanguage.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,22 @@ | ||
package com.molohala.grow.core.language.domain.entity | ||
|
||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
|
||
@Entity(name = "tbl_many_member_language") | ||
class MemberAndLanguage( | ||
val memberId: Long, | ||
val languageId: Long, | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column( | ||
name = "id", | ||
nullable = false, | ||
updatable = false | ||
) | ||
val id: Long? = null, | ||
) |
13 changes: 13 additions & 0 deletions
13
grow-core/src/main/kotlin/com/molohala/grow/core/language/exception/LanguageExceptionCode.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,13 @@ | ||
package com.molohala.grow.core.language.exception | ||
|
||
import com.molohala.grow.common.exception.ExceptionCode | ||
import org.springframework.http.HttpStatus | ||
|
||
enum class LanguageExceptionCode(private val status: HttpStatus, private val message: String) : ExceptionCode { | ||
LANGUAGE_NOT_FOUND(HttpStatus.BAD_REQUEST, "해당하는 언어를 찾을 수 없음"), | ||
; | ||
|
||
override fun getHttpStatus() = status | ||
override fun getExceptionName() = name | ||
override fun getMessage() = message | ||
} |
6 changes: 6 additions & 0 deletions
6
...-core/src/main/kotlin/com/molohala/grow/core/language/repository/LanguageJpaRepository.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.molohala.grow.core.language.repository | ||
|
||
import com.molohala.grow.core.language.domain.entity.Language | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface LanguageJpaRepository : JpaRepository<Language, Long> |
8 changes: 8 additions & 0 deletions
8
...src/main/kotlin/com/molohala/grow/core/language/repository/MemberLanguageJpaRepository.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,8 @@ | ||
package com.molohala.grow.core.language.repository | ||
|
||
import com.molohala.grow.core.language.domain.entity.MemberAndLanguage | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface MemberLanguageJpaRepository : JpaRepository<MemberAndLanguage, Long> { | ||
fun findAllByMemberIdIs(memberId: Long): List<MemberAndLanguage> | ||
} |
29 changes: 29 additions & 0 deletions
29
...ain/kotlin/com/molohala/grow/core/language/repository/MemberLanguageQueryDslRepository.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.molohala.grow.core.language.repository | ||
|
||
import com.molohala.grow.core.language.domain.entity.Language | ||
import com.molohala.grow.core.language.domain.entity.QLanguage.language | ||
import com.molohala.grow.core.language.domain.entity.QMemberAndLanguage.memberAndLanguage | ||
import com.querydsl.core.types.Projections | ||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class MemberLanguageQueryDslRepository( | ||
private val queryFactory: JPAQueryFactory | ||
) : MemberLanguageQueryRepository { | ||
override fun getLanguagesByMemberId(memberId: Long): List<Language> { | ||
return queryFactory | ||
.select( | ||
Projections.constructor( | ||
Language::class.java, | ||
language.name, | ||
language.id | ||
) | ||
) | ||
.from(memberAndLanguage) | ||
.where(memberAndLanguage.memberId.eq(memberId)) | ||
.innerJoin(language) | ||
.on(memberAndLanguage.languageId.eq(language.id)) | ||
.fetch() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...c/main/kotlin/com/molohala/grow/core/language/repository/MemberLanguageQueryRepository.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,7 @@ | ||
package com.molohala.grow.core.language.repository | ||
|
||
import com.molohala.grow.core.language.domain.entity.Language | ||
|
||
interface MemberLanguageQueryRepository { | ||
fun getLanguagesByMemberId(memberId: Long): List<Language> | ||
} |
Oops, something went wrong.