Commit 8a51b553 authored by Khalid Ali's avatar Khalid Ali
Browse files

Merge branch 'feature/4-get-user' into 'master'

Feature/4 get user

See merge request kali21/bookshare-backend!2
parents 11fca6fc 9fa2c300
......@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class ShareUserService {
......@@ -26,4 +27,18 @@ public class ShareUserService {
return user;
}
}
public ShareUser getShareUserByEmail(String email) {
List<ShareUser> foundUsers = shareUserRepository.findByEmail(email);
if (foundUsers.size() > 0) {
return foundUsers.get(0);
} else {
return null;
}
}
public ShareUser getShareUserById(Long id) {
Optional<ShareUser> shareUser = shareUserRepository.findById(id);
return shareUser.orElse(null);
}
}
......@@ -101,6 +101,24 @@ public class BookshareApiController {
return convertBidToDto(bidCreated);
}
@GetMapping(value = "/user/email/{email}")
ShareUserDto getByEmail(@PathVariable String email) {
ShareUser user = shareUserService.getShareUserByEmail(email);
if (user == null) {
return new ShareUserDto("", "");
}
return convertShareUserToDto(user);
}
@GetMapping(value = "/user/id/{id}")
ShareUserDto getById(@PathVariable Long id) {
ShareUser user = shareUserService.getShareUserById(id);
if (user == null) {
return new ShareUserDto("", "");
}
return convertShareUserToDto(user);
}
@PostMapping(value = "/user", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public ShareUserDto newListing(@RequestBody ShareUserDto shareUserDto) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment