Skip to main content

Bookmark service (MongoDB & Spring REST)

Completed a working version of Bookmark service. Feeling great~~ ha! ha! Finding something to practice is an efficient way of learning. The project concept is redesigned from a MongoDB project. Weeks ago, I was learning MongoDB and NodeJS. Mixing everything together is my hobby. There might be conflictions, but putting all strengths together has higher potential to resolve difficult and complex problems. Elites getting together might sometimes not be easy, I mean technology, of course. Nice things deserve practice. 

https://www.mongodb.com/blog/post/building-your-first-application-mongodb-creating-rest-api-using-mean-stack-part-1
 
After redesign…… is ….extremely simple…. But contains enough new topics for me to explore. I’m just a starter of Spring (and a veteran of OO and Cloud programming). Keep everything simple and fast. 
image host

 
I applied to cloud services (like AWS), online artist supporting platform (like Patreon), delivery service (like foodpanda),  bioinformatics (so curious…),  education (like D2L), etc. …. Don’t know why no further response…. Anyway, I focus on what I can do to prove myself. When I’m an IT, I probably would avoid IT topics. If my current part-time work depletes my strength, I may need to hide in a hospital (just kidding). An IT usually has habits of sharing. We grow up upon others sharing, and just do the same vice versa. (I'll change this when my status is different.)
 
Other than IT, my expertise are analyzing and learning. My sharing is usually not to show my skills, but to guide the progress. Since starting from C socket to Spring REST takes me 10 days, it’s no point to estimate my current capability or predict how far I can go in the next half year. Here shows how I started a topic and proceeded to working status. To be expert at any IT skill needs practice. And I constantly go astray and mix together all I know are my way of practice. Maybe I’m learning WordPress or Bootstrap. Maybe I’m learning NodeJS or MongoDB. Maybe I’m learning Flask or Python. Maybe… I like multiphase~
 
https://spring.io/guides/tutorials/rest/
 
Spring’s REST tutorial is a good reference for this bookmark project. I only read half to complete the working version. Of course with a lot of research. The previous MongoDB is too simple so I lost my previous concept of Spring MVC. Combined with Baeldung’s explain on annotation, path variables, and parameters, and endless debugging…… It’s really helpful.
 
https://www.baeldung.com/spring-request-param
 
Bookmark service was designed as 3 layers, but I would pause at 2 layers, because when I master the structure of the 1st layer, the second layer is almost copy-past….
 
Spring provides two types of database access. One is Database-client, the other is Repository.  I already knew how to use databases, so I tried Repository. The default output looks pretty(previous MongoDB sample) and attractive. …..but when Spring hands out the data to me….. Understandable is good enough….. 
 
https://docs.spring.io/spring-data/mongodb/docs/3.0.0.RELEASE/reference/html/#mongodb.repositories.queries

 
Bookmark service is using Page to handle a list of URL(string) as the first layer. And use Bookmark to collect Pages as the second layer. From MongoDB example, it shows how to use Spring provided CURD commands to directly access class properties. 
What I need in Page is to access property as a list.  @RequestBody analyses class structure. It’s convenient. Correctly writing the json list is a valid way to create class data. 
 
https://github.com/atfuture7/awsrepo/tree/master/java/04_mongoBookmark/
 
To modify a list requires customized functionality. I don’t want to write the entire list each time when adding/deleting one string. Here came a terrible divorce (just kidding). Spring doesn’t introduce my extended interface. I have to write my own controllers and show not-pretty-at-all results. 
 
If you don’t want anything mysterious to happen to you, follow the naming convention…
<class name>Repository  (for repository interface)
<class name>Repository + Custom (for extended interface)
<class name>Repository + Impl (the implementation of extended interface…)
 
Spring keeps one instance in the factory (what visible is assigned to Controller), so the variable in Repository should be denoted as @Autowire for linking. If you forget @Autoware and declare the object somewhere else, service won’t start and it will probably be difficult to find where the problem is…. I fixed linking error on PageRepositoryImpl and lost my version due to Git revert while adding Bookmk layer. And the linking error then appeared at BookmkRepositoryImpl …. 
 
This post is long enough for now. The progress of Page development is better as:
Page 
-> PageRepository 
-> PageController 
-> PageRepositoryCustom 
-> PageRepositoryImpl 
(->PageNotFoundException 
-> PageNotFoundAdvice ) (or ignore while can’t figure out how pageNotFoundHandler jumps out …. Naming convention? ) 
 
(to be continue…)

Comments

Popular posts from this blog

Bookmark service (MongoDB & Spring REST) -2/2

    I accidentally deleted my development VM. I got lucky having the habit of taking notes. This blog is useful. Development VM is doom to be lost. Rebuild it waste time, but having a clean slate is refreshing~. What concerns me more is my AWS free quota this month is reaching 85%. The second VM I launched but never being used might be the one to blame. (Of course, my mistake.) I terminated the wrong VM. Now I got Linux 2 built. Great, just threw away everything happened on AMI.  1st layer: Page Page class   Originally, I need to prepare getter/setter for all class properties for Spring. By using lombok, I only need to create constructors. lombok will deal with getter/setter and toString(). But there are chances to call getter/setter, but how? .......Naming convention.... Capitalize the 1st character with the prefix get/set.  Annotation @Data was used on this class.  Repository class Spring Docs: Repository https://docs.spring.io/spring-data/mongodb/docs/3.0.0.RELEASE/reference/html/#m

Comments for my Server/Client Web API samples

        Finally, I finished the comments for python/07 and 09 projects. I almost forgot to put the date on source code which is used to note how long it took me. Not precisely in hours….. I didn’t include source code in my previous post. If choosing code-section for this post…… maybe I want to mark out my comment….. (Really?!)          Once my work was developing websites for enterprises, including ERP, CRM or content sites. The sustainability of network and security are important issues. There are 2 methods for HTML Form submission: GET and POST. Submit via POST is secure, compared to GET which piles parameters on URL. RESTful API is mainly using GET.         Yup, even if you have a certification key, if you put the value on the URL, it is visible data. When writing socket-communication, client-server sockets are a pair; both follow the agreement on commands and structures; and there are countless ports for usage. Plain text on the message of socket communication usually wouldn’t be

Built LAMP on AWS AMI, and update/install Python3.6, pip v20, Apache wsgi and Flask

I got one half day free and I spent it on building a LAMP on AWS AMI. I also wanted to squeeze Flask into Apache. So I also install/update Python 3.6, pip V.20.1, Apache wsgi and Flask. I wrapped up progress for now before I forgot all resources.    On AWS marketplace, everyone can pay for a good suit such as Django. I’m not interested in content creation unless there are interesting topics to resolve. I don’t know what left to do if I bought a solution; and I may get annoyed like everyone else if the solution causes more problems. To build on my own is more realistic and practical. Installing a LAMP (Linux, Apache, MySQL, PHP) was smooth while following AWS tutorial. Tutorial: Install a LAMP Web Server with the Amazon Linux AMI https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/install-LAMP.html To build Flask is absolutely a different thing….  still failed before I fell asleep... If I choose AWS EC2 Ubuntu instance, most tutorials are based on this Linux version. Unfortunately I oft