Skip to content

Commit 04f4058

Browse files
committed
feat: user login basic #29
1 parent 6798fde commit 04f4058

File tree

11 files changed

+131
-0
lines changed

11 files changed

+131
-0
lines changed

backend/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ dependencies {
2727
// https://mvnrepository.com/artifact/org.postgresql/postgresql
2828
implementation 'org.postgresql:postgresql:42.7.3' // PostgreSQL JDBC 드라이버 의존성 추가
2929
runtimeOnly 'org.postgresql:postgresql:42.7.3' // 실행 시에만 필요한 의존성 추가
30+
31+
// Spring Data JPA 의존성 추가
32+
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
33+
34+
// Lombok 의존성 추가
35+
compileOnly 'org.projectlombok:lombok:1.18.30'
36+
annotationProcessor 'org.projectlombok:lombok:1.18.30'
3037
}
3138

3239
tasks.named('test') {

backend/src/main/java/com/example/backend/user/controller/.gitkeep

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.backend.user.controller;
2+
3+
import com.example.backend.user.dto.UserRequestDto;
4+
import com.example.backend.user.dto.UserResponseDto;
5+
import com.example.backend.user.service.UserService;
6+
import org.springframework.web.bind.annotation.*;
7+
8+
@RestController
9+
@RequestMapping("/api/v1")
10+
public class UserController {
11+
12+
private final UserService userService;
13+
14+
// userService를 주입받아서 사용
15+
public UserController(UserService userService) {
16+
this.userService = userService;
17+
}
18+
19+
@PostMapping("/auth")
20+
// RequestBody의 데이터를 UserRequestDto 객체로 변환해서 받음
21+
public UserResponseDto authenticate(@RequestBody UserRequestDto requestDto) {
22+
// 메서드 수행 결과 반환
23+
return userService.authenticate(requestDto);
24+
}
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.example.backend.user.domain;
2+
3+
import jakarta.persistence.*;
4+
import lombok.Getter;
5+
import lombok.NoArgsConstructor;
6+
7+
@Entity
8+
@Getter
9+
@NoArgsConstructor
10+
@Table(name = "police_info") // 실제 DB 테이블명에 맞게 수정
11+
public class UserEntity {
12+
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.IDENTITY)
15+
private int id; // PK
16+
17+
@Column(name = "office_id")
18+
private int officeId;
19+
20+
@Column(name = "name", nullable = false)
21+
private String name;
22+
23+
@Column(name = "user_id", unique = true, nullable = false)
24+
private String userId;
25+
26+
@Column(name = "password", nullable = false)
27+
private String password;
28+
29+
@Column(name = "profile_url", nullable = false)
30+
private String profileUrl;
31+
}

backend/src/main/java/com/example/backend/user/dto/.gitkeep

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.backend.user.dto;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
@Getter
7+
@Setter
8+
public class UserRequestDto {
9+
private String userId;
10+
private String password;
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.example.backend.user.dto;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
@Getter
7+
@AllArgsConstructor
8+
public class UserResponseDto {
9+
private int officeId;
10+
private String name;
11+
private String profileUrl;
12+
}

backend/src/main/java/com/example/backend/user/repository/.gitkeep

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.backend.user.repository;
2+
3+
import com.example.backend.user.domain.UserEntity;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
import java.util.Optional;
7+
8+
9+
public interface UserRepository extends JpaRepository<UserEntity, Long> {
10+
Optional<UserEntity> findByUserIdAndPassword(String userId, String password);
11+
}

backend/src/main/java/com/example/backend/user/service/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)