Skip to content

Commit b6d8373

Browse files
cleaned up code to make more presentable
1 parent d3ec99b commit b6d8373

File tree

7 files changed

+5
-63
lines changed

7 files changed

+5
-63
lines changed

assignment14/src/main/java/com/coderscampus/assignment14/repository/UserRepository.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,5 @@ public void addUser(User user) {
1919
public User getUserById(Long userId) {
2020
return users.get(userId);
2121
}
22-
23-
public User getUserbyUsername(String username) {
24-
return users.values()
25-
.stream()
26-
.filter(user -> username.equals(user.getUsername()))
27-
.findFirst()
28-
.orElse(null);
29-
}
30-
31-
public boolean userExists(Long userId) {
32-
return users.containsKey(userId);
33-
}
34-
35-
public void removeUser(Long userId) {
36-
users.remove(userId);
37-
}
22+
3823
}

assignment14/src/main/java/com/coderscampus/assignment14/service/ChannelService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
@Service
1111
public class ChannelService {
1212

13-
private ChannelRepository channelRepo;
13+
private final ChannelRepository channelRepo;
1414

1515
public ChannelService(ChannelRepository channelRepo) {
1616
this.channelRepo = channelRepo;

assignment14/src/main/java/com/coderscampus/assignment14/service/UserService.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ public User createUser(String username) {
2424
public User getUserById(Long userId) {
2525
return userRepo.getUserById(userId);
2626
}
27-
28-
public User getUserByUsername(String username) {
29-
return userRepo.getUserbyUsername(username);
30-
}
31-
32-
public boolean userExists(Long userId) {
33-
return userRepo.userExists(userId);
34-
}
3527

3628
private Long generateUniqueId() {
3729
// TODO Auto-generated method stub

assignment14/src/main/java/com/coderscampus/assignment14/web/ChannelController.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,7 @@ public String showChannelPage(@PathVariable Long channelId, Model model) {
4949
public Channel getChannelDetails(@PathVariable Long channelId) {
5050
return channelService.getChannelById(channelId);
5151
}
52-
53-
// @GetMapping("/{channelId}/messages")
54-
// @ResponseBody
55-
// public List<Message> getMessagesByChannel(@PathVariable Long channelId){
56-
// return messageService.getMessagesByChannel(channelId);
57-
// }
58-
52+
5953
@PostMapping("/{channelId}/messages")
6054
@ResponseBody
6155
public Message postMessageToChannel(@PathVariable Long channelId, @RequestParam String username, @RequestParam String messageContent) {

assignment14/src/main/java/com/coderscampus/assignment14/web/UserController.java

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,5 @@ public UserController(UserService userService) {
2929
public User createUser(@RequestParam String username) {
3030
return userService.createUser(username);
3131
}
32-
//
33-
// @GetMapping("/{username}")
34-
// @ResponseBody
35-
// public User getUserByUsername(@PathVariable String username) {
36-
// return userService.getUserByUsername(username);
37-
// }
38-
//
39-
// @GetMapping("/exists/{userId}")
40-
// @ResponseBody
41-
// public boolean userExists(@PathVariable Long userId) {
42-
// return userService.userExists(userId);
43-
// }
44-
45-
//user doesn't need a dedicated page for this assignment.
46-
@GetMapping
47-
public String showUserPage() {
48-
return "user";
49-
}
50-
32+
5133
}

assignment14/src/main/resources/static/js/channel.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ function pollMessages(){
4141
messageElement.classList.add('message-item');
4242

4343
const timestamp = new Date(message.timestamp).toLocaleTimeString([],{hour: '2-digit', minute:'2-digit'});
44-
// messageElement.textContent = `${message.username}: ${message.messageContent} ${timestamp}`;
4544
messageElement.innerHTML = `
4645
<span class="username">${message.username}:</span>
4746
<span class="message-content">${message.messageContent}</span>
@@ -64,13 +63,3 @@ document.getElementById('messageInput').addEventListener('keydown', (event) => {
6463
})
6564

6665
setInterval(pollMessages, 500);
67-
68-
// Original way I was displaying channel name in the chat room. Switched to thymeleaf
69-
//
70-
//document.addEventListener('DOMContentLoaded', () =>{
71-
// fetch(`/channels/${channelId}/details`)
72-
// .then(response => response.json())
73-
// .then(channel => {
74-
// document.getElementById('channelName').textContent = `Channel: ${channel.channelName}`;
75-
// });
76-
//});

assignment14/src/main/resources/static/js/channels.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
document.addEventListener('DOMContentLoaded', () =>{
22
const username = sessionStorage.getItem('username');
3-
const userId = sessionStorage.getItem('userId');
3+
44

55
if(username){
66
document.getElementById('welcomeMessage').textContent = `Welcome, ${username}`;

0 commit comments

Comments
 (0)