리그 서비스 클래스 추
This commit is contained in:
parent
78037ab0d4
commit
a6cfca98aa
|
@ -0,0 +1,56 @@
|
||||||
|
package com.totopia.server.modules.game.controller;
|
||||||
|
|
||||||
|
import com.totopia.server.commons.data.payload.ApiResponse;
|
||||||
|
import com.totopia.server.modules.game.entity.LeagueEntity;
|
||||||
|
import com.totopia.server.modules.game.service.LeagueService;
|
||||||
|
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 LeagueController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LeagueService leagueService;
|
||||||
|
|
||||||
|
@GetMapping(value = "/league")
|
||||||
|
public Page<LeagueEntity> all(
|
||||||
|
@SortDefault.SortDefaults({
|
||||||
|
@SortDefault(
|
||||||
|
sort = "createdAt",
|
||||||
|
direction = Sort.Direction.DESC) })
|
||||||
|
Pageable pageable) {
|
||||||
|
return this.leagueService.getAllLeagueByPageable(pageable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(value = "/league/{sprotName}")
|
||||||
|
public ResponseEntity<LeagueEntity> findBySportsName(@PathVariable String sportName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(value = "/league")
|
||||||
|
@ResponseStatus(code = HttpStatus.CREATED)
|
||||||
|
public ResponseEntity<?> save(@Valid @RequestBody LeagueEntity leagueEntity) throws Exception{
|
||||||
|
this.leagueService.save(leagueEntity);
|
||||||
|
return ResponseEntity.ok().body(new ApiResponse(true, "League registered successfully"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping(value = "/league/{leagueId}")
|
||||||
|
public ResponseEntity<?> updateLeague(@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) {
|
||||||
|
Long res = this.leagueService.removeById(leagueId);
|
||||||
|
return ResponseEntity.ok(res);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.totopia.server.modules.game.service;
|
||||||
|
|
||||||
|
import com.totopia.server.commons.exception.ResourceNotFoundException;
|
||||||
|
import com.totopia.server.modules.game.entity.LeagueEntity;
|
||||||
|
import com.totopia.server.modules.game.repository.LeagueRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LeagueService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LeagueRepository leagueRepository;
|
||||||
|
|
||||||
|
public LeagueEntity save(LeagueEntity leagueEntity) {
|
||||||
|
return this.leagueRepository.save(leagueEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LeagueEntity modify(LeagueEntity leagueEntity) {
|
||||||
|
return this.leagueRepository.save(leagueEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Page<LeagueEntity> getAllLeagueByPageable(Pageable pageable) {
|
||||||
|
Page<LeagueEntity> entities = null;
|
||||||
|
|
||||||
|
// if (null == username) {
|
||||||
|
entities = leagueRepository.findAll(pageable);
|
||||||
|
// } else {
|
||||||
|
// entities = userRepository.findByUsernameContainingIgnoreCase(username, pageable);
|
||||||
|
// }
|
||||||
|
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long removeById(Long leagueId) {
|
||||||
|
return leagueRepository.findById(leagueId).map(league -> {
|
||||||
|
leagueRepository.delete(league);
|
||||||
|
return leagueId;
|
||||||
|
}).orElseThrow(() -> new ResourceNotFoundException("League", "leagueId", leagueId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getLeagueById() {}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.totopia.server.modules.game.service;
|
||||||
|
|
||||||
|
import com.totopia.server.commons.exception.ResourceNotFoundException;
|
||||||
|
import com.totopia.server.modules.game.entity.SportsEntity;
|
||||||
|
import com.totopia.server.modules.game.repository.SportsRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SportsService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SportsRepository sportsRepository;
|
||||||
|
|
||||||
|
public Page<SportsEntity> getAllSportsByPageable(Pageable pageable) {
|
||||||
|
Page<SportsEntity> entities = null;
|
||||||
|
entities = this.sportsRepository.findAll(pageable);
|
||||||
|
return entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SportsEntity getSportsById(Short sportId) {
|
||||||
|
return this.sportsRepository.findById(sportId).orElseThrow(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SportsEntity save(SportsEntity sportsEntity) {
|
||||||
|
return this.sportsRepository.save(sportsEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SportsEntity modify(SportsEntity sportsEntity) {
|
||||||
|
return this.sportsRepository.save(sportsEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Short remove(Short sportsId) {
|
||||||
|
return sportsRepository.findById(sportsId).map(sports -> {
|
||||||
|
sportsRepository.delete(sports);
|
||||||
|
return sportsId;
|
||||||
|
}).orElseThrow(() -> new ResourceNotFoundException("Sports", "sportsId", sportsId));
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,10 +2,8 @@ package com.totopia.server.modules.user.controller;
|
||||||
|
|
||||||
import com.totopia.server.auth.payload.SignupRequest;
|
import com.totopia.server.auth.payload.SignupRequest;
|
||||||
import com.totopia.server.commons.data.payload.ApiResponse;
|
import com.totopia.server.commons.data.payload.ApiResponse;
|
||||||
import com.totopia.server.commons.exception.ResourceNotFoundException;
|
|
||||||
import com.totopia.server.modules.user.entity.UserEntity;
|
import com.totopia.server.modules.user.entity.UserEntity;
|
||||||
import com.totopia.server.modules.user.payload.UserUpdateRequest;
|
import com.totopia.server.modules.user.payload.UserUpdateRequest;
|
||||||
import com.totopia.server.modules.user.repository.UserRepository;
|
|
||||||
import com.totopia.server.modules.user.service.UserService;
|
import com.totopia.server.modules.user.service.UserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.*;
|
import org.springframework.data.domain.*;
|
||||||
|
@ -13,20 +11,16 @@ import org.springframework.data.web.SortDefault;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
import java.net.URI;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
public class UserController {
|
public class UserController {
|
||||||
@Autowired
|
|
||||||
private UserRepository userRepository;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
@PostMapping(value = "/regist")
|
@PostMapping(value = "/users")
|
||||||
@ResponseStatus(code = HttpStatus.CREATED)
|
@ResponseStatus(code = HttpStatus.CREATED)
|
||||||
public ResponseEntity<?> save(@Valid @RequestBody SignupRequest signupRequest) throws Exception{ // User user 파라미터는 추후에 수
|
public ResponseEntity<?> save(@Valid @RequestBody SignupRequest signupRequest) throws Exception{ // User user 파라미터는 추후에 수
|
||||||
|
|
||||||
|
@ -48,10 +42,10 @@ public class UserController {
|
||||||
direction = Sort.Direction.DESC) })
|
direction = Sort.Direction.DESC) })
|
||||||
Pageable pageable) {
|
Pageable pageable) {
|
||||||
|
|
||||||
return this.userService.getUsersByPageable(username, pageable);
|
return this.userService.getAllUsersByPageable(username, pageable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping(value = "/connect-users")
|
@GetMapping(value = "/users/connect-users")
|
||||||
public Page<UserEntity> connectUsers(@RequestParam(value = "username", required = false) String username,
|
public Page<UserEntity> connectUsers(@RequestParam(value = "username", required = false) String username,
|
||||||
@SortDefault.SortDefaults({ @SortDefault(sort = "createdAt", direction = Sort.Direction.DESC) }) Pageable pageable) {
|
@SortDefault.SortDefaults({ @SortDefault(sort = "createdAt", direction = Sort.Direction.DESC) }) Pageable pageable) {
|
||||||
// final List<String> curUsers = sessionRegistry.getAllPrincipals().stream()
|
// final List<String> curUsers = sessionRegistry.getAllPrincipals().stream()
|
||||||
|
|
|
@ -2,10 +2,7 @@ package com.totopia.server.modules.user.entity;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.totopia.server.commons.data.entity.DateAuditEntity;
|
import com.totopia.server.commons.data.entity.DateAuditEntity;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.*;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
@ -19,6 +16,7 @@ import java.util.Set;
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@Builder
|
||||||
public class UserEntity extends DateAuditEntity {
|
public class UserEntity extends DateAuditEntity {
|
||||||
private static final long serialVersionUID = 8891163223262220481L;
|
private static final long serialVersionUID = 8891163223262220481L;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class UserService {
|
||||||
@Autowired
|
@Autowired
|
||||||
PasswordEncoder passwordEncoder;
|
PasswordEncoder passwordEncoder;
|
||||||
|
|
||||||
public Page<UserEntity> getUsersByPageable(String username, Pageable pageable) {
|
public Page<UserEntity> getAllUsersByPageable(String username, Pageable pageable) {
|
||||||
Page<UserEntity> entities = null;
|
Page<UserEntity> entities = null;
|
||||||
|
|
||||||
if (null == username) {
|
if (null == username) {
|
||||||
|
@ -61,7 +61,6 @@ public class UserService {
|
||||||
|
|
||||||
public void regist(SignupRequest signupRequest) throws Exception{
|
public void regist(SignupRequest signupRequest) throws Exception{
|
||||||
|
|
||||||
|
|
||||||
// Creating user's account
|
// Creating user's account
|
||||||
UserEntity user = UserEntity.builder().username(signupRequest.getUsername()).email(signupRequest.getEmail())
|
UserEntity user = UserEntity.builder().username(signupRequest.getUsername()).email(signupRequest.getEmail())
|
||||||
.nickname(signupRequest.getNickname()).phone(signupRequest.getPhone()).descriptions(signupRequest.getDescriptions())
|
.nickname(signupRequest.getNickname()).phone(signupRequest.getPhone()).descriptions(signupRequest.getDescriptions())
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package com.totopia.server.modules.game.service;
|
||||||
|
|
||||||
|
import com.totopia.server.modules.game.entity.LeagueEntity;
|
||||||
|
import com.totopia.server.modules.game.repository.LeagueRepository;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class LeagueServiceTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
LeagueRepository leagueRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void save() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void modify() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllLeagueByPageable() {
|
||||||
|
// new PageImpl<UserEntity>(users, new PageRequest(pageable.getPageNumber(), pageable.getPageSize()), users.size());
|
||||||
|
Pageable pageable = PageRequest.of(0, 10);
|
||||||
|
Page<LeagueEntity> entities = this.leagueRepository.findAll(pageable);
|
||||||
|
|
||||||
|
assertEquals(10, entities.getContent().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void removeById() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLeagueById() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.totopia.server.modules.game.service;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest
|
||||||
|
public class SportsServiceTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAllSportsByPageable() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSportsById() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void save() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void modify() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void remove() {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user