Skip to content

Commit

Permalink
Merge pull request #31 from cearps/feature/api-features
Browse files Browse the repository at this point in the history
API features
  • Loading branch information
maxjaszewski authored Aug 17, 2024
2 parents c9e26b1 + 8ecd41f commit 73ab34d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.backend.backend.controller;

import com.backend.backend.dto.CurrentUserDto;
import com.backend.backend.dto.LoginResponse;
import com.backend.backend.dto.LoginUserDto;
import com.backend.backend.dto.RegisterUserDto;
import com.backend.backend.model.User;
import com.backend.backend.service.AuthenticationService;
import com.backend.backend.service.JwtService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/auth")
@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.backend.backend.controller;

import com.backend.backend.dto.CurrentUserDto;
import com.backend.backend.model.User;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/user")
@RestController
public class UserController {

@GetMapping("/me")
public ResponseEntity<CurrentUserDto> getCurrentUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
User currentUser = (User) authentication.getPrincipal();
CurrentUserDto response = new CurrentUserDto();
response.setEmail(currentUser.getEmail());
response.setFullName(currentUser.getFullName());
response.setId(currentUser.getId());
return ResponseEntity.ok(response);
}

}
10 changes: 10 additions & 0 deletions api/src/main/java/com/backend/backend/dto/CurrentUserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.backend.backend.dto;

import lombok.Data;

@Data
public class CurrentUserDto {
private Long id;
private String email;
private String fullName;
}
2 changes: 1 addition & 1 deletion api/src/main/java/com/backend/backend/model/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Task {
private String description;
private LocalDate dueDate;
private Integer urgency;
private Integer taskCategory;
private Integer taskCategory = 1;

@ManyToOne
@JoinColumn(name = "board_id", nullable = false)
Expand Down

0 comments on commit 73ab34d

Please sign in to comment.