Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified FeedApp/fullstack_db.mv.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,21 @@ public ResponseEntity<String> createPoll( @RequestHeader("Authorization") String
public Poll getPoll(@PathVariable UUID pollId) { return manager.getPoll(pollId); }

@DeleteMapping
public void deleteAllPolls() { manager.deleteAllPolls(); }
public void deleteAllPolls() {
manager.deleteAllPolls();
}

@DeleteMapping("/{pollId}")
public void deletePoll(@PathVariable UUID pollId) { manager.deletePoll(pollId); }
public void deletePoll(@RequestHeader("Authorization") String token, @PathVariable UUID pollId) {
String jwt = token.replace("Bearer ", "").trim();
UUID userId = JwtService.parseToken(jwt);
logger.info("UserId from token: {}", userId);
logger.info("PollId from token: {}", pollId);
logger.info("UserId equals to pollcreatorid: {}", userId == getPoll(pollId).getCreatorUserID());
if(userId.equals(getPoll(pollId).getCreatorUserID())){
manager.deletePoll(pollId);
}
}

@PutMapping("/{pollId}")
public void updatePoll(@PathVariable UUID pollId, @RequestBody Poll poll) { manager.updatePoll(pollId, poll); }
Expand Down
15 changes: 15 additions & 0 deletions Frontend/src/components/SeePolls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ async function vote(pollid: string, optionid: number) {
}
}

// Lets a user delete their own polls
async function deleteOwnPoll(id: string) {
try {
const url = `/polls/${id}`
await defaultFetch(url, 'DELETE', getUserToken())
} catch (error) {
console.error('Error:', error)
}
}

// Fetch the poll owners
async function fetchPollOwners() {
try {
Expand Down Expand Up @@ -90,6 +100,7 @@ fetchPolls()
<li>
{{ poll.question }} created by:
{{ pollOwners[poll.creatorUserID]?.email || 'Unknown' }}
<p @click="deleteOwnPoll(poll.id)">X</p>
</li>
<div v-for="option in poll.options" :key="option.id">
<button @click="vote(poll.id, option.id)">
Expand All @@ -109,4 +120,8 @@ fetchPolls()
border: 1px solid #ccc;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
p {
cursor: pointer;
color: red;
}
</style>