-
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.
Merge pull request #105 from Sexy-Sisters/feat/teacher
Feat/teacher
- Loading branch information
Showing
31 changed files
with
367 additions
and
109 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
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
14 changes: 0 additions & 14 deletions
14
src/main/kotlin/com/sexysisters/tojserverv2/domain/teacher/TeacherEntityMapper.kt
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/sexysisters/tojserverv2/domain/teacher/TeacherReader.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,10 @@ | ||
package com.sexysisters.tojserverv2.domain.teacher | ||
|
||
import com.sexysisters.tojserverv2.domain.school.domain.School | ||
import com.sexysisters.tojserverv2.domain.teacher.domain.Teacher | ||
|
||
interface TeacherReader { | ||
fun search(schoolCode: String): List<Teacher> | ||
fun getTeacher(id: Long): Teacher | ||
fun getTeacher(id: Long, school: School): Teacher | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/sexysisters/tojserverv2/domain/teacher/TeacherResponseMapper.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,10 @@ | ||
package com.sexysisters.tojserverv2.domain.teacher | ||
|
||
import org.mapstruct.* | ||
|
||
@Mapper( | ||
componentModel = "spring", | ||
injectionStrategy = InjectionStrategy.CONSTRUCTOR, | ||
unmappedTargetPolicy = ReportingPolicy.ERROR, | ||
) | ||
interface TeacherResponseMapper |
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
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
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: 6 additions & 1 deletion
7
src/main/kotlin/com/sexysisters/tojserverv2/domain/teacher/service/TeacherService.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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package com.sexysisters.tojserverv2.domain.teacher.service | ||
|
||
import com.sexysisters.tojserverv2.domain.teacher.TeacherCommand | ||
import com.sexysisters.tojserverv2.interfaces.teacher.dto.TeacherResponse | ||
|
||
interface TeacherService { | ||
fun createTeacher(command: TeacherCommand.Create) | ||
fun create(command: TeacherCommand.Create) | ||
fun getTeachers(schoolCode: String): List<TeacherResponse.Main> | ||
fun getTeacher(id: Long): TeacherResponse.Main | ||
fun update(id: Long, request: TeacherCommand.Update) | ||
fun delete(id: Long) | ||
} |
55 changes: 50 additions & 5 deletions
55
src/main/kotlin/com/sexysisters/tojserverv2/domain/teacher/service/TeacherServiceImpl.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 |
---|---|---|
@@ -1,24 +1,69 @@ | ||
package com.sexysisters.tojserverv2.domain.teacher.service | ||
|
||
import com.sexysisters.tojserverv2.domain.school.exception.SchoolException | ||
import com.sexysisters.tojserverv2.domain.student.domain.Student | ||
import com.sexysisters.tojserverv2.domain.student.domain.isAttendSchool | ||
import com.sexysisters.tojserverv2.domain.student.exception.StudentException | ||
import com.sexysisters.tojserverv2.domain.teacher.* | ||
import com.sexysisters.tojserverv2.domain.teacher.domain.* | ||
import com.sexysisters.tojserverv2.domain.user.UserReader | ||
import com.sexysisters.tojserverv2.domain.user.hasStudent | ||
import com.sexysisters.tojserverv2.interfaces.teacher.dto.TeacherDtoMapper | ||
import com.sexysisters.tojserverv2.interfaces.teacher.dto.TeacherResponse | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
@Transactional | ||
class TeacherServiceImpl( | ||
private val userReader: UserReader, | ||
private val teacherStore: TeacherStore, | ||
private val teacherEntityMapper: TeacherEntityMapper, | ||
private val teacherReader: TeacherReader, | ||
private val teacherDtoMapper: TeacherDtoMapper, | ||
) : TeacherService { | ||
|
||
@Transactional | ||
override fun createTeacher(command: TeacherCommand.Create) { | ||
override fun create(command: TeacherCommand.Create) { | ||
checkStudentIdentity() | ||
val teacher = createTeacherEntity(command) | ||
teacherStore.store(teacher) | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
override fun getTeachers(schoolCode: String): List<TeacherResponse.Main> { | ||
val teachers = teacherReader.search(schoolCode) | ||
return teachers.map { teacherDtoMapper.of(it) } | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
override fun getTeacher(id: Long): TeacherResponse.Main { | ||
val teacher = teacherReader.getTeacher(id) | ||
return teacherDtoMapper.of(teacher) | ||
} | ||
|
||
override fun update(id: Long, request: TeacherCommand.Update) { | ||
val student = checkStudentIdentity() | ||
if (!student.isAttendSchool()) throw SchoolException.SchoolNotFound() | ||
val teacher = teacherReader.getTeacher(id, student.school!!) | ||
teacher.update(request.image, request.name, request.nickname, request.bio) | ||
} | ||
|
||
override fun delete(id: Long) { | ||
val student = checkStudentIdentity() | ||
if (!student.isAttendSchool()) throw SchoolException.SchoolNotFound() | ||
val teacher = teacherReader.getTeacher(id, student.school!!) | ||
teacherStore.delete(teacher) | ||
} | ||
|
||
private fun createTeacherEntity(command: TeacherCommand.Create) = Teacher( | ||
Image(command.image), | ||
Name(command.name), | ||
Nickname(command.nickname), | ||
Bio(command.bio), | ||
) | ||
|
||
private fun checkStudentIdentity(): Student { | ||
val user = userReader.getCurrentUser() | ||
if (!user.hasStudent()) throw StudentException.StudentNotFound() | ||
val teacher = teacherEntityMapper.of(command) | ||
teacherStore.store(teacher) | ||
return user.student!! | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Email.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.sexysisters.tojserverv2.domain.user | ||
|
||
import com.sexysisters.tojserverv2.domain.user.exception.UserException | ||
import javax.persistence.Column | ||
import javax.persistence.Embeddable | ||
import javax.validation.constraints.NotNull | ||
|
||
@Embeddable | ||
class Email( | ||
@field:NotNull | ||
@Column(name = "email") | ||
private val value: String, | ||
) { | ||
init { | ||
val EMAIL_FORMAT = "@" | ||
if (value.isBlank()) throw UserException.UserNotValid() | ||
if (!value.contains(EMAIL_FORMAT)) throw UserException.UserNotValid() | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/kotlin/com/sexysisters/tojserverv2/domain/user/Image.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,17 @@ | ||
package com.sexysisters.tojserverv2.domain.user | ||
|
||
import com.sexysisters.tojserverv2.domain.user.exception.UserException | ||
import javax.persistence.Column | ||
import javax.persistence.Embeddable | ||
import javax.validation.constraints.NotNull | ||
|
||
@Embeddable | ||
class Image( | ||
@field:NotNull | ||
@Column(name = "image") | ||
private val value: String, | ||
) { | ||
init { | ||
if (value.isBlank()) throw UserException.UserNotValid() | ||
} | ||
} |
Oops, something went wrong.