Skip to content

Commit 593619f

Browse files
committed
update demo
1 parent 38923b5 commit 593619f

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

demo/src/main/java/lazy/fast/code/demo/address/AddressController.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import io.swagger.annotations.ApiImplicitParam;
55
import io.swagger.annotations.ApiImplicitParams;
66
import io.swagger.annotations.ApiOperation;
7+
import lazy.fast.code.core.exception.NoContentNotException;
8+
import lazy.fast.code.core.exception.NotFoundException;
79
import lazy.fast.code.core.orm.BaseController;
810
import lazy.fast.code.core.orm.BaseService;
911
import org.springframework.http.ResponseEntity;
12+
import org.springframework.util.CollectionUtils;
1013
import org.springframework.web.bind.annotation.DeleteMapping;
1114
import org.springframework.web.bind.annotation.GetMapping;
1215
import org.springframework.web.bind.annotation.PathVariable;
@@ -36,14 +39,22 @@ public AddressController(BaseService<Address> baseService) {
3639
@ApiOperation(value = "获取地址信息列表")
3740
@GetMapping
3841
public List<Address> list() {
39-
return this.getBaseService().list(null);
42+
List<Address> list = this.getBaseService().list(null);
43+
if (CollectionUtils.isEmpty(list)) {
44+
throw new NoContentNotException();
45+
}
46+
return list;
4047
}
4148

4249
@ApiOperation(value = "根据ID获取地址信息")
4350
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "地址ID", required = true, paramType = "path")})
4451
@GetMapping("/{id}")
4552
public Address get(@PathVariable String id) {
46-
return this.getBaseService().get(id);
53+
Address address = this.getBaseService().get(id);
54+
if (address == null) {
55+
throw new NotFoundException();
56+
}
57+
return address;
4758
}
4859

4960
@ApiOperation(value = "保存地址信息")

demo/src/main/java/lazy/fast/code/demo/user/UserController.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import io.swagger.annotations.ApiImplicitParam;
55
import io.swagger.annotations.ApiImplicitParams;
66
import io.swagger.annotations.ApiOperation;
7+
import lazy.fast.code.core.exception.NoContentNotException;
8+
import lazy.fast.code.core.exception.NotFoundException;
79
import lazy.fast.code.core.orm.BaseController;
810
import lazy.fast.code.core.orm.BaseService;
911
import org.springframework.http.ResponseEntity;
12+
import org.springframework.util.CollectionUtils;
1013
import org.springframework.web.bind.annotation.DeleteMapping;
1114
import org.springframework.web.bind.annotation.GetMapping;
1215
import org.springframework.web.bind.annotation.PathVariable;
@@ -39,14 +42,22 @@ public UserController(BaseService<User> baseService) {
3942
@ApiOperation(value = "获取用户信息列表")
4043
@GetMapping
4144
public List<User> list() {
42-
return this.getBaseService().list(null);
45+
List<User> users = this.getBaseService().list(null);
46+
if (CollectionUtils.isEmpty(users)) {
47+
throw new NoContentNotException();
48+
}
49+
return users;
4350
}
4451

4552
@ApiOperation(value = "根据ID获取用户信息")
4653
@ApiImplicitParams({@ApiImplicitParam(name = "id", value = "用户ID", required = true, paramType = "path")})
4754
@GetMapping("/{id}")
4855
public User get(@PathVariable Long id) {
49-
return this.getBaseService().get(id);
56+
User user = this.getBaseService().get(id);
57+
if (user == null) {
58+
throw new NotFoundException();
59+
}
60+
return user;
5061
}
5162

5263
@ApiOperation(value = "获取用户信息列表 - 使用Repository中的自定义方法")

demo/src/main/java/lazy/fast/code/demo/user/UserServiceImpl.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import lazy.fast.code.core.orm.BaseRepository;
55
import lazy.fast.code.core.orm.BaseServiceImpl;
66
import lazy.fast.code.demo.address.Address;
7-
import lazy.fast.code.demo.address.AddressRepository;
7+
import lazy.fast.code.demo.address.AddressService;
88
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.stereotype.Service;
1010
import org.springframework.util.CollectionUtils;
@@ -21,18 +21,22 @@
2121
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {
2222

2323
private final UserRepository userRepository;
24-
private final AddressRepository addressRepository;
24+
private final AddressService addressService;
2525

2626
@Autowired
27-
public UserServiceImpl(BaseRepository<User> baseRepository, AddressRepository addressRepository) {
27+
public UserServiceImpl(BaseRepository<User> baseRepository, AddressService addressService) {
2828
super(baseRepository);
2929
this.userRepository = (UserRepository)baseRepository;
30-
this.addressRepository = addressRepository;
30+
this.addressService = addressService;
3131
}
3232

3333
@Override
3434
public List<User> listUsers() {
35-
return this.userRepository.listUsers();
35+
List<User> users = this.userRepository.listUsers();
36+
if (CollectionUtils.isEmpty(users)) {
37+
throw new NoContentNotException();
38+
}
39+
return users;
3640
}
3741

3842
@Override
@@ -47,8 +51,7 @@ public List<UserAddressDTO> listUserAddress() {
4751
dto.setUser(o);
4852
Address address = Address.of();
4953
address.setUserId(o.getId());
50-
List<Address> addressList = this.addressRepository.select(address);
51-
dto.setAddressList(addressList);
54+
dto.setAddressList(this.addressService.list(address));
5255
res.add(dto);
5356
});
5457
return res;

0 commit comments

Comments
 (0)