diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index a1757ae52c775b88df6c02cfd7eb346687391f4e..0000000000000000000000000000000000000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index da0415a0f5aad2f6109ef1e7ffdcdd1165577665..0000000000000000000000000000000000000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index c4be5fbe7a7713108f730e4ba7e92ee22d7d9ecc..0000000000000000000000000000000000000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 7280f0035ff554996c5802bd753f698672e5a12b..0000000000000000000000000000000000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/qa-service/pom.xml b/qa-service/pom.xml index 0b70349fcbb4e8f68efabbf1733a3d46456fd39c..818cb500773aee1d738dd9a2969f28de1a8afa0c 100644 --- a/qa-service/pom.xml +++ b/qa-service/pom.xml @@ -5,28 +5,33 @@ com.example qa-service 0.0.1-SNAPSHOT + pom qa-service qa-service + + qa-service-domain + qa-service-bootstrap + qa-service-adapter + qa-service-application + qa-service-common + - 17 + 21 UTF-8 UTF-8 - 3.0.2 + 3.2.4 + 2023.0.1.0 + 2023.0.1 - - - org.springframework.boot - spring-boot-starter - - - - org.springframework.boot - spring-boot-starter-test - test - - + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + org.springframework.boot spring-boot-dependencies @@ -34,6 +39,20 @@ pom import + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + ${spring-cloud-alibaba.version} + pom + import + + + + com.baomidou + mybatis-plus-spring-boot3-starter + 3.5.14 + + @@ -44,8 +63,8 @@ maven-compiler-plugin 3.8.1 - 17 - 17 + 21 + 21 UTF-8 diff --git a/qa-service/qa-service-adapter/.gitignore b/qa-service/qa-service-adapter/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /dev/null +++ b/qa-service/qa-service-adapter/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-adapter/pom.xml b/qa-service/qa-service-adapter/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..0074d0c8f60c8bf3868ca60caccd07f5c42eb7fd --- /dev/null +++ b/qa-service/qa-service-adapter/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + com.example + qa-service-adapter + 0.0.1-SNAPSHOT + qa-service-adapter + qa-service-adapter + + pom + + + com.example + qa-service + 0.0.1-SNAPSHOT + + + + qa-adapter-in + qa-adapter-out + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + diff --git a/qa-service/qa-service-adapter/qa-adapter-in/.gitignore b/qa-service/qa-service-adapter/qa-adapter-in/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-adapter/qa-adapter-in/pom.xml b/qa-service/qa-service-adapter/qa-adapter-in/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..473ef75673f90161aee8129d1094187b03635b29 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + com.example + qa-adapter-in + 0.0.1-SNAPSHOT + qa-adapter-in + qa-adapter-in + + pom + + + com.example + qa-service-adapter + 0.0.1-SNAPSHOT + + + + qa-adapter-in-web + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/.gitignore b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..549e00a2a96fa9d7c5dbc9859664a78d980158c2 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/pom.xml b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..ba230d13d8c08ff3ed547cc65b43f0baa5b9c7c0 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + com.example + qa-adapter-in-web + 0.0.1-SNAPSHOT + qa-adapter-in-web + qa-adapter-in-web + + + com.example + qa-adapter-in + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + provided + + + org.projectlombok + lombok + + + + com.example + qa-service-application + 0.0.1-SNAPSHOT + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/controller/QaController.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/controller/QaController.java new file mode 100644 index 0000000000000000000000000000000000000000..ac12f6c800c0b75036a0c0b105f8f5ab5faf9d62 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/controller/QaController.java @@ -0,0 +1,73 @@ +package com.example.qa.adapter.in.web.controller; + +import com.example.qa.adapter.in.web.dto.CreateQaRequestDTO; +import com.example.qa.adapter.in.web.dto.UpdateQaRequestDTO; +import com.example.qa.adapter.in.web.dto.QaResponseDTO; +import com.example.qa.service.application.command.CreateQaCommand; +import com.example.qa.service.application.command.UpdateQaCommand; +import com.example.qa.service.application.port.in.*; +import com.example.qa.service.domain.Qa; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@Slf4j +@RequestMapping("/qas") +@RestController +@RequiredArgsConstructor +public class QaController { + + private final GetQaListUseCase getQaListUseCase; + private final CreateQaUseCase createQaUseCase; + private final DeleteQaUseCase deleteQaUseCase; + private final UpdateQaUseCase updateQaUseCase; + private final GetQaByIdUseCase getQaByIdUseCase; + + @GetMapping("") + public List getQas() { + log.info("getQas"); + return getQaListUseCase.getQas(); + } + + @PostMapping() + public Qa createQa(@RequestBody CreateQaRequestDTO createQaRequestDTO){ + + CreateQaCommand command=CreateQaCommand.builder() + .answer(createQaRequestDTO.answer()) + .question(createQaRequestDTO.question()) + .build(); + + return createQaUseCase.createQa(command); + } + + + @DeleteMapping("/{id}") + public String deleteQa(@PathVariable("id") Long id){ + deleteQaUseCase.deleteQa(id); + return "success"; + } + + @PutMapping("") + public Qa updateQa(@RequestBody UpdateQaRequestDTO updateQaRequestDTO){ + UpdateQaCommand command=UpdateQaCommand.builder() + .id(updateQaRequestDTO.id()) + .answer(updateQaRequestDTO.answer()) + .question(updateQaRequestDTO.question()) + .build(); + Qa qa = updateQaUseCase.updateQa(command); + return qa; + } + + @GetMapping("/{id}") + public QaResponseDTO getQaById(@PathVariable("id") Long id){ + Qa qa = getQaByIdUseCase.getQaById(id); + QaResponseDTO qaResponseDTO = new QaResponseDTO( + qa.getId().id(), + qa.getQuestion().question(), + qa.getAnswer().answer() + ); + return qaResponseDTO; + } +} diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/dto/CreateQaRequestDTO.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/dto/CreateQaRequestDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..1662ec223761fc22c701d21d0d52a370e974be12 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/dto/CreateQaRequestDTO.java @@ -0,0 +1,7 @@ +package com.example.qa.adapter.in.web.dto; + +public record CreateQaRequestDTO( + String question, + String answer) { + +} diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/dto/QaResponseDTO.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/dto/QaResponseDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..1a36793ca1b0862c1eecefa2cf86a1db2534fddd --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/dto/QaResponseDTO.java @@ -0,0 +1,14 @@ +package com.example.qa.adapter.in.web.dto; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class QaResponseDTO { + private long id; + private String question; + private String answer; +} diff --git a/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/dto/UpdateQaRequestDTO.java b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/dto/UpdateQaRequestDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..56ebfd86092855cba1c75f51a1ca52abad318a3c --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-in/qa-adapter-in-web/src/main/java/com/example/qa/adapter/in/web/dto/UpdateQaRequestDTO.java @@ -0,0 +1,6 @@ +package com.example.qa.adapter.in.web.dto; + +public record UpdateQaRequestDTO(Long id, + String question, + String answer) { +} diff --git a/qa-service/qa-service-adapter/qa-adapter-out/pom.xml b/qa-service/qa-service-adapter/qa-adapter-out/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..b63a0d4277082e81e20fcd01ce16433a9e9ffc0d --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + com.example + qa-service-adapter + 0.0.1-SNAPSHOT + + pom + + qa-adapter-out-persistence + + qa-adapter-out + + + 21 + 21 + UTF-8 + + + \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/pom.xml b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..1b02a83b8be96fef975e3f244060760c7d66db86 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + com.example + qa-adapter-out + 0.0.1-SNAPSHOT + + + qa-adapter-out-persistence + + + 21 + 21 + UTF-8 + + + + + org.projectlombok + lombok + provided + + + + com.example + qa-service-domain + 0.0.1-SNAPSHOT + + + + com.baomidou + mybatis-plus-spring-boot3-starter + + + + com.mysql + mysql-connector-j + runtime + + + + \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateQaBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateQaBridge.java new file mode 100644 index 0000000000000000000000000000000000000000..a7a2fdf3217d719419446bb833d94527645d2f47 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/CreateQaBridge.java @@ -0,0 +1,27 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.convertor.QaConvertor; +import com.example.qa.adapter.out.persistence.entity.QaEntity; +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.port.CreateQaPort; +import com.example.qa.service.domain.Qa; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class CreateQaBridge implements CreateQaPort { + + @Resource + private QaMapper qaMapper; + + @Override + public Qa createQa(Qa qa) { + QaEntity entity = QaConvertor.toEntity(qa); + int result = qaMapper.insert(entity); + log.info("Create qa success, affected rows: {}", result); + return QaConvertor.toDomain(entity); + } +} + \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteQaBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteQaBridge.java new file mode 100644 index 0000000000000000000000000000000000000000..220da702c9cdef3d4b3d77a0254dac46b22b9e57 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/DeleteQaBridge.java @@ -0,0 +1,22 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.port.DeleteQaPort; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class DeleteQaBridge implements DeleteQaPort { + + @Resource + private QaMapper qaMapper; + + @Override + public void deleteQa(Long qaId) { + int result = qaMapper.deleteById(qaId); + log.info("Delete qa [ID: {}] success, affected rows: {}", qaId, result); + } +} + \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaByIdBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaByIdBridge.java new file mode 100644 index 0000000000000000000000000000000000000000..fe6fc58c158e892ee0c6ecf2393fb09d9828c15c --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaByIdBridge.java @@ -0,0 +1,26 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.convertor.QaConvertor; +import com.example.qa.adapter.out.persistence.entity.QaEntity; +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.GetQaByIdPort; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class GetQaByIdBridge implements GetQaByIdPort { + + @Resource + private QaMapper qaMapper; + + @Override + public Qa getQaById(Long qaId) { + QaEntity entity = qaMapper.selectById(qaId); + log.info("Get qa [ID: {}] result: {}", qaId, entity != null ? "exists" : "not exists"); + return QaConvertor.toDomain(entity); + } +} + \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java new file mode 100644 index 0000000000000000000000000000000000000000..c8e902d8c2d605c1025d6913f3b4a8a99a51fb1a --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/GetQaListBridge.java @@ -0,0 +1,31 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.convertor.QaConvertor; +import com.example.qa.adapter.out.persistence.entity.QaEntity; +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.GetQaListPort; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.stream.Collectors; + +@Slf4j +@Component +public class GetQaListBridge implements GetQaListPort { + + @Resource + private QaMapper qaMapper; + + @Override + public List getQas() { + List entityList = qaMapper.selectList(null); + log.info("Get qa list success, total count: {}", entityList.size()); + return entityList.stream() + .map(QaConvertor::toDomain) + .collect(Collectors.toList()); + } +} + \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/UpdateQaBridge.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/UpdateQaBridge.java new file mode 100644 index 0000000000000000000000000000000000000000..376030b10fc00481bbefe59dac35f377ab7c90db --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/bridge/UpdateQaBridge.java @@ -0,0 +1,26 @@ +package com.example.qa.adapter.out.persistence.bridge; + +import com.example.qa.adapter.out.persistence.convertor.QaConvertor; +import com.example.qa.adapter.out.persistence.mapper.QaMapper; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.UpdateQaPort; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class UpdateQaBridge implements UpdateQaPort { + + @Resource + private QaMapper qaMapper; + + @Override + public Qa updateQa(Qa qa) { + int result = qaMapper.updateById(QaConvertor.toEntity(qa)); + log.info("Update qa [ID: {}] success, affected rows: {}", + qa.getId().getValue(), result); + return qa; + } +} + \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/convertor/QaConvertor.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/convertor/QaConvertor.java new file mode 100644 index 0000000000000000000000000000000000000000..dd0f5337a4aea7b50789bd4caaad9d7eb15911c8 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/convertor/QaConvertor.java @@ -0,0 +1,33 @@ +package com.example.qa.adapter.out.persistence.convertor; + +import com.example.qa.adapter.out.persistence.entity.QaEntity; +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.valueobject.QaAnswer; +import com.example.qa.service.domain.valueobject.QaId; +import com.example.qa.service.domain.valueobject.QaQuestion; + +public class QaConvertor { + + public static Qa toDomain(QaEntity entity) { + if (entity == null) { + return null; + } + return new Qa( + new QaId(entity.getId()), + new QaQuestion(entity.getQuestion()), + new QaAnswer(entity.getAnswer()) + ); + } + + public static QaEntity toEntity(Qa domain) { + if (domain == null) { + return null; + } + return new QaEntity( + domain.getId().getValue(), + domain.getQuestion().getValue(), + domain.getAnswer().getValue() + ); + } +} + \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/QaEntity.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/QaEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..8fcbf6fdb900d29b3a6a37d6a5c12c59e6d40074 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/entity/QaEntity.java @@ -0,0 +1,20 @@ +package com.example.qa.adapter.out.persistence.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("qa") +public class QaEntity { + @TableId(type = IdType.ASSIGN_ID) + private long id; + private String question; + private String answer; +} + \ No newline at end of file diff --git a/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/QaMapper.java b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/QaMapper.java new file mode 100644 index 0000000000000000000000000000000000000000..370b807e8f589d9227ddcf3a82784e0be97217c5 --- /dev/null +++ b/qa-service/qa-service-adapter/qa-adapter-out/qa-adapter-out-persistence/src/main/java/com/example/qa/adapter/out/persistence/mapper/QaMapper.java @@ -0,0 +1,12 @@ +/** + * @author zhouxudong + * @return + */ +package com.example.qa.adapter.out.persistence.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.example.qa.adapter.out.persistence.entity.QaEntity; + +public interface QaMapper extends BaseMapper { +} + \ No newline at end of file diff --git a/qa-service/qa-service-application/pom.xml b/qa-service/qa-service-application/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..8d9eb8b60832982af28d84f7a38d2ae55832bfa6 --- /dev/null +++ b/qa-service/qa-service-application/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + com.example + qa-service-application + 0.0.1-SNAPSHOT + qa-service-application + qa-service-application + + + com.example + qa-service + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + provided + + + + com.example + qa-service-domain + 0.0.1-SNAPSHOT + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/CreateQaCommand.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/CreateQaCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..ae2d0e847c6cd65a89de62de12a0d291e74ac4b0 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/CreateQaCommand.java @@ -0,0 +1,15 @@ +package com.example.qa.service.application.command; + +/* + @author xuyihua + * @return + */ +import lombok.Builder; + +@Builder +public record CreateQaCommand( + Long id, + String answer, + String question +) { +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/UpdateQaCommand.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/UpdateQaCommand.java new file mode 100644 index 0000000000000000000000000000000000000000..b95ba5cf9a8953512eb0310218fae2f8a190433a --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/command/UpdateQaCommand.java @@ -0,0 +1,12 @@ +package com.example.qa.service.application.command; +/* + * @author xuyihua + * @return + */ +import lombok.Builder; + +@Builder +public record UpdateQaCommand(Long id, + String answer, + String question) { +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/CreateQaUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/CreateQaUseCase.java new file mode 100644 index 0000000000000000000000000000000000000000..c13d38ba9ef144fbe30957e4441a9942558d5984 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/CreateQaUseCase.java @@ -0,0 +1,11 @@ +package com.example.qa.service.application.port.in; +/* + * @author xuyihua + * @return + */ +import com.example.qa.service.application.command.CreateQaCommand; +import com.example.qa.service.domain.Qa; + +public interface CreateQaUseCase { + Qa createQa(CreateQaCommand QaCommand); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteQaUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteQaUseCase.java new file mode 100644 index 0000000000000000000000000000000000000000..5d28dae31642ec9f1fbb7005e8d0bf359b5f852e --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/DeleteQaUseCase.java @@ -0,0 +1,5 @@ +package com.example.qa.service.application.port.in; + +public interface DeleteQaUseCase { + void deleteQa(Long id); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaByIdUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaByIdUseCase.java new file mode 100644 index 0000000000000000000000000000000000000000..ad231c0664a886cf7a253f26d6241f17eb9b5598 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaByIdUseCase.java @@ -0,0 +1,7 @@ +package com.example.qa.service.application.port.in; + +import com.example.qa.service.domain.Qa; + +public interface GetQaByIdUseCase { + Qa getQaById(Long id); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java new file mode 100644 index 0000000000000000000000000000000000000000..9a0dd8dc37e6a90a179fc31eec0fde6b922a5c96 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/GetQaListUseCase.java @@ -0,0 +1,8 @@ +package com.example.qa.service.application.port.in; + +import com.example.qa.service.domain.Qa; +import java.util.List; + +public interface GetQaListUseCase { + List getQas(); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/UpdateQaUseCase.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/UpdateQaUseCase.java new file mode 100644 index 0000000000000000000000000000000000000000..abf509b323d6dedda4ddaf9b1d10a450844d61ef --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/port/in/UpdateQaUseCase.java @@ -0,0 +1,8 @@ +package com.example.qa.service.application.port.in; + +import com.example.qa.service.application.command.UpdateQaCommand; +import com.example.qa.service.domain.Qa; + +public interface UpdateQaUseCase { + Qa updateQa(UpdateQaCommand command); +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/CreateQarService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/CreateQarService.java new file mode 100644 index 0000000000000000000000000000000000000000..0dd447b8d4b277147a2b5c6b8571ec4384ec6106 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/CreateQarService.java @@ -0,0 +1,30 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.command.CreateQaCommand; +import com.example.qa.service.application.port.in.CreateQaUseCase; + + +import com.example.qa.service.domain.Qa; +import com.example.qa.service.domain.port.CreateQaPort; + +import com.example.qa.service.domain.valueobject.QaAnswer; +import com.example.qa.service.domain.valueobject.QaQuestion; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +@Slf4j +@Service +public class CreateQarService implements CreateQaUseCase { + @Resource + private CreateQaPort createQaPort; + @Override + public Qa createQa(CreateQaCommand createQaCommand) { + //command -> domain + Qa qa=new Qa( + new QaQuestion(createQaCommand.question()), + new QaAnswer(createQaCommand.answer())); + log.info("qa:{}",qa); + return createQaPort.createQa(qa); + } +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteQaService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteQaService.java new file mode 100644 index 0000000000000000000000000000000000000000..d3a9e3d394df885f15614d4389ebbde0853773c6 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/DeleteQaService.java @@ -0,0 +1,16 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.port.in.DeleteQaUseCase; +import com.example.qa.service.domain.port.DeleteQaPort; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; + +@Service +public class DeleteQaService implements DeleteQaUseCase { + @Resource + private DeleteQaPort deleteQaPort; + @Override + public void deleteQa(Long id) { + deleteQaPort.deleteQa(id); + } +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaByIdService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaByIdService.java new file mode 100644 index 0000000000000000000000000000000000000000..27e680addd68ea8c3e0fb7c606051909af57cd5d --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaByIdService.java @@ -0,0 +1,21 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.port.in.GetQaByIdUseCase; + +import com.example.qa.service.domain.Qa; + +import com.example.qa.service.domain.port.GetQaByIdPort; + +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; + +@Service +public class GetQaByIdService implements GetQaByIdUseCase { + + @Resource + private GetQaByIdPort getQaByIdPort; + @Override + public Qa getQaById(Long id) { + return getQaByIdPort.getQaById(id); + } +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java new file mode 100644 index 0000000000000000000000000000000000000000..c32ba31da9d651c0bb655f52697b6eae38da110c --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/GetQaListService.java @@ -0,0 +1,24 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.port.in.GetQaListUseCase; + +import com.example.qa.service.domain.Qa; + +import com.example.qa.service.domain.port.GetQaListPort; + +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class GetQaListService implements GetQaListUseCase { + + @Resource + GetQaListPort getQaListPort; + @Override + public List getQas() { + List qas = Qa.getQas(getQaListPort); + return qas; + } +} diff --git a/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQaService.java b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQaService.java new file mode 100644 index 0000000000000000000000000000000000000000..4c4115dbf108744c155f57a8c62664dcca77ebb2 --- /dev/null +++ b/qa-service/qa-service-application/src/main/java/com/example/qa/service/application/service/UpdateQaService.java @@ -0,0 +1,29 @@ +package com.example.qa.service.application.service; + +import com.example.qa.service.application.command.UpdateQaCommand; +import com.example.qa.service.application.port.in.UpdateQaUseCase; + +import com.example.qa.service.domain.Qa; + +import com.example.qa.service.domain.port.UpdateQaPort; + +import com.example.qa.service.domain.valueobject.QaAnswer; +import com.example.qa.service.domain.valueobject.QaId; +import com.example.qa.service.domain.valueobject.QaQuestion; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; + +@Service +public class UpdateQaService implements UpdateQaUseCase { + @Resource + private UpdateQaPort updateQaPort; + + @Override + public Qa updateQa(UpdateQaCommand command) { + Qa qa = new Qa( + new QaId(command.id()), + new QaQuestion(command.question()), + new QaAnswer(command.answer())); + return updateQaPort.updateQa(qa); + } +} diff --git a/qa-service/qa-service-bootstrap/pom.xml b/qa-service/qa-service-bootstrap/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..70bc6d301790c64b8424215711edd0f19ed950bb --- /dev/null +++ b/qa-service/qa-service-bootstrap/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + + com.example + qa-service + 0.0.1-SNAPSHOT + + + qa-service-bootstrap + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + com.mysql + mysql-connector-j + runtime + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + com.baomidou + mybatis-plus-spring-boot3-starter + + + com.example + qa-adapter-in-web + 0.0.1-SNAPSHOT + + + + com.example + qa-adapter-out-persistence + 0.0.1-SNAPSHOT + + + + + + \ No newline at end of file diff --git a/qa-service/qa-service-bootstrap/src/main/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplication.java b/qa-service/qa-service-bootstrap/src/main/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplication.java new file mode 100644 index 0000000000000000000000000000000000000000..28d2b44ac5367617d8be05146cac2f528395a88a --- /dev/null +++ b/qa-service/qa-service-bootstrap/src/main/java/com/example/qa/service/bootstrap/QaServiceBootstrapApplication.java @@ -0,0 +1,14 @@ +package com.example.qa.service.bootstrap; + + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication(scanBasePackages = "com.example") +@MapperScan("com.example.qa.adapter.out.persistence.mapper") +public class QaServiceBootstrapApplication{ + public static void main(String[] args) { + SpringApplication.run(QaServiceBootstrapApplication.class, args); + } +} \ No newline at end of file diff --git a/qa-service/qa-service-bootstrap/src/main/resources/application.properties b/qa-service/qa-service-bootstrap/src/main/resources/application.properties new file mode 100644 index 0000000000000000000000000000000000000000..ed16249112dcf645e026555daf9385bd1754349d --- /dev/null +++ b/qa-service/qa-service-bootstrap/src/main/resources/application.properties @@ -0,0 +1,27 @@ +server.port=28081 + +spring.application.name=qa-service + + +# Nacos认证信息 +spring.cloud.nacos.discovery.username=nacos +spring.cloud.nacos.discovery.password=nacos +# Nacos 服务发现与注册配置,其中子属性 server-addr 指定 Nacos 服务器主机和端口 +spring.cloud.nacos.discovery.server-addr=192.168.168.128:8848 +# 注册到 nacos 的指定 namespace,默认为 public +spring.cloud.nacos.discovery.namespace=public + +# Nacos帮助文档: https://nacos.io/zh-cn/docs/concepts.html +# Nacos认证信息 +spring.cloud.nacos.config.username=nacos +spring.cloud.nacos.config.password=nacos +spring.cloud.nacos.config.contextPath=/nacos +# 设置配置中心服务端地址 +spring.cloud.nacos.config.server-addr=192.168.168.128:8848 +# Nacos 配置中心的namespace。需要注意,如果使用 public 的 namcespace ,请不要填写这个值,直接留空即可 +# spring.cloud.nacos.config.namespace= +spring.config.import=nacos:${spring.application.name}.properties?refresh=true + + + + diff --git a/qa-service/qa-service-common/pom.xml b/qa-service/qa-service-common/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..4b3c0425a6f3c5db948041da325542c845caa2de --- /dev/null +++ b/qa-service/qa-service-common/pom.xml @@ -0,0 +1,64 @@ + + + 4.0.0 + qa-service-common + 0.0.1-SNAPSHOT + qa-service-common + qa-service-common + + com.example + qa-service + 0.0.1-SNAPSHOT + + + + 21 + 22 + 22 + UTF-8 + UTF-8 + 3.0.2 + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + \ No newline at end of file diff --git a/qa-service/qa-service-common/src/main/java/com/example/qa/service/common/IdWorker.java b/qa-service/qa-service-common/src/main/java/com/example/qa/service/common/IdWorker.java new file mode 100644 index 0000000000000000000000000000000000000000..ff31bfc231c9a3111d0fe30f82626e3a390a8910 --- /dev/null +++ b/qa-service/qa-service-common/src/main/java/com/example/qa/service/common/IdWorker.java @@ -0,0 +1,183 @@ +package com.example.qa.service.common; + +import java.lang.management.ManagementFactory; +import java.net.InetAddress; +import java.net.NetworkInterface; + +//TIP 要运行代码,请按 或 +// 点击装订区域中的 图标。 +public class IdWorker { + /** + * 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动) + */ + private final static long TWEPOCH = 1288834974657L; + + /** + * 机器标识位数 + */ + private final static long WORKER_ID_BITS = 5L; + + /** + * 数据中心标识位数 + */ + private final static long DATA_CENTER_ID_BITS = 5L; + + /** + * 机器ID最大值 + */ + private final static long MAX_WORKER_ID = ~(-1L << WORKER_ID_BITS); + + /** + * 数据中心ID最大值 + */ + private final static long MAX_DATACENTER_ID = ~(-1L << DATA_CENTER_ID_BITS); + + /** + * 毫秒内自增位 + */ + private final static long SEQUENCE_BITS = 12L; + + /** + * 机器ID偏左移12位 + */ + private final static long WORKER_ID_SHIFT = SEQUENCE_BITS; + + /** + * 数据中心ID左移17位 + */ + private final static long DATACENTER_ID_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS; + + /** + * 时间毫秒左移22位 + */ + private final static long TIMESTAMP_LEFT_SHIFT = SEQUENCE_BITS + WORKER_ID_BITS + DATA_CENTER_ID_BITS; + + private final static long SEQUENCE_MASK = ~(-1L << SEQUENCE_BITS); + + /** + * 上次生产id时间戳 + */ + private static long lastTimestamp = -1L; + + /** + * 0,并发控制 + */ + private long sequence = 0L; + + private final long workerId; + + /** + * 数据标识id部分 + */ + private final long datacenterId; + + public IdWorker() { + this.datacenterId = getDatacenterId(); + this.workerId = getMaxWorkerId(datacenterId); + } + + /** + * @param workerId 工作机器ID + * @param datacenterId 序列号 + */ + public IdWorker(long workerId, long datacenterId) { + if (workerId > MAX_WORKER_ID || workerId < 0) { + throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", MAX_WORKER_ID)); + } + if (datacenterId > MAX_DATACENTER_ID || datacenterId < 0) { + throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", MAX_DATACENTER_ID)); + } + this.workerId = workerId; + this.datacenterId = datacenterId; + } + + /** + * 获取下一个ID + * + * @return + */ + public synchronized long nextId() { + long timestamp = timeGen(); + if (timestamp < lastTimestamp) { + throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp)); + } + + if (lastTimestamp == timestamp) { + // 当前毫秒内,则+1 + sequence = (sequence + 1) & SEQUENCE_MASK; + if (sequence == 0) { + // 当前毫秒内计数满了,则等待下一秒 + timestamp = tilNextMillis(lastTimestamp); + } + } else { + sequence = 0L; + } + lastTimestamp = timestamp; + // ID偏移组合生成最终的ID,并返回ID + + return ((timestamp - TWEPOCH) << TIMESTAMP_LEFT_SHIFT) + | (datacenterId << DATACENTER_ID_SHIFT) + | (workerId << WORKER_ID_SHIFT) | sequence; + } + + private long tilNextMillis(final long lastTimestamp) { + long timestamp = this.timeGen(); + while (timestamp <= lastTimestamp) { + timestamp = this.timeGen(); + } + return timestamp; + } + + private long timeGen() { + return System.currentTimeMillis(); + } + + /** + *

+ * 获取 MAX_WORKER_ID + *

+ */ + protected static long getMaxWorkerId(long datacenterId) { + StringBuilder mpid = new StringBuilder(); + mpid.append(datacenterId); + String name = ManagementFactory.getRuntimeMXBean().getName(); + if (!name.isEmpty()) { + /* + * GET jvmPid + */ + mpid.append(name.split("@")[0]); + } + /* + * MAC + PID 的 hashcode 获取16个低位 + */ + return (mpid.toString().hashCode() & 0xffff) % (IdWorker.MAX_WORKER_ID + 1); + } + + /** + *

+ * 数据标识id部分 + *

+ */ + protected static long getDatacenterId() { + long id = 0L; + try { + InetAddress ip = InetAddress.getLocalHost(); + NetworkInterface network = NetworkInterface.getByInetAddress(ip); + if (network == null) { + id = 1L; + } else { + byte[] mac = network.getHardwareAddress(); + id = ((0x000000FF & (long) mac[mac.length - 1]) + | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6; + id = id % (IdWorker.MAX_DATACENTER_ID + 1); + } + } catch (Exception e) { + System.out.println(" getDatacenterId: " + e.getMessage()); + } + return id; + } + + + + +} \ No newline at end of file diff --git a/qa-service/qa-service-domain/pom.xml b/qa-service/qa-service-domain/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..a561c5ec49651a814240624e8b0e399d547efd40 --- /dev/null +++ b/qa-service/qa-service-domain/pom.xml @@ -0,0 +1,57 @@ + + + 4.0.0 + com.example + qa-service-domain + 0.0.1-SNAPSHOT + qa-service-domain + qa-service-domain + + + com.example + qa-service + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + provided + + + + com.example + qa-service-common + 0.0.1-SNAPSHOT + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 21 + 21 + UTF-8 + + + + + + + diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java new file mode 100644 index 0000000000000000000000000000000000000000..1072f4dd959b43a3a662f2c9197117d1cb002288 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/Qa.java @@ -0,0 +1,49 @@ +package com.example.qa.service.domain; + +import com.example.qa.service.common.IdWorker; +import com.example.qa.service.domain.port.GetQaListPort; +import com.example.qa.service.domain.valueobject.QaQuestion; +import com.example.qa.service.domain.valueobject.QaId; +import com.example.qa.service.domain.valueobject.QaAnswer; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; + +/* + * @Author brokenpoems + * @Description + * @Date 22:10 2025/9/10 + **/ +@Setter +@Getter +@ToString +public class Qa { + private QaId id; + private QaQuestion question; + private QaAnswer answer; + + public Qa() { + } + + public Qa(QaId id, QaQuestion question, QaAnswer answer) { + this.id = id; + this.question = question; + this.answer = answer; + } + + public Qa( QaQuestion question, QaAnswer answer) { + this.id= genId() ; + this.question = question; + this.answer = answer; + } + + public static List getQas(GetQaListPort getQaListPort){ + return getQaListPort.getQas(); + } + + public QaId genId(){ + return new QaId(new IdWorker().nextId()); + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateQaPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateQaPort.java new file mode 100644 index 0000000000000000000000000000000000000000..bd2a2a02acc476482081efc06ae36fb750cde1d3 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/CreateQaPort.java @@ -0,0 +1,12 @@ +package com.example.qa.service.domain.port; + +import com.example.qa.service.domain.Qa; + +/* + * @Author brokenpoems + * @Description + * @Date 20:05 2025/9/10 + **/ +public interface CreateQaPort { + Qa createQa(Qa qa); +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteQaPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteQaPort.java new file mode 100644 index 0000000000000000000000000000000000000000..cd4ee52d9efd413b2a2d55270e0d519dc11a1234 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/DeleteQaPort.java @@ -0,0 +1,10 @@ +package com.example.qa.service.domain.port; + +/* + * @Author brokenpoems + * @Description + * @Date 20:06 2025/9/10 + **/ +public interface DeleteQaPort { + void deleteQa(Long id); +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaByIdPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaByIdPort.java new file mode 100644 index 0000000000000000000000000000000000000000..c5faac7dfb661f7fcfdd2fbcf6d42943ed5ef97c --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaByIdPort.java @@ -0,0 +1,12 @@ +package com.example.qa.service.domain.port; + +import com.example.qa.service.domain.Qa; + +/* + * @Author brokenpoems + * @Description + * @Date 20:06 2025/9/10 + **/ +public interface GetQaByIdPort { + Qa getQaById(Long id); +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaListPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaListPort.java new file mode 100644 index 0000000000000000000000000000000000000000..b798e78974b30411f1a16c75bd6881223fe02e97 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/GetQaListPort.java @@ -0,0 +1,14 @@ +package com.example.qa.service.domain.port; + +import com.example.qa.service.domain.Qa; + +import java.util.List; + +/* + * @Author brokenpoems + * @Description + * @Date 20:06 2025/9/10 + **/ +public interface GetQaListPort { + List getQas(); +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/UpdateQaPort.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/UpdateQaPort.java new file mode 100644 index 0000000000000000000000000000000000000000..42018e7d67b16124462d7cbd1d2884ac7165f864 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/port/UpdateQaPort.java @@ -0,0 +1,12 @@ +package com.example.qa.service.domain.port; + +import com.example.qa.service.domain.Qa; + +/* + * @Author brokenpoems + * @Description + * @Date 20:06 2025/9/10 + **/ +public interface UpdateQaPort { + Qa updateQa(Qa qa); +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaAnswer.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaAnswer.java new file mode 100644 index 0000000000000000000000000000000000000000..a6b4b86a09cd3550b2c8553a547da9030c8d58e0 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaAnswer.java @@ -0,0 +1,7 @@ +package com.example.qa.service.domain.valueobject; + +public record QaAnswer(String answer) { + public String getValue() { + return answer; + } +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaId.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaId.java new file mode 100644 index 0000000000000000000000000000000000000000..ea201ec9c04293b15114f7e82a6a58d6521f1274 --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaId.java @@ -0,0 +1,9 @@ +package com.example.qa.service.domain.valueobject; + +public record QaId(long id) { + + public long getValue(){ + return id; + } + +} diff --git a/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaQuestion.java b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaQuestion.java new file mode 100644 index 0000000000000000000000000000000000000000..fbae4ac346e8b2a4d5f72d785d84039a27a7315c --- /dev/null +++ b/qa-service/qa-service-domain/src/main/java/com/example/qa/service/domain/valueobject/QaQuestion.java @@ -0,0 +1,7 @@ +package com.example.qa.service.domain.valueobject; + +public record QaQuestion(String question) { + public String getValue() { + return question; + } +} diff --git a/user-service/user-service-bootstrap/src/main/resources/application.properties b/user-service/user-service-bootstrap/src/main/resources/application.properties index e07349119b451d5eb0e5e8ed5e458e646d9eaf6d..cd28c710f717c21a4ca0208490ac2bb8b3d27f5c 100644 --- a/user-service/user-service-bootstrap/src/main/resources/application.properties +++ b/user-service/user-service-bootstrap/src/main/resources/application.properties @@ -17,7 +17,7 @@ spring.cloud.nacos.config.username=nacos spring.cloud.nacos.config.password=nacos spring.cloud.nacos.config.contextPath=/nacos # 设置配置中心服务端地址 -spring.cloud.nacos.config.server-addr=192.168.168.128::8848 +spring.cloud.nacos.config.server-addr=192.168.168.128:8848 # Nacos 配置中心的namespace。需要注意,如果使用 public 的 namcespace ,请不要填写这个值,直接留空即可 # spring.cloud.nacos.config.namespace= spring.config.import=nacos:${spring.application.name}.properties?refresh=true