Skip to content

Commit 35dce1e

Browse files
committed
feat: comment reply, delete
0 parents  commit 35dce1e

29 files changed

+1454
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.nullvariable.devlog;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
import java.nio.file.Paths;
12+
13+
@EnableJpaRepositories
14+
@SpringBootApplication
15+
public class DevlogApplication {
16+
public static void main(String[] args) {
17+
String currentDirectory = System.getProperty("user.dir");
18+
19+
try {
20+
Path userDirectory = Paths.get(currentDirectory + File.separator + "user/");
21+
if (!Files.exists(userDirectory) && !Files.isDirectory(userDirectory)) {
22+
Files.createDirectory(userDirectory);
23+
}
24+
25+
Path profileDirectory = Paths.get(currentDirectory + File.separator + "user/profile/");
26+
if (!Files.exists(profileDirectory) && !Files.isDirectory(profileDirectory)) {
27+
Files.createDirectory(profileDirectory);
28+
}
29+
} catch (IOException e) {
30+
System.out.println("Required Directory");
31+
return;
32+
}
33+
34+
SpringApplication.run(DevlogApplication.class, args);
35+
}
36+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.nullvariable.devlog.entites;
2+
3+
import com.nullvariable.devlog.enums.Roles;
4+
import jakarta.persistence.*;
5+
import lombok.*;
6+
import org.springframework.data.annotation.CreatedDate;
7+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
8+
9+
import java.time.LocalDateTime;
10+
11+
@Builder
12+
@Entity
13+
@Getter
14+
@Setter
15+
@Table(name = "AuthEntity")
16+
@NoArgsConstructor
17+
@AllArgsConstructor
18+
@EntityListeners(AuditingEntityListener.class)
19+
public class AuthEntity {
20+
@Id
21+
@GeneratedValue(strategy = GenerationType.UUID)
22+
@Column(name = "uuid", length = 36, columnDefinition = "varchar(36)", nullable = false)
23+
private String uuid;
24+
25+
@Column(name = "username", columnDefinition = "varchar(24)", nullable = false, unique = true)
26+
private String username;
27+
28+
@Column(name = "nickname", columnDefinition = "varchar(22)", nullable = false)
29+
private String nickname;
30+
31+
@Column(name = "password", columnDefinition = "text", nullable = false)
32+
private String password;
33+
34+
@Column(name = "salt", columnDefinition = "varchar(32)", length = 32, nullable = false)
35+
private String salt;
36+
37+
@Column(name = "profilePath", columnDefinition = "text", nullable = true)
38+
private String profilePath;
39+
40+
@CreatedDate
41+
@Column(updatable = false, nullable = false, name = "createdAt")
42+
private LocalDateTime createdAt;
43+
44+
@Enumerated(EnumType.STRING)
45+
private Roles role;
46+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.nullvariable.devlog.entites;
2+
3+
import jakarta.persistence.*;
4+
import lombok.*;
5+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
6+
7+
import java.util.List;
8+
import java.util.Optional;
9+
10+
@Builder
11+
@Entity
12+
@Getter
13+
@Setter
14+
@Table(name = "CommentEntity")
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
@EntityListeners(AuditingEntityListener.class)
18+
public class CommentEntity {
19+
@Id
20+
@GeneratedValue(strategy = GenerationType.UUID)
21+
@Column(name = "uuid", length = 36, columnDefinition = "varchar(36)", nullable = false)
22+
private String uuid;
23+
24+
@Column(name = "content", columnDefinition = "text", nullable = false)
25+
private String content;
26+
27+
@ManyToOne(fetch = FetchType.EAGER)
28+
@JoinColumn(name = "target", referencedColumnName = "uuid")
29+
private PostEntity target;
30+
31+
@ManyToOne(fetch = FetchType.EAGER, optional = true)
32+
@JoinColumn(name = "author", referencedColumnName = "uuid", nullable = true)
33+
private Optional<AuthEntity> author;
34+
35+
@ManyToOne(fetch = FetchType.EAGER, optional = true)
36+
@JoinColumn(name = "parent", referencedColumnName = "uuid", nullable = true)
37+
private Optional<CommentEntity> parent;
38+
39+
@OneToMany(fetch = FetchType.EAGER, mappedBy = "parent", orphanRemoval = true)
40+
@JoinColumn(name = "children", referencedColumnName = "uuid")
41+
private List<CommentEntity> children;
42+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.nullvariable.devlog.entites;
2+
3+
import jakarta.persistence.*;
4+
import lombok.*;
5+
import org.springframework.data.annotation.CreatedDate;
6+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
7+
8+
import java.time.LocalDateTime;
9+
import java.util.List;
10+
import java.util.Optional;
11+
12+
@Builder
13+
@Entity
14+
@Getter
15+
@Setter
16+
@Table(name = "PostEntity")
17+
@NoArgsConstructor
18+
@AllArgsConstructor
19+
@EntityListeners(AuditingEntityListener.class)
20+
public class PostEntity {
21+
@Id
22+
@GeneratedValue(strategy = GenerationType.UUID)
23+
@Column(name = "uuid", length = 36, columnDefinition = "varchar(36)", nullable = false)
24+
private String uuid;
25+
26+
@Column(name = "title", length = 24, columnDefinition = "varchar(24)", nullable = false)
27+
private String title;
28+
29+
@Column(name = "content", columnDefinition = "text", nullable = false)
30+
private String content;
31+
32+
@Column(name = "thumbnailPath", columnDefinition = "text", nullable = true)
33+
private String thumbnail;
34+
35+
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
36+
@JoinTable(
37+
name = "tagsRelations",
38+
joinColumns = @JoinColumn(name = "tags", referencedColumnName = "uuid")
39+
)
40+
private List<TagsEntity> tags;
41+
42+
@ManyToOne(fetch = FetchType.EAGER, optional = true)
43+
@JoinColumn(name = "author", referencedColumnName = "uuid", nullable = true)
44+
private Optional<AuthEntity> author;
45+
46+
@CreatedDate
47+
@Column(updatable = false, nullable = false, name = "createdAt")
48+
private LocalDateTime createdAt;
49+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.nullvariable.devlog.entites;
2+
3+
import jakarta.persistence.*;
4+
import lombok.*;
5+
import org.springframework.data.annotation.CreatedDate;
6+
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
7+
8+
import java.time.LocalDateTime;
9+
10+
@Builder
11+
@Entity
12+
@Getter
13+
@Setter
14+
@Table(name = "TagsEntity")
15+
@NoArgsConstructor
16+
@AllArgsConstructor
17+
@EntityListeners(AuditingEntityListener.class)
18+
public class TagsEntity {
19+
@Id
20+
@GeneratedValue(strategy = GenerationType.UUID)
21+
@Column(name = "uuid", length = 36, columnDefinition = "varchar(36)", nullable = false)
22+
private String uuid;
23+
24+
@Column(name = "name", length = 20, columnDefinition = "varchar(20)", nullable = false, unique = true)
25+
private String name;
26+
27+
@CreatedDate
28+
@Column(updatable = false, nullable = false, name = "createdAt")
29+
private LocalDateTime createdAt;
30+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.nullvariable.devlog.enums;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
@Getter
7+
@AllArgsConstructor
8+
public enum Roles {
9+
ROLE_USER, ROLE_ADMIN
10+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.nullvariable.devlog.functions.auth;
2+
3+
import com.nullvariable.devlog.utils.responses.BasicResponse;
4+
import org.jose4j.jwt.MalformedClaimException;
5+
import org.jose4j.jwt.consumer.InvalidJwtException;
6+
import org.jose4j.lang.JoseException;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.web.bind.annotation.*;
11+
import org.springframework.web.multipart.MultipartFile;
12+
13+
import java.io.IOException;
14+
import java.util.Optional;
15+
16+
@RestController
17+
@RequestMapping("/auth")
18+
public class AuthController {
19+
private final AuthService authService;
20+
21+
@Autowired
22+
public AuthController(AuthService authService) {
23+
this.authService = authService;
24+
}
25+
26+
@GetMapping("/get/profile")
27+
public ResponseEntity<Object> getProfile(@RequestParam("uuid") String uuid) throws IOException {
28+
return authService.getProfile(uuid);
29+
}
30+
31+
@PostMapping("/login")
32+
public ResponseEntity<Object> Login(
33+
@RequestParam(value = "username") String username,
34+
@RequestParam(value = "password") String password
35+
) throws JoseException {
36+
return authService.Login(username, password);
37+
}
38+
39+
@PostMapping("/signup")
40+
public ResponseEntity<Object> SignUp(
41+
@RequestParam(value = "username") String username,
42+
@RequestParam(value = "nickname") String nickname,
43+
@RequestParam(value = "password") String password,
44+
@RequestParam(value = "file") MultipartFile file
45+
) {
46+
if (username == null || username.trim().isEmpty()) {
47+
BasicResponse response = BasicResponse.builder()
48+
.success(false)
49+
.message(Optional.of("username을 입력해주세요."))
50+
.build();
51+
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response);
52+
}
53+
if (nickname == null || nickname.trim().isEmpty()) {
54+
BasicResponse response = BasicResponse.builder()
55+
.success(false)
56+
.message(Optional.of("nickname을 입력해주세요."))
57+
.build();
58+
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response);
59+
}
60+
61+
if (password == null || password.trim().isEmpty()) {
62+
BasicResponse response = BasicResponse.builder()
63+
.success(false)
64+
.message(Optional.of("password를 입력해주세요."))
65+
.build();
66+
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response);
67+
}
68+
69+
if (file.isEmpty()) {
70+
BasicResponse response = BasicResponse.builder()
71+
.success(false)
72+
.message(Optional.of("file을 업로드 해주세요"))
73+
.build();
74+
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response);
75+
}
76+
77+
return authService.SignUp(username, nickname, password, file);
78+
}
79+
80+
@GetMapping("/@me")
81+
public ResponseEntity<Object> Me(
82+
@RequestHeader(value = "Authorization") String token
83+
) throws JoseException, InvalidJwtException, MalformedClaimException {
84+
return authService.Me(token);
85+
}
86+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.nullvariable.devlog.functions.auth;
2+
3+
import com.nullvariable.devlog.entites.AuthEntity;
4+
import org.jose4j.jwt.MalformedClaimException;
5+
import org.jose4j.jwt.consumer.InvalidJwtException;
6+
import org.jose4j.lang.JoseException;
7+
import org.springframework.data.repository.query.Param;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.stereotype.Service;
10+
import org.springframework.web.bind.annotation.RequestHeader;
11+
import org.springframework.web.bind.annotation.RequestParam;
12+
import org.springframework.web.multipart.MultipartFile;
13+
14+
import java.io.IOException;
15+
import java.util.List;
16+
17+
@Service
18+
public interface AuthService {
19+
ResponseEntity<Object> Login(
20+
@RequestParam(value = "username") String username,
21+
@RequestParam(value = "password") String password
22+
) throws JoseException;
23+
ResponseEntity<Object> SignUp(
24+
@RequestParam(value = "username") String username,
25+
@RequestParam(value = "nickname") String nickname,
26+
@RequestParam(value = "password") String password,
27+
@RequestParam(value = "file") MultipartFile file
28+
);
29+
ResponseEntity<Object> getProfile(@RequestParam("uuid") String uuid) throws IOException;
30+
ResponseEntity<Object> Me(@RequestHeader(value = "Authorization") String token) throws JoseException, InvalidJwtException, MalformedClaimException;
31+
}

0 commit comments

Comments
 (0)