From 634ea931084896aa26defe79f8c87ce01691a3e1 Mon Sep 17 00:00:00 2001 From: byung eun park Date: Wed, 6 Nov 2019 21:48:10 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=90=EC=9C=A0=EA=B2=8C=EC=8B=9C=ED=8C=90?= =?UTF-8?q?=20=EB=AA=A8=EB=8D=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 +++ .../game/controller/LeagueController.java | 4 +- .../game/entity/SportsEventResultEntity.java | 10 ++- .../info/controller/FreeBoardController.java | 61 +++++++++++++++++++ .../modules/info/entity/FreeBoardEntity.java | 3 + .../info/repository/FreeBoardRepository.java | 7 +++ .../info/service/FreeBoardService.java | 41 +++++++++++++ .../modules/user/entity/UserEntity.java | 4 +- .../user/repository/UserRepository.java | 2 +- .../user/repository/UserRepositoryTest.java | 6 +- 10 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/totopia/server/modules/info/controller/FreeBoardController.java create mode 100644 src/main/java/com/totopia/server/modules/info/repository/FreeBoardRepository.java create mode 100644 src/main/java/com/totopia/server/modules/info/service/FreeBoardService.java diff --git a/pom.xml b/pom.xml index 27b873d..5179c26 100644 --- a/pom.xml +++ b/pom.xml @@ -84,6 +84,14 @@ spring-security-test test + + + + com.vladmihalcea + hibernate-types-52 + 2.7.1 + + diff --git a/src/main/java/com/totopia/server/modules/game/controller/LeagueController.java b/src/main/java/com/totopia/server/modules/game/controller/LeagueController.java index 5b9093a..a4ad93e 100644 --- a/src/main/java/com/totopia/server/modules/game/controller/LeagueController.java +++ b/src/main/java/com/totopia/server/modules/game/controller/LeagueController.java @@ -43,13 +43,13 @@ public class LeagueController { } @PutMapping(value = "/league/{leagueId}") - public ResponseEntity updateLeague(@PathVariable Long leagueId, LeagueEntity leagueEntity) throws Exception { + public ResponseEntity modify(@PathVariable Long leagueId, LeagueEntity leagueEntity) throws Exception { LeagueEntity leagueEntity1 = this.leagueService.modify(leagueEntity); return ResponseEntity.ok(leagueEntity1); } @DeleteMapping(value = "/league/{leagueId}") - public ResponseEntity deleteLeague(@PathVariable Long leagueId) { + public ResponseEntity removeById(@PathVariable Long leagueId) { Long res = this.leagueService.removeById(leagueId); return ResponseEntity.ok(res); } diff --git a/src/main/java/com/totopia/server/modules/game/entity/SportsEventResultEntity.java b/src/main/java/com/totopia/server/modules/game/entity/SportsEventResultEntity.java index b9c8830..a22e17f 100644 --- a/src/main/java/com/totopia/server/modules/game/entity/SportsEventResultEntity.java +++ b/src/main/java/com/totopia/server/modules/game/entity/SportsEventResultEntity.java @@ -1,11 +1,15 @@ package com.totopia.server.modules.game.entity; import com.totopia.server.commons.data.entity.DateAuditEntity; +import com.vladmihalcea.hibernate.type.json.JsonStringType; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; +import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; +import org.hibernate.annotations.TypeDefs; import javax.persistence.*; import java.util.Map; @@ -17,6 +21,9 @@ import java.util.Map; @NoArgsConstructor @AllArgsConstructor @Builder +@TypeDefs({ + @TypeDef(name = "json", typeClass = JsonStringType.class) +}) public class SportsEventResultEntity extends DateAuditEntity { @Id @@ -42,7 +49,8 @@ public class SportsEventResultEntity extends DateAuditEntity { @Column(name = "away_final_score") private Short awayFinalScore; - @Column(name = "score_Info", columnDefinition = "json") + @Type(type = "json") + @Column(name = "score_info", columnDefinition = "json") private Map scoreInfo; } diff --git a/src/main/java/com/totopia/server/modules/info/controller/FreeBoardController.java b/src/main/java/com/totopia/server/modules/info/controller/FreeBoardController.java new file mode 100644 index 0000000..8b51310 --- /dev/null +++ b/src/main/java/com/totopia/server/modules/info/controller/FreeBoardController.java @@ -0,0 +1,61 @@ +package com.totopia.server.modules.info.controller; + +import com.totopia.server.commons.data.payload.ApiResponse; +import com.totopia.server.modules.info.entity.FreeBoardEntity; +import com.totopia.server.modules.info.service.FreeBoardService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.SortDefault; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +@RestController +public class FreeBoardController { + + @Autowired + private FreeBoardService freeBoardService; + + @PostMapping(value = "/free-board") + @ResponseStatus(code = HttpStatus.CREATED) + public ResponseEntity save(@Valid @RequestBody FreeBoardEntity freeBoardEntity) throws Exception{ + this.freeBoardService.save(freeBoardEntity); + return ResponseEntity.ok().body(new ApiResponse(true, "FreeBoard registered successfully")); + } + + @GetMapping(value = "/free-board") + public Page all( + @SortDefault.SortDefaults({ + @SortDefault( + sort = "createdAt", + direction = Sort.Direction.DESC) }) + Pageable pageable) { + return this.freeBoardService.getAllByPageable(pageable); + } +// +// @GetMapping(value = "/users/{userId}") +// public UserEntity findByUserId(@PathVariable Long userId) { +// return this.userService.getUserById(userId); +// } + @GetMapping(value = "/free-board/{boardId}") + public FreeBoardEntity findById( + @PathVariable Long boardId) { + return this.freeBoardService.getBoardById(boardId); + } + + @PutMapping(value = "/free-board/{boardId}") + public ResponseEntity modify(@PathVariable Long boardId, FreeBoardEntity freeBoardEntity) throws Exception { + FreeBoardEntity board = this.freeBoardService.modify(freeBoardEntity); + return ResponseEntity.ok(board); + } + + @DeleteMapping(value = "/free-board/{boardId}") + public ResponseEntity removeById(@PathVariable Long boardId) { + Long res = this.freeBoardService.removeById(boardId); + return ResponseEntity.ok(res); + } +} diff --git a/src/main/java/com/totopia/server/modules/info/entity/FreeBoardEntity.java b/src/main/java/com/totopia/server/modules/info/entity/FreeBoardEntity.java index 6e7fcd8..a4f664d 100644 --- a/src/main/java/com/totopia/server/modules/info/entity/FreeBoardEntity.java +++ b/src/main/java/com/totopia/server/modules/info/entity/FreeBoardEntity.java @@ -36,4 +36,7 @@ public class FreeBoardEntity extends UserDateAuditEntity { @Column(name = "attach_id", nullable = true) private Long attachFile; + @Transient + private Long owner; + } diff --git a/src/main/java/com/totopia/server/modules/info/repository/FreeBoardRepository.java b/src/main/java/com/totopia/server/modules/info/repository/FreeBoardRepository.java new file mode 100644 index 0000000..144e0b8 --- /dev/null +++ b/src/main/java/com/totopia/server/modules/info/repository/FreeBoardRepository.java @@ -0,0 +1,7 @@ +package com.totopia.server.modules.info.repository; + +import com.totopia.server.modules.info.entity.FreeBoardEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface FreeBoardRepository extends JpaRepository { +} diff --git a/src/main/java/com/totopia/server/modules/info/service/FreeBoardService.java b/src/main/java/com/totopia/server/modules/info/service/FreeBoardService.java new file mode 100644 index 0000000..dc085cc --- /dev/null +++ b/src/main/java/com/totopia/server/modules/info/service/FreeBoardService.java @@ -0,0 +1,41 @@ +package com.totopia.server.modules.info.service; + +import com.totopia.server.modules.info.entity.FreeBoardEntity; +import com.totopia.server.modules.info.repository.FreeBoardRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.Date; + +@Service +public class FreeBoardService { + + @Autowired + private FreeBoardRepository freeBoardRepository; + + public void save(FreeBoardEntity freeBoardEntity) throws Exception { + freeBoardEntity.setCreatedBy(freeBoardEntity.getOwner()); + this.freeBoardRepository.save(freeBoardEntity); + } + + public Page getAllByPageable(Pageable pageable) { + return this.freeBoardRepository.findAll(pageable); + } + + public FreeBoardEntity modify(FreeBoardEntity freeBoardEntity) { + freeBoardEntity.setUpdatedBy(1L); + freeBoardEntity.setUpdatedAt(new Date()); + return this.freeBoardRepository.save(freeBoardEntity); + } + + public Long removeById(Long boardId) { + this.freeBoardRepository.deleteById(boardId); + return boardId; + } + + public FreeBoardEntity getBoardById(Long boardId) { + return this.freeBoardRepository.findById(boardId).orElseThrow(null); + } +} diff --git a/src/main/java/com/totopia/server/modules/user/entity/UserEntity.java b/src/main/java/com/totopia/server/modules/user/entity/UserEntity.java index 22fa755..4a7a6e3 100644 --- a/src/main/java/com/totopia/server/modules/user/entity/UserEntity.java +++ b/src/main/java/com/totopia/server/modules/user/entity/UserEntity.java @@ -48,11 +48,11 @@ public class UserEntity extends DateAuditEntity { private Boolean block = false; @Basic - @Column(name = "ref_enable", nullable = false) + @Column(name = "ref_enable", nullable = true) private Boolean refEnable = false; @Basic - @Column(name = "ref_id", nullable = false) + @Column(name = "ref_id", nullable = true) private Long ref; @Basic diff --git a/src/main/java/com/totopia/server/modules/user/repository/UserRepository.java b/src/main/java/com/totopia/server/modules/user/repository/UserRepository.java index a2fe068..6670dc9 100644 --- a/src/main/java/com/totopia/server/modules/user/repository/UserRepository.java +++ b/src/main/java/com/totopia/server/modules/user/repository/UserRepository.java @@ -32,7 +32,7 @@ public interface UserRepository extends JpaRepository { // Page findAllByIsAdminTrue(Pageable pageable) throws Exception; // 패스워드 리셋이 트루인 유저 리스 - Page findAllByRequireResetTrue(Pageable pageable) throws Exception; +// Page findAllByRequireResetTrue(Pageable pageable) throws Exception; // // 어드민이 펄스이며, 활동중인 현재 회원 리스트 // Page findAllByIsAdminFalseAndActivationEquals(String activation, diff --git a/src/test/java/com/totopia/server/modules/user/repository/UserRepositoryTest.java b/src/test/java/com/totopia/server/modules/user/repository/UserRepositoryTest.java index 3eeea7c..f4ac207 100644 --- a/src/test/java/com/totopia/server/modules/user/repository/UserRepositoryTest.java +++ b/src/test/java/com/totopia/server/modules/user/repository/UserRepositoryTest.java @@ -86,9 +86,9 @@ public class UserRepositoryTest { public void findAllByIsAdminTrue() { } - @Test - public void findAllByRequireResetTrue() { - } +// @Test +// public void findAllByRequireResetTrue() { +// } @Test public void findAllByIsAdminFalseAndActivationEquals() {