-
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
1 parent
e8498d2
commit e5909ab
Showing
10 changed files
with
206 additions
and
4 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
25 changes: 25 additions & 0 deletions
25
code/jvm/src/main/kotlin/pt/isel/ion/teams/tags/TagsController.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 pt.isel.ion.teams.tags | ||
|
||
import org.jdbi.v3.sqlobject.customizer.BindBean | ||
import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys | ||
import org.springframework.web.bind.annotation.* | ||
import pt.isel.ion.teams.common.Uris | ||
|
||
@RestController | ||
@RequestMapping(Uris.Tags.PATH) | ||
class TagsController(val tagsService: TagsService) { | ||
|
||
@GetMapping | ||
fun getAllTags(@PathVariable teamId: Int): List<TagOutputModel> = | ||
tagsService.getAllTags(teamId).map { it.toOutput() } | ||
|
||
@PostMapping | ||
@GetGeneratedKeys | ||
fun createTag(@PathVariable teamId: Int, @BindBean tag: TagInputModel) = | ||
tagsService.createTag(tag.toDb(teamId)) | ||
|
||
@PutMapping(Uris.Tags.Tag.PATH) | ||
@GetGeneratedKeys | ||
fun updateTag(@PathVariable tagId: Int,@PathVariable teamId: Int, @BindBean tag: TagUpdateModel) = | ||
tagsService.updateTag(tag.toDb(tagId,teamId)) | ||
} |
22 changes: 22 additions & 0 deletions
22
code/jvm/src/main/kotlin/pt/isel/ion/teams/tags/TagsDAO.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 pt.isel.ion.teams.tags | ||
|
||
import org.jdbi.v3.sqlobject.customizer.Bind | ||
import org.jdbi.v3.sqlobject.customizer.BindBean | ||
import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys | ||
import org.jdbi.v3.sqlobject.statement.SqlQuery | ||
import org.jdbi.v3.sqlobject.statement.SqlUpdate | ||
import pt.isel.ion.teams.organizations.OrganizationDbRead | ||
|
||
interface TagsDAO { | ||
|
||
@SqlQuery("SELECT * FROM tags WHERE teamid=:teamId") | ||
fun getAllTags(@Bind("teamId") teamId: Int): List<TagDbRead> | ||
|
||
@SqlUpdate("INSERT INTO tags (name,date,delId,teamId) VALUES (:name,:date,:delId,:teamId)") | ||
@GetGeneratedKeys | ||
fun createTag(@BindBean tag: TagDbWrite): OrganizationDbRead | ||
|
||
@SqlUpdate("UPDATE tags SET name=:name,date=:date,delId=:delId,teamId=:teamId WHERE id=:id") | ||
@GetGeneratedKeys | ||
fun updateTag(@BindBean tag: TagDbUpdate): Int | ||
} |
14 changes: 14 additions & 0 deletions
14
code/jvm/src/main/kotlin/pt/isel/ion/teams/tags/TagsService.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,14 @@ | ||
package pt.isel.ion.teams.tags | ||
|
||
import org.jdbi.v3.core.Jdbi | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class TagsService(val jdbi: Jdbi) { | ||
|
||
fun getAllTags(teamId: Int) = jdbi.onDemand(TagsDAO::class.java).getAllTags(teamId) | ||
|
||
fun createTag(tagDbWrite: TagDbWrite) = jdbi.onDemand(TagsDAO::class.java).createTag(tagDbWrite) | ||
|
||
fun updateTag(tagDbUpdate: TagDbUpdate) = jdbi.onDemand(TagsDAO::class.java).updateTag(tagDbUpdate) | ||
} |
60 changes: 60 additions & 0 deletions
60
code/jvm/src/main/kotlin/pt/isel/ion/teams/teacher/Teacher.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,60 @@ | ||
package pt.isel.ion.teams.teacher | ||
|
||
import java.util.* | ||
|
||
|
||
/** | ||
* For internal use only. | ||
*/ | ||
data class TeacherDbRead( | ||
val number: Int, | ||
val name: String, | ||
val email: String, | ||
val office: String | ||
) | ||
|
||
data class TeacherDbWrite( | ||
val number: Int, | ||
val name: String, | ||
val email: String, | ||
val office: String | ||
) | ||
|
||
data class TeacherDbUpdate( | ||
val number: Int, | ||
val name: String?, | ||
val email: String?, | ||
val office: String? | ||
) | ||
|
||
/** | ||
* For external use only. | ||
*/ | ||
|
||
data class TeacherOutputModel( | ||
val number: Int, | ||
val name: String, | ||
val email: String, | ||
val office: String | ||
) | ||
|
||
data class TeacherInputModel( | ||
val number: Int, | ||
val name: String, | ||
val email: String, | ||
val office: String | ||
) | ||
|
||
data class TeacherUpdateModel( | ||
val name: String?, | ||
val email: String?, | ||
val office: String? | ||
) | ||
|
||
/** | ||
* Functions to transition from external to internal, or vice-versa. | ||
*/ | ||
|
||
fun TeacherInputModel.toDb() = TeacherDbWrite(this.number,this.name,this.email,this.office) | ||
fun TeacherUpdateModel.toDb(number: Int) = TeacherDbUpdate(number,this.name,this.email,this.office) | ||
fun TeacherDbRead.toOutput() = TeacherOutputModel(this.number,this.name,this.email,this.office) |
15 changes: 15 additions & 0 deletions
15
code/jvm/src/main/kotlin/pt/isel/ion/teams/teacher/TeacherController.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,15 @@ | ||
package pt.isel.ion.teams.teacher | ||
|
||
import org.springframework.web.bind.annotation.* | ||
import pt.isel.ion.teams.common.Uris | ||
|
||
@RestController | ||
@RequestMapping(Uris.Teachers.PATH) | ||
class TeacherController(val service: TeacherService) { | ||
|
||
@GetMapping() | ||
fun getTeachers(@PathVariable classroomId: Int) = service.getTeachers(classroomId) | ||
|
||
@GetMapping(Uris.Teachers.Teacher.PATH) | ||
fun getTeacher(@PathVariable number: Int) = service.getTeacher(number) | ||
} |
24 changes: 24 additions & 0 deletions
24
code/jvm/src/main/kotlin/pt/isel/ion/teams/teacher/TeacherDAO.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,24 @@ | ||
package pt.isel.ion.teams.teacher | ||
|
||
import org.jdbi.v3.sqlobject.customizer.Bind | ||
import org.jdbi.v3.sqlobject.customizer.BindBean | ||
import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys | ||
import org.jdbi.v3.sqlobject.statement.SqlQuery | ||
import org.jdbi.v3.sqlobject.statement.SqlUpdate | ||
|
||
interface TeacherDAO { | ||
|
||
@SqlQuery("SELECT * FROM teacher WHERE cId=:classroomId") | ||
fun getTeachers(@Bind("classroomId") classroomId: Int): List<TeacherDbRead> | ||
|
||
@SqlQuery("SELECT * FROM teacher WHERE number=:number") | ||
fun getTeacher(@Bind("number")number: Int): TeacherDbRead | ||
|
||
@SqlUpdate("INSERT INTO teacher (number,name,email,office) VALUES (:number,:name,:email,:office)") | ||
@GetGeneratedKeys | ||
fun createTeacher(@BindBean teacher: TeacherDbWrite): TeacherDbRead | ||
|
||
@SqlUpdate("UPDATE teacher SET name=:name,email=:email,office=:office WHERE number=:number") | ||
@GetGeneratedKeys | ||
fun updateTeacher(@BindBean teacher: TeacherDbUpdate): Int | ||
} |
16 changes: 16 additions & 0 deletions
16
code/jvm/src/main/kotlin/pt/isel/ion/teams/teacher/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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package pt.isel.ion.teams.teacher | ||
|
||
import org.jdbi.v3.core.Jdbi | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class TeacherService(val jdbi: Jdbi) { | ||
|
||
fun getTeachers(classroomId: Int) = jdbi.onDemand(TeacherDAO::class.java).getTeachers(classroomId) | ||
|
||
fun getTeacher(number: Int) = jdbi.onDemand(TeacherDAO::class.java).getTeacher(number) | ||
|
||
fun createTeacher(teacher: TeacherDbWrite) = jdbi.onDemand(TeacherDAO::class.java).createTeacher(teacher) | ||
|
||
fun updateTeacher(teacher: TeacherDbUpdate) = jdbi.onDemand(TeacherDAO::class.java).updateTeacher(teacher) | ||
} |
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