-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Sam3Star/gayeong
feat: set structure
- Loading branch information
Showing
18 changed files
with
316 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/kr/hs/dgsw/clock_server/domain/routine/entity/RoutineEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package kr.hs.dgsw.clock_server.domain.routine.entity; | ||
|
||
import jakarta.persistence.*; | ||
import kr.hs.dgsw.clock_server.global.common.entity.BaseTimeEntity; | ||
import kr.hs.dgsw.clock_server.global.common.enums.ColorEnum; | ||
import kr.hs.dgsw.clock_server.global.common.enums.ImportanceEnum; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
import org.hibernate.annotations.DynamicUpdate; | ||
|
||
@Entity | ||
@Table(name = "tbl_routine") | ||
@Getter | ||
@DynamicUpdate | ||
@SuperBuilder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class RoutineEntity extends BaseTimeEntity { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "routine_id", nullable = false) | ||
private Long routineId; | ||
|
||
@Column(name = "routine_name", nullable = false) | ||
private String name; | ||
|
||
@Column(name = "importance", nullable = false) | ||
private ImportanceEnum importanceEnum; | ||
|
||
@Column(name = "color", nullable = false) | ||
private ColorEnum colorEnum; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/kr/hs/dgsw/clock_server/domain/routine/mapper/RoutineMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package kr.hs.dgsw.clock_server.domain.routine.mapper; | ||
|
||
import kr.hs.dgsw.clock_server.domain.routine.entity.RoutineEntity; | ||
import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.RoutineDto; | ||
import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req.RoutineGenerateReq; | ||
import kr.hs.dgsw.clock_server.global.anotation.Mapper; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Mapper | ||
@RequiredArgsConstructor | ||
public class RoutineMapper { | ||
public RoutineDto mapToDomain(RoutineEntity routineEntity){ | ||
return RoutineDto.builder() | ||
.routineId(routineEntity.getRoutineId()) | ||
.name(routineEntity.getName()) | ||
.importanceEnum(routineEntity.getImportanceEnum()) | ||
.colorEnum(routineEntity.getColorEnum()) | ||
.build(); | ||
} | ||
|
||
public RoutineEntity mapToEntity(RoutineDto routineDto){ | ||
return RoutineEntity.builder() | ||
.routineId(routineDto.getRoutineId()) | ||
.name(routineDto.getName()) | ||
.importanceEnum(routineDto.getImportanceEnum()) | ||
.colorEnum(routineDto.getColorEnum()) | ||
.build(); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...ava/kr/hs/dgsw/clock_server/domain/routine/presentation/controller/RoutineController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package kr.hs.dgsw.clock_server.domain.routine.presentation.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req.RoutineGenerateReq; | ||
import kr.hs.dgsw.clock_server.domain.routine.service.RoutineService; | ||
import kr.hs.dgsw.clock_server.global.reponse.Response; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
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; | ||
|
||
@Tag(name = "routine", description = "routine Api") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/routine") | ||
public class RoutineController { | ||
private final RoutineService routineService; | ||
|
||
@PostMapping() | ||
@Operation(summary = "generate routine", description = "generate routine") | ||
public Response generate( | ||
@RequestBody RoutineGenerateReq req | ||
){ | ||
routineService.generate(req); | ||
return Response.of(HttpStatus.OK, "생성성공"); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/kr/hs/dgsw/clock_server/domain/routine/presentation/dto/RoutineDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package kr.hs.dgsw.clock_server.domain.routine.presentation.dto; | ||
|
||
import kr.hs.dgsw.clock_server.global.common.enums.ColorEnum; | ||
import kr.hs.dgsw.clock_server.global.common.enums.ImportanceEnum; | ||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class RoutineDto { | ||
private Long routineId; | ||
private String name; | ||
private ImportanceEnum importanceEnum; | ||
private ColorEnum colorEnum; | ||
} |
15 changes: 15 additions & 0 deletions
15
.../java/kr/hs/dgsw/clock_server/domain/routine/presentation/dto/req/RoutineGenerateReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req; | ||
|
||
import kr.hs.dgsw.clock_server.global.common.enums.ColorEnum; | ||
import kr.hs.dgsw.clock_server.global.common.enums.ImportanceEnum; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class RoutineGenerateReq{ | ||
String name; | ||
ImportanceEnum importanceEnum; | ||
ColorEnum colorEnum; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/kr/hs/dgsw/clock_server/domain/routine/repository/RoutineRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kr.hs.dgsw.clock_server.domain.routine.repository; | ||
|
||
import kr.hs.dgsw.clock_server.domain.routine.entity.RoutineEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface RoutineRepository extends JpaRepository<RoutineEntity, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/kr/hs/dgsw/clock_server/domain/routine/service/RoutineService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package kr.hs.dgsw.clock_server.domain.routine.service; | ||
|
||
import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req.RoutineGenerateReq; | ||
|
||
public interface RoutineService { | ||
void generate(RoutineGenerateReq req); | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/kr/hs/dgsw/clock_server/domain/routine/service/RoutineServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package kr.hs.dgsw.clock_server.domain.routine.service; | ||
|
||
import kr.hs.dgsw.clock_server.domain.routine.entity.RoutineEntity; | ||
import kr.hs.dgsw.clock_server.domain.routine.mapper.RoutineMapper; | ||
import kr.hs.dgsw.clock_server.domain.routine.presentation.dto.req.RoutineGenerateReq; | ||
import kr.hs.dgsw.clock_server.domain.routine.repository.RoutineRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RoutineServiceImpl implements RoutineService{ | ||
private final RoutineRepository routineRepository; | ||
private final RoutineMapper routineMapper; | ||
|
||
@Override | ||
@Transactional(rollbackFor = Exception.class) | ||
public void generate(RoutineGenerateReq req){ | ||
routineRepository.save(RoutineEntity.builder() | ||
.name(req.getName()) | ||
.importanceEnum(req.getImportanceEnum()) | ||
.colorEnum(req.getColorEnum()) | ||
.build()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/kr/hs/dgsw/clock_server/global/anotation/Mapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.hs.dgsw.clock_server.global.anotation; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Component | ||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface Mapper { | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/kr/hs/dgsw/clock_server/global/common/entity/BaseTimeEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package kr.hs.dgsw.clock_server.global.common.entity; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.EntityListeners; | ||
import jakarta.persistence.MappedSuperclass; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.SuperBuilder; | ||
import org.springframework.data.annotation.CreatedDate; | ||
import org.springframework.data.annotation.LastModifiedDate; | ||
import org.springframework.data.jpa.domain.support.AuditingEntityListener; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@SuperBuilder | ||
@MappedSuperclass | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EntityListeners(AuditingEntityListener.class) | ||
public abstract class BaseTimeEntity { | ||
@CreatedDate | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
protected LocalDateTime createdDate; | ||
|
||
@LastModifiedDate | ||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") | ||
protected LocalDateTime modifiedDate; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/kr/hs/dgsw/clock_server/global/common/enums/ColorEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package kr.hs.dgsw.clock_server.global.common.enums; | ||
|
||
public enum ColorEnum { | ||
green, | ||
red, | ||
orange, | ||
yellow, | ||
blue, | ||
pink | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/kr/hs/dgsw/clock_server/global/common/enums/ImportanceEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package kr.hs.dgsw.clock_server.global.common.enums; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public enum ImportanceEnum { | ||
veryImportant, | ||
important, | ||
soso, | ||
baggy, | ||
less | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/kr/hs/dgsw/clock_server/global/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package kr.hs.dgsw.clock_server.global.config; | ||
|
||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
class SwaggerConfig { | ||
@Bean | ||
public OpenAPI openAPI() { | ||
SecurityScheme securityScheme = new SecurityScheme() | ||
.name("Authorization") | ||
.type(SecurityScheme.Type.HTTP) | ||
.in(SecurityScheme.In.HEADER) | ||
.bearerFormat("JWT") | ||
.scheme("bearer"); | ||
OpenAPI openAPI = new OpenAPI().addSecurityItem(new SecurityRequirement().addList("JWT Token")) | ||
.components(new Components()) | ||
.info(apiInfo()); | ||
openAPI.getComponents().addSecuritySchemes("JWT Token", securityScheme); | ||
return openAPI; | ||
} | ||
|
||
private Info apiInfo() { | ||
return new Info() | ||
.title("Java.") | ||
.description("Java API") | ||
.version("0.0.1"); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/kr/hs/dgsw/clock_server/global/reponse/Response.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kr.hs.dgsw.clock_server.global.reponse; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public record Response(int status, String message) { | ||
public static Response of(HttpStatus status, String message) { | ||
return new Response(status.value(), message); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/kr/hs/dgsw/clock_server/global/reponse/ResponseData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package kr.hs.dgsw.clock_server.global.reponse; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public record ResponseData<T>( | ||
int status, | ||
String message, | ||
T data | ||
) { | ||
public static <T> ResponseData<T> of(HttpStatus status, String message, T data) { | ||
return new ResponseData<>(status.value(), message, data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,6 @@ spring: | |
hibernate: | ||
format_sql: true | ||
show_sql: true | ||
|
||
server: | ||
port: 8080 |