Skip to content
Open
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
4 changes: 4 additions & 0 deletions 351003/brezgunov/distcomp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
kotlin("jvm") version "2.3.0"
kotlin("plugin.spring") version "2.3.0"
kotlin("plugin.jpa") version "2.3.0"
kotlin("kapt") version "2.3.0"
id("org.springframework.boot") version "4.0.2"
id("io.spring.dependency-management") version "1.1.7"
Expand All @@ -22,11 +23,14 @@ repositories {

dependencies {
implementation("org.springframework.boot:spring-boot-starter-webmvc")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("tools.jackson.module:jackson-module-kotlin")
implementation("org.mapstruct:mapstruct:1.7.0.Beta1")
implementation("org.springframework.boot:spring-boot-starter-actuator")
kapt("org.mapstruct:mapstruct-processor:1.7.0.Beta1")
runtimeOnly("org.postgresql:postgresql")
testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.distcomp.controller
import com.distcomp.dto.marker.MarkerRequestTo
import com.distcomp.dto.marker.MarkerResponseTo
import com.distcomp.service.MarkerService
import jakarta.validation.Valid
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.*

Expand All @@ -13,7 +14,7 @@ class MarkerController(
) {
@PostMapping(version = "1.0")
@ResponseStatus(HttpStatus.CREATED)
fun createMarker(@RequestBody markerRequestTo: MarkerRequestTo): MarkerResponseTo {
fun createMarker(@Valid @RequestBody markerRequestTo: MarkerRequestTo): MarkerResponseTo {
return markerService.createMarker(markerRequestTo)
}

Expand All @@ -30,7 +31,7 @@ class MarkerController(
@PutMapping(path = ["/{id}", ""], version = "1.0")
@ResponseStatus(HttpStatus.OK)
fun updateMarker(
@RequestBody markerRequestTo: MarkerRequestTo,
@Valid @RequestBody markerRequestTo: MarkerRequestTo,
@PathVariable("id") id: Long?
): MarkerResponseTo {
return markerService.updateMarker(markerRequestTo, id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.distcomp.controller
import com.distcomp.dto.news.NewsRequestTo
import com.distcomp.dto.news.NewsResponseTo
import com.distcomp.service.NewsService
import jakarta.validation.Valid
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
Expand All @@ -21,7 +22,7 @@ class NewsController (
) {
@PostMapping(version = "1.0")
@ResponseStatus(HttpStatus.CREATED)
fun createUser(@RequestBody newsRequestTo: NewsRequestTo): NewsResponseTo {
fun createUser(@Valid @RequestBody newsRequestTo: NewsRequestTo): NewsResponseTo {
return newsService.createNews(newsRequestTo)
}

Expand All @@ -37,7 +38,7 @@ class NewsController (

@PutMapping(path = ["/{id}", ""], version = "1.0")
@ResponseStatus(HttpStatus.OK)
fun updateUser(@RequestBody newsRequestTo: NewsRequestTo,
fun updateUser(@Valid @RequestBody newsRequestTo: NewsRequestTo,
@PathVariable("id") userId: Long?): NewsResponseTo {
return newsService.updateNews(newsRequestTo, userId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.distcomp.controller
import com.distcomp.dto.notice.NoticeRequestTo
import com.distcomp.dto.notice.NoticeResponseTo
import com.distcomp.service.NoticeService
import jakarta.validation.Valid
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.*

Expand All @@ -13,7 +14,7 @@ class NoticeController(
) {
@PostMapping(version = "1.0")
@ResponseStatus(HttpStatus.CREATED)
fun createNotice(@RequestBody noticeRequestTo: NoticeRequestTo): NoticeResponseTo {
fun createNotice(@Valid @RequestBody noticeRequestTo: NoticeRequestTo): NoticeResponseTo {
return noticeService.createNotice(noticeRequestTo)
}

Expand All @@ -30,7 +31,7 @@ class NoticeController(
@PutMapping(path = ["/{id}", ""], version = "1.0")
@ResponseStatus(HttpStatus.OK)
fun updateNotice(
@RequestBody noticeRequestTo: NoticeRequestTo,
@Valid @RequestBody noticeRequestTo: NoticeRequestTo,
@PathVariable("id") id: Long?
): NoticeResponseTo {
return noticeService.updateNotice(noticeRequestTo, id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.distcomp.controller
import com.distcomp.dto.user.UserRequestTo
import com.distcomp.dto.user.UserResponseTo
import com.distcomp.service.UserService
import jakarta.validation.Valid
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.DeleteMapping
import org.springframework.web.bind.annotation.GetMapping
Expand All @@ -21,7 +22,7 @@ class UserController (
) {
@PostMapping(version = "1.0")
@ResponseStatus(HttpStatus.CREATED)
fun createUser(@RequestBody userRequestTo: UserRequestTo): UserResponseTo {
fun createUser(@Valid @RequestBody userRequestTo: UserRequestTo): UserResponseTo {
return userService.createUser(userRequestTo)
}

Expand All @@ -37,7 +38,7 @@ class UserController (

@PutMapping(version = "1.0")
@ResponseStatus(HttpStatus.OK)
fun updateUser(@RequestBody userRequestTo: UserRequestTo): UserResponseTo {
fun updateUser(@Valid @RequestBody userRequestTo: UserRequestTo): UserResponseTo {
return userService.updateUser(userRequestTo)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.distcomp.dto.marker

import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.Size

data class MarkerRequestTo(
val id: Long? = null,
@field:NotBlank
@field:Size(min = 3, max = 32)
val name: String,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package com.distcomp.dto.news

import com.distcomp.dto.marker.MarkerRequestTo
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size

data class NewsRequestTo (
val id: Long? = null,
@field:NotBlank
@field:Size(min = 3, max = 64)
val title: String,
@field:NotBlank
@field:Size(min = 4, max = 2048)
val content: String,
val userId: Long
@field:NotNull
val userId: Long,
val markers: List<String>?,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.distcomp.dto.notice

import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull
import jakarta.validation.constraints.Size

data class NoticeRequestTo (
val id: Long? = null,
@field:NotNull
val newsId: Long,
@field:NotBlank
@field:Size(min = 4, max = 2048)
val content: String
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package com.distcomp.dto.user

import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.Size

data class UserRequestTo(
val id: Long? = null,
@field:NotBlank
@field:Size(min = 2, max = 64)
val login: String,
@field:NotBlank
@field:Size(min = 8, max = 128)
val password: String,
@field:NotBlank
@field:Size(min = 2, max = 64)
val firstname: String,
@field:NotBlank
@field:Size(min = 2, max = 64)
val lastname: String,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package com.distcomp.entity

class Marker (
var id: Long,
import jakarta.persistence.*

@Entity
@Table(name = "tbl_marker")
class Marker(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
var id: Long = 0,
var name: String,
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package com.distcomp.entity

import jakarta.persistence.*
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.Size
import java.time.LocalDateTime

@Entity
@Table(name = "tbl_news")
class News(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
var id: Long? = null,
var title: String,
var content: String,
var created: LocalDateTime = LocalDateTime.now(),
var modified: LocalDateTime = LocalDateTime.now(),
var user: User? = null
@ManyToOne
@JoinColumn(name = "user_id")
var user: User? = null,
@OneToMany(cascade = [(CascadeType.ALL)], orphanRemoval = true)
var markers: MutableList<Marker> = mutableListOf(),
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package com.distcomp.entity

class Notice (
import jakarta.persistence.*

@Entity
@Table(name = "tbl_notice")
class Notice(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
var id: Long,
var content: String,
@ManyToOne
@JoinColumn(name = "news_id")
var news: News? = null
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.distcomp.entity

class User (
import jakarta.persistence.*

@Entity
@Table(name = "tbl_user")
class User(
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
var id: Long? = null,
var login: String,
var password: String,
var firstname: String,
var lastname: String,
var news: List<News>?
@OneToMany(mappedBy = "user", cascade = [CascadeType.ALL])
var news: MutableList<News>? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.distcomp.exception

import org.springframework.http.HttpStatus

class DuplicateUserException(errorMsg: String) :
AbstractException(HttpStatus.FORBIDDEN, errorMsg)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.distcomp.exception

import org.springframework.http.HttpStatus

class NewsTitleDuplicateException (errorMessage: String)
: AbstractException(HttpStatus.FORBIDDEN, errorMessage)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.distcomp.repository

import com.distcomp.entity.Marker
import org.springframework.data.jpa.repository.JpaRepository

interface MarkerRepository : JpaRepository<Marker, Long>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.distcomp.repository

import com.distcomp.entity.News
import org.springframework.data.jpa.repository.JpaRepository

interface NewsRepository : JpaRepository<News, Long> {
fun existsByTitle(title: String): Boolean
}
Loading