4 changed files with 110 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||||
|
package app.controllers.bot; |
||||
|
|
||||
|
import app.entities.db.Annonce; |
||||
|
import app.repositories.AnnonceRepository; |
||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||
|
import org.springframework.http.ResponseEntity; |
||||
|
import org.springframework.web.bind.annotation.PostMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
@RestController |
||||
|
@RequestMapping("api/bot/discord") |
||||
|
public class DiscordNewsController { |
||||
|
|
||||
|
@Autowired |
||||
|
private AnnonceRepository annonceRepository; |
||||
|
|
||||
|
@PostMapping("/news") |
||||
|
public ResponseEntity createNews(@RequestBody Annonce annonce) { |
||||
|
annonce.setId(null); |
||||
|
annonceRepository.save(annonce); |
||||
|
return ResponseEntity.ok().body(null); |
||||
|
} |
||||
|
} |
@ -0,0 +1,53 @@ |
|||||
|
package app.entities.db; |
||||
|
|
||||
|
import com.fasterxml.jackson.annotation.JsonIgnore; |
||||
|
import jakarta.persistence.Column; |
||||
|
import jakarta.persistence.Entity; |
||||
|
import jakarta.persistence.Id; |
||||
|
import jakarta.persistence.Table; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.sql.Timestamp; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Entity |
||||
|
@Data |
||||
|
@Table(schema = "tf2_facti13", name = "annonces") |
||||
|
public class Annonce { |
||||
|
@Id |
||||
|
@Column(name = "id") |
||||
|
private Long id; |
||||
|
|
||||
|
@Column(name = "header") |
||||
|
private String header; |
||||
|
|
||||
|
@Column(name = "short") |
||||
|
private String shortText; |
||||
|
|
||||
|
@Column(name = "full") |
||||
|
private String fullText; |
||||
|
|
||||
|
@Column(name = "type") |
||||
|
private String type; |
||||
|
|
||||
|
@Column(name = "redirect") |
||||
|
private String redirect; |
||||
|
|
||||
|
@Column(name = "attachments") |
||||
|
private String attachments; |
||||
|
|
||||
|
@Column(name = "timestamp") |
||||
|
private Timestamp timestamp; |
||||
|
|
||||
|
@Column(name = "author") |
||||
|
private String author; |
||||
|
|
||||
|
@Column(name = "deleted") |
||||
|
@JsonIgnore |
||||
|
private Boolean deleted; |
||||
|
|
||||
|
public String[] getAttachments() { |
||||
|
return attachments != null?attachments.split("\n"):new String[]{}; |
||||
|
} |
||||
|
} |
@ -0,0 +1,17 @@ |
|||||
|
package app.repositories; |
||||
|
|
||||
|
import app.entities.db.Annonce; |
||||
|
import org.springframework.data.domain.Page; |
||||
|
import org.springframework.data.domain.Pageable; |
||||
|
import org.springframework.data.jpa.repository.Query; |
||||
|
import org.springframework.data.repository.PagingAndSortingRepository; |
||||
|
|
||||
|
public interface AnnonceRepository extends PagingAndSortingRepository<Annonce, Long> { |
||||
|
@Query(value = "select n from Annonce n where n.type like 'news' and n.deleted = false order by n.id desc") |
||||
|
Page<Annonce> getNews(Pageable pageable); |
||||
|
|
||||
|
@Query(value = "select n from Annonce n where n.type like 'reason4play' and n.deleted = false order by n.id desc") |
||||
|
Page<Annonce> getAnnonce(Pageable pageable); |
||||
|
|
||||
|
void save(Annonce annonce); |
||||
|
} |
Loading…
Reference in new issue